feat(codegen): complete .twasm front-end for the example corpus (2/6 → 6/6)#167
Merged
Conversation
…-> 6/6) Extends the v0 front-end + codegen so all six canonical examples parse, emit valid wasm, and round-trip through the verifier (Phase 1 / #130): - parser: ptr<T>/unique<T>/ref<T> field pointers (03); optional/unnamed fn params + &mut/&/own region<T> borrow params (05, 06); general annotation-clause skip (cost_bound { ... } etc., 05); import region X from "..." {...}|; with quoted module source (06, 02); invariant { ... } region constraint blocks (02). - codegen: typed result stubs — Op::{I64Const,F32Const,F64Const} + mappings, so representative bodies type-check against f32/i64/f64 result types (03). - tests: parsed_example_corpus_round_trips round-trips all six examples (the #130 soundness gate over real .twasm, not just paint-type/example-01). Still v0 (type-correct representative bodies, not full region.get/set lowering; the six canonical examples, not arbitrary .twasm). 31/31 codegen tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The error path in expect() sliced self.src[pos..pos+20], panicking with an out-of-bounds (or non-UTF-8-boundary) slice when a parse error occurred near end-of-input. peek_word() had the same self.src[start..] hazard. A malformed .twasm must be a clean Err diagnostic, never a crash. - expect/peek_word now use self.src.get(..) and a length-clamped error window. - regression test parser_never_panics_on_malformed_input feeds char-boundary truncations of all six examples + adversarial fragments (unbalanced delimiters, UTF-8, partial type forms); previously 6 inputs panicked, now 0. 32/32 codegen tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Extends the v0
.twasmfront-end + codegen so all six canonical examples parse, emit valid wasm, and round-trip through the verifier — the #130 round-trip soundness corpus over real.twasm(not just paint-type/example-01). Takes the corpus from 2/6 → 6/6.Parser
ptr<T>/unique<T>/ref<T>field pointers → 03&mut/&/own region<T>borrow params → 05, 06cost_bound { … }, etc.) → 05import region X from "…" { … }/;with quoted module source → 06, 02invariant { … }region constraint blocks → 02Codegen
Op::{I64Const,F32Const,F64Const}+ instruction mappings, so representative bodies type-check againstf32/i64/f64result types → 03 (verify)Tests
parsed_example_corpus_round_tripsround-trips all six examples (build → emit →verify_from_module+ access-sites). 31/31 codegen tests pass.Honest scope
Still v0: type-correct representative bodies (no
region.get/set/alloclowering yet), and the six canonical examples (not arbitrary.twasm). Full body-lowering + general schemas are the next climb; this PR locks in + CI-enforces the front-end breadth at the v0 level.🤖 Generated with Claude Code