Skip to content

Parser: block literals and __block variables#971

Open
dotcarmen wants to merge 17 commits into
Vexu:masterfrom
dotcarmen:dotcarmen/block-literals
Open

Parser: block literals and __block variables#971
dotcarmen wants to merge 17 commits into
Vexu:masterfrom
dotcarmen:dotcarmen/block-literals

Conversation

@dotcarmen

@dotcarmen dotcarmen commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

blocked on/ part 2 of #969, wip towards closing #825

This PR implements parsing of block literals according to the language extension specification by Clang. Caveat: while the spec document specifies that the parameter list may only be omitted when the return type is omitted, Clang actually compiles programs that omit the return type but not the parameter list (excuse the linker error). The behavior here matches that behavior

Additionally, this change makes no attempt to track __block variable references within block bodies, since that's not necessary for the parse to complete, and that extra information would not be used anywhere yet. in the future, when implementing lowering support for blocks, this information tracking can be added

@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 2 times, most recently from f0b3a01 to 4a15846 Compare February 27, 2026 01:06
@dotcarmen
dotcarmen marked this pull request as ready for review February 27, 2026 01:27
@dotcarmen

This comment was marked as resolved.

@dotcarmen

This comment was marked as outdated.

@dotcarmen
dotcarmen marked this pull request as draft February 27, 2026 02:14
@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 10 times, most recently from a82f534 to 51c20b7 Compare February 28, 2026 15:54
@dotcarmen
dotcarmen marked this pull request as ready for review February 28, 2026 15:54
@dotcarmen

dotcarmen commented Feb 28, 2026

Copy link
Copy Markdown
Contributor Author

i just realized aro doesn't support lowering to aarch64-macos - since macos is currently the only platform that works for testing blocks, i think this is enough to mark Blocks support as "completed" with the caveat that blocks don't get lowered, and an additional ticket should be opened for lowering literals and calls.

@dotcarmen dotcarmen mentioned this pull request Feb 28, 2026
12 tasks
@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 2 times, most recently from 22a3bdb to 201fca6 Compare March 4, 2026 14:42
@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch from 201fca6 to a66ae0c Compare March 18, 2026 00:55
@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 2 times, most recently from a295122 to 4f224ce Compare March 25, 2026 22:08
dotcarmen

This comment was marked as outdated.

@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 4 times, most recently from 73b3cad to c9e93a3 Compare March 28, 2026 12:33
@dotcarmen

Copy link
Copy Markdown
Contributor Author

^ still working on addressing review comments

@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 2 times, most recently from 34e3c24 to 538b1e1 Compare July 10, 2026 00:52
@dotcarmen
dotcarmen requested a review from Vexu July 10, 2026 01:04
Comment thread src/aro/Attribute/Map.zig Outdated
Comment thread src/aro/features.zig Outdated
Comment thread test/cases/block literals.c Outdated
Comment thread src/aro/Parser.zig Outdated
Comment thread src/aro/Parser.zig Outdated
.keyword_forceinline,
.keyword_forceinline2,
=> {
try p.err(bad_attr_tok_i, .block_does_not_allow_specifier, .{"function specifier"});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this warning in 2750279. You'll probably want to inline typeNameExtra here to handle decl attributes in the type properly:

int (^a)(int) = ^int __attribute__((const)) (int a){
    return a;
};

@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 2 times, most recently from 907f240 to 6a78430 Compare July 10, 2026 22:21
@dotcarmen dotcarmen changed the title feat: parser-level support for block literals and __block variables Parser: block literals and __block variables Jul 16, 2026
use repr.data directly for the token in attr map

undo marking implicit return with implicit-true operand
@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch 4 times, most recently from bef07be to fccb197 Compare July 19, 2026 22:35
@dotcarmen
dotcarmen force-pushed the dotcarmen/block-literals branch from fccb197 to 9f8271f Compare July 19, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants