diff --git a/docs/SOUNDNESS.adoc b/docs/SOUNDNESS.adoc index 21bccb16..e8e4c10a 100644 --- a/docs/SOUNDNESS.adoc +++ b/docs/SOUNDNESS.adoc @@ -4,7 +4,7 @@ // Freshness stamp — a real main-ancestor commit (survives squash-merge); advance // it (and --reseal) in any change that touches a soundness path. See "Keeping // this honest" and tools/check-soundness-ledger.sh (property 4). -:ground-truth-sha: 84eca60 +:ground-truth-sha: 220d6f1 :ground-truth-date: 2026-12-01 :stamp-verified-by: tools/check-soundness-ledger.sh :toc: macro @@ -311,6 +311,26 @@ write into the literal region. Layout invariant: `test_wasm_heap_literals_intact_after_alloc` — run under Bun's WASI; `test_wasm_heap_exhaustion_traps`); `lib/codegen.ml` `memory_layout_of_datas` / `check_memory_layout` + +| #833 +| The tree-walking interpreter — the oracle the compiled backends are compared +against — runs the programs the checker accepts and agrees with Bun-ESM on +them. It used to refuse a function that calls itself, one that calls a later +declaration, any `let mut` / `const mut` assignment, and any use of an +imported `Some` / `None` / `Ok` / `Err` (all loud). One shape was *silent*: an +early `return` evaluated its operand and carried on, so +`if c { return 1; } 2` yielded `2`. (The assignment arm also ignored a +compound operator — `a += 5` would have stored `5` — which a +`let mut` program could not reach, because the assignment failed first.) `affinescript eval` also type-checked +with its own fold of `Typecheck.check_decl`, without the signature +pre-registration of `Typecheck.check_program`, so it rejected forward and +mutual references that `check` and `compile` accept; it now calls +`check_program`. Not changed: `eval` still does not run the borrow checker +(`check` and `compile` do), so it accepts programs they reject. +| `fixed` +| `test/test_interp_eval.ml` (18 cases: each program passes the full frontend, +then its interpreter output is compared with the expected lines and with the +Bun-ESM output of the same program; all 18 fail on `4248912`). |=== == Still open — read before claiming "sound" diff --git a/docs/UNICODE-STRINGS.adoc b/docs/UNICODE-STRINGS.adoc index 365b559a..94f37283 100644 --- a/docs/UNICODE-STRINGS.adoc +++ b/docs/UNICODE-STRINGS.adoc @@ -129,7 +129,7 @@ Which backend runs which part: | the three primitives | yes | yes | yes | yes | `utf8_width`, `code_point_count`, `code_point_slice` | yes | yes | no (the backend has no `len`) | no (stdlib modules do not link) -| `code_points_within_octets` | no (self-recursion, see Findings) | yes | no | no +| `code_points_within_octets` | yes (since #833) | yes | no | no |=== === Ill-formed input fails loudly @@ -234,22 +234,25 @@ memory access`; the interpreter prints all 60. This is silent memory corruption before the trap. Proposed fix: start the heap after the last data segment (`align(next_string_offset, 8)`). `test/test_unicode_octets.ml` keeps its success path allocation-free so that it tests the primitives, not this. -. *`affinescript eval` cannot run a self-recursive top-level function.* In +. *`affinescript eval` cannot run a self-recursive top-level function. Fixed by #843 (#833).* In `lib/interp.ml`, `TopFn` builds the closure with `cl_env = env` *before* binding the function's own name, so `fn g(x: Int) -> Int { if x <= 0 { 0 } else { g(x - 1) + 2 } }` fails with `Unbound variable: g`. Bun ESM gives `6` for `g(3)`. -. *`affinescript eval` rejects mutable locals.* `let mut k = 0; while k < 3 { +. *`affinescript eval` rejects mutable locals. Fixed by #843 (#833).* `let mut k = 0; while k < 3 { k = k + 1; }` fails with `Type mismatch: Expected mutable reference`, in `main` or in any function. -. *`string::char_at` fails under `affinescript eval`* with `Unbound variable: -Some`, even with `use prelude::{Option, Some, None}` in the caller. The root -cause is not established. +. *`string::char_at` fails under `affinescript eval`. Fixed by #843 (#833).* It failed with +`Unbound variable: Some`, even with `use prelude::{Option, Some, None}` in the +caller. Root cause: the flattener does not carry the prelude's `Option` / +`Result`, because the compiled backends' preamble defines `Some` / `None` / +`Ok` / `Err`, and the interpreter had no preamble. It now binds the four. . *The plain-JS backend lowers no string builtins* (`len`, `int_to_string`, `string_sub`, …): each is a `ReferenceError` at run time, not a compile-time refusal. It now lowers the three primitives above. -. *The interpreter's `println` shows a `String` as an escaped OCaml literal* -(`"\195\169"`, with quotes), while the other backends print the text. +. *The interpreter's `println` shows a `String` as an escaped OCaml literal. +Fixed by #843 (#833).* It printed `"\195\169"`, with quotes, while the other +backends print the text; it now prints the text. . *Core wasm ignored a user function that shadows an intrinsic. Fixed by #841 (#836).* With `fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }`, a call `string_sub("x", 0, 1)` printed `7` on the interpreter and Bun ESM, but a heap diff --git a/stdlib/utf8.affine b/stdlib/utf8.affine index dbfc1e71..8317bc4a 100644 --- a/stdlib/utf8.affine +++ b/stdlib/utf8.affine @@ -32,10 +32,8 @@ // Backends: the three primitives are lowered on the interpreter, Bun-ESM, // plain JS and core wasm. The functions below are AffineScript, so they run // wherever a backend can link a stdlib module and supports `len`/`slice` on -// arrays: utf8_width, code_point_count and code_point_slice run on the -// interpreter and Bun-ESM today. code_points_within_octets runs on Bun-ESM -// only: its helper is self-recursive, and the interpreter cannot yet run a -// self-recursive top-level fn (docs/UNICODE-STRINGS.adoc, "Findings"). +// arrays: the interpreter and Bun-ESM today. (code_points_within_octets has a +// self-recursive helper, which the interpreter could not run before #833.) // ============================================================================ // Per-code-point octet width diff --git a/test/test_unicode_octets.ml b/test/test_unicode_octets.ml index abb1afee..d595ef86 100644 --- a/test/test_unicode_octets.ml +++ b/test/test_unicode_octets.ml @@ -100,15 +100,12 @@ let exec b ~name src = let out = Filename.concat workdir (name ^ ".wasm") in Result.map (fun () -> run ("bun run " ^ q out)) (compile out "") -(* The interpreter's println shows a String as an OCaml-quoted literal; the - labels are ASCII, so stripping the quotes recovers the line. *) +(* The printed lines. Every backend, the interpreter included (since #833), + prints a String as its characters, so no line is unquoted here. *) let lines s = String.split_on_char '\n' s |> List.map String.trim |> List.filter (fun l -> l <> "") - |> List.map (fun l -> - let n = String.length l in - if n >= 2 && l.[0] = '"' && l.[n - 1] = '"' then String.sub l 1 (n - 2) else l) let skip b what = Printf.printf "SKIP [%s] %s: host runtime not on PATH\n%!" (backend_name b) what @@ -218,9 +215,9 @@ let stdlib_labels = [ "width_1"; "width_2"; "width_2_top"; "width_3"; "width_3_top"; "width_4"; "count"; "slice_mid"; "slice_astral"; "slice_clamped"; "slice_empty" ] -(* code_points_within_octets recurses; the tree-walking interpreter cannot - yet run a self-recursive top-level fn (docs/UNICODE-STRINGS.adoc, - "Findings"), so this runs on Bun-ESM only. *) +(* code_points_within_octets recurses. The tree-walking interpreter could not + run a self-recursive top-level fn until #833, so this used to run on + Bun-ESM only; it now runs on the interpreter as well. *) let fit_program = {|use utf8::{code_points_within_octets, code_point_slice}; |} ^ check_fn ^ Printf.sprintf {| pub fn main() -> () { @@ -299,6 +296,6 @@ let tests = `Quick (expect_loud_failure b ~name src)) bs) failing_programs @ List.map (fun b -> per b "stdlib utf8" stdlib_program stdlib_labels) [ Interp; Bun_esm ] - @ [ per Bun_esm "stdlib utf8 fit" fit_program fit_labels ] + @ List.map (fun b -> per b "stdlib utf8 fit" fit_program fit_labels) [ Interp; Bun_esm ] @ List.map (fun b -> per b "user definitions shadow the intrinsics" shadow_program shadow_labels) [ Interp; Bun_esm; Js; Wasm ] diff --git a/tools/soundness-anchors.sha256 b/tools/soundness-anchors.sha256 index 2d788c56..8d9a6543 100644 --- a/tools/soundness-anchors.sha256 +++ b/tools/soundness-anchors.sha256 @@ -9,7 +9,6 @@ 20e73d88738c8fd075f81a36803554f92fa4ee53f71e33fa6759eae07c6e70f4 suite:test/test_intrinsic_shadow.ml 2bbd1b989fd0097530eede3e5230258e0e1092271a23ff7dff20cca65c0e612e suite:test/test_wasm_call_resolution.ml 2dfe36a21983a7dfb7ffa1157f7ddec9865a531a92682976b8fd677e4825e78d test:test_801_impl_methods_refused -3b74c20f201d0d53c2fbab5582a681d3dfc3cf978a0aea676ecc6400087452d9 suite:test/test_intrinsic_shadow.ml 45eb0f3aa5f643afbd003248998dd5a046688418647b491e0f2d4bb55fcbd0f2 test:test_wasm_heap_exhaustion_traps 546939eaa3c64c82edd23da0a3ba7f74bcf7378cfe1e426132dd1a9f8fd46050 test:test_801_transitive_public_and_const 5b84a4f71aa65f9aa9383e31c0cb624291c4f9d0de7cca4a0ea6a76fe85aea35 fixture:test/e2e/fixtures/handle_resume_nontail.affine