Skip to content

Reject handles in the value types of maps - #2791

Merged
fitzgen merged 1 commit into
bytecodealliance:mainfrom
jrandolf:map-value-handles
Oct 23, 2026
Merged

fitzgen merged 1 commit into
bytecodealliance:mainfrom
jrandolf:map-value-handles

Conversation

@jrandolf

Copy link
Copy Markdown
Contributor

This implements the rule from WebAssembly/component-model#756 (proposed in WebAssembly/component-model#751): the value type of a map can't transitively contain an own, borrow, future, stream or error-context. Bindings that keep only the last value of a duplicate key would otherwise have to dispose of the handles in the values they drop (bytecodealliance/wasmtime#14812).

Types already record whether they contain a borrow, for function results. This adds a bit next to it for any handle, and map validation checks it on the value type.

LLM summary of the changes

Validation (validator/component_types.rs, validator/component.rs)

  • AbiInfo uses its previously unused bit 31 to record whether a type transitively contains a handle. own, borrow, future, stream and error-context set it, and records, variants, lists, maps and fixed-length lists inherit it from their fields, cases or elements, the same way as the existing borrow bit.
  • Validating (map K V) fails with "map value type cannot contain a handle" when V has the bit set. Keys can't contain handles already.
  • wit-parser isn't changed, so a WIT map with handles in its values still parses. Components using it fail validation.

Tests (tests/cli/component-model/map.wast)

  • Handles in map values are rejected directly and when nested in option, record, list, tuple, variant and another map, including in an imported function's parameter.
  • Maps can still be the payload of a stream or future.
  • The test enables cm-error-context for the error-context case.

This implements the validation rule proposed in
WebAssembly/component-model#756: a `map`'s value type can't transitively
contain an `own`, `borrow`, `future`, `stream` or `error-context`.
@jrandolf
jrandolf requested a review from a team as a code owner October 23, 2026 21:00
@jrandolf
jrandolf requested review from fitzgen and removed request for a team October 23, 2026 21:00

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

LGTM, thanks

@fitzgen
fitzgen added this pull request to the merge queue Oct 23, 2026
Merged via the queue into bytecodealliance:main with commit 2e6b2d6 Oct 23, 2026
37 checks passed
@jrandolf
jrandolf deleted the map-value-handles branch October 23, 2026 22:00
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