Skip to content

Commit f043b95

Browse files
Merge branch 'main' into claude/js-backend-builtin-refusal-832
2 parents 2ed54da + 0cf73b2 commit f043b95

7 files changed

Lines changed: 558 additions & 36 deletions

File tree

‎docs/SOUNDNESS.adoc‎

Lines changed: 19 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: ee211d3
7+
:ground-truth-sha: 4248912
88
:ground-truth-date: 2026-12-01
99
:stamp-verified-by: tools/check-soundness-ledger.sh
1010
:toc: macro
@@ -261,6 +261,24 @@ function compiled before its closure signature existed emit invalid wasm.
261261
| `test/test_wasm_call_resolution.ml` (`test_wasm_param_shadows_fn`,
262262
`test_wasm_let_shadows_fn`, `test_wasm_unshadowed_fn_still_direct`,
263263
`test_wasm_call_indirect_type_interned` — all four fail on `ee211d3`)
264+
265+
| #836
266+
| On core wasm a function the program defines is called even when it is named
267+
like a compiler intrinsic, as on the interpreter and Bun-ESM. The intrinsic
268+
arms of `gen_expr`'s call dispatch matched the callee by spelling, so
269+
`fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }` was never called: the
270+
intrinsic ran and the program printed a heap pointer (1024). All 26 arms
271+
(28 names) now dispatch on `intrinsic_callee`, which is empty for a name the
272+
program binds: a `fn` with a body or a `const` (here or imported), or a
273+
local. A name that is only declared (`extern fn`) keeps its lowering, so the
274+
WASI lowerings are unchanged. The calls that elaboration makes for `show` on
275+
Int and `slice` on a String are now named `__builtin:…`, which no program can
276+
write, so a user `int_to_string` / `string_slice` does not capture them.
277+
| `fixed`
278+
| `test/test_intrinsic_shadow.ml` (each name on the interpreter, Bun-ESM and
279+
core wasm; every wasm case fails on `4248912`. Also: an `extern fn` in scope
280+
keeps the lowering; the lowerings still run; `show`/`slice` are not captured;
281+
a local and an imported definition win)
264282
|===
265283

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

‎lib/codegen.ml‎

Lines changed: 83 additions & 31 deletions
Large diffs are not rendered by default.

‎lib/typecheck.ml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,10 @@ let reset_float_heap_sites () : unit = float_heap_sites := []
848848
the instantiated function type at that call. After checking, the first
849849
parameter of that type is the argument's type, so
850850
{!elaborate_string_concat} can pick a monomorphic lowering:
851-
`slice` on a String becomes `string_slice`; `show` on Int becomes
852-
`int_to_string`, on Bool an if over two literals. Same physical-identity
851+
`slice` on a String becomes `__builtin:string_slice`; `show` on Int
852+
becomes `__builtin:int_to_string` (names no program can write, so its own
853+
`string_slice` / `int_to_string` cannot capture them, #836); on Bool an if
854+
over two literals. Same physical-identity
853855
discipline as {!string_concat_sites}. *)
854856
let poly_builtin_sites : (expr * ty) list ref = ref []
855857

@@ -1787,8 +1789,10 @@ let elab_poly_builtin (id : ident) (fty : ty) (args : expr list) : expr =
17871789
let arg_ty = match repr fty with TArrow (a, _, _, _) -> Some (repr a) | _ -> None in
17881790
let call name = ExprApp (ExprVar { id with name }, args) in
17891791
match id.name, arg_ty, args with
1790-
| "slice", Some (TCon "String"), _ -> call "string_slice"
1791-
| "show", Some (TCon "Int"), _ -> call "int_to_string"
1792+
(* #836: `__builtin:` names cannot be written in source, so a program's
1793+
own `string_slice` / `int_to_string` never captures these calls. *)
1794+
| "slice", Some (TCon "String"), _ -> call "__builtin:string_slice"
1795+
| "show", Some (TCon "Int"), _ -> call "__builtin:int_to_string"
17921796
| "show", Some (TCon "Bool"), [b] ->
17931797
ExprIf { ei_cond = b;
17941798
ei_then = ExprLit (LitString ("true", id.span));

‎test/dune‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
(source_tree e2e)
77
(source_tree ../examples)
88
(source_tree ../stdlib)
9+
(file ../lib/codegen.ml)
910
(file ../lib/codegen_deno.ml)))

0 commit comments

Comments
 (0)