Repository navigation
Commit 98a4dff
committed
fix(codegen): a user fn named like an intrinsic is called on wasm (#836)
The intrinsic arms of gen_expr's ExprApp dispatch matched the callee by
spelling, before asking whether the program binds that name. On core wasm
`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) where the
interpreter and Bun-ESM print 7.
All 26 arms 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; that is why the guard is a set of
user-defined names and not membership of func_indices.
The WASI import pre-scan skips a name the program defines, so no unused
import is emitted. The calls elaboration makes for `show` on Int and
`slice` on a String are renamed `__builtin:...`, which no program can
write, so a user int_to_string / string_slice does not capture them.
test/test_intrinsic_shadow.ml covers every name on the interpreter,
Bun-ESM and core wasm. docs/SOUNDNESS.adoc gains the #836 row and the
ground-truth stamp advances to 4248912.
Closes #836
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDfoRYrnr6w2SMcxvze1 parent 4248912 commit 98a4dff
7 files changed
Lines changed: 558 additions & 36 deletions
File tree
- docs
- lib
- test
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
264 | 282 | | |
265 | 283 | | |
266 | 284 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
851 | | - | |
852 | | - | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
853 | 855 | | |
854 | 856 | | |
855 | 857 | | |
| |||
1787 | 1789 | | |
1788 | 1790 | | |
1789 | 1791 | | |
1790 | | - | |
1791 | | - | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
1792 | 1796 | | |
1793 | 1797 | | |
1794 | 1798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
0 commit comments