Repository navigation
A file's names are keyed ns:name inside the compiler, so no declaration lands in another file's namespace and a foreign CID(None) keeps meaning Base's None (#1045) - #1156
Merged
Conversation
nicolas-abril
force-pushed
the
ns-slash
branch
from
September 28, 2026 12:31
8216ab2 to
84a057d
Compare
nicolas-abril
force-pushed
the
ns-slash
branch
from
September 28, 2026 13:06
84a057d to
93f54e7
Compare
nicolas-abril
force-pushed
the
ns-slash
branch
from
October 1, 2026 16:09
93f54e7 to
bce1a23
Compare
…on lands in another file's namespace and a foreign CID(None) keeps meaning Base's None (#1045) A file's names were keyed namespace + "." + name, and the entry file, whose namespace is "", keys its names bare. So the entry's declaration lib.None took the key lib.bend's own None would have had, and lib.bend's foreign C and JS, whose CID(k) tries lib.k before k once every file has loaded, returned the entry's constructor where lib.bend meant Base's None: the wrong match arm, and on C a read of the allocator's bump word and a free into the wrong size class. A key now joins its namespace with ":", which neither a name nor a path holds, so a key names its file: lib.bend's None is lib:None, and the entry's lib.None stays lib.None. An alias expands to ns:name, c_ids tries ns:k then k, and name_show splits a key at its ":". The ":" never leaves the compiler: name_key spells ns:name as ns.name wherever a key is written out (messages, the unsafe lists, a printed main, JS tags, effect ids and exports, SHOW_NAMES, BendTT names), so every output reads as before. The entry may now declare lib.x beside lib.bend's x, a file may be named like a Base type (U32.bend with show) or declare its own name (lib.bend with lib.lib), and a file reaches another's names only through its aliases. tests/io/cid_capture is from #1095: a forged None and a three-field Con over a List node print None and 6 on every lane. Co-authored-by: oxura <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s own keys are ns:name (#1124) Word.bend's namespace is Word, so its bare Nil was looked up as Word.Nil first, which is Base's Word.Nil, and Nil{} became the Word constructor. With ns:name keys the file's own guess is Word:Nil, which no file declares, and Nil is List's. tests/import/base_family_file imports a sibling Word.bend and prints 1n on every lane (main: the Word.Nil error). A test file may now be named with capitals, like the family it stands for. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril
force-pushed
the
ns-slash
branch
from
October 1, 2026 16:29
bce1a23 to
d1b565c
Compare
nicolas-abril
added a commit
that referenced
this pull request
Oct 1, 2026
… import_Word no longer glues onto the test before it #1156 let tests/ hold A-Z file names (tests/import/Word.bend), but the test gate still split the --checkup output on a lowercase-only header. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1045. Closes #1124. Closes #1184. Supersedes #1095.
The bug
A file's names were keyed
namespace + "." + name. The entry file's namespace is"", so its names are keyed bare. As a result, the entry's declarationlib.Nonegot exactly the key thatlib.bend's ownNonewould have. Two things then went wrong:lib.bend's Bend code was resolved whilelib.bendwas parsed, so itsNonemeant Base'sNone.CID(None)trieslib.Nonefirst and so took the entry's constructor.The same spelling meant two different constructors in the two halves of one library. The result was the wrong
matcharm, and on C, a read of the allocator's bump word plus a free into the wrong size class:import ./lib.bend as Q+type Evil is Data: lib.None{}SomeSomeSome 97NoneNoneNoneThe fix
The ambiguity was in the key encoding, so this fixes the encoding. #1095 instead kept the ambiguous keys and made
c_idscompute an ownership scope per foreign source to work around them.Keys: inside the compiler, a namespace now joins its names with
:. A name is words joined by dots and a namespace is a path, so neither can contain:, and a key always names its file:lib.bend'sNoneislib:None, and the entry'slib.Nonestayslib.None.Lookups:
parse_qualjoins with:, an alias expands tons:name,c_idstriesns:kthenk, andname_showsplits a key at its:.Output: the
:never leaves the compiler.name_keyspellsns:nameasns.nameeverywhere a key is written out:mainvalue, inSHOW_NAMESfor C and in the JS show table;.mjsexports;Every output reads exactly as on main.
Size: after the rebase,
bend.ts+114 ttok,comp.ts+96 (63,213 → 63,309, under its 64k cap),safe.ts+37,main.ts+4.Also fixes #1124
The same encoding caused #1124 from the other side.
Word.bend's namespace isWord, so its bareNilwas first looked up as its ownWord.Nil, which is Base'sWord.Nil. Withns:namekeys the file's own guess isWord:Nil, which no file declares, soNilis List's. Likewise,String.bend's bareeq, which nothing declares, is now refused as undefined, instead of silently binding Base'sString.eq.Only a sibling of the entry file gets a bare family name as its namespace (
libs/Word.bendislibs/Word), so the test sits next to its entry:tests/import/base_family_file.bendimports a siblingtests/import/Word.bendand prints1non every lane. Onmainthe check, JS and C lanes all fail with theWord.Nilerror.gates/repo.tsnow allows capital letters in a test's file name, so a test can be named like the family it stands for.Behaviour changes
lib.xnext tolib.bend'sx; main refuses it as a duplicate.U32.benddeclaringshow; main clashed it with Base'sU32.show.lib.benddeclaringlib.lib.lib.bend's law withdef lib.one()instead ofdef L.one(), now says the name isn't in scope. This is Imported files answer to their file name as well as to their alias, so one prefix can point at two files #1184: an importedX.bendno longer answers toX.fwhen its alias isZ.lib.xandlib.bend'sxboth print aslib.x. The program still behaves correctly because the keys differ. In JS, two such foreign effects fail loudly ("two effects register"), and two such.mjsexports share one export name.Verification
Each program was run on this branch and on main (
ef66a7cc) through the interpreter,--check-only,-o .js+ node, native-o+ run,--verdictand-o .bendtt, and all outputs were diffed. The programs:tests/,bench/runtimeanddemos;../climb, chain with diamond) × 4 name shapes (bare,Geo.x,lib.x,A.B.x) × def/type/constructor, working and with errors;BEND_LIB, hyphenated paths, cycles, one file under two aliases, colliding aliases, laws andLAWS/PROOF, templates, operators,.mjsinterop, foreign effects insub/deepand../shared,@unsafein nested files, and every error message that names a key;Results:
:in any output: in the output of all 1773 programs (every lane's output and the emitted.c,.js,.mjsand.bendtt, string literals included), noname:nametoken appears that isn't in main's output.tests/io/cid_capture(fixed);tests/io/cid_captureis from Foreign effect IDs resolve only in the owner's import scope (#1045) #1095 (by @oxura). It forgesNoneand a three-fieldConover aListnode and printsNone/6on every lane (main:Some/Some 97).gates/repo.tspasses, 49 / 49.After the rebase onto main (
607a095a)comp.ts, all against The compiler says the same in 658 fewer tokens, with the same output and compile time #1235's rewrites and the newer comment-skippingCIDscan. Each hunk keepsmain's code with this PR'sname_keyand:applied.main's 31 new commits add no namespace joins or key printing of their own.has no tagmessage: this PR had broken it over three lines to fitname_key, which changed the emitted JS text. It now keepsmain's layout, with the two names computed first.tests/io/cid_capture_lib.bendhad no#|lines, but in the check lane it prints the usual "2 defs rely on unsafe or foreign code" error, so the gate would have failed it. It now pins that error, as the other foreign-code helpers do..bendfiles undertests/,bench/anddemos/, comparing--check-onlyoutput,.c,.js,.bendttand every log againstmain:cid_capture(fixed)..bendttlogs differ only by the output path written into them..jsfiles differ only there. A:in a key is mangled as$058($alias_lib$058two$). That keeps the entry'slib.twoandlib.bend'stwoas two JS functions, so it is intended. It does mean the.jsabove is identical tomainonly up to these internal names.cid_capturefiles pass the gate's check lane, run as its aggregator, and their JS and C lanes.tscreports the same 12 errors asmain.gates/repo.tspasses, 50 / 50.Not run
🤖 Generated with Claude Code