Repository navigation
Description
Found by the #829 thread. Reproduced independently on main ee211d3 and on #835's branch.
Evidence
fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }
fn main() -> () { println(int_to_string(string_sub("hello", 0, 2))); }
| Backend | Output |
|---|---|
interp (eval) |
7 |
| Bun-ESM | 7 |
| core wasm | 1024 on main (1040 with #835) |
The wasm number is a heap pointer: the address of the intrinsic's substring.
wasm-tools print shows the user's function compiled as func 1. main never calls it.
Classification
Soundness-class hole: a silent wrong value. A well-typed program prints a plausible number and nothing fails.
Cause
gen_expr in lib/codegen.ml intercepts calls by name, as in ExprVar id when id.name = "string_sub". It does this before it checks whether the name resolves to a user declaration. Twenty names are intercepted this way: char_to_int clock_now_ms file_close file_fd_write file_open file_read float_to_string int_to_string net_accept net_recv net_send net_shutdown print println string_char_code_at string_find string_from_char_code string_slice string_sub trim.
#829 fixed only its three new intrinsics.
Options
Ranked by elegance and correctness first, then by dependability.
- (Recommended: most elegant and correct) Intercept on resolution, not on spelling. The resolver should tag a call as a builtin only when the name resolves to the builtin or stdlib-extern symbol. Codegen should match on that tag, so a user declaration always shadows. Some arms deliberately intercept stdlib
extern fndeclarations, for example the net and file externs. Those arms must keep matching the extern symbol, so each of the 20 arms needs auditing to confirm which interceptions are intended. - (Most dependable, smaller) At the top of each arm, guard:
not (is_user_defined ctx id.name). The user's function then wins. One test per name, compiled to wasm and run, asserts the user's result. - (Fail-loud stop-gap) Refuse, at compile time, a user top-level declaration that reuses an intercepted name on the wasm backend.
Pinned in docs/SOUNDNESS.adoc as open (tracked) by an xfail pin (PR #835). Audit: docs/reports/AUDIT-2026-12-01-backend-divergences.adoc.
Generated by Claude Code
Activity
whatproblem-ai commentedon Dec 1, 2026
Problem: On the core wasm backend, a user function whose name matches one of 20 intercepted intrinsics (e.g.
string_sub) is never called.gen_exprinlib/codegen.mlmatches calls by name before resolving them, so the intrinsic runs in its place. The program silently returns a heap pointer (1024onee211d3), while interp and Bun-ESM return7.Expected: A user declaration shadows the intrinsic on every backend. wasm output should match interp and Bun-ESM (
7).Missing: which of the 20 arms are meant to intercept stdlib
extern fnsymbols (file/net) and must keep doing soClarity: 95%. Clear enough to work on.
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
coderabbitai commentedon Dec 1, 2026
🔗 Related PRs
#829 - feat(strings): backend-independent UTF-8 octet count and code-point view [open]
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
test(soundness): pin #836 wasm intrinsic-name shadowing as open (trac…
fix(codegen): a local shadows a same-named fn on wasm; intern call_in…
test(soundness): pin #836 wasm intrinsic-name shadowing as open (trac…
Merge main (#841) into claude/unicode-octets; adopt intrinsic_callee …
docs(audit): add #836 and #837 to the backend-divergence audit
docs(audit): #841 merged — mark #836 fixed
Merge origin/main into fix/833-interp-recursion-mut
fix(codegen): start the wasm heap after the last data segment (#830) (#…