Skip to content

Track unsafe dependencies in datatype kinds (#1205) - #1220

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/verdict-kind-dependencies
Oct 5, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/verdict-kind-dependencies

Conversation

@oxura

@oxura oxura commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #1205.

book_promises walks 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.join dependency 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:

  • Before: both the reported attack and the empty-constructor variant return ALL PROOFS CHECK from the real Lean-built BendTT kernel.
  • After: default verdict and --verdict reject the attack with D, use, and reject the empty variant with Zero, exit 1.
  • Reported def-body control remains rejected. On this snapshot, dependency reporting becomes complete: qv, D, use instead of only qv. 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.
  • Pure-kind and pure empty-kind controls pass the real kernel.
  • Existing constructor-field and def-type/body regressions retain their unsafe sets; sound is not falsely reported.
  • bun gates/repo.ts: PASS 49/49.

No changes to bend2/bend.ts; no caps changed.

@oxura

oxura commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Joint verification of #1215, #1216, #1218, #1219 and #1220 against main commit 0187512:

  • All five independent PR branches merge cleanly in one octopus merge. Documentation hunks were separated and shared wording shortened so the combined guide stays within the original cap.
  • Combined bun gates/repo.ts: PASS 49/49; no caps changed.
  • Real Lean 4.34.0-built BendTT kernel accepts all three new positive proof regressions, unchanged vec_safe_lookup, and the five reported grouping/label/model-search witnesses.
  • Four runtime regressions produce 5n, 6n, 7n, 204 on interpreter, emitted JS and native C. All four C programs were exercised with AddressSanitizer and UndefinedBehaviorSanitizer; no diagnostics.
  • The merged emitted fb3 value passes an added {main == (.False, ()) : Bool} oracle. The corresponding .True oracle fails in the actual kernel, so successful type-checking is not the only evidence of value preservation.
  • Kind-only and empty-datatype unsafe dependencies still reject with exit 1 and the expected dependency sets.
  • The genuinely required unavailable model rejects promptly; -o explicitly reports no model for reflexive~n as out of scope. Search-limit exhaustion remains fail-closed, not an unchecked placeholder.

The cluster-wide corpus gates were not run; this evidence is the local repository gate, actual CLI/compiler runs and actual kernel checks.

nicolas-abril added a commit that referenced this pull request Oct 5, 2026
… 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]>
nicolas-abril added a commit that referenced this pull request Oct 5, 2026
… 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]>
nicolas-abril added a commit that referenced this pull request Oct 5, 2026
… 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 Lorenzobattistela self-assigned this Oct 5, 2026

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  1. 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.

  2. 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.

@oxura

oxura commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The unsafe/foreign gate misses an @unsafe dependency that appears only in a datatype's is Kind(..)

2 participants