Repository navigation
Bound BendTT model search and retain finite alternatives (#1181) - #1218
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. |
|
Thanks for this. Comparing the path's types with term_compare is the right fix for the W overflow. But four files that pass --verdict on main fail on this branch:
Run time. The budget counts visits, but each visit runs a full term_compare against every entry on the path. The G case above makes about 466k comparisons per attempt, and Vec(120n) takes 0.51 s against main's 0.07 s. Two cheaper alternatives:
Also, a failing ~ constant is searched in root_cols and again in def_emit, so each "no model" pays for all four attempts. Suggestion. Instead of one shared budget plus a reorder, try iterative deepening: search in declaration order with a depth limit that grows each round, under the same total budget. That finds the shallowest model, keeps every model main picks today (fixing 2 and 3), and still ends Nest/Grow. It should also make the rebase with #1263, which changes the same function, simpler. Smaller points:
|
Keep nested model binders scoped, search constructors in declaration order across budgeted deepening rounds, and memoize spine comparisons within each probe. Report model exhaustion distinctly from kernel mismatches and pin real verdict regressions, including imported names.
This gives "no model (model search limit reached)". With fallback ??= v moved above the break, it checks in 88 ms.
is_c(r: R<Id(Nat)>) returns True{} for C and False{} for N. Main picks C{N{}} and checks; this PR picks N{} and fails with no model for t~ok. The cycle check only needs to see the same type again, not a convertible one. A comparison that doesn't unfold definitions, or a key without binder levels as #1181 suggested, would keep main's choices. It would also replace about 57 lines that copy compare_go and would drift from it.
The fallback also changes model choice quietly. With model_order's Choice at Vec(400n), the budget runs out while deepening and mk gets Shallow{}. The error then reads no model for choice_t~ok, with no limit hint, because the limit was hit on mk. Main checks that file in 107 ms. Please either size the budget so this doesn't happen in practice, or let a model-search limit leave the root's other constants out of scope with that reason, instead of handing out a fallback model.
The core is close: dropping the gate changes and fixing 2 and 3 should leave a small diff. Without the #> gate, though, nothing in CI checks the verdict for these cases, so please describe what you checked by hand in the PR body. |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s counted from the search's depth, and it deepens in declaration order under a fuel of visits and key characters (bendlang#1181) Narrow the PR to the fix bendlang#1181 needs: drop model_key's structural interner, the e.models cache, the later-constant limit rule, the out-of-scope CLI message and the tests for them. model_key is term_key on the lowered type with bound levels relative to d; a key's length counts against the fuel, so a nested type whose key doubles each level runs out instead of growing. Co-Authored-By: oxura <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Thanks for the detailed review and merged corrections. Checked the final implementation: declaration order is retained, iterative deepening uses the named 8-depth / 2^22 work budget, complete cut-round models are retained, the cycle key stays structural, and nested lambda binders are left for rebinding. No gate, cap, GUIDE or CLI-message changes remain in this PR. Fresh hand checks on upstream |
Fixes #1181.
Cause
A root with a
~parameter needs a model of that parameter's type.model_atinsafe.tsbuilds one by walking constructors. The issue's two shapes break that walk in two ways:W<(n => Nat)>withC{g: Nat -> W<F>}overflows the stack. The path that stops cycles keyed each datatype asterm_key(term_lower(F, d)). That key holds the absolute level of every binder insideF's arguments. A field under a∀raisesd, soW<F>never meets its own key again.Nest<A>withNCons{x: A, rest: Nest<Pair(A, A)>}grows memory without bound. Every step meets a genuinely new type, so no cycle check can end the walk. The type's key also doubles in size at each level.Change (
safe.tsonly)model_keyis the sameterm_key(term_lower(F, d)), except that levels at or abovedare written relative tod. A datatype under a∀field now meets its own key again. Free levels stay absolute, so they can't collide with bound ones.model_bykeeps declaration order and searches in rounds of doubling depth, fromMODEL_DEPTH = 8.MODEL_FUEL = 1 << 22is shared by all rounds. It counts a step per type visited and a step per character of each datatype key. A nested type whose key doubles at each level therefore runs out of fuel instead of memory. Running out means no model, so the def is out of scope.substat each use, instead of re-running the search from a closure. Only the outer levels are fixed; binders inside the body still rebind.Checks
On
b4a9a028, against main75cc3602:gates/test.ts: PASS 1536 / 1536 (main: 1531 / 1531).gates/perf.ts: 123 / 124, the same as main.gates/ping.ts: PASS 46 / 46, the same as main.gates/repo.ts: 48 / 49, the same as main. The failure isbend2/comp.tsat 64,251 tokens against its 64,000 cap, and this PR doesn't touchcomp.ts.safe.tsgoes from 21,139 to 21,624 tokens, under its 24k cap.gates/safe.ts tests: 988 agree, 2 out of scope, 1 false reject (agree_32, also on main). Compared file by file with main, all 1542 existing files give the same exit code and the same output bytes. The only new entries are the 5 new tests.--verdictresults on the issue's files and on the review's repros:W<(n => Nat)>andNest<Nat>: ALL PROOFS CHECK in about 0.1 s. On main they overflow the stack or run out of memory.Grow, onlyGCons): out of scope in about 0.2 s.~v: Vec(2000n): checks in 0.49 s.Tests
tests/proof/model_search.bend: the issue's two shapes, a nested proof λ, and a runtime check that prints7n.tests/proof/model_no_base.bend: a required model that doesn't exist.tests/proof/model_lambdas.bendandtests/proof/model_false.bend: a model λ's inner variables still bind, in both directions.tests/proof/model_order.bend: constructors are tried in declaration order, including the earlier deep constructor atVec(400n).No changes to
bend2/bend.ts, the gates or any caps.🤖 Generated with Claude Code
Fresh hand verification (Linux, upstream 237c722)
Built the current Book-map / UTF-8-parser Lean source using Lean 4.34.0 in a fresh isolated cache.
model_lambdas,model_order, andmodel_searchreportALL PROOFS CHECK. A separate combined review witness for G's finite leaf, B's complete fallback, R<Id(Nat)> versus R, and Vec at 130, 400, 600 and 2000 also reportsALL PROOFS CHECK. This is local hand verification, not a new cluster/gate claim.