diff --git a/docs/SOUNDNESS.adoc b/docs/SOUNDNESS.adoc index 77449ac2..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: 4a55253 +:ground-truth-sha: 220d6f1 :ground-truth-date: 2026-12-01 :stamp-verified-by: tools/check-soundness-ledger.sh :toc: macro 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 ]