Skip to content

Commit ff3f08d

Browse files
feat(strings): backend-independent UTF-8 octet count and code-point view (#829)
## For the DEED printer thread (metadatastician/standards) Switch to these names. They mean the same thing on every backend: | Name | Kind | Meaning | |---|---|---| | `utf8_byte_length(s: String) -> Int` | intrinsic | octets of the UTF-8 encoding of `s` | | `code_points(s: String) -> [Int]` | intrinsic | the Unicode scalar values of `s` | | `string_from_code_points(cps: [Int]) -> String` | intrinsic | inverse of `code_points` | | `utf8_width(cp: Int) -> Int` | `use utf8::{…}` | 1/2/3/4 octets for one scalar value | | `code_point_count(s: String) -> Int` | `use utf8::{…}` | number of scalar values | | `code_point_slice(s, start, end) -> String` | `use utf8::{…}` | `[start, end)` in code points, clamped; never splits a character | | `code_points_within_octets(s, max_octets) -> Int` | `use utf8::{…}` | how many leading code points fit in `max_octets`; Bun-ESM only (the interpreter can't run self-recursion, see Findings) | Do **not** use `len`, `string_get`, `string_sub`, `string_length`, `char_at` or `substring` to count octets. On Bun-ESM they count UTF-16 code units. ## What and why Ground truth is recorded in `docs/UNICODE-STRINGS.adoc`. It was measured by compiling and running probes on `main` `ee211d3`: | Operation | interp | Bun ESM | plain JS | core wasm | |---|---|---|---|---| | `len` of `a`/`é`/`漢`/`🦜` | 1/2/3/4 (octets) | 1/1/1/2 (UTF-16 units) | `ReferenceError` | 1/2/3/4 | | `string_get("🦜",0)` → `char_to_int` | 240 | 55358 (lone surrogate) | `ReferenceError` | refused at compile time | | `string_char_code_at("🦜",0/1)` | 240/159 | 55358/56732 | `ReferenceError` | 240/159 | | `string_sub("🦜x",0,1)` | ill-formed octet | lone surrogate | `ReferenceError` | ill-formed octet | | char literal `'é'` | lexer rejects it on every backend (`Char` is one octet) | | | | Deno-ESM is retired (`--deno-esm` is refused), so the Bun-ESM column covers it. This PR is **additive**: `len`, `string_get` and `string_sub` keep their current meaning. The three intrinsics are lowered on the interpreter, Bun-ESM, plain JS and core wasm. Each is defined only on well-formed input and fails loudly otherwise: a run-time error on the interpreter, a JS throw, or a wasm trap. Ill-formed input means a string cut by `string_sub`, a lone surrogate, overlong or truncated UTF-8, or a non-scalar `Int`. None of them ever substitutes U+FFFD. ## Assumptions a later proof can rely on (tested, not proved) 1. A well-formed `String` denotes a sequence of Unicode scalar values. 2. `string_from_code_points ∘ code_points = id` on well-formed strings, and `code_points ∘ string_from_code_points = id` on arrays of scalar values. 3. `utf8_byte_length(s) = Σ utf8_width(cp)` over `code_points(s)`, using RFC 3629 shortest-form widths. 4. On Bun, writing a well-formed string as UTF-8 emits exactly `utf8_byte_length(s)` octets. 5. There is no Unicode normalisation. 6. Integers are exact: wasm i32 and JS Number. 7. The trusted base is OCaml's `String.get_utf_8_uchar`/`Uchar`, JS `charCodeAt`/`fromCodePoint`, and the wasm decode and encode loops in `lib/codegen.ml`. ## Tests `test/test_unicode_octets.ml` is part of `dune runtest`. It runs fixtures through the real CLI on interp, Bun-ESM, plain JS (node) and core wasm (`bun run`, Bun's WASI). No hand-written JS is involved. Each backend is checked against RFC 3629 / Unicode values, not against another backend. The suite was mutation-checked: - a wrong 2-octet width in the Bun helper fails the Bun-ESM checks; - a missing surrogate check in the wasm encoder fails the wasm loud-failure check. ``` just check → exit 0 test_main: Test Successful, 691 tests run (incl. 28 new Unicode cases) res-to-affine walker: Test Successful, 32 tests run OK: no extension.ts / doc-truthing / DEED gates / soundness ledger (5 properties) / capability anchors tools/run_codegen_wasm_tests.sh → All codegen WASM tests passed (48 JS harnesses) tools/run_codegen_deno_tests.sh → All codegen Bun-ESM (legacy codegen-deno corpus) tests passed (42 harnesses) tools/run_codegen_bun_tests.sh → All native Bun-ESM tests passed (8 harnesses) ``` Notes on the test run: - `lint` is a no-op: the repo has no `.ocamlformat`, so ocamlformat disables itself. That predates this PR. - In CI's coverage job (no Bun), the Bun and wasm cases print `SKIP` and the interp cases still run. The `build` job has Bun and Node and runs all four backends. ## Soundness-ledger stamp and gate fix (owner decision: "thread bumps + fixes check") This PR touches `lib/{interp,codegen,codegen_deno,typecheck}.ml`, which are ledger soundness paths. - `66a314e` advances `:ground-truth-sha:` to `ee211d3` and `:ground-truth-date:` to `2026-12-01`. That is current `main`, verified together with this branch's changes. - `34f5ecc` and `f2ef469` fix ledger **property 4**, in their own commits. - `b70e9df` advances the stamp again, to `c2a5493`. The owner merged `main` into this branch (`809c42d`), bringing in #840, which had itself set the stamp to `ee211d3`, so property 4 correctly required a fresh bump against the new base. I re-verified on the merged head: `dune runtest --force` 701 + 32 + 3 tests pass; the codegen corpora (48 + 42 + 8 harnesses) pass; all 5 guards pass. **The bug.** Property 4 diffed the tree against the stamp commit `S` and passed if that diff showed a stamp-line change. The commit that sets the stamp to `S` always comes after `S`, so the diff always contained one, and the property passed for every later change. At least ten unbumped soundness-path PRs merged after #802 that way. **The new rule (`f2ef469`).** Property 4 judges *the change*: `merge-base(HEAD, origin/main)` to the working tree, which is what gets squash-merged. If that change touches a soundness path, it must also change `:ground-truth-sha:`. Without `origin/main`, the fallback is a history rule: nothing on a soundness path may change after the last commit that changed the stamp line. That rule is merge-aware, so a bump made in a merge commit is found. I first used the history rule as the primary check (`34f5ecc`). It could never pass a PR that re-verifies against an unchanged `main`, because re-stamping to the same SHA changes no line, and it turned every PR red while `main` was stale. `f2ef469` replaces it. Planted cases, run in an isolated clone: | Case | Old | New (with `origin/main`, as in CI) | New (fallback) | |---|---|---|---| | A pristine `main` | pass | pass | FAIL (stale `main`) | | B unbumped soundness edit | pass | **FAIL** | **FAIL** | | C edit + bump in one change | pass | pass | pass | | D bump, then a later edit in the same branch | pass | pass (same change) | FAIL | | E edit commit, then bump commit | pass | pass | pass | | F bump made in a merge commit | pass | pass | pass | | G merge of an unbumped soundness change | pass | **FAIL** | **FAIL** | | H unrelated docs-only change | pass | pass | FAIL (stale `main`) | **Effect on other open PRs.** None, unless the PR touches a soundness path; then it must advance the stamp in that PR. A stale `main` no longer turns unrelated PRs red. The existing "main moved a soundness path under this branch; rebase" check is unchanged. ## Review follow-ups (CodeRabbit) - **User definitions now shadow the three intrinsics on every backend (`4f5eb58`).** - Core wasm used to emit the intrinsic anyway and print a heap pointer; its three arms are now guarded by `user_binds`. - The plain-JS backend refused such declarations, a regression from this PR. Its helpers are now internal `__as_*` names, bound to the source names only when the program doesn't declare them. - The JS int-division classifier no longer treats a declared fn named like an Int intrinsic as returning Int. - New tests cover all four backends plus two int-division cases. Each was mutation-checked: it fails with its fix reverted. - **The `stdlib/utf8.affine` header** now says `code_points_within_octets` runs on Bun-ESM only. - **Not changed here: using an intrinsic as a value on Bun-ESM** (for example `let f = code_points; f(s)`). It emits a bare name for every intrinsic, `len` included, and that predates this PR. Direct calls work on all four backends, and on plain JS the three new names now also work as values. - **Fixed on `main` by #840: a wasm parameter now shadows a same-named top-level fn.** I reported this case with a repro in review, and it now prints 9 on the merged head, matching interp and Bun-ESM. - **Also not changed: shadowing for the older wasm intrinsics.** A user `string_sub` still prints a heap pointer on wasm, on `main` today. Some of those arms deliberately intercept stdlib externs, so it needs its own audit; it is recorded in `docs/UNICODE-STRINGS.adoc`. Fresh results on `f2ef469`'s code: - `dune runtest --force`: 697 + 32 + 3 tests pass; - the 3 codegen corpora: 48 + 42 + 8 harnesses pass; - all 5 guards: OK. ## Owner decision still open - **Commit signatures.** The commits are signed by the session's own Claude key. You planned to re-sign them before merge. ## Findings (all reproduce on `main` without this PR; only 8 is fixed here) 1. **The string builtins disagree between backends** (the table above). This is a semantic divergence in the #560 class, not type unsoundness. Proposed separate fix: - make string indices octet offsets everywhere (the Rust model); - make `string_sub`/`string_get` fail loudly off a character boundary; - point code that needs characters at this API. 2. **Core-wasm heap overwrites string literals.** This is the most serious finding. The heap starts at a fixed `1024`, but literals are laid out from `2048`. Any program that allocates more than about 1 KiB corrupts its own literals. Repro: 60 × `println("label_number_N" ++ " ok")` compiled to wasm prints 21 lines, then `label_number_22abe`, then traps with `Out of bounds memory access`. The interpreter prints all 60. Proposed fix: start the heap at `align(next_string_offset, 8)`. The new suite keeps its success path allocation-free so it tests the primitives, not this. 3. **`affinescript eval` can't run a self-recursive top-level fn.** `TopFn` builds the closure with `cl_env = env` before binding its own name. `fn g(x) { … g(x - 1) … }` fails with `Unbound variable: g`; Bun gives the right answer. 4. **`affinescript eval` rejects all mutable locals.** `let mut k = 0; while k < 3 { k = k + 1; }` fails with `Type mismatch: Expected mutable reference`. 5. **`string::char_at` fails under `eval`** with `Unbound variable: Some`. The root cause is not established. 6. **The plain-JS backend lowers no string builtins** (`len`, `int_to_string`, …). Each is a run-time `ReferenceError`, not a compile-time refusal. 7. **Interp `println` prints a String as an escaped OCaml literal**, quotes included. 8. **Soundness-ledger property 4** could not detect a missing stamp bump. This one *is* fixed here, in `34f5ecc` and `f2ef469`, by owner decision (see above). ## Coordination The new Bun-ESM entries sit in the shared `deno_builtins` string-primitive block next to `string_sub`, plus helpers next to `__as_strFind`. The `bun_builtins` table is untouched, so this should not collide with the typed-Bun-host-I/O thread. https://claude.ai/code/session_01J4QvDfgDTxx9Bumfa2XXcQ --- _Generated by [Claude Code](https://claude.ai/code)_ --------- Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2f1526e commit ff3f08d

18 files changed

Lines changed: 1110 additions & 15 deletions

‎docs/SOUNDNESS.adoc‎

Lines changed: 1 addition & 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: 0cf73b2
7+
:ground-truth-sha: 84eca60
88
:ground-truth-date: 2026-12-01
99
:stamp-verified-by: tools/check-soundness-ledger.sh
1010
:toc: macro

‎docs/UNICODE-STRINGS.adoc‎

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
// SPDX-License-Identifier: CC-BY-SA-4.0
2+
// SPDX-FileCopyrightText: 2026 hyperpolymath
3+
= Unicode Strings and UTF-8 Octets Across Backends
4+
:toc: macro
5+
:toclevels: 2
6+
:icons: font
7+
8+
What `String` operations mean on each backend, and the additive API that has
9+
one meaning on every backend. Written for the estate DEED printer, which must
10+
count line length in UTF-8 octets (a DEED line is at most 998 octets,
11+
`deed.abnf` v1.3.0) and must never split a character.
12+
13+
toc::[]
14+
15+
== Ground truth before this change
16+
17+
Measured on `main` at `ee211d3` (2026-12-01) by compiling and running probe
18+
programs through the real CLI: `affinescript eval` (interp),
19+
`compile --bun-esm` then `bun` (Bun ESM), `compile x.js` then `node` (plain
20+
JS), and `compile x.wasm` then `bun run` (core wasm, via Bun's WASI). The
21+
inputs mix 1-octet (`a`), 2-octet (`é` U+00E9), 3-octet (`漢` U+6F22) and
22+
4-octet (`🦜` U+1F99C) characters.
23+
24+
[cols="2,2,2,2,2",options="header"]
25+
|===
26+
| Operation | interp | Bun ESM | plain JS | core wasm
27+
28+
| `len` on `a` / `é` / `漢` / `🦜`
29+
| 1 / 2 / 3 / 4 (UTF-8 octets)
30+
| 1 / 1 / 1 / 2 (UTF-16 code units)
31+
| not lowered: `ReferenceError: len is not defined` at run time
32+
| 1 / 2 / 3 / 4 (octets)
33+
34+
| `len("aé漢🦜")`
35+
| 10 | 5 | `ReferenceError` | 10
36+
37+
| `string_length("🦜")`
38+
| 4 | 2 | `ReferenceError` | 4
39+
40+
| `string_get("🦜", 0)` then `char_to_int`
41+
| 240 (first octet, `0xF0`)
42+
| 55358 (lone high surrogate `0xD83E`)
43+
| `ReferenceError`
44+
| rejected at compile time (`string_get` not lowered)
45+
46+
| `string_char_code_at("🦜", 0)` / `(…, 1)`
47+
| 240 / 159 (octets) | 55358 / 56732 (UTF-16 units) | `ReferenceError` | 240 / 159
48+
49+
| `string_sub("🦜x", 0, 1)`
50+
| one octet `0xF0`: ill-formed UTF-8
51+
| one lone surrogate: ill-formed UTF-16
52+
| `ReferenceError`
53+
| one octet `0xF0`: ill-formed UTF-8
54+
55+
| stdlib `string::length("🦜")`
56+
| 4 | 2 | `ReferenceError` (uses `len`) | stdlib modules do not link on wasm (unresolved import `string:substring`)
57+
58+
| stdlib `string::char_at("🦜", 1)`
59+
| run-time error `Unbound variable: Some` (see Findings) | 56732 | `ReferenceError` | does not link
60+
61+
| Char literal `'é'`
62+
4+| rejected by the lexer on every backend (`Invalid character literal`): a
63+
`Char` is one octet in the AST (`LitChar of char`)
64+
|===
65+
66+
Deno ESM was retired: `--deno-esm` and a `.deno.js` output are refused
67+
("Deno-ESM was removed"), and `lib/codegen_deno.ml` now emits Bun ESM only.
68+
The Bun-ESM column covers it.
69+
70+
Summary: *index and length units differ by backend*. The interpreter and core
71+
wasm store a `String` as its UTF-8 octets and index by octet. Bun ESM stores a
72+
JS (UTF-16) string and indexes by UTF-16 code unit. The plain-JS backend does
73+
not lower the string builtins at all. `string_sub` can cut a character on
74+
every backend and yields a string that is not a sequence of Unicode scalar
75+
values.
76+
77+
== The additive API
78+
79+
Nothing above was changed: `len`, `string_get`, `string_sub`, `char_at` and
80+
`substring` keep their current per-backend meaning, because existing code
81+
depends on it. Three new primitives have *one* meaning on every backend:
82+
83+
[cols="3,5",options="header"]
84+
|===
85+
| Primitive | Meaning
86+
87+
| `utf8_byte_length(s: String) -> Int`
88+
| The number of octets of the UTF-8 encoding of `s`.
89+
90+
| `code_points(s: String) -> [Int]`
91+
| The Unicode scalar values of `s`, in order.
92+
93+
| `string_from_code_points(cps: [Int]) -> String`
94+
| The string whose scalar values are `cps`: the inverse of `code_points`.
95+
|===
96+
97+
Code points are `Int`, not `Char`, because a `Char` is one octet on the
98+
interpreter and wasm and cannot hold U+1F99C. These primitives are intrinsics,
99+
registered in `lib/resolve.ml` and `lib/typecheck.ml` like `string_sub`, and
100+
lowered in `lib/interp.ml`, `lib/codegen_deno.ml` (Bun ESM), `lib/js_codegen.ml`
101+
(plain JS) and `lib/codegen.ml` (core wasm).
102+
103+
`stdlib/utf8.affine` adds functions written in AffineScript on top of them:
104+
105+
[cols="3,5",options="header"]
106+
|===
107+
| Function | Meaning
108+
109+
| `utf8_width(cp: Int) -> Int`
110+
| Octets in the UTF-8 encoding of one scalar value: 1, 2, 3 or 4.
111+
112+
| `code_point_count(s: String) -> Int`
113+
| Number of scalar values in `s`.
114+
115+
| `code_point_slice(s: String, start: Int, end: Int) -> String`
116+
| The scalar values with index in `[start, end)`, clamped. Never splits a
117+
character.
118+
119+
| `code_points_within_octets(s: String, max_octets: Int) -> Int`
120+
| How many leading code points fit in `max_octets` octets. With that `k`,
121+
`code_point_slice(s, 0, k)` is the longest prefix that fits.
122+
|===
123+
124+
Which backend runs which part:
125+
126+
[cols="3,1,1,1,1",options="header"]
127+
|===
128+
| | interp | Bun ESM | plain JS | core wasm
129+
130+
| the three primitives | yes | yes | yes | yes
131+
| `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
133+
|===
134+
135+
=== Ill-formed input fails loudly
136+
137+
Each primitive is defined only on well-formed input:
138+
139+
* a `String` that is a sequence of Unicode scalar values;
140+
* an `[Int]` of values in `0..0x10FFFF` that excludes the surrogates
141+
`0xD800..0xDFFF`.
142+
143+
On anything else it fails instead of guessing or substituting U+FFFD. The
144+
interpreter raises a run-time error, Bun ESM and plain JS throw, and core wasm
145+
traps (`unreachable`). That covers:
146+
147+
* overlong forms, surrogates encoded in UTF-8, values above U+10FFFF and
148+
truncated sequences, on the octet backends;
149+
* lone surrogates, on the JS backends;
150+
* a string that `string_sub` cut in half, on every backend.
151+
152+
The interpreter decodes with OCaml's strict `String.get_utf_8_uchar`. The wasm
153+
decoder (`gen_utf8_decode_loop` in `lib/codegen.ml`) rejects the same set of
154+
inputs.
155+
156+
== Assumptions the octet count rests on
157+
158+
A later formal proof of the DEED printer's round trip will rely on these. Each
159+
is *tested, not proved*.
160+
161+
. *Abstract value.* A well-formed `String` denotes a finite sequence of Unicode
162+
scalar values. The three primitives are defined only on well-formed input and
163+
fail loudly otherwise; they never return a value for ill-formed input.
164+
. *Isomorphism.* `string_from_code_points(code_points(s)) == s` for every
165+
well-formed `s`, and `code_points(string_from_code_points(cps)) == cps` for
166+
every `cps` made only of scalar values.
167+
. *Octet law.* `utf8_byte_length(s)` equals the sum of `utf8_width(cp)` over
168+
`code_points(s)`. `utf8_width` follows RFC 3629 shortest form: 1 octet below
169+
`0x80`, 2 below `0x800`, 3 below `0x10000`, 4 otherwise. On the interpreter and
170+
wasm, the count is the stored byte length after validation. On the JS backends,
171+
it is computed from the decoded scalar values.
172+
. *Output equals count.* On Bun, writing a well-formed string as UTF-8 (`fs`
173+
with `"utf8"`, or `TextEncoder`) emits exactly `utf8_byte_length(s)` octets.
174+
On the interpreter and wasm, the stored bytes are the bytes written. A lone
175+
surrogate would be written as the 3-octet U+FFFD; that is why the primitives
176+
refuse one instead of counting it.
177+
. *No normalisation.* Counts are over the scalar values as given. NFC and NFD
178+
forms of the same text have different counts, and nothing here normalises.
179+
. *Integer range.* Lengths are exact: wasm `i32` (strings under 2^31 octets)
180+
and JS `Number` (exact below 2^53).
181+
. *Trusted base.*
182+
** The interpreter: OCaml's `String.get_utf_8_uchar`, `Uchar.is_valid` and
183+
`Buffer.add_utf_8_uchar`.
184+
** JS: `String.prototype.charCodeAt` and `String.fromCodePoint`.
185+
** Wasm: the hand-written decode and encode loops in `lib/codegen.ml`.
186+
** Everything else (`stdlib/utf8.affine`) is AffineScript over these.
187+
188+
== Tests
189+
190+
`test/test_unicode_octets.ml` (in `dune runtest`) compiles and runs fixture
191+
programs through the real CLI on the interp, Bun ESM, plain JS and core wasm.
192+
It checks each backend against values from RFC 3629 and Unicode, not against
193+
another backend, so two backends agreeing on a wrong answer still fail.
194+
195+
Covered:
196+
197+
* octet counts for 0- to 4-octet characters, plus a maximal 998-octet DEED line;
198+
* `code_points` values and round trips;
199+
* encoding at every width boundary (`0`, `0x7F`, `0x80`, `0x7FF`, `0x800`,
200+
`0xFFFF`, `0x10000`, `0x10FFFF`);
201+
* loud failure on surrogates, values above U+10FFFF, negative values, and
202+
strings cut by `string_sub` (both a cut lead and a cut tail);
203+
* the `stdlib/utf8.affine` functions where a backend runs them.
204+
205+
A backend whose host runtime is not on `PATH` is skipped with a printed SKIP
206+
line. The CI `build` job provides Bun and Node, so all four backends run there.
207+
208+
The suite was mutation-checked:
209+
210+
* a wrong 2-octet width in the Bun helper fails the Bun-ESM checks;
211+
* a missing surrogate check in the wasm encoder fails the wasm loud-failure
212+
check.
213+
214+
== Findings (reported, not fixed here)
215+
216+
These came up while establishing ground truth. Each reproduces on `main` at
217+
`ee211d3` without this change, and each is left for a separate change.
218+
219+
. *`len` / `string_get` / `string_sub` / `string_char_code_at` disagree
220+
between backends* (table above). This is a cross-backend *semantic*
221+
divergence, not a type-soundness hole: every result is a well-typed `Int` or
222+
`String`. It is the same class as #560, where `show` disagreed between
223+
backends and was fenced. Proposed fix, separately:
224+
** make string indices octet offsets on every backend (the Rust model);
225+
** make `string_sub` and `string_get` fail loudly off a character boundary;
226+
** point code that needs characters at the API above.
227+
. *Core-wasm heap overwrites string literals.* The heap pointer starts at a
228+
fixed `1024` (`ensure_heap_ptr`), while string literals are laid out from
229+
`2048` upward (`next_string_offset`). A program that allocates more than about
230+
1 KiB overwrites its own literals. Repro: 60 statements of
231+
`println("label_number_N" ++ " ok")` compiled to core wasm print 21 lines,
232+
then a corrupted label (`label_number_22abe`), then trap with `Out of bounds
233+
memory access`; the interpreter prints all 60. This is silent memory
234+
corruption before the trap. Proposed fix: start the heap after the last data
235+
segment (`align(next_string_offset, 8)`). `test/test_unicode_octets.ml` keeps
236+
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
238+
`lib/interp.ml`, `TopFn` builds the closure with `cl_env = env` *before*
239+
binding the function's own name, so
240+
`fn g(x: Int) -> Int { if x <= 0 { 0 } else { g(x - 1) + 2 } }` fails with
241+
`Unbound variable: g`. Bun ESM gives `6` for `g(3)`.
242+
. *`affinescript eval` rejects mutable locals.* `let mut k = 0; while k < 3 {
243+
k = k + 1; }` fails with `Type mismatch: Expected mutable reference`, in
244+
`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.
248+
. *The plain-JS backend lowers no string builtins* (`len`, `int_to_string`,
249+
`string_sub`, …): each is a `ReferenceError` at run time, not a compile-time
250+
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+
. *Core wasm ignored a user function that shadows an intrinsic. Fixed by #841
254+
(#836).* With `fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }`, a call
255+
`string_sub("x", 0, 1)` printed `7` on the interpreter and Bun ESM, but a heap
256+
pointer (`1024`) on wasm. Every name-matched arm in `lib/codegen.ml` now
257+
dispatches on `intrinsic_callee`, which skips the intrinsic when the program
258+
defines the name (a `fn` with a body, or a `const`), while the deliberate WASI
259+
lowerings of stdlib `extern fn`s still apply. The three Unicode primitives here
260+
go through the same dispatch and are covered by `test/test_intrinsic_shadow.ml`
261+
and `test/test_unicode_octets.ml` on every backend.

0 commit comments

Comments
 (0)