Repository navigation
safe.ts: simplify; three small fixes - #1930
Merged
nicolas-abril merged 10 commits intoOct 29, 2026
Merged
Conversation
nicolas-abril
force-pushed
the
refactor/safe-simplify
branch
2 times, most recently
from
October 28, 2026 22:57
8d08447 to
1e0aad0
Compare
An Of<K> alias for Extract<HTerm, { $: K }>, and helpers beside the
ones there: vr(l) for the kernel variable, apps(f, xs) for a head at its
arguments (eight hand-written reduces), tup(xs) for a constructor's or a
selector's tuple, ann(e, s, o, T) for a term annotated unless the
kernel infers it (spine, let_term, rwt_term), wnf(e, T), fill(e, T, xs)
for B.tele_fill at no context, and tkey(t) for a closed term's key.
group_emit's selector types go through alls and apps. B.term_strip(t)
stands for open(t)[0], and a missing entry is `?? oos(..)`. quant and
mark are tables, as bend.ts's quant_show is. Locals no longer shadow
module functions (oos, pick, arm, args, tree, put).
safe_pass keeps the out-of-scope lines as it prints them, group_of is
inlined, args checks whether k is a name once, a few duplicate cases are
merged (o_show's ∀ and Σ, ctr_term's label, arm's scope_bind), and
one-liners are inlined. Scope and Safe comment each field in place of
one run-on list, the Model comment describes instead of instructing,
redundant parentheses go, and comments that repeat the header or read
garbled are rewritten. Five generic constructors are typed HTerm, so
safe.ts type-checks under bend2/pack's tsconfig.
-o emits the same BendTT, with the same messages, on all 1794 files of
tests/. safe.ts goes from 23996 to 23451 ttok.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
nicolas-abril
force-pushed
the
refactor/safe-simplify
branch
from
October 28, 2026 23:12
1e0aad0 to
11b5e5c
Compare
… kernel variable, for scope_kq and scope_bind's flag; the stack stands for going
…lab and node for the kernel's Ref, Lab and a case tree's node; arm always substitutes
… and tags go into its scope at once
…tree's λ copies through lams
…he trimmed output for both verdicts; copies is the one copy rule - swi's Efq default emits its λ pair at q again, as on main, not through pair_lams - kernel_check tests SOME PROOFS FAIL on the trimmed output, as it does ALL PROOFS CHECK - tree's λ takes its domain's weak head once, and only when it would rebuild - def_emit builds its no-model reason only when no model is found - item_ref checks a live cycle in the going set again, not a scan of the stack - wnf and fill take the book, so the Model section uses them at e.mb - ann's why is required; null makes the bare fallback explicit (rwt_term) - copies(e, q, b, ls) holds the copy rule of lams, pair_lams and let_term Co-Authored-By: Claude Opus 5.5 <[email protected]>
…node narrows; no shadowed locals - pair_lams copies a default's tag and fields whenever b uses either twice, at any q, as swi did before copies - quant is the ternary again, so a quantity it does not know reads as Many - node is a type guard - arg_term's lam is bare: a λ, a match, a refutation or a constructor - scope_hide copies kq only when it sets a quantity - o_uses' inner kept, apps' reduce f and model's find k no longer shadow Co-Authored-By: Claude Opus 5.5 <[email protected]>
…=0 default's tag refutes nothing and stays erased - rwt_term gives ann a reason, so evidence the kernel cannot infer and bend2 left unannotated is out of scope, not emitted bare for the kernel to reject; ann's why is a plain string again - swi's default refutes with its tag only at q > 0, as tree's λ does - pair_lams copies through copies at its own q, so a q=0 tag and fields stay erased Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #1896, to merge before it: the parts of that PR that only simplify
safe.ts, with nothing about η, a further cleanup pass, and three small fixes the reviews of it found (see Behaviour changes). Meant for a squash merge, so #1896 rebases cleanly after it.What
New helpers, beside the existing
alls,lamsandmats:Of<K>forExtract<HTerm, { $: K }>.vr(l),ref(k)andlab(k)for the kernel'sVar,RefandLab.apps(f, xs)for a head applied to its arguments, each at its quantity. It replaces eight hand-writtenreduces:root_emit's annotationadt_emit'sattree's convoy and dry matchargsgroup_callgroup_emitarmann(e, s, o, T, why)for a kernel term annotated atTunless the kernel infers it.spine,let_termandrwt_termeach spelled this out, with their own handling of a missingT. With noT,whyis the out-of-scope reason.tup(xs)for the tuple(x, y, .., ()).ctr_termbuilds constructors with it, andgroup_callbuilds selectors.wnf(b, T)forB.term_wnf(b, T)(27 uses).fill(b, T, xs)forB.tele_fill(b, T, xs, B.ctx_nil())(7 uses).e.mband the rest ate.book.tkey(t)forB.term_key(B.term_lower(t))(3 uses).node(x): a type guard for whetherxis a λ, a match or a refutation, whichtreeandarg_termeach tested by hand.pass(e, s, n, ps, live, qs)for a call's non-specialized arguments, each at its quantity.argsandgroup_callshare it.pair_lams(e, q, l, b)for a default arm's λs over its tag and fields.copies(e, q, b, ls):q, or 2 whenqis 1 andbuses one of the levelslstwice. This rule is now written once, forlams,pair_lamsandlet_term.scope_var(s, T, q)binds the next bend2 variable to a new kernel binder. It replacesscope_bind'skbflag andscope_kq.scope_hide(s, q)takes the binder's quantity directly.group_emitbuilds its selector types withallsandapps, instead of nesting the Σ and ∀ by hand.convoy_bindalways ends in a functionf(s), which every caller already built, instead of taking a tree and its chain too.A tree's λ goes through
lams, which handles the copy, instead of reassigningq.o_showando_useswalk with an inner closure.o_usesno longer threads its accumulator through its own signature.A binder's refutation and tag go into its scope as it is built, in
tree's λ andswi's default.Reuse and consistency:
B.term_strip(t)replacesopen(t)[0](9 uses).safe.ts'sopenstays for the uses that need the annotation too.x ?? oos(..), asspinealready did:item_emit,swi,term's variables andctr_term.markis a lookup table, asbend.ts'squant_showis.safe_pass'soosis nowgone;root_emit'spickis nowchosen;tree's andrebuild'sarmare nowhandbranch;group_call'sargsis nowpass;arg_term'streeis nowbare;let_term'sputis nowinl.Other changes:
safe_passkeeps the out-of-scope lines as it prints them (string[]), sosafe_book's two callers stop formatting[name, why]pairs.group_ofis inlined (e.groups.get).argschecks once whetherkis a name, instead of three times.modelfinds its fallback def withfind.kernel_checktrims the kernel's output once.def_emitbuilds its no-model reason apart from the term, and only when no model is found.tree's λ normalises its domain only when it might rebuild the λ, and only once.closed_valreads a variable's level once, instead of casting it four times.safe_bookruns one pass per loop round, with no repeated call in the loop header.def_emit's comment points to the header for how a def with no body goes out, instead of repeating it.Duplicate cases merged:
o_show's∀andΣ;ctr_termstarts its fields with the label;armcallsscope_bindonce.One-liners inlined (
o_refs,o_uses),.at(-1)for last elements, redundant parentheses and!== undefined && !== ""checks dropped.Comments:
ScopeandSafecomment each field in place, asbend.ts'sTermOfdoes, instead of one run-on list.Scopegainsd, which the list left out.tele_open's garbled sentence is rewritten;qsig_eqloses a clause that restated the rest;Safe's list now names the undo log and is rewrapped.Types: five generic constructors (
B.Var,B.App) are typedHTerm, sosafe.tstype-checks underbend2/pack'stsconfig.json. Onmainit has 5 errors there, and the rest ofbend2/is unchanged at 7.Behaviour changes
No file in
tests/reaches any of these; the output on all of them is unchanged (see Checks).kernel_checktestsSOME PROOFS FAILagainst the trimmed output, as it already didALL PROOFS CHECK. Output with leading whitespace before the failure line used to be an infrastructure error; it is now a verdict.a rewrite's evidence with no known type). Onmainit went out bare, the kernel rejected it, and--verdictreported a false reject.swi's default arm at q=0 no longer adds its tag to the refutations, astree's λ already did not. Its tag and fields stay at q=0 instead of becoming q=2 when the body uses one twice.Checks
-oon all 1794 files oftests/,main(4f99f4c) against this branch: the same BendTT and the same messages on every file.bunx tsc -p bend2/pack: no errors insafe.ts.bun gates/_run.ts: repo 54 / 54, test 1781 / 1781, perf 122 / 124 (pass), ping 80 / 81 (pass).safe.tsgoes from 23996 to 23289 ttok.bun gates/safe.ts tests: the same table asmain: agree 1143, unsafe 141, bend2 rejects 507, out of scope 3, false reject 0, timeout 0, infrastructure 0.🤖 Generated with Claude Code