Repository navigation
The C leak guard skips the effect sources, which may say undefined - #1049
Conversation
compile_book refuses a C build whose text holds the word undefined, since in the C the emitter generates it can only be a JS undefined that leaked. It tested [tabs, spins, segs, fl.reqs], and fl.reqs is the effect sources pasted in verbatim, so an effect .c that said undefined anywhere, even in a comment, failed `-o` with "Error: an unbound name in the emitted C" and no location, while the check, the interpreter and the JS build ran the same program. The guard now tests [tabs, spins, segs]. The guard came with d7af6bf over the whole output; 85d805b narrowed it to the code fills so a constructor named undefined could pass through SHOW_NAMES. Until bendlang#1042, fl.reqs also held generated lines (#pragma push_macro and #define CID_x CID_y around each source), which the guard rightly read. Since bendlang#1042 it holds only the sources, their CID(k) and FID(k) replaced by c_ids, which writes an uppercase id or dies on an unknown name. A foreign def's generated segment goes to fl.segs and is still read. tests/io/effect_undefined_word: the C twin says undefined in a comment and in a string; main prints 18. On 95317d9 the build fails with the error above (lanes: check PASS, interp 18, js and c BUILDFAIL); with the word respelled the program builds and runs there. On this branch the check passes and interp, js and c all print 18. The guard still fires on generated C: a temporary `#define LEAK ${fl.cids.get("nope")}` in the tables, and a `WL_RETN(${...})` of the same miss in the foreign def's segment, each failed the build with the same error on this branch (both edits reverted). Regression, Linux x86-64: the 9 tests/io tests with a .c twin, four lanes, same results as main but the new one; the tests/io checkup (118 modules) prints the same as main; -o x.c over all 118 tests/io programs: 76 byte-identical, 41 refused alike, the new test the only difference; gates/repo.ts 46/46; comp.ts ttok 62602 -> 62632. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you, this is merged. Your history checks out: before #1042 Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself. |
What changes
compile_bookrefuses a C build whose text contains the wordundefined(
/\bundefined\b/). In C the compiler generates, the word can only come froma JS
undefinedthat leaked into it. The test ran over[tabs, spins, segs, fl.reqs], andfl.reqsholds the effect sources,pasted in verbatim. It now runs over
[tabs, spins, segs]. One line changesin
bend2/comp.ts, plus a two-line comment. There is one new test,tests/io/effect_undefined_word.{bend,c,js}.Why
A user effect
.cthat containsundefinedanywhere, even in a comment suchas
// the sum wraps at 2^32, so it is never undefined, fails the nativebuild with:
The error does not say where the word is. For the same program, the check,
the interpreter and a JS-only build (
-o x.js) all run correctly. If theword is spelled differently, the program builds and runs natively.
History, as far as I could trace it:
to the code fills. That let a constructor named
undefinedpass throughthe names table.
fl.reqsalso held generated lines: a#pragma push_macro/#define CID_x CID_ypair around each source.The guard was right to read those.
fl.reqsholds only the sources, withCID(k)/FID(k)replaced by
c_ids.c_idswrites an uppercase id or dies on an unknownname. No generated text remains in
fl.reqsfor the guard to catch.A foreign def's generated request segment (
compile_reqspushes it tofl.segs) is still read.Test
tests/io/effect_undefined_word: the C twin containsundefinedin acomment and in a string literal (
strlen("undefined")).mainprints18.an unbound name in the emitted Can unbound name in the emitted C(The js lane fails on main because the test builds
-o t.js -o tin onecommand, as gates/test.ts does. A JS-only build on main runs and prints 18.)
The guard still fires on generated C. I checked with two temporary edits on
this branch, both reverted:
#define LEAK ${fl.cids.get("nope")}line in the tablesWL_RETN(${fl.cids.get("nope")})in the foreign def's generated segmentEach edit made the build fail with the same error.
Regression
These runs were on Linux x86-64, Bun 1.3.11 and clang 22:
tests/iothat have a.ctwin: thesame results as main, except for the new test.
tests/iocheckup (118 modules, one process): output identical tomain.
-o x.cover all 118tests/ioprograms, on main and on this branch:errors).
gates/repo.ts: 46 / 46.bend2/comp.tsttok: 62602 -> 62632.Not tested here
paths.
gates/test.tsandgates/perf.tson the cluster.