Repository navigation
Track unsafe dependencies in datatype kinds (#1205) - #1220
Conversation
|
Joint verification of #1215, #1216, #1218, #1219 and #1220 against main commit 0187512:
The cluster-wide corpus gates were not run; this evidence is the local repository gate, actual CLI/compiler runs and actual kernel checks. |
… chain of meets and a kind computed through an @unsafe def check as on main Running every snippet in the open issues on main and on this branch found two files main checked and this branch did not, both from no longer folding closed quantities: - #984's chain q(n+1) = q(n) <&> q(n) up to q26, in a kind: bend2 computes it with sharing, the kernel tree-walks 2^26 meets and runs out of fuel. - #1205's Kind(qsize(Array.join(...))): main folded it to &1; without the fold the kind names base's @unsafe Array.join and goes out of scope. (#1205 holds that main's pass is the gate's bug; that is #1220's to fix, and this keeps main's behavior until then.) A closed call or meet of type Quant now goes out as the literal bend2's evaluator gives (quant_lit): the kernel would compute the same, so this is exact, unlike the &0 -> *(.Q1) fold this branch dropped. It applies wherever a term is known to be a Quant: a kind's quantity, a meet's sides, an argument at a Quant parameter, and any term bend2 annotated as one. Closedness is read first, on the variables with no value in scope, so an open term costs no normal form and nothing throws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… chain of meets and a kind computed through an @unsafe def check as on main Running every snippet in the open issues on main and on this branch found two files main checked and this branch did not, both from no longer folding closed quantities: - #984's chain q(n+1) = q(n) <&> q(n) up to q26, in a kind: bend2 computes it with sharing, the kernel tree-walks 2^26 meets and runs out of fuel. - #1205's Kind(qsize(Array.join(...))): main folded it to &1; without the fold the kind names base's @unsafe Array.join and goes out of scope. (#1205 holds that main's pass is the gate's bug; that is #1220's to fix, and this keeps main's behavior until then.) A closed call or meet of type Quant now goes out as the literal bend2's evaluator gives (quant_lit): the kernel would compute the same, so this is exact, unlike the &0 -> *(.Q1) fold this branch dropped. It applies wherever a term is known to be a Quant: a kind's quantity, a meet's sides, an argument at a Quant parameter, and any term bend2 annotated as one. Closedness is read first, on the variables with no value in scope, so an open term costs no normal form and nothing throws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… chain of meets and a kind computed through an @unsafe def check as on main Running every snippet in the open issues on main and on this branch found two files main checked and this branch did not, both from no longer folding closed quantities: - #984's chain q(n+1) = q(n) <&> q(n) up to q26, in a kind: bend2 computes it with sharing, the kernel tree-walks 2^26 meets and runs out of fuel. - #1205's Kind(qsize(Array.join(...))): main folded it to &1; without the fold the kind names base's @unsafe Array.join and goes out of scope. (#1205 holds that main's pass is the gate's bug; that is #1220's to fix, and this keeps main's behavior until then.) A closed call or meet of type Quant now goes out as the literal bend2's evaluator gives (quant_lit): the kernel would compute the same, so this is exact, unlike the &0 -> *(.Q1) fold this branch dropped. It applies wherever a term is known to be a Quant: a kind's quantity, a meet's sides, an argument at a Quant parameter, and any term bend2 annotated as one. Closedness is read first, on the variables with no value in scope, so an open term costs no normal form and nothing throws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lorenzobattistela
left a comment
There was a problem hiding this comment.
Thanks for this. I ran the PR merged onto current main (95217e9, which includes #1334's rework of book_promises). It merges cleanly and every gate passes:
- repo 50/50, ping 47/47, test 1561/1561, perf 124/124
- gates/safe.ts tests: same as main, plus your two new tests flagged unsafe as expected
Both new tests print ALL PROOFS CHECK on main, so they do catch the bug, and --verdict agrees with the new output. The demo and bench files report the same as before.
A few things before merging:
-
Missing coverage. The fix also catches an @unsafe call in a datatype's parameter types, which main misses:
type P<-A: Kind(qsize(Array.join(Nat, ALeaf{0n}, ALeaf{0n})))> is Type:
It passes on main and is rejected here with "- P". The issue's control case also changed:
type D is Kind(qv())now reports qv, D and use instead of only qv. Neither is pinned by a test, so a later rewrite could drop either one and the gates would still pass. Please add both. -
tests/check/unsafe_kind_empty.bend and unsafe_kind.bend could be one file. Declare D (with Mk and use), Zero and P together, and expect one combined list. Each test file costs its own check, and this is really one case seen from a few sides.
-
Both tests start with "# attack.bend — the identical expression inlined into the kind", copied from the issue. That names a file that isn't in the repo, and it's wrong for the zero-constructor case. Like unsafe_field.bend and unsafe_relies.bend, please open with a comment saying what is under test: an @unsafe reference reaching a datatype through its kind, its parameters, or with no constructors at all.
-
bend2/main.ts: the issue's one-liner is enough here:
for (const c of t.$ === "ADT" ? [t, ...t.c] : [t]) {
main.ts is under a permanent ttok cap, and the extra branch and second term_refs call cost tokens to save one small array per datatype, in a walk that runs once per check.
-
The doc comment on book_promises (main.ts:731) still lists only "type, body or constructor fields". Please add the datatype's kind and parameters. That list is the spec for what gets walked, and leaving kinds out of it is how #1205 happened.
-
GUIDE.md: please drop the new sentence. It sits in the BendTT theory paragraph and names a check the guide describes elsewhere (around lines 328-331), and it spends space under the guide's cap. If you think it's needed, fold "kinds" into the existing sentence there instead.
|
Checked the merged kind coverage with the real current kernel: the combined fixture flags D/use/Zero/P, and the qv control flags qv/D/use. The walk now reuses [t, ...t.c] and includes datatype kinds/parameter types, without the extra GUIDE sentence or a release-note change. Thanks for the full cluster verification and for consolidating the regression coverage. |
Fixes #1205.
book_promiseswalks every declaration's own type/kind before walking an ADT's constructor types. Empty datatypes receive the same check. The existing reverse dependency flood then marks the datatype and its consumers. The loops reuse existing arrays rather than allocating[t, ...t.c].Permanent regressions cover a kind-only
Array.joindependency with a constructor and consumer, and a zero-constructor datatype. The guide names kinds as part of the dependency check.Actual CLI/kernel verification on main 2.0.34:
--verdictreject the attack withD,use, and reject the empty variant withZero, exit 1.qv,D,useinstead of onlyqv. This differs from the issue's 2.0.32 note about the control's unchanged list, but preserves its rejection and follows the same transitive-dependency rule; no name-based special case.soundis not falsely reported.bun gates/repo.ts: PASS 49/49.No changes to
bend2/bend.ts; no caps changed.