Commit 3ff5eae
feat(verify): scaffold typed-wasm-verify Rust crate (C1)
Adds a new Cargo workspace at the repo root with one member:
`crates/typed-wasm-verify`. The crate is the Rust home for typed-wasm's
post-codegen L7 (aliasing) + L10 (linearity) verifier. This commit lands
the scaffolding only — public types, error enums, and stubbed entry
points. Real implementations come in follow-ups C2/C3/C4.
Why a Rust crate here?
----------------------
- The ReScript parser/checker in `src/parser/*.res` is on the way out
(ReScript ban across hyperpolymath repos), so the canonical
surface-level checker will be Rust. Starting with the post-codegen
verifier — a self-contained piece that operates on emitted wasm
rather than on `.twasm` source — lets the port begin without first
needing a `.twasm` parser.
- Downstream consumers want a Rust dependency: ephapax (already Rust)
to call into directly via a Cargo path/git dep, and affinescript
(OCaml) to invoke as a subprocess until full FFI lands.
Spec of record
--------------
Both modules are direct ports of:
- hyperpolymath/affinescript:lib/tw_verify.ml (~246 LOC OCaml)
- hyperpolymath/affinescript:lib/tw_interface.ml (~245 LOC OCaml)
Until the cross-compat suite (C5) is green, those OCaml files remain
authoritative.
Public surface (this commit)
----------------------------
- `OwnershipKind` — 4-variant enum with `from_byte` decoder matching the
OCaml fallback semantics (anything outside 0..=3 → Unrestricted).
- `OwnershipError` — 4 variants for intra-function violations
(LinearNotUsed / LinearDroppedOnSomePath / LinearUsedMultiple /
ExclBorrowAliased), each carrying `func_idx` + `param_idx` and a
`thiserror`-derived Display matching the OCaml `pp_error` output.
- `CrossError` — 2 variants for cross-module boundary violations
(LinearImportCalledMultiple / LinearImportDroppedOnSomePath) carrying
`caller_func_idx`, `import_func_idx`, `import_name`.
- `FuncInterface` — exported-function signature carrying its ownership
kinds, mirroring `Tw_interface.func_interface`.
- `VerifyError` — top-level error type covering wasmparser failures plus
the two violation vectors.
- `OWNERSHIP_SECTION_NAME` — the `affinescript.ownership` custom-section
name constant.
- Three stubbed entry points (`verify_from_module`, `extract_exports`,
`verify_cross_module`) — all `todo!()` until C2/C3/C4 land. Signatures
are pinned now so consumers can already start writing call sites.
Dependencies
------------
- wasmparser 0.221 — for module/instruction walking in C3/C4
- thiserror 2 — error-enum derive
- wasm-encoder 0.221 (dev) — for synthesising test fixtures in C2/C3
Build status
------------
$ cargo build -p typed-wasm-verify
Finished `dev` profile [unoptimized + debuginfo] target(s)
$ cargo test -p typed-wasm-verify
running 1 test
test tests::ownership_kind_byte_roundtrip ... ok
test result: ok. 1 passed; 0 failed; 0 ignored
Follow-up tasks
---------------
C2 (#37) — wire the `affinescript.ownership` custom-section parser
(u32le count + per-entry header)
C3 (#38) — port `tw_verify.count_uses_range` over wasmparser ops and
implement the per-fn / per-module verifier proper
C4 (#39) — port `tw_interface.{extract_exports, verify_cross_module}`
C5 (#40) — cross-compat test against affinescript-emitted modules
C6 (#41) — ephapax-wasm emits the custom section
C7 (#42) — ephapax-cli gets `--verify-ownership`
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 5456b1e commit 3ff5eae
5 files changed
Lines changed: 399 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
0 commit comments