Skip to content

Add annotations proposal implementation#322

Open
MaxDesiatov wants to merge 1 commit into
mainfrom
maxd/annotations-support
Open

Add annotations proposal implementation#322
MaxDesiatov wants to merge 1 commit into
mainfrom
maxd/annotations-support

Conversation

@MaxDesiatov

@MaxDesiatov MaxDesiatov commented Mar 3, 2026

Copy link
Copy Markdown
Member

wasm-tools print includes custom annotations on certain Wasm components, which WasmKit is currently unable to read.

Annotations proposal enables usage of custom sections and names in WAT that weren't previously expressible as WAT ids or strings. See proposal overview for more details.

Base automatically changed from maxd/fix-name-section to main March 10, 2026 21:27
@MaxDesiatov MaxDesiatov force-pushed the maxd/annotations-support branch 2 times, most recently from 34d122b to abf4c6c Compare March 16, 2026 18:50
@MaxDesiatov MaxDesiatov marked this pull request as ready for review March 16, 2026 18:52

@kateinoigakukun kateinoigakukun 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.

I feel like this change is too vibey 😞

Comment thread Vendor/dependencies.json Outdated
Comment on lines +2 to +12
"spec": {
"repository": "https://github.com/WebAssembly/spec.git",
"revision": "1c9a04e7b9d6998b9a30c6edf40b42d4c2a13c7b",
"categories": ["spec"]
},
"annotations": {
"repository": "https://github.com/WebAssembly/annotations.git",
"revision": "20a8e4f125d5d856aac392105c35055af9ed49f7",
"sparse-checkout": "test/custom",
"categories": ["default"]
},

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.

Do we need those repositories as dependencies?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Only these repositories have relevant WAST tests for the proposal. We could use a sparse checkout to pull in just the few WAST files if you prefer that?

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.

Ok, the root problem here is that those wast files are not included in testsuite repository. I've submitted a fix now WebAssembly/testsuite#155

Also do we still need spec repository?

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.

The testsuite PR has been merged

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unfortunately, the PR has been merged post Wasm-3.0 additions, which merged all proposals into the main test suite directory, which means we can't easily exclude GC tests directory wholesale if we bump to the commit where this PR is merged.

I'm vendoring the new tests for now.

}

static func wastFiles(include: [String] = [], exclude: [String] = ["annotations.wast"]) -> [URL] {
static func wastFiles(include: [String] = [], exclude: [String] = ["id.wast"]) -> [URL] {

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.

Why do we need to add id.wast as a new excluded test case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

id.wast needed to be excluded because this function runs against WABT/WasmTools baseline, and neither of those support this WAST file, it's tested separately in func annotationProposalSpectest(), and that also has an explanation comment

emitCustomSections(placement: .after(.import), encoder: &encoder)

// Section 3: Function section
emitCustomSections(placement: .before(.func), encoder: &encoder)

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.

It's very error-prune to enforce inserting emitCustomSections before/after each section manually. Can we make it as a part of Encoder.section?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense, done.

Comment thread Sources/WAT/Lexer.swift Outdated
let range: Range<Lexer.Index>
let kind: TokenKind
/// For quoted identifiers ($"..."), the decoded string bytes (not including the `$` prefix).
let quotedIdBytes: [UInt8]?

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.

Why do we need to hold it here? Can't we simply interpret it in Parser?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, that's cleaned up.

Comment thread Sources/WAT/Lexer.swift Outdated
}

/// Recognized annotation IDs that the parser needs to handle.
private static let recognizedAnnotations: Set<String> = ["name", "custom"]

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.

I don't think Lexer needs to know about them. We can treat all custom section annotation items as opaque in Lexer, and parse known custom sections in Parser when needed. We can remove skipAnnotationBody.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's addressed on the Parser level now.

@MaxDesiatov MaxDesiatov force-pushed the maxd/annotations-support branch 2 times, most recently from fe6353b to 37d96ee Compare June 4, 2026 17:32
@MaxDesiatov MaxDesiatov force-pushed the maxd/annotations-support branch from 37d96ee to fe0f8de Compare June 4, 2026 18:18
# Conflicts:
#	README.md
#	Sources/WAT/BinaryEncoding/Encoder.swift
@MaxDesiatov MaxDesiatov force-pushed the maxd/annotations-support branch from 5e5dd36 to 920bca2 Compare June 18, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants