Repository navigation
Reject handles in the value types of maps - #2791
Merged
Merged
Conversation
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`.
alexcrichton
approved these changes
Oct 23, 2026
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.
This implements the rule from WebAssembly/component-model#756 (proposed in WebAssembly/component-model#751): the value type of a
mapcan't transitively contain anown,borrow,future,streamorerror-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)AbiInfouses its previously unused bit 31 to record whether a type transitively contains a handle.own,borrow,future,streamanderror-contextset it, and records, variants, lists, maps and fixed-length lists inherit it from their fields, cases or elements, the same way as the existingborrowbit.(map K V)fails with "map value type cannot contain a handle" whenVhas the bit set. Keys can't contain handles already.mapwith handles in its values still parses. Components using it fail validation.Tests (
tests/cli/component-model/map.wast)option,record,list,tuple,variantand anothermap, including in an imported function's parameter.streamorfuture.cm-error-contextfor theerror-contextcase.