Skip to content

Comments

wit-parser: Add spans to function parameters#2445

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
wilfreddenton:wit-parser-function-param-spans
Feb 9, 2026
Merged

wit-parser: Add spans to function parameters#2445
alexcrichton merged 1 commit intobytecodealliance:mainfrom
wilfreddenton:wit-parser-function-param-spans

Conversation

@wilfreddenton
Copy link
Contributor

#2418

Another follow-up to #2419. This introduces a Param struct to replace (String, Type) in Function.params, adding a Span field that tracks where each parameter name appears in the source WIT file.

Changes

  • wit-parser: Add a public Param struct with name, ty, and span fields. The span is captured from the parameter name's Id::span during AST resolution. The span field is skipped during serialization, preserving the existing JSON format.
  • wit-component: Add a ParamSignatures newtype in encoding/types.rs that wraps &[Param] with custom Hash/PartialEq implementations comparing only name and ty, ignoring span. This is needed because FunctionKey uses these traits to deduplicate component function types. Without it, two functions with identical signatures but different source locations would produce separate type entries in the encoded component. An alternative would be to have FunctionKey use &[Param] directly and then add the custom impls directly to it.
  • wasm-wave, wit-dylib, wit-encoder: Update param construction and iteration to use the new Param struct.

Tests

  • param_spans_point_to_names: Verifies that resolved param spans point exactly to the parameter names in source text.
  • param_spans_preserved_through_merge: Verifies that param spans remain valid (is_known()) after merging two Resolve instances.

@wilfreddenton wilfreddenton requested a review from a team as a code owner February 8, 2026 15:00
@wilfreddenton wilfreddenton requested review from fitzgen and removed request for a team February 8, 2026 15:00
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks!

@alexcrichton alexcrichton added this pull request to the merge queue Feb 9, 2026
Merged via the queue into bytecodealliance:main with commit 6afe0a3 Feb 9, 2026
35 checks passed
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