wasm-wave: parse wit ItemNames as UntypedFuncCall names#2530
Merged
Conversation
6b1f805 to
3697b12
Compare
alexcrichton
approved these changes
May 27, 2026
3697b12 to
ae1f90a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #2529
Prior to this PR, wasm-wave defined a complete grammar for values, and additionally it provided a
UntypedFuncCall::parseparser, which extends the grammar to include function calls.UntypedFuncCallwas not described in the ebnf grammar, but instead is just tacked on as a special entrypoint to the ParserParser::parse_raw_func_call. In short, the implementation was "a label, followed by parenthesis, which are empty or contain a tuple value".The parenthesis and values are unambigiously the right choice for the syntax, but representing the function name as a single label is limiting: functions can exist anonymously (in no package, and in no interface), at the root of a package (in a package but not in an interface), or inside a package's interface. The parser gave us no way to parse or represent these cases, and it led to problems in implementations where a bare label might be ambigious, for example in the implementation of
wasmtime run --invoke, which is the use case that led us to move wasm-wave into wasm-tools and take a dependency on wasmtime in the first case.So, drawing on the work to define a parser in wit-parser for
ItemName(which accepts strings likenamespace:packagename/interface.funcname@0.1.0), which is capable of representing all of the above cases unambiguously, this PR reworks theUntypedFuncCallparser to be able to parse those cases as well.The new parser is no longer a special entrypoint for
Parserbut instead a standalone functionparse_raw_func_callin the same module. It re-uses theParsermachinery for parsing all wave values, but for the parsing the function name portion of the parse, it actually uses a totally separatelogos::Lexerthat accepts anItemName-shaped string using a single regex. This approach was required because adding anItemName-shaped token to the lexer conflicts with the parser which already accept a sequence of label, colon, label productions in several real cases, e.g. the record{a:none}would get rejected at the}for expecting a token/since the lexer would try to consume it as a package namespace and name.Because wit-parser is an optional dependency on wasm-wave, finally parsing the
UntypedFuncCall's name into aItemNameis done with an accessor method instead of in the parsing stage. Users who don't want to depend on wasm-wave can still consume the parsed function name as a&str, but don't get any help parsing it into a structure, in order to prevent duplicated code and the possibility of a confused deputy. (The alternative to this is making use of the entireuntypedmod always depend onwit-parser, which seemed like it was too heavyweight for this particular case.)