Skip to content

Read @name annotations on functions and tags - #496

Merged
kateinoigakukun merged 2 commits into
mainfrom
name-annot
Oct 4, 2026
Merged

kateinoigakukun merged 2 commits into
mainfrom
name-annot

Conversation

@kateinoigakukun

Copy link
Copy Markdown
Member

custom/name_annot.wast now runs with no skipped directives. The WAT parser accepts (@name "...") on functions and tags, both defined and imported, and the name section uses it instead of the $id. Tag names (name subsection 11) are now written too, so the encoder tests compare the whole name section with wasm-tools again.

What's included

Tag names in the name section

The encoder didn't write the tag name subsection, so a tag's $id was lost. The encoder tests were dropping subsection 11 from wasm-tools' output to hide this. The encoder now writes it like the other name maps, and the comparison no longer filters it out. This is its own commit.

The name maps now hold names without the $, so a name can also come from an annotation. A small nameMapEntries helper replaces the seven copies of the same compactMap.

@name on functions and tags

The parser took @name only on a module, so a function or tag with one failed to parse. It's now taken directly after the optional $id of a func or tag field, and of a function or tag import, as the spec's name annotation appendix places it. As with module names, an annotation takes precedence over the $id in the name section.

A misplaced or second annotation is still rejected as an unexpected token.

Testing

  • swift test --traits FileSystem,MultiThread,Disassembler,ComponentModel --filter "WATTests|Spectest" passes. name_annot.wast passes under both threading models.
  • Tests/WasmKitTests/ExtraSuite/annotations/name.wast now covers functions and tags: defined, imported and exported, with and without a $id, and three malformed placements. The encoder tests check its name section byte-for-byte against wasm-tools.
    • wasm-tools rejects @name on a tag import, though the spec allows it. That module is written as (module quote ...), so the engine parses and links it but the encoder tests don't compare it.

Not included

  • @name on parameters, locals, types and struct fields, which the spec also allows. No spec test uses them yet.
  • Reading tag names back in NameSectionParser. It still skips subsection 11.

The encoder wrote no tag name subsection (id 11), so a tag's `$id` was
lost, and the encoder tests had to drop that subsection from wasm-tools'
output before comparing. Write it like the other name maps, and compare
the whole name section with wasm-tools again.

The name maps now hold names without the `$`, so that a name can also come
from somewhere other than a `$id`.
The parser took `(@name "...")` only on a module, so a function or tag
carrying one failed to parse, and custom/name_annot.wast skipped the two
modules that use them. Take it after the `$id` of a function or tag,
defined or imported, as the spec's name annotation appendix places it.
The name section prefers it over the `$id`, as it already does for the
module name.

Parameters, locals, types and fields can carry one too, but no spec test
uses them yet.
@kateinoigakukun
kateinoigakukun merged commit 09d340b into main Oct 4, 2026
19 checks passed
@kateinoigakukun
kateinoigakukun deleted the name-annot branch October 4, 2026 15:34
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.

1 participant