Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion docs/SOUNDNESS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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: ee211d3
:ground-truth-sha: 4248912
:ground-truth-date: 2026-12-01
:stamp-verified-by: tools/check-soundness-ledger.sh
:toc: macro
Expand Down Expand Up @@ -261,6 +261,24 @@ function compiled before its closure signature existed emit invalid wasm.
| `test/test_wasm_call_resolution.ml` (`test_wasm_param_shadows_fn`,
`test_wasm_let_shadows_fn`, `test_wasm_unshadowed_fn_still_direct`,
`test_wasm_call_indirect_type_interned` — all four fail on `ee211d3`)

| #836
| On core wasm a function the program defines is called even when it is named
like a compiler intrinsic, as on the interpreter and Bun-ESM. The intrinsic
arms of `gen_expr`'s call dispatch matched the callee by spelling, so
`fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }` was never called: the
intrinsic ran and the program printed a heap pointer (1024). All 26 arms
(28 names) now dispatch on `intrinsic_callee`, which is empty for a name the
program binds: a `fn` with a body or a `const` (here or imported), or a
local. A name that is only declared (`extern fn`) keeps its lowering, so the
WASI lowerings are unchanged. The calls that elaboration makes for `show` on
Int and `slice` on a String are now named `__builtin:…`, which no program can
write, so a user `int_to_string` / `string_slice` does not capture them.
| `fixed`
| `test/test_intrinsic_shadow.ml` (each name on the interpreter, Bun-ESM and
core wasm; every wasm case fails on `4248912`. Also: an `extern fn` in scope
keeps the lowering; the lowerings still run; `show`/`slice` are not captured;
a local and an imported definition win)
|===

== Still open — read before claiming "sound"
Expand Down
114 changes: 83 additions & 31 deletions lib/codegen.ml

Large diffs are not rendered by default.

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

Expand Down Expand Up @@ -1787,8 +1789,10 @@ let elab_poly_builtin (id : ident) (fty : ty) (args : expr list) : expr =
let arg_ty = match repr fty with TArrow (a, _, _, _) -> Some (repr a) | _ -> None in
let call name = ExprApp (ExprVar { id with name }, args) in
match id.name, arg_ty, args with
| "slice", Some (TCon "String"), _ -> call "string_slice"
| "show", Some (TCon "Int"), _ -> call "int_to_string"
(* #836: `__builtin:` names cannot be written in source, so a program's
own `string_slice` / `int_to_string` never captures these calls. *)
| "slice", Some (TCon "String"), _ -> call "__builtin:string_slice"
| "show", Some (TCon "Int"), _ -> call "__builtin:int_to_string"
| "show", Some (TCon "Bool"), [b] ->
ExprIf { ei_cond = b;
ei_then = ExprLit (LitString ("true", id.span));
Expand Down
1 change: 1 addition & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
(source_tree e2e)
(source_tree ../examples)
(source_tree ../stdlib)
(file ../lib/codegen.ml)
(file ../lib/codegen_deno.ml)))
Loading
Loading