Repository navigation
The root file gets its own namespace, so sugar's bare names can only mean Base's - #1585
nicolas-abril wants to merge 3 commits into
Conversation
…mean Base's The root file and Base shared the empty namespace, so a bare name written by sugar (Empty for !=, Exists for where, Nat and Succ for literals, Con and Nil for lists, Tuple for pairs, the operators' Type.op) resolved to whatever the root file declared. A module's != law could take its Empty from the entry that imported it (#1331). The root now loads under the namespace an import of it would get (its file name); Base keeps the empty one. Sugar is unchanged and still writes Base's bare names: in a file without Base they are undefined, and a file's own Nat or List is never what a literal means. - tlds["main"] points at the root's main, for the runner and the compiler. - name_key prints the root's own names bare, as before. - cli_verdict's "own def" test reads the root's namespace. - A forward reference to a dotted type applied to <..> was qualified twice (lib:lib:Vec.Con); it already happened in imported modules. - parse_qual builds each ns:name once, and parse_reso tests the far name only when the own one is missing: the longer root keys cost the checker benchmarks about 7% otherwise. Tests: the Base-free tests whose root declares its own Nat, String, List or a U32 constructor now expect the refusal (nat_literal_*, string_literal_own_scon, safe_box_word_def, safe_parameterized_box_word) or print the constructors (cop_bare_trio_000, flatten type_param_match_000); beta_ann_match and grade accept_data spell their constructors; show cons_chain_readback uses Base's List. The checker benchmarks spell Tuple{..} and Pair(..) for their own Sigma. New: import/root_ns_empty (#1331 from the entry's side).
|
This fixes #1331: every capture repro we tried is refused, including one #1577 misses (a Base-free LAWS with
Smaller: C ids now depend on the file name ( Separately, a heads up: bend-lint ( |
|
One more for the list, from #1514. This fixes the Either his three-line guard at the top of |
I pushed two commits on top of bccd6d1. The PR description now covers both.
At 22764c3: repo 54/54, ping 57/57, test 1637/1637, perf 124/124. safe.ts has 0 false rejects on tests/. Not run: Linux, CUDA, hub. This doesn't address review items 1–7 or @HamedShams's |
The root file and Base shared the empty namespace. Because of that, a bare name written by sugar (
Emptyfor!=,Existsforwhere,Nat/Succfor literals,Con/Nilfor lists,Tuplefor pairs,Type.opfor operators) resolved to whatever the root file declared. One result is that a module's!=law could take itsEmptyfrom the entry that imported it (#1331).With this PR the root file loads under its own namespace, the one an import of it would get (its file name). Base keeps the empty one. Sugar itself doesn't change: it still writes Base's bare names. In a file without Base those names are undefined, and a literal never means a file's own
NatorList. This matches the guide: "Operators, literals and brackets are sugar for names in Base."Code (
bend.ts+136 tokens,main.ts+110):book_readloads the root underbasename(file).tlds["main"]points at the root'smain.name_keyprints the root's own names bare, so output is unchanged.cli_verdictdecides whether a def belongs to the root by checking the root's namespace.<..>was qualified twice (lib:lib:Vec.Con).parse_qualnow builds eachns:nameonly once, andparse_resochecks the far name only when the own one is missing. Without these two changes, the longer root keys madegenerics_3200about 7% slower and pushed it past the perf gate's 1.15x limit.Dropping the TLD
bflag (dc7c14d). Once the root file has its own namespace, a name with no:belongs to Base. Theb("from Base") field on top-level definitions doesn't tell you anything the name doesn't, so this commit removes it:Bend.is_base(k)(the name has no:and no~) replaces every read ofbinbend.ts,comp.ts,main.tsandsafe.ts.balso marked a template's stand-in constants (f~T) whiledef_checkruns. That job now has its own flag,o.OWNEDincomp.ts, plus thebguards inintr_of,io_base, literals and foreign IO). The root'sNatis nowfile:Nat, so it can't be taken for Base's. A Base-free file that declares its ownNatnow builds, where main refused it with "Nat is a name the compiler encodes itself".book_loadrefuses the empty namespace for any file except Base.gates/test.ts(state_run) loads each file under its own namespace, the way the CLI does.bend.ts+59,comp.ts-111,safe.ts-5,main.ts-1.bend-lint (22764c3). bend-lint found the root file by the empty namespace, so on this PR its self-check threw
DriftErroron every file.tools/bend-lint/src/seam.tsnow finds the root by its namespace and shows rules the root's own names bare: fact names, owners, thedefs/namesfilters,body(name)and the self-check. Rules and their configs don't change. The format guard also deletes themainalias when it removesns:main. Without that, every format fix failed with "duplicate declaration: main". The tests that read bend's internal data now expectns:namekeys. bend-lint: 126/126 pass, the same as main. The gates don't run bend-lint.Behaviour change. These Base-free tests declare their own
Nat/String/List/U32constructor in the root and relied on literals or printing using them. Their expected output changed:nat_literal_custom_arithmetic,nat_literal_no_arithmetic(fix(verdict): preserve Base-free large Nat literals #1337),nat_literal_own_succ,string_literal_own_scon(A literal trusts a user-defined Nat/String constructor name, forges its field type, and admits Empty #941, still refused, with a different message),nat_literal_pattern_arity,nat_literal_pattern_empty,safe_box_word_def,safe_parameterized_box_word(fix(verdict): respect Unit provenance and word constructor families #1338).cop_bare_trio_000,flatten/type_param_match_000.beta_ann_match,grade/accept_data.show/cons_chain_readbacknow uses Base'sList.bench/checker/*, Base-free) spellTuple{..}andPair(..)instead of tuple and&sugar.import/root_ns_empty. The entry offers its own inhabitedEmptyfor a module's!=law. It was certified on main and is refused here.Relation to #1577. #1577 fixes #1331 from the module's side, making sugar use the writing file's own name. This PR fixes it from the entry's side. Whichever merges second will need its
tests/importexpectations re-pinned.Checks (macOS M-series, at 22764c3): repo 54/54, ping 57/57, test 1637/1637, perf 124/124; bend-lint 126/126. safe.ts on 1650 files: 0 false rejects (run with dc7c14d; 22764c3 only touches bend-lint and doesn't change
bend2/). No new tsc errors inbend2/. Not run: bend-lint'stsc(its@types/bundev dependency isn't installed here), Linux, CUDA, hub corpus.