Skip to content

Commit ddf2bbf

Browse files
committed
fix(ledger): restore the #833 soundness row; run utf8 fit on the interpreter
Follow-up to #843 (squash 220d6f1), which left the soundness-ledger gate red on main (property 3, anchor content drift): - tools/soundness-anchors.sha256 carried the test/test_interp_eval.ml anchor, but the #833 row that cites it was lost from docs/SOUNDNESS.adoc when the PR's conflict with #829 was resolved; - the manifest also held a second, stale digest for test/test_intrinsic_shadow.ml (already the case at ff3f08d). The #833 row is restored unchanged, the stamp advances from 84eca60 to 220d6f1 (lib/interp.ml moved in #829 and #843), and the manifest is resealed. Now that #829 has merged: its "stdlib utf8 fit" case (code_points_within_octets, self-recursive) was Bun-ESM only because the interpreter could not run self-recursion. It now also runs on the interpreter. The test's unquoting of interpreter output is removed, since println writes the string itself. The Bun-only note in stdlib/utf8.affine and the support table and findings in docs/UNICODE-STRINGS.adoc are updated; the char_at finding now records its root cause. Refs #833 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDgaiMn26BfqukYvBwf
1 parent 464f7c6 commit ddf2bbf

5 files changed

Lines changed: 40 additions & 23 deletions

File tree

‎docs/SOUNDNESS.adoc‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Freshness stamp — a real main-ancestor commit (survives squash-merge); advance
55
// it (and --reseal) in any change that touches a soundness path. See "Keeping
66
// this honest" and tools/check-soundness-ledger.sh (property 4).
7-
:ground-truth-sha: 84eca60
7+
:ground-truth-sha: 220d6f1
88
:ground-truth-date: 2026-12-01
99
:stamp-verified-by: tools/check-soundness-ledger.sh
1010
:toc: macro
@@ -311,6 +311,26 @@ write into the literal region. Layout invariant:
311311
`test_wasm_heap_literals_intact_after_alloc` — run under Bun's WASI;
312312
`test_wasm_heap_exhaustion_traps`); `lib/codegen.ml`
313313
`memory_layout_of_datas` / `check_memory_layout`
314+
315+
| #833
316+
| The tree-walking interpreter — the oracle the compiled backends are compared
317+
against — runs the programs the checker accepts and agrees with Bun-ESM on
318+
them. It used to refuse a function that calls itself, one that calls a later
319+
declaration, any `let mut` / `const mut` assignment, and any use of an
320+
imported `Some` / `None` / `Ok` / `Err` (all loud). One shape was *silent*: an
321+
early `return` evaluated its operand and carried on, so
322+
`if c { return 1; } 2` yielded `2`. (The assignment arm also ignored a
323+
compound operator — `a += 5` would have stored `5` — which a
324+
`let mut` program could not reach, because the assignment failed first.) `affinescript eval` also type-checked
325+
with its own fold of `Typecheck.check_decl`, without the signature
326+
pre-registration of `Typecheck.check_program`, so it rejected forward and
327+
mutual references that `check` and `compile` accept; it now calls
328+
`check_program`. Not changed: `eval` still does not run the borrow checker
329+
(`check` and `compile` do), so it accepts programs they reject.
330+
| `fixed`
331+
| `test/test_interp_eval.ml` (18 cases: each program passes the full frontend,
332+
then its interpreter output is compared with the expected lines and with the
333+
Bun-ESM output of the same program; all 18 fail on `4248912`).
314334
|===
315335

316336
== Still open — read before claiming "sound"

‎docs/UNICODE-STRINGS.adoc‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Which backend runs which part:
129129

130130
| the three primitives | yes | yes | yes | yes
131131
| `utf8_width`, `code_point_count`, `code_point_slice` | yes | yes | no (the backend has no `len`) | no (stdlib modules do not link)
132-
| `code_points_within_octets` | no (self-recursion, see Findings) | yes | no | no
132+
| `code_points_within_octets` | yes (since #833) | yes | no | no
133133
|===
134134

135135
=== Ill-formed input fails loudly
@@ -234,22 +234,25 @@ memory access`; the interpreter prints all 60. This is silent memory
234234
corruption before the trap. Proposed fix: start the heap after the last data
235235
segment (`align(next_string_offset, 8)`). `test/test_unicode_octets.ml` keeps
236236
its success path allocation-free so that it tests the primitives, not this.
237-
. *`affinescript eval` cannot run a self-recursive top-level function.* In
237+
. *`affinescript eval` cannot run a self-recursive top-level function. Fixed by #843 (#833).* In
238238
`lib/interp.ml`, `TopFn` builds the closure with `cl_env = env` *before*
239239
binding the function's own name, so
240240
`fn g(x: Int) -> Int { if x <= 0 { 0 } else { g(x - 1) + 2 } }` fails with
241241
`Unbound variable: g`. Bun ESM gives `6` for `g(3)`.
242-
. *`affinescript eval` rejects mutable locals.* `let mut k = 0; while k < 3 {
242+
. *`affinescript eval` rejects mutable locals. Fixed by #843 (#833).* `let mut k = 0; while k < 3 {
243243
k = k + 1; }` fails with `Type mismatch: Expected mutable reference`, in
244244
`main` or in any function.
245-
. *`string::char_at` fails under `affinescript eval`* with `Unbound variable:
246-
Some`, even with `use prelude::{Option, Some, None}` in the caller. The root
247-
cause is not established.
245+
. *`string::char_at` fails under `affinescript eval`. Fixed by #843 (#833).* It failed with
246+
`Unbound variable: Some`, even with `use prelude::{Option, Some, None}` in the
247+
caller. Root cause: the flattener does not carry the prelude's `Option` /
248+
`Result`, because the compiled backends' preamble defines `Some` / `None` /
249+
`Ok` / `Err`, and the interpreter had no preamble. It now binds the four.
248250
. *The plain-JS backend lowers no string builtins* (`len`, `int_to_string`,
249251
`string_sub`, …): each is a `ReferenceError` at run time, not a compile-time
250252
refusal. It now lowers the three primitives above.
251-
. *The interpreter's `println` shows a `String` as an escaped OCaml literal*
252-
(`"\195\169"`, with quotes), while the other backends print the text.
253+
. *The interpreter's `println` shows a `String` as an escaped OCaml literal.
254+
Fixed by #843 (#833).* It printed `"\195\169"`, with quotes, while the other
255+
backends print the text; it now prints the text.
253256
. *Core wasm ignored a user function that shadows an intrinsic. Fixed by #841
254257
(#836).* With `fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }`, a call
255258
`string_sub("x", 0, 1)` printed `7` on the interpreter and Bun ESM, but a heap

‎stdlib/utf8.affine‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
// Backends: the three primitives are lowered on the interpreter, Bun-ESM,
3333
// plain JS and core wasm. The functions below are AffineScript, so they run
3434
// wherever a backend can link a stdlib module and supports `len`/`slice` on
35-
// arrays: utf8_width, code_point_count and code_point_slice run on the
36-
// interpreter and Bun-ESM today. code_points_within_octets runs on Bun-ESM
37-
// only: its helper is self-recursive, and the interpreter cannot yet run a
38-
// self-recursive top-level fn (docs/UNICODE-STRINGS.adoc, "Findings").
35+
// arrays: the interpreter and Bun-ESM today. (code_points_within_octets has a
36+
// self-recursive helper, which the interpreter could not run before #833.)
3937

4038
// ============================================================================
4139
// Per-code-point octet width

‎test/test_unicode_octets.ml‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,12 @@ let exec b ~name src =
100100
let out = Filename.concat workdir (name ^ ".wasm") in
101101
Result.map (fun () -> run ("bun run " ^ q out)) (compile out "")
102102

103-
(* The interpreter's println shows a String as an OCaml-quoted literal; the
104-
labels are ASCII, so stripping the quotes recovers the line. *)
103+
(* The printed lines. Every backend, the interpreter included (since #833),
104+
prints a String as its characters, so no line is unquoted here. *)
105105
let lines s =
106106
String.split_on_char '\n' s
107107
|> List.map String.trim
108108
|> List.filter (fun l -> l <> "")
109-
|> List.map (fun l ->
110-
let n = String.length l in
111-
if n >= 2 && l.[0] = '"' && l.[n - 1] = '"' then String.sub l 1 (n - 2) else l)
112109

113110
let skip b what =
114111
Printf.printf "SKIP [%s] %s: host runtime not on PATH\n%!" (backend_name b) what
@@ -218,9 +215,9 @@ let stdlib_labels =
218215
[ "width_1"; "width_2"; "width_2_top"; "width_3"; "width_3_top"; "width_4";
219216
"count"; "slice_mid"; "slice_astral"; "slice_clamped"; "slice_empty" ]
220217

221-
(* code_points_within_octets recurses; the tree-walking interpreter cannot
222-
yet run a self-recursive top-level fn (docs/UNICODE-STRINGS.adoc,
223-
"Findings"), so this runs on Bun-ESM only. *)
218+
(* code_points_within_octets recurses. The tree-walking interpreter could not
219+
run a self-recursive top-level fn until #833, so this used to run on
220+
Bun-ESM only; it now runs on the interpreter as well. *)
224221
let fit_program = {|use utf8::{code_points_within_octets, code_point_slice};
225222
|} ^ check_fn ^ Printf.sprintf {|
226223
pub fn main() -> () {
@@ -299,6 +296,6 @@ let tests =
299296
`Quick (expect_loud_failure b ~name src)) bs)
300297
failing_programs
301298
@ List.map (fun b -> per b "stdlib utf8" stdlib_program stdlib_labels) [ Interp; Bun_esm ]
302-
@ [ per Bun_esm "stdlib utf8 fit" fit_program fit_labels ]
299+
@ List.map (fun b -> per b "stdlib utf8 fit" fit_program fit_labels) [ Interp; Bun_esm ]
303300
@ List.map (fun b -> per b "user definitions shadow the intrinsics" shadow_program shadow_labels)
304301
[ Interp; Bun_esm; Js; Wasm ]

‎tools/soundness-anchors.sha256‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
20e73d88738c8fd075f81a36803554f92fa4ee53f71e33fa6759eae07c6e70f4 suite:test/test_intrinsic_shadow.ml
1010
2bbd1b989fd0097530eede3e5230258e0e1092271a23ff7dff20cca65c0e612e suite:test/test_wasm_call_resolution.ml
1111
2dfe36a21983a7dfb7ffa1157f7ddec9865a531a92682976b8fd677e4825e78d test:test_801_impl_methods_refused
12-
3b74c20f201d0d53c2fbab5582a681d3dfc3cf978a0aea676ecc6400087452d9 suite:test/test_intrinsic_shadow.ml
1312
45eb0f3aa5f643afbd003248998dd5a046688418647b491e0f2d4bb55fcbd0f2 test:test_wasm_heap_exhaustion_traps
1413
546939eaa3c64c82edd23da0a3ba7f74bcf7378cfe1e426132dd1a9f8fd46050 test:test_801_transitive_public_and_const
1514
5b84a4f71aa65f9aa9383e31c0cb624291c4f9d0de7cca4a0ea6a76fe85aea35 fixture:test/e2e/fixtures/handle_resume_nontail.affine

0 commit comments

Comments
 (0)