wasm-gc: tuple elements keep generic payload types; Char.toCode returns Unicode scalars#504
Merged
Merged
Conversation
…ns Unicode scalars Two backend fixes plus a type-checker fix they surfaced: - A tuple literal in a driven position (declared return, annotated binding, verify expectation) now adopts the expected Tuple<...> type element-wise, so generic constructors in tuple slots - (Option.None, n), (Result.Ok(2), Result.Ok(0)) - keep their concrete payload types instead of reaching the wasm-gc lowerer as Option<T> / Result<Int,E>. The same change fixes a false type error on (Result.Ok(n), n) against a declared Tuple<Result<Int,String>, Int>. - Char.toCode on wasm-gc decodes the first UTF-8 scalar instead of returning the first byte, so multi-byte characters match the VM and roundtrip through Char.fromCode. Lowering moved from an inline MIR arm to a demand-driven helper; modules that never call it are unchanged byte-for-byte. - Independent products keep their element validation: the expected-type path deliberately excludes (...)! so a non-call element is still rejected at check time (pinned by new type-checker tests). Known residuals stay documented: a hand-written == between such tuples outside a verify block, and reading back compound Option values from Vector<Option<T>> in verify diagnostics. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes the two wasm-gc residuals documented in the 0.25.0 changelog, plus a type-checker bug the repro matrix surfaced.
What was broken
Tuple<Option<Int>, Int>with anOption.Nonebranch failed to compile on wasm-gc withcannot lower type `Option<T>` to a wasm representation— theNoneliteral nested in a tuple element never inherited the concrete payload type. Same for tuples holdingResult(verifyexpectations like(Result.Ok(2), Result.Ok(0))). VM ran both fine.Char.toCodeon wasm-gc returned the first UTF-8 byte instead of the Unicode scalar:'ż'gave 197 instead of 380,'😀'gave 240 instead of 128512. ASCII masked the bug.(Result.Ok(n), n)against a declaredTuple<Result<Int,String>, Int>was a false type error even on the VM.The fix
Tuple<...>element-wise — the same bidirectional context list elements already receive. Side effect, now documented in the changelog: an element that doesn't fit the annotation is rejected at check time instead of failing at run time.Char.toCodelowers through a demand-driven helper that decodes the first UTF-8 scalar (2/3/4-byte lead masks per spec). Modules that never call it are byte-identical to before.(...)!products, so their "element must be a function call" validation still fires — pinned by new type-checker tests (this was caught in adversarial review of the first version of this change).Verification
(f(), g())!), byte-reproducibilitycmp3×, zero drift on untouched modules (order_total.wasmbyte-identical), test honesty revert-checked (new tests fail without the source fix).==between such tuples outside verify — stays a documented residual rather than a speculative fix.cargo test --workspace --features wasm,wasip2(80 suites), fmt, clippy: green. wasip2 smoke compile withChar.toCode: green.🤖 Generated with Claude Code