Skip to content

Commit 55af7bb

Browse files
docs(adr): ADR-0008 — typed-wasm-verify + Idris2 VerifierSpec are the spec of record (#202)
Item 4 of the construction sequence (owner: "4 do that"). Flips the wire-level verifier's spec-of-record from AffineScript's OCaml files to this repo, on the grounds the repo itself set: the C5 parity criterion is met (synthetic table + real AffineScript-emitted fixtures, both green) — and the Rust crate now implements behaviour the OCaml reference never had (L13 both forms, L2/L15 carriers, link-graph certification, third-producer conformance). - **Spec of record**: `VerifierSpec.idr` (+ `MultiModule.idr`) as the formal statement, `typed-wasm-verify` as the executable reference. - OCaml `tw_verify.ml`/`tw_interface.ml` demoted to conforming implementation; presumed wrong on divergence; parity suites retained as regression armour. - AffineScript's Track B (adopting this crate as its verifier) retires the OCaml files entirely, on AffineScript's schedule. - Companion to ADR-0006: with the parser (front-end axis) and now the verifier (semantics axis) both canonical in-tree, no structural dependency on a sibling repo remains. Docs-only; no code change. The three passages still deferring to the OCaml files (verify README, lib.rs header comment, LEVEL-STATUS trust table) are updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent cc0d9cc commit 55af7bb

4 files changed

Lines changed: 110 additions & 14 deletions

File tree

LEVEL-STATUS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ this crate re-checks them on the emitted IR to catch codegen bugs.
129129
| Source checker | Source program respects discipline | `hyperpolymath/affinescript:lib/codegen.ml` (QTT pass), upcoming `.twasm` parser/checker |
130130
| **Post-codegen verifier** | **Emitted wasm respects discipline** | **`crates/typed-wasm-verify/` (Rust)** + `hyperpolymath/affinescript:lib/{tw_verify,tw_interface}.ml` (OCaml, reference impl) |
131131

132-
The Rust crate is a faithful port of the OCaml reference; the OCaml
133-
files remain the spec of record. The synthetic-fixture cross-compat
132+
The Rust crate + Idris2 `VerifierSpec.idr` are the **spec of record**
133+
(ADR-0008, 2026-07-07); the OCaml files are a conforming
134+
implementation. The synthetic-fixture cross-compat
134135
suite at `crates/typed-wasm-verify/tests/cross_compat.rs` is the
135136
parity oracle; **C5.1** (`tests/cross_compat_real.rs`, landed
136137
2026-05-27 via PR #81) cross-checks it against real

crates/typed-wasm-verify/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ for each entry:
2424

2525
## Spec of record
2626

27-
This crate is a Rust port of `hyperpolymath/affinescript`:
28-
29-
- `lib/tw_verify.ml` — intra-function verifier (~246 LOC OCaml)
30-
- `lib/tw_interface.ml` — cross-module boundary verifier (~245 LOC OCaml)
31-
32-
The OCaml files remain the spec of record until behavioural parity is established by the cross-compat test suite (workspace task C5).
27+
**This crate + the Idris2 `VerifierSpec.idr` ARE the spec of record** (ADR-0008, 2026-07-07). The crate began as a Rust port of `hyperpolymath/affinescript`'s `lib/tw_verify.ml` / `lib/tw_interface.ml`; the parity criterion those files were pinned behind (workspace task C5) was met by `tests/cross_compat.rs` (synthetic table) + `tests/cross_compat_real.rs` (real producer bytes), and the crate has since grown past the OCaml reference (L13 both forms, L2/L15 carriers, link-graph certification, third-producer conformance). The OCaml files are a conforming implementation; on divergence, they are presumed wrong unless `src/abi/TypedWasm/ABI/VerifierSpec.idr` says otherwise.
3328

3429
## Consumers
3530

crates/typed-wasm-verify/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// section, then runs per-path min/max use-range analysis on every
99
// function body in the module.
1010
//
11-
// Rust port of hyperpolymath/affinescript:
12-
// - lib/tw_verify.ml (intra-function verifier, ~246 lines OCaml)
13-
// - lib/tw_interface.ml (cross-module boundary verifier, ~245 lines OCaml)
14-
//
15-
// The OCaml files are the spec of record until this crate reaches
16-
// behavioural parity (tracked by C5 in the workspace task list).
11+
// SPEC OF RECORD (ADR-0008): this crate, with the formal statement in
12+
// src/abi/TypedWasm/ABI/VerifierSpec.idr (+ MultiModule.idr for the
13+
// cross-module layer). Historically a Rust port of affinescript's
14+
// lib/tw_verify.ml / lib/tw_interface.ml — those OCaml files are now a
15+
// conforming implementation, pinned by the cross_compat parity suites.
1716

1817
use thiserror::Error;
1918

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
= Architecture Decision Record: 0008-verifier-spec-of-record
2+
<!-- SPDX-License-Identifier: CC-BY-SA-4.0 -->
3+
<!-- Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> -->
4+
5+
# 8. `typed-wasm-verify` + the Idris2 `VerifierSpec` are the spec of record
6+
7+
Date: 2026-07-07
8+
9+
## Status
10+
11+
Accepted
12+
13+
Owner direction (2026-07-07 session, independence construction path,
14+
item 4): flip the wire-level verifier's spec-of-record from
15+
AffineScript's OCaml files to this repository. Companion to
16+
link:0006-rust-frontend-canonical.adoc[ADR-0006] (which made the
17+
in-tree Rust parser the canonical front-end); this ADR removes the last
18+
structural dependency on a sibling repository.
19+
20+
## Context
21+
22+
`crates/typed-wasm-verify` began as a Rust port of
23+
`hyperpolymath/affinescript`'s `lib/tw_verify.ml` (intra-function
24+
L7/L10) and `lib/tw_interface.ml` (cross-module boundary). The port's
25+
own README pinned the handover criterion:
26+
27+
> The OCaml files remain the spec of record until behavioural parity is
28+
> established by the cross-compat test suite (workspace task C5).
29+
30+
That criterion is met, and exceeded:
31+
32+
* **C5 synthetic parity** — `tests/cross_compat.rs` (10 tests): a
33+
hand-built fixture table exercising both verifiers' semantics
34+
(accept + reject cases, intra- and cross-module), green.
35+
* **C5.1 real-producer parity**`tests/cross_compat_real.rs`
36+
(5 tests) against real AffineScript-emitted bytes
37+
(`tests/fixtures/c5_real/`, capture pinned to affinescript
38+
`21edc159`), green.
39+
* Since the criterion was written, the Rust crate has grown **past**
40+
the OCaml reference: L13 negative-form isolation (PR #37), carrier
41+
passes for L2/L15 (`unstable-l2`/`unstable-l15`), L13 positive-form
42+
region imports + link-graph certification
43+
(link:0007-region-imports-carrier.adoc[ADR-0007]), access-typing,
44+
and third-producer conformance (`tests/third_producer_zig.rs`). The
45+
OCaml files cannot serve as spec of record for behaviour they do not
46+
implement.
47+
* The formal side already lives here:
48+
`src/abi/TypedWasm/ABI/VerifierSpec.idr` (total, no escape hatches)
49+
states what the verifier must decide; `MultiModule.idr` grounds the
50+
cross-module certificates.
51+
52+
## Decision
53+
54+
1. **Spec of record for wire-level verification is this repository**:
55+
the Idris2 `VerifierSpec.idr` (and `MultiModule.idr` for the
56+
cross-module layer) as the formal statement, and
57+
`crates/typed-wasm-verify` as the executable reference.
58+
2. **AffineScript's `lib/tw_verify.ml` / `lib/tw_interface.ml` are
59+
demoted to a conforming implementation** (and historical origin).
60+
On any behavioural divergence, the OCaml side is presumed wrong
61+
unless the Idris2 spec says otherwise; fixes flow AffineScript-ward.
62+
3. **The parity suites remain as regression armour**, not as a
63+
pending criterion: `cross_compat.rs` / `cross_compat_real.rs` keep
64+
pinning the shared semantics so the demoted implementation cannot
65+
silently drift while it remains in use.
66+
4. AffineScript's eventual adoption of `typed-wasm-verify` as its
67+
verifier (its Track B, queued for its v1.0) retires the OCaml files
68+
entirely; that is AffineScript's call to schedule.
69+
70+
## Consequences
71+
72+
### Positive
73+
74+
- typed-wasm's verification semantics are defined, proven, implemented,
75+
and tested in one repository — the compile-target independence
76+
property, completed on the verifier axis.
77+
- New carriers (ADR-0007 and the coming L8/L9 proposals) have exactly
78+
one place to specify behaviour; no cross-repo spec drift is possible.
79+
80+
### Negative
81+
82+
- The OCaml implementation persists in AffineScript until its Track B
83+
lands; until then two implementations exist and the parity suites are
84+
load-bearing (they already run in CI here).
85+
86+
### Neutral
87+
88+
- No wire-format change; no producer is affected.
89+
90+
## Cross-references
91+
92+
* link:0006-rust-frontend-canonical.adoc[ADR-0006] — front-end
93+
canonicalisation (the sibling decision on the parser axis)
94+
* link:0007-region-imports-carrier.adoc[ADR-0007] — first carrier
95+
specified wholly under the new regime
96+
* `src/abi/TypedWasm/ABI/VerifierSpec.idr`, `MultiModule.idr` — the
97+
formal spec layer
98+
* `crates/typed-wasm-verify/tests/cross_compat.rs`,
99+
`tests/cross_compat_real.rs` — the met parity criterion
100+
* `crates/typed-wasm-verify/tests/third_producer_zig.rs` — producer
101+
neutrality under the new regime

0 commit comments

Comments
 (0)