Skip to content

Ensure that inline (data)s and (elem)s count toward identifiers - #2242

Open
bvisness wants to merge 1 commit into
WebAssembly:mainfrom
bvisness:data-elem-ids
Open

Ensure that inline (data)s and (elem)s count toward identifiers#2242
bvisness wants to merge 1 commit into
WebAssembly:mainfrom
bvisness:data-elem-ids

Conversation

@bvisness

@bvisness bvisness commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The (memory (data ...)) and (table (elem ...)) abbreviations were not correctly counting the indices of the data and elem segments, causing the identifiers' indices on later data and elem segments to be off by one. Because the identifier context needs to be updated as we parse, memory_fields and table_fields are updated to do some of their work in the first pass.

The (memory (data ...)) and (table (elem ...)) syntax sugar was not
correctly counting the indices of the data and elem segments, causing
the identifiers' indices on later data and elem segments to be off by one.
Because the identifier context needs to be updated as we parse,
memory_fields and table_fields are updated to do some of their work in
the first pass.

@rossberg rossberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, thanks! That must have been a pain to debug, since this code is a mess.

Comment on lines -1119 to -1121
{ fun c x loc -> [Memory ($1 c) @@ loc], [], [], [] }
{ fun c -> fun x loc -> [Memory ($1 c) @@ loc], [], [], [] }
| inline_import memorytype /* Sugar */
{ fun c x loc ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: these changes are redundant, since the old version is sugar for the new.

Comment on lines +1196 to +1201
{ fun c -> fun x loc -> [Table ($1 c, $2 c) @@ loc], [], [], [] }
| tabletype /* Sugar */
{ fun c x loc -> let TableT (_, _, (_, ht)) as tt = $1 c in
{ fun c -> fun x loc -> let TableT (_, _, (_, ht)) as tt = $1 c in
[Table (tt, [RefNull ht @@ loc] @@ loc) @@ loc], [], [], [] }
| inline_import tabletype /* Sugar */
{ fun c x loc ->
{ fun c -> fun x loc ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

@redianthus

Copy link
Copy Markdown
Contributor

I feel like having a test for this would be a nice addition, would you be willing to add one @bvisness?

@bvisness

bvisness commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

I went back and forth on including tests because they are very fiddly, identifier-specific, and...where would they go? Do we have a place for "regression tests" of sorts? I'm happy to add one, it's just so niche that I struggled with it.

@rossberg

rossberg commented Sep 3, 2026

Copy link
Copy Markdown
Member

I think elem.wast and data.wast would be natural places. They aren't really regression tests (nor do I see a need to distinguish those in the test suite).

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.

3 participants