Skip to content

feat(producer): third typedwasm.ownership producer in Zig — the language-agnosticism proof#200

Merged
hyperpolymath merged 2 commits into
mainfrom
feat/zig-third-producer
Jul 7, 2026
Merged

feat(producer): third typedwasm.ownership producer in Zig — the language-agnosticism proof#200
hyperpolymath merged 2 commits into
mainfrom
feat/zig-third-producer

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Increment 3 of 3 on the independence construction path.

A compile target is only language-agnostic if a toolchain with no shared code can participate. This lands that proof: ffi/zig/src/twasm_producer.zig hand-assembles a core wasm module byte-by-byte (no wasm-encoder, no typed-wasm-verify encoders, no sibling-compiler code) and attaches typedwasm.ownership per the documented wire format. typed-wasm-verify then:

  • accepts the honest module (Linear param consumed exactly once),
  • reads its carrier identically to a first-party one (extract_exportsconsume: [Linear] → Unrestricted),
  • rejects the double-consume mutant (LinearUsedMultiple — a wasm-level double-free).

Fixtures are committed under crates/typed-wasm-verify/tests/fixtures/zig_producer/ with a provenance README (capture 2026-07-07, zig 0.15.2; zig build gen-fixtures regenerates; generator determinism is test-asserted) — the same pattern as the c5_real AffineScript corpus. The Zig generator's own 4 tests are wired into zig build test.

170 workspace tests, 0 failures; zig build test green.

🤖 Generated with Claude Code

hyperpolymath and others added 2 commits July 7, 2026 05:53
…ccess + skip_declaration bug fix

Takes example 03/04 system bodies from representative stubs to REAL
typed loads/stores with pinned access sites, executed correctly in a
real engine.

- parser: general statement lowerer (tried after the exact reader/
  writer shapes; bails to the stub on anything unsupported). Covers
  `let [mut] x: ty = expr`, assignment, `if`/`else`, `while` (block/
  loop/br_if), `return [expr]`, indexed `region.get/set $h[i] .f`
  (base + i*stride), `cast<i32|f32|f64>`, typed expression lowering
  with precedence (cmp > add > mul > primary) and no implicit
  promotion. Each region param is copied to a base local ONCE in the
  prologue so own/&mut discipline holds under per-path use counting
  regardless of how many accesses follow.
- IR: Op gains locals/control-flow/arithmetic/conversion instructions;
  Func gains `locals` (emitted via Function::new_with_locals_types).
- REAL BUG FIX: skip_declaration skipped a balanced `{...}` block and
  then KEPT SCANNING for a `;` — so example-04's top-level
  `invariant ... { ... }` blocks swallowed every following declaration:
  ex04's functions were never parsed at all (its "6/6 corpus
  round-trip" was regions-only). Now returns after a block-shaped
  declaration; ex04 parses 4 functions, 3 lower for real.
- tests/example04.rs: real-lowering assertions for ex03/ex04 bodies
  (pinned sites), all-verifier-passes gate (validate + L7/L10 + L2
  bounds + L2 access-typing), and a wasmi execution gate proving
  while/if-else/indexed/cast lowering COMPUTES correct results
  (sum-abs + f32-scale over a cell array).

Workspace: 166 tests, 0 failures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…age-agnosticism proof

typed-wasm's claim is "independent compile target", not "companion
library of two sibling languages". This lands the proof: a producer
sharing NO ancestry with AffineScript (OCaml), Ephapax (Rust), or the
in-tree Rust codegen — ffi/zig/src/twasm_producer.zig hand-assembles a
core wasm module byte-by-byte and attaches the typedwasm.ownership
section per the documented wire format.

- Zig generator: buildModule(allocator, double_use) emits
  consume(x: Linear i32) using its param once (honest) or twice (a
  wasm-level double-free). Deterministic (test-asserted); 4 Zig tests
  wired into `zig build test`; `zig build gen-fixtures` regenerates the
  committed fixtures.
- Fixtures committed under
  crates/typed-wasm-verify/tests/fixtures/zig_producer/ (74/77 bytes,
  provenance README, capture 2026-07-07 zig 0.15.2) — same pattern as
  the c5_real AffineScript corpus.
- tests/third_producer_zig.rs: the Zig bytes validate as wasm, the
  honest module PASSES L7/L10, extract_exports reads the carrier
  exactly as a first-party one (consume: [Linear] -> Unrestricted),
  and the double-use mutant is REJECTED (LinearUsedMultiple).

Workspace: 170 tests, 0 failures; zig build test green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hyperpolymath
hyperpolymath merged commit a0f50ac into main Jul 7, 2026
24 checks passed
@hyperpolymath
hyperpolymath deleted the feat/zig-third-producer branch July 7, 2026 04:57
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

1 participant