Repository navigation
A name is words joined by dots, a namespace is the file's real path, a C id is unique, and every clash is refused - #1042
Merged
Merged
Conversation
…a C id is unique, and every clash is refused Names that differed only in special characters or case, or in a namespace and a dotted name, met under one key, one C id or one JS tag: a later def could take a template's opaque ~ name and admit Empty (#994, after #905), case-distinct constructors shared a CID macro (#989), and a file could register keys in another file's namespace (#1002) or take a hub package's 0x<hash> namespace (#1005). - A declared name matches [A-Za-z_]\w*(\.[A-Za-z_]\w*)*; ~ is left to names the checker and compiler mint (k~binder, Clo~apply, IO~emit). - An import path is plain names (letters, digits, _ and -), with ../ and / as separators. The namespace is the real path relative to the entry's real dir, or to BEND_LIB for hub files, so a file reached by two paths loads once. Only a path spelled 0x<hash>/ goes to the hub, and a hub file imports only the hub. - A name declared twice, a Base name redeclared in a module, an alias given twice, an alias that shadows a dotted name or a declaration, a foreign def named like a constructor, one effect file imported from two namespaces, and an effect registered twice all fail to compile. - C ids come from one table: CID_/FID_ plus the cleaned name, suffixed _N when taken, never a runtime id. Effect files write CID(Name) and FID(name), read in the effect's namespace and then as written; an unknown name fails. In JS, CID(Name) is the constructor's key, which is its tag, and names mangle reversibly. - A JS effect registers itself with io_eff(CID(Name), run, need), as a C effect does; the C and JS runtimes refuse a second registration. bend2/effs and guide/EFFECTS.md use the new form. Closes #994, #989, #1002, #1005. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril
added a commit
that referenced
this pull request
Sep 25, 2026
…me) form The Process.run branch predates #1042, so its JS file never called io_eff and the interpreter and JS lanes stopped with "no effect registers Process.run", while C still built from the old CID_PROCESS_RUN macro. The JS file now registers with io_eff(CID(Process.run), ...) and walks the argument list by CID(Con), and the C file registers under CID(Process.run), as every other effect does. tests/io/process_run and process_run_parallel pass on the interpreter, JS and C. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
MattCozendey
added a commit
to MattCozendey/bend
that referenced
this pull request
Sep 25, 2026
…mes: op_name, and a constructor's full name as its JS tag Co-Authored-By: Claude Opus 5.5 <[email protected]>
nicolas-abril
pushed a commit
that referenced
this pull request
Sep 25, 2026
…1049) 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 #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 #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]>
Merged
This was referenced Sep 25, 2026
VictorTaelin
added a commit
that referenced
this pull request
Sep 27, 2026
… kernel `bend <file> --safe` runs bend2's checker, then elaborates the checked book to a .bendtt file (bend2/safe.ts) and checks it with the BendTT kernel's CLI (bend2/bendtt.lean, bend5 main 8284f4a8: one Lean file with the kernel, its claims and their proofs). - safe.ts (19,924 ttok): per-def scope; convoys through matches and refutations; eta-long at binder or kind mismatch; bodiless defs go out as opaque defs at a model built from their type; items specialize at every parameter a kind depends on; templates specialize at their ~ arguments (or check at bend2's instances when an opaque constant has no model); a law-declared def and the helpers that call it back go out as one group def with a selector; a linear pair used twice is matched once and rebuilt at each use; it reads main's typed literals (#1004): a Nat literal past 4096 goes out as Nat.add(Nat.mul(q, 4096), r), a U32 or F32 literal as one def per word. - base.bend: Array.get.go, Array.swap.go, Map.get, Map.put, Map.ins, Map.seek, Map.has and Map.pop recurse on their own pieces; the forward helpers (.bit/.deep/.if) and five laws go. tests/flatten/array_statement expects Array.get.go. - gates/safe.ts (+ safe_node.ts, safe_diag.ts): bend2's verdict against BendTT's per file, on the minis, for tests/ or a BendHub store. Last run: tests 979 agree, 1 partial (base's @unsafe Array.join), 24 user @unsafe, 481 bend2 rejects, 0 false rejects, 0 timeouts; hub 715 agree, 11 vacuous, 2 partial (F32 LtOk, no model for the native), 78 user @unsafe, 213 bend2 rejects, 0 false rejects, 0 timeouts. Since the old base, bend2 itself rejects 155 more hub files: 101 name clashes and 52 digit words (#1042), 2 calls to the gone Nat.read.fit; every other file that agreed still agrees. - main.ts takes --safe; repo.ts and AGENTS.md list safe.ts and bendtt.lean; .gitignore skips the *.bendtt files --safe writes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Oct 17, 2026
4 of 7 tasks
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.
Several soundness bugs came from names that looked different but met under one key, one C id or one JS tag. This PR stops that at the source: names and import paths are validated, every generated id is unique, and every clash is a compile error.
Closes #994, closes #989, closes #1002, closes #1005. Supersedes #1006. It also covers what #905, #790, #870 and #914 fixed one by one.
What changes
[A-Za-z_]\w*(\.[A-Za-z_]\w*)*.~is only for names the checker and compiler mint (k~binder,k~n,Clo~apply,IO~emit), so a user name can never land on one. This closes A constructor name reused by a later definition bypasses #905 and admits Empty #994: a later def or constructor can no longer take a template's opaque~name._,-), with/and../as separators. The namespace is the file's real path, relative to the entry's real dir, or toBEND_LIBfor hub files. A file reached through two paths (a symlink,a/../b) loads once. Only a path spelled0x<hash>/…goes to the hub, and a hub file imports only the hub. A local../0x<hash>/f.bendor./0x<hash>/f.bendis refused (A local file can take a hub package's0x…namespace:../0x<hash>/f.bendfrom a subdirectory is loaded locally but named like the package #1005). A dotted file name likeLAWS.Nat.bendis refused, andLAWS/Nat.bendgets its own namespace,LAWS/Nat. So no file can register keys in another file's namespace (Names resolve to keys other files register under the importer's namespace: an app file can rewrite what LAWS.bend says, or make PROOF.bend check different code thanbend main.bendruns #1002).book_loadwas rewritten around this.CID_/FID_plus the cleaned name, suffixed_Nwhen taken, never equal to a runtime id (FID_EXIT,CID_ARITY_T, …). Case-distinct constructors get distinct ids (C backend rejects case-distinct constructors because both names become the same CID macro #989).CID(Name)andFID(name). They are substituted at compile time, reading the name in the effect's namespace first, then as written. An unknown name is an error. In JS,CID(Name)is the constructor's key, which is its tag, and JS names mangle reversibly (JS backend silently merges distinct defs whose names mangle to the same identifier (C lane refuses the same program) #790).io_eff(CID(Name), run, need), as C effects do, instead of being found by name.bend2/effs/*andguide/EFFECTS.mduse the new form.Breaking changes
CID_FOOtoCID(Foo)and, in JS, add theio_eff(...)registration line.~, spaces or other characters in a segment are refused, and so are def names outside the rule above.Verification
tests/import/{alias_*,dotted_path,tilde_path,hub_head_*,js_names_apart},tests/io/{cid_unknown,effect_ctr_name},tests/parse/decl_name_words,tests/run/ids_unique. Five existing tests changed to match the new rules.main(b7ebee9):mainexcept the new and changed tests.mainexcept the new and changed tests.gates/repo.ts: 46/46.bend main.bendruns #1002 and A local file can take a hub package's0x…namespace:../0x<hash>/f.bendfrom a subdirectory is loaded locally but named like the package #1005 are refused with the errors above. The hub package in A local file can take a hub package's0x…namespace:../0x<hash>/f.bendfrom a subdirectory is loaded locally but named like the package #1005 still loads when nothing imitates it.bend2-fuzzergot a modules lane, an effects lane (CID/io_eff) and a clash lane that must see each of the refusals above. A 2-hour run on this branch covered 49,499 programs, and every clash kind came up at least 260 times. Nothing in the run traced to this change. The 16 divergences it found also happen onmain: a Bool returned by a lambda that is called immediately is read wrong by the C backend (to be filed separately). The same lanes onmainflag 266 of 300 programs.ttokgrows by +779 in the compiler (bend.ts+406,comp.ts+387,main.ts−14) and +486 inbend2/effs(the JS registration lines).bend.tsis at 43,761 of its 44,000 cap.Not done
gates/test.ts, perf and GPU gates were not run.bend.ts'sbook_loadis rewritten from scratch, so it needs a careful human read.🤖 Generated with Claude Code