Repository navigation
The != and where sugar mean the Empty and Exists of the file they are written in, not the entry's - #1577
Conversation
|
This comment and commit ba7e90a were written by an AI agent (Unii) working for @nicolas-abril, without line-by-line human review. This PR fixed
New tests in
Checks (macOS M4): repo 54/54, ping 57/57, test 1643/1643, perf 124/124; safe.ts 1654 files, 0 false rejects. Linux and CUDA were not run. Not covered: a |
Pushed 3819102, which replaces ba7e90a's approach:
A follow-up PR will give the root file its own namespace, the way an imported file already has one. Bare sugar names then can only mean Base's, which is the underlying cause of #1331. |
|
@nicolas-abril Thanks for carrying it through the rest of the sugar; I left the infix table out on purpose, so good to see it go through the same helper. Keeping literals bare makes sense too, a type error on a file’s own Also tried #1585 on top of this branch to see how the two sit together: one small conflict, both rewrite the tail of |
|
I pushed 9a795af on top of your branch. It drops Why: the only new rule here is the name rule. Sugar takes the file's own name if it has one, else the bare one, and user aliases don't apply. It's also smaller: Checked: all 1,654 The PR description still says the four sites use |
|
@nicolas-abril Thanks for the cleanup; pulled it here and the sweep agrees. Description updated to match. On Also merged the branch onto today's |
… written in, not the entry's The !=, exs and where sugar wrote Empty and Exists as bare names that never went through parse_reso. Without Base in scope the bare key is whatever the entry file declares, so a library's != negated into the entry's Empty and its where ranged over the entry's Exists: a false law certified, and a module that declared its own Empty lost it once imported. The four sites now build the reference with parse_call, through parse_reso in the file where the sugar is written. With Base loaded nothing changes, and a local binder still cannot capture the codomain, since the sugar yields a top-level Ref. Closes bendlang#1331.
…list, tuple, char and number literals, number and list patterns and array shortcuts resolve through parse_reso at parse time, so an importing file can't change what they mean
…n, which takes the file's own name if it has one, else the bare one Covers != (Empty), where/exists (Exists), Array.new, xs[i] and xs[i] <- (Array.get/set, U32 index), the infix operators and <>, the &&/||/++ check, and the xs[i] <- statement read back. Literals keep the bare names, as before this PR: a file with its own Nat gets a type error, not its own constructors.
… is gone, since the name rule is the only new thing Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tten
`300n+x` lowers to Nat.add applied to the literal, and that Nat.add was
the one bare name the sugar still wrote, so a Base-free module's big
literal reached for whatever Nat.add the entry declared. A LAWS file
with its own Nat and the law "300n+Zero{} is zero" certifies when the
proof file supplies a Nat.add that returns its second argument. The
reference now goes through parse_own like the rest of the sugar: the
file's own Nat.add if it declares one, else the bare name. Literals
themselves are untouched; `Lit`, `Zero` and `Succ` stay the plain
names. tests/import/big_lit_add pins the pair: the module alone is
missing Nat.add as before, and the entry's proof is refused instead of
certified.
… tlds, sugar that builds a constructor in ctrs; list and tuple literals go through it too A file's constructor named like Base's type (Empty, Pair, Or, Exists) no longer takes over !=, &, | or &x: A -> B, and a def named Con no longer takes over <>. [a, b] and (a, b) now build the file's own Con/Nil/Tuple, as <> already did. Char, string and number literals stay bare, like the Lit nodes they unfold from. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
255c954 to
1f1ff5a
Compare
|
Two commits on top of the branch (
Now sugar that names a def or type looks only in List and tuple literals go through Also dropped Tests: new Performance: the 🤖 Generated with Claude Code |
Closes #1331.
The
!=,exsandwheresugar wroteEmptyandExistsas bare names that never went throughparse_reso. With Base loaded that is harmless, since the bare key is Base's andparse_freshkeeps anyone from redeclaring it. Without Base, the bare key is whatever the entry file declares, so a library's!=meant the entry'sEmpty, and itswherethe entry'sExists. The issue's PROOF.bend certifies a false law that way, and a LAWS.bend that declares its ownEmptychecks alone but loses it the moment it is imported.The sugar now takes its name from
parse_own, in the file where it is written: the file's ownEmpty/Existsif the file declares one, else the bare name, which is Base's when Base is in scope; a user alias is not consulted, and when neither exists the usual "a defined name" error points at the sugar. The four sites write the call as plainApps aroundRef(parse_own(p, …)), so againstmainthe diff is mostlyRef("X")→Ref(parse_own(p, "X")). Nothing changes for a book that imports Base. A local binder still cannot capture the codomain, since the sugar yields a top-levelRef, never aVar;tests/check/neq_qualified_capture.bendis unchanged.@nicolas-abril's commits on this branch put the rest of the sugar through the same rule:
Array.new,xs[i]andxs[i] <-(Array.get/Array.setand theU32index), the infix operators and<>, and the&&/||/++check.parse_ownlooks in one table: sugar that names a def or type (!=,&,|,&x: A -> B, the operators) looks intlds, sugar that builds a constructor (<>) inctrs, so a file's constructor namedEmpty,Pair,OrorExistsno longer takes over!=,&,|or&x: A -> B, and a def namedConno longer takes over<>. List and tuple literals ([a, b],(a, b)) now build the file's ownCon/Nil/Tuple, as<>already did. Char, string and number literals (Zero/Succ) stay bare, as onmain, like theLitnodes they unfold from: a file with its ownNatgets a type error rather than its own constructors, which also avoids a stack overflow on large literals. The one name the literal path still wrote bare was theNat.adda big literal (300n+x) lowers to; the fifth commit sends it throughparse_ownas well, since a Base-free LAWS file's300n+Zero{}otherwise reaches for the proof file'sNat.addand a law that 300 is zero certifies (tests/import/big_lit_addpins the pair, refused now). The literals themselves stay plain.Of the two directions the issue lists, this is the second. Binding the sugar to Base only would refuse
!=andwherein a Base-free book outright; resolving in place keeps a Base-free module's oWhat I ran: every file undertests/throughbend <file>onmainand on each commit of this branch, byte-identical output on the shared files (1,641 files at the time). Rebased onmain(757180e); gates on Mac: repo 54/54 (bend.ts at 44,493 of 48,000,mainis 44,345), test 1768/1768, perf 124/124, ping 80/81 (the BendHublic_bom--namecheck, which fails onmaintoo). Not run: safe (needs abendttbuild), the cluster gates.