gdp-wired 0.48.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/core/bmc.js +10 -7
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/check.js +7 -2
- package/dist/core/cli.js +3 -0
- package/dist/core/count-attempt-work.d.ts +29 -0
- package/dist/core/count-attempt-work.js +96 -0
- package/dist/core/count-boolean-partition.d.ts +5 -0
- package/dist/core/count-boolean-partition.js +47 -0
- package/dist/core/count-bounded-quotient.d.ts +2 -0
- package/dist/core/count-bounded-quotient.js +13 -0
- package/dist/core/count-case-compose.d.ts +20 -0
- package/dist/core/count-case-compose.js +289 -0
- package/dist/core/count-cases.js +3 -2
- package/dist/core/count-cert-rename.d.ts +10 -0
- package/dist/core/count-cert-rename.js +69 -0
- package/dist/core/count-cert-transport.d.ts +10 -2
- package/dist/core/count-cert-transport.js +60 -9
- package/dist/core/count-certificate-minimize.d.ts +57 -0
- package/dist/core/count-certificate-minimize.js +263 -0
- package/dist/core/count-closed-family.d.ts +32 -0
- package/dist/core/count-closed-family.js +143 -0
- package/dist/core/count-closing-budget.d.ts +10 -0
- package/dist/core/count-closing-budget.js +49 -0
- package/dist/core/count-closing-needs.d.ts +5 -0
- package/dist/core/count-closing-needs.js +9 -0
- package/dist/core/count-component-budget.d.ts +5 -0
- package/dist/core/count-component-budget.js +9 -0
- package/dist/core/count-copy-shape.d.ts +11 -0
- package/dist/core/count-copy-shape.js +40 -0
- package/dist/core/count-disjoint-funding.d.ts +75 -0
- package/dist/core/count-disjoint-funding.js +284 -0
- package/dist/core/count-emitter-frame-pool.d.ts +23 -0
- package/dist/core/count-emitter-frame-pool.js +87 -0
- package/dist/core/count-final-step.d.ts +5 -0
- package/dist/core/count-final-step.js +20 -0
- package/dist/core/count-fixed-frame.d.ts +4 -0
- package/dist/core/count-fixed-frame.js +30 -0
- package/dist/core/count-frames.d.ts +25 -0
- package/dist/core/count-frames.js +118 -0
- package/dist/core/count-frozen-guard.d.ts +2 -0
- package/dist/core/count-frozen-guard.js +31 -0
- package/dist/core/count-generation-phase.d.ts +7 -0
- package/dist/core/count-generation-phase.js +33 -0
- package/dist/core/count-guard-composition.d.ts +12 -0
- package/dist/core/count-guard-composition.js +48 -0
- package/dist/core/count-guard-context.d.ts +11 -0
- package/dist/core/count-guard-context.js +50 -0
- package/dist/core/count-guard-facts.d.ts +50 -0
- package/dist/core/count-guard-facts.js +97 -0
- package/dist/core/count-guard-proposals.d.ts +7 -0
- package/dist/core/count-guard-proposals.js +106 -0
- package/dist/core/count-guard-shape.d.ts +18 -0
- package/dist/core/count-guard-shape.js +100 -0
- package/dist/core/count-guard-tree.d.ts +17 -0
- package/dist/core/count-guard-tree.js +125 -0
- package/dist/core/count-leader-facts.d.ts +10 -0
- package/dist/core/count-leader-facts.js +52 -0
- package/dist/core/count-leader.d.ts +10 -0
- package/dist/core/count-leader.js +331 -0
- package/dist/core/count-lemma-transport.d.ts +8 -0
- package/dist/core/count-lemma-transport.js +47 -0
- package/dist/core/count-lifted-budget.d.ts +54 -0
- package/dist/core/count-lifted-budget.js +97 -0
- package/dist/core/count-lifted-copy.d.ts +3 -0
- package/dist/core/count-lifted-copy.js +166 -0
- package/dist/core/count-lifted-increment.d.ts +3 -0
- package/dist/core/count-lifted-increment.js +146 -0
- package/dist/core/count-lifted-load.d.ts +5 -0
- package/dist/core/count-lifted-load.js +179 -0
- package/dist/core/count-lifted-prerequisite.d.ts +14 -0
- package/dist/core/count-lifted-prerequisite.js +53 -0
- package/dist/core/count-lifted-replacement.d.ts +3 -0
- package/dist/core/count-lifted-replacement.js +540 -0
- package/dist/core/count-lifted-shape.d.ts +63 -0
- package/dist/core/count-lifted-shape.js +115 -0
- package/dist/core/count-lifted-strategy.d.ts +7 -0
- package/dist/core/count-lifted-strategy.js +226 -0
- package/dist/core/count-lifted-transports.d.ts +32 -0
- package/dist/core/count-lifted-transports.js +293 -0
- package/dist/core/count-load-shape.d.ts +17 -0
- package/dist/core/count-load-shape.js +67 -0
- package/dist/core/count-minimal-view.d.ts +26 -0
- package/dist/core/count-minimal-view.js +46 -0
- package/dist/core/count-operation-observation.d.ts +9 -0
- package/dist/core/count-operation-observation.js +22 -0
- package/dist/core/count-operation-order.d.ts +5 -0
- package/dist/core/count-operation-order.js +4 -0
- package/dist/core/count-phase.d.ts +9 -0
- package/dist/core/count-phase.js +127 -0
- package/dist/core/count-premise-search.d.ts +9 -0
- package/dist/core/count-premise-search.js +41 -0
- package/dist/core/count-premise-view.d.ts +19 -0
- package/dist/core/count-premise-view.js +220 -0
- package/dist/core/count-prerequisite-components.d.ts +67 -0
- package/dist/core/count-prerequisite-components.js +239 -0
- package/dist/core/count-prerequisite-memory.d.ts +24 -0
- package/dist/core/count-prerequisite-memory.js +37 -0
- package/dist/core/count-prerequisite-plan.d.ts +12 -0
- package/dist/core/count-prerequisite-plan.js +88 -0
- package/dist/core/count-primitive-budget.d.ts +1 -0
- package/dist/core/count-primitive-budget.js +8 -0
- package/dist/core/count-project-free.d.ts +3 -0
- package/dist/core/count-project-free.js +24 -0
- package/dist/core/count-project-witness.d.ts +4 -0
- package/dist/core/count-project-witness.js +48 -0
- package/dist/core/count-proof-rescope.d.ts +14 -0
- package/dist/core/count-proof-rescope.js +71 -0
- package/dist/core/count-proof-scope.d.ts +68 -0
- package/dist/core/count-proof-scope.js +333 -0
- package/dist/core/count-prune-owned-root.d.ts +5 -0
- package/dist/core/count-prune-owned-root.js +27 -0
- package/dist/core/count-query-context.d.ts +3 -0
- package/dist/core/count-query-context.js +7 -0
- package/dist/core/count-query.d.ts +15 -0
- package/dist/core/count-query.js +59 -0
- package/dist/core/count-quorum-leaf.d.ts +9 -0
- package/dist/core/count-quorum-leaf.js +38 -0
- package/dist/core/count-reachability-budget.d.ts +1 -0
- package/dist/core/count-reachability-budget.js +7 -0
- package/dist/core/count-reachability-reconcile.d.ts +11 -0
- package/dist/core/count-reachability-reconcile.js +19 -0
- package/dist/core/count-reachability.d.ts +50 -0
- package/dist/core/count-reachability.js +351 -0
- package/dist/core/count-rebase-path.d.ts +9 -0
- package/dist/core/count-rebase-path.js +68 -0
- package/dist/core/count-recipe-context.d.ts +45 -0
- package/dist/core/count-recipe-context.js +71 -0
- package/dist/core/count-recipe-controller.d.ts +115 -0
- package/dist/core/count-recipe-controller.js +417 -0
- package/dist/core/count-recipe-graph.d.ts +36 -0
- package/dist/core/count-recipe-graph.js +211 -0
- package/dist/core/count-recovery/conditional-check-cache.js +3 -2
- package/dist/core/count-recovery/conditional-cuts.js +5 -4
- package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
- package/dist/core/count-recovery/conditional-proof.js +72 -30
- package/dist/core/count-recovery/derivability-closure.js +2 -1
- package/dist/core/count-recovery/guard-cases.js +2 -1
- package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
- package/dist/core/count-recovery/reframe-tree.js +24 -0
- package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
- package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
- package/dist/core/count-recovery/row-cases.js +2 -1
- package/dist/core/count-rejection-budget.d.ts +8 -0
- package/dist/core/count-rejection-budget.js +15 -0
- package/dist/core/count-replacement.d.ts +5 -0
- package/dist/core/count-replacement.js +129 -0
- package/dist/core/count-replay-diagnostic.d.ts +21 -0
- package/dist/core/count-replay-diagnostic.js +49 -0
- package/dist/core/count-replay-skeleton.d.ts +4 -0
- package/dist/core/count-replay-skeleton.js +28 -0
- package/dist/core/count-rescope-funding.d.ts +3 -0
- package/dist/core/count-rescope-funding.js +17 -0
- package/dist/core/count-restrictions.d.ts +11 -0
- package/dist/core/count-restrictions.js +31 -0
- package/dist/core/count-retry-budget.d.ts +67 -0
- package/dist/core/count-retry-budget.js +114 -0
- package/dist/core/count-retry-round.d.ts +24 -0
- package/dist/core/count-retry-round.js +44 -0
- package/dist/core/count-row-agreement.d.ts +35 -0
- package/dist/core/count-row-agreement.js +270 -0
- package/dist/core/count-row-aliases.d.ts +3 -0
- package/dist/core/count-row-aliases.js +59 -0
- package/dist/core/count-row-composition.d.ts +6 -0
- package/dist/core/count-row-composition.js +55 -0
- package/dist/core/count-row-copy-linear.d.ts +4 -0
- package/dist/core/count-row-copy-linear.js +83 -0
- package/dist/core/count-row-copy.d.ts +4 -0
- package/dist/core/count-row-copy.js +94 -0
- package/dist/core/count-row-policy.d.ts +3 -0
- package/dist/core/count-row-policy.js +56 -0
- package/dist/core/count-row-reindex.d.ts +11 -0
- package/dist/core/count-row-reindex.js +126 -0
- package/dist/core/count-row-support.d.ts +9 -0
- package/dist/core/count-row-support.js +42 -0
- package/dist/core/count-row-symmetry.d.ts +7 -0
- package/dist/core/count-row-symmetry.js +100 -0
- package/dist/core/count-scope-hyps.d.ts +2 -0
- package/dist/core/count-scope-hyps.js +163 -0
- package/dist/core/count-scope-row-reuse.d.ts +3 -0
- package/dist/core/count-scope-row-reuse.js +92 -0
- package/dist/core/count-search-allowance.d.ts +1 -0
- package/dist/core/count-search-allowance.js +17 -0
- package/dist/core/count-stabilize-tree.d.ts +9 -0
- package/dist/core/count-stabilize-tree.js +35 -0
- package/dist/core/count-stage-trace.d.ts +8 -0
- package/dist/core/count-stage-trace.js +45 -0
- package/dist/core/count-strategies.d.ts +16 -0
- package/dist/core/count-strategies.js +155 -0
- package/dist/core/count-strategy-premises.d.ts +5 -0
- package/dist/core/count-strategy-premises.js +14 -0
- package/dist/core/count-strategy.d.ts +41 -0
- package/dist/core/count-strategy.js +76 -0
- package/dist/core/count-support.d.ts +1 -0
- package/dist/core/count-support.js +26 -4
- package/dist/core/count-tier-budget.d.ts +14 -0
- package/dist/core/count-tier-budget.js +64 -0
- package/dist/core/count-unwritten-prefix.d.ts +24 -0
- package/dist/core/count-unwritten-prefix.js +97 -0
- package/dist/core/count-write-shape.d.ts +15 -0
- package/dist/core/count-write-shape.js +73 -0
- package/dist/core/counted-candidate-seeds.d.ts +12 -0
- package/dist/core/counted-candidate-seeds.js +31 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +999 -129
- package/dist/core/cycles.js +5 -4
- package/dist/core/cyclic.js +11 -10
- package/dist/core/data.js +16 -15
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +27 -0
- package/dist/core/dsl.d.ts +32 -2
- package/dist/core/dsl.js +202 -64
- package/dist/core/evaluation-admission.d.ts +1 -0
- package/dist/core/evaluation-admission.js +3 -0
- package/dist/core/exists.d.ts +6 -1
- package/dist/core/exists.js +53 -10
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +159 -3
- package/dist/core/finite-houdini.d.ts +6 -0
- package/dist/core/finite-houdini.js +63 -21
- package/dist/core/finite-tiny.js +95 -67
- package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
- package/dist/core/fresh.js +5 -1
- package/dist/core/infer.js +49 -33
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/lift-cli.d.ts +11 -0
- package/dist/core/lift-cli.js +113 -0
- package/dist/core/linear-admission.d.ts +14 -0
- package/dist/core/linear-admission.js +151 -0
- package/dist/core/machine.d.ts +5 -2
- package/dist/core/machine.js +105 -31
- package/dist/core/meter.d.ts +22 -0
- package/dist/core/meter.js +34 -0
- package/dist/core/nonterm.js +4 -3
- package/dist/core/proof-output.d.ts +53 -0
- package/dist/core/proof-output.js +38 -0
- package/dist/core/prover-row-budget.d.ts +3 -0
- package/dist/core/prover-row-budget.js +106 -0
- package/dist/core/quorum-laws.d.ts +21 -1
- package/dist/core/quorum-laws.js +80 -17
- package/dist/core/rationals.js +3 -2
- package/dist/core/rejection-discovery.d.ts +34 -0
- package/dist/core/rejection-discovery.js +36 -0
- package/dist/core/rejection-stage.d.ts +39 -0
- package/dist/core/rejection-stage.js +205 -0
- package/dist/core/request-quotient.d.ts +8 -0
- package/dist/core/request-quotient.js +299 -0
- package/dist/core/row-agreement-shape.d.ts +15 -0
- package/dist/core/row-agreement-shape.js +68 -0
- package/dist/core/runtime-wall.d.ts +2 -0
- package/dist/core/search-policy.d.ts +15 -0
- package/dist/core/search-policy.js +68 -0
- package/dist/core/solver.d.ts +1 -1
- package/dist/core/solver.js +40 -6
- package/dist/core/step-work.d.ts +12 -0
- package/dist/core/step-work.js +14 -0
- package/dist/core/strategy-premises.d.ts +8 -0
- package/dist/core/strategy-premises.js +64 -0
- package/dist/core/system.js +4 -3
- package/dist/core/table-admission.d.ts +1 -0
- package/dist/core/table-admission.js +3 -0
- package/dist/core/trace-clock.d.ts +3 -0
- package/dist/core/trace-clock.js +16 -0
- package/dist/core/transfer.js +3 -2
- package/dist/core/translate.js +16 -3
- package/dist/core/wall.d.ts +6 -1
- package/dist/core/wall.js +23 -9
- package/dist/core/watch.d.ts +1 -1
- package/dist/core/watch.js +13 -4
- package/dist/core/work-admission.d.ts +164 -0
- package/dist/core/work-admission.js +418 -0
- package/dist/core/work-amount.d.ts +21 -0
- package/dist/core/work-amount.js +80 -0
- package/dist/core/work-collections.d.ts +11 -0
- package/dist/core/work-collections.js +198 -0
- package/dist/core/work-kinds.d.ts +11 -0
- package/dist/core/work-kinds.js +9 -0
- package/dist/core/work-meter.d.ts +8 -0
- package/dist/core/work-meter.js +83 -0
- package/dist/core/work-observe.d.ts +12 -0
- package/dist/core/work-observe.js +39 -0
- package/dist/core/work-profile.d.ts +10 -0
- package/dist/core/work-profile.js +21 -0
- package/dist/core/work-refusal.d.ts +1 -0
- package/dist/core/work-refusal.js +6 -0
- package/dist/interchange/format.js +2 -0
- package/dist/kernel/cdcl.js +93 -40
- package/dist/kernel/epr.js +23 -8
- package/dist/kernel/function-instances.d.ts +45 -0
- package/dist/kernel/function-instances.js +460 -0
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +61 -6
- package/dist/kernel/prove.js +625 -205
- package/dist/kernel/prover-rows.d.ts +1 -0
- package/dist/kernel/prover-rows.js +12 -1
- package/dist/kernel/reader.d.ts +1 -1
- package/dist/kernel/reader.js +57 -12
- package/dist/kernel/simplex.js +9 -2
- package/dist/lean-kernel/axiom-audit.d.ts +11 -0
- package/dist/lean-kernel/axiom-audit.js +50 -0
- package/dist/lean-kernel/emit.d.ts +34 -3
- package/dist/lean-kernel/emit.js +215 -28
- package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-library.js +5 -0
- package/dist/lean-kernel/legacy-family-order.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-order.js +26 -0
- package/dist/lean-kernel/library.js +25 -3
- package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
- package/dist/lean-kernel/lift/counted-source-data.js +78 -0
- package/dist/lean-kernel/lift/index.d.ts +82 -0
- package/dist/lean-kernel/lift/index.js +116 -0
- package/dist/lean-kernel/lift/project.d.ts +4 -0
- package/dist/lean-kernel/lift/project.js +15 -0
- package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
- package/dist/lean-kernel/lift/proof-capture.js +216 -0
- package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
- package/dist/lean-kernel/lift/proof-codec.js +299 -0
- package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
- package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
- package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
- package/dist/lean-kernel/lift/proof-frontier.js +153 -0
- package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
- package/dist/lean-kernel/lift/proof-graph.js +130 -0
- package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
- package/dist/lean-kernel/lift/proof-parts.js +131 -0
- package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
- package/dist/lean-kernel/lift/proof-prelude.js +38 -0
- package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
- package/dist/lean-kernel/lift/proof-witness.js +283 -0
- package/dist/lean-kernel/lift/shape.d.ts +5 -0
- package/dist/lean-kernel/lift/shape.js +57 -0
- package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
- package/dist/lean-kernel/lift/source-projection.js +81 -0
- package/dist/lean-kernel/lift/source.d.ts +23 -0
- package/dist/lean-kernel/lift/source.js +111 -0
- package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
- package/dist/lean-kernel/lift/witness-alpha.js +31 -0
- package/dist/lean-kernel/lift-legacy.d.ts +58 -0
- package/dist/lean-kernel/lift-legacy.js +84 -0
- package/dist/lean-kernel/lift-names.d.ts +22 -0
- package/dist/lean-kernel/lift-names.js +36 -0
- package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
- package/dist/lean-kernel/lift-simulation/index.js +352 -0
- package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
- package/dist/lean-kernel/lift-simulation/shape.js +173 -0
- package/dist/lean-kernel/lift-special/index.d.ts +36 -0
- package/dist/lean-kernel/lift-special/index.js +241 -0
- package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
- package/dist/lean-kernel/lift-special/structural.js +126 -0
- package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
- package/dist/lean-kernel/lift-typed/index.js +256 -0
- package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
- package/dist/lean-kernel/lift-typed/roles.js +170 -0
- package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
- package/dist/lean-kernel/lift-typed/shape.js +12 -0
- package/dist/lean-kernel/lift.d.ts +30 -0
- package/dist/lean-kernel/lift.js +97 -0
- package/package.json +5 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// A proposer only: late-added guarded facts can change input-row indices.
|
|
2
|
+
// Reindex complete branch proofs against the final facts, then check them.
|
|
3
|
+
import { canon, check, framePath } from "../kernel/kernel.js";
|
|
4
|
+
import { late } from "../kernel/prove.js";
|
|
5
|
+
import { rebasePath } from "./count-rebase-path.js";
|
|
6
|
+
export function stabilizeGuardedTree(goal, tree, frames, lins, roots, until, options = {}) {
|
|
7
|
+
let rebased = 0, failed = false;
|
|
8
|
+
const visit = (t, path) => {
|
|
9
|
+
if (late(until)) {
|
|
10
|
+
failed = true;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const before = roots.get(t);
|
|
14
|
+
if (before) {
|
|
15
|
+
const after = framePath(frames, options.lemmas ?? [], path, [], lins);
|
|
16
|
+
if (!options.deferCheck && check(goal, t, after))
|
|
17
|
+
return t;
|
|
18
|
+
const fixed = rebasePath(goal, t, before, after, until);
|
|
19
|
+
if (fixed && (options.deferCheck || check(goal, fixed, after))) {
|
|
20
|
+
rebased++;
|
|
21
|
+
return fixed;
|
|
22
|
+
}
|
|
23
|
+
failed = true;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if ('leaf' in t) {
|
|
27
|
+
failed = true;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const id = canon(t.split), yes = visit(t.yes, new Map(path).set(id, { lin: t.split, holds: true }));
|
|
31
|
+
const no = yes && visit(t.no, new Map(path).set(id, { lin: t.split, holds: false }));
|
|
32
|
+
return yes && no ? { split: t.split, yes, no } : undefined;
|
|
33
|
+
};
|
|
34
|
+
return { tree: visit(tree, new Map()), rebased, failed };
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type CountStageRole = 'untrusted-assembly' | 'untrusted-search' | 'trusted-check';
|
|
2
|
+
export type CountStageObserver = (event: Record<string, unknown>) => void;
|
|
3
|
+
export declare function countStageTrace(observe?: CountStageObserver, total?: string): {
|
|
4
|
+
mark(part: string, role: CountStageRole, value?: number): void;
|
|
5
|
+
pause: () => void;
|
|
6
|
+
finish(): void;
|
|
7
|
+
};
|
|
8
|
+
export declare function traceCountStage<T>(observe: CountStageObserver | undefined, part: string, role: CountStageRole, run: () => T): T;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Observation only: never a budget, proof, or authorization. No clock is read
|
|
2
|
+
// without an observer. Native checks remain in their original call sites.
|
|
3
|
+
import { fullRate, fullWork } from "../kernel/prove.js";
|
|
4
|
+
import { traceNow } from "./trace-clock.js";
|
|
5
|
+
export function countStageTrace(observe, total) {
|
|
6
|
+
const now = () => ({ wall: traceNow(), work: fullWork() });
|
|
7
|
+
const begin = observe ? now() : undefined;
|
|
8
|
+
let current, finished = false;
|
|
9
|
+
const close = () => {
|
|
10
|
+
if (!observe || !current)
|
|
11
|
+
return;
|
|
12
|
+
const end = now(), { part, role, value, at } = current;
|
|
13
|
+
current = undefined;
|
|
14
|
+
observe({ stage: 'tail', part, role, ...(value === undefined ? {} : { value }), wallMs: end.wall - at.wall, units: (end.work - at.work) / fullRate });
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
mark(part, role, value) {
|
|
18
|
+
if (!observe || finished)
|
|
19
|
+
return;
|
|
20
|
+
close();
|
|
21
|
+
current = { part, role, value, at: now() };
|
|
22
|
+
},
|
|
23
|
+
pause: close,
|
|
24
|
+
finish() {
|
|
25
|
+
if (finished)
|
|
26
|
+
return;
|
|
27
|
+
finished = true;
|
|
28
|
+
close();
|
|
29
|
+
if (!observe || !begin || !total)
|
|
30
|
+
return;
|
|
31
|
+
const end = now();
|
|
32
|
+
observe({ stage: 'tail', part: total, aggregate: true, wallMs: end.wall - begin.wall, units: (end.work - begin.work) / fullRate });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function traceCountStage(observe, part, role, run) {
|
|
37
|
+
const trace = countStageTrace(observe);
|
|
38
|
+
trace.mark(part, role);
|
|
39
|
+
try {
|
|
40
|
+
return run();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
trace.finish();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type CountRequestBuilder, type CountStrategyProof } from './count-strategy.js';
|
|
3
|
+
import { type LiftedWorkBudget } from './count-lifted-budget.js';
|
|
4
|
+
export declare function assertLiftedWorkLease(plan: LiftedWorkBudget | undefined | null): asserts plan is LiftedWorkBudget;
|
|
5
|
+
export declare function prepareCountStrategyMachine(m: Machine, family: Law[], until: number, observe?: (event: Record<string, unknown>) => void): Machine;
|
|
6
|
+
export declare function countStrategyKind(m: Machine, family: Law[], law: Law): 'row' | 'guard' | 'lifted' | undefined;
|
|
7
|
+
export declare function selectedCountStrategies(m: Machine, family: Law[]): Law[];
|
|
8
|
+
export declare function proveCountStrategyPool(m: Machine, family: Law[], until: number, request: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, workAllowance?: number): {
|
|
9
|
+
proofs: Map<string, CountStrategyProof>;
|
|
10
|
+
declined: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function proveCountStrategies(m: Machine, family: Law[], law: Law, until: number, request: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, workAllowance?: number, shapeFamily?: readonly Law[], liftedBudget?: LiftedWorkBudget): CountStrategyProof | undefined;
|
|
13
|
+
export declare function proposeCountStrategiesForClosing(m: Machine, family: Law[], law: Law, until: number, request: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, workAllowance?: number, shapeFamily?: readonly Law[], liftedBudget?: LiftedWorkBudget): CountStrategyProof | undefined;
|
|
14
|
+
export type NonLiftedCountStrategyKind = 'row' | 'guard';
|
|
15
|
+
export declare function proveCountStrategyKind(kind: NonLiftedCountStrategyKind, m: Machine, family: Law[], law: Law, until: number, request: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, workAllowance?: number, shapeFamily?: readonly Law[]): CountStrategyProof | undefined;
|
|
16
|
+
export declare function proposeCountStrategyKindForClosing(kind: NonLiftedCountStrategyKind, m: Machine, family: Law[], law: Law, until: number, request: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, workAllowance?: number, shapeFamily?: readonly Law[]): CountStrategyProof | undefined;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { familyStepProposal, finalCountStepDeferralEnabled } from "./count-final-step.js";
|
|
2
|
+
import { strategyLeafUnits } from "./count-strategy.js";
|
|
3
|
+
import { discoverRowAgreement } from "./row-agreement-shape.js";
|
|
4
|
+
import { discoverLiftedCountGuard } from "./count-lifted-shape.js";
|
|
5
|
+
import { discoverLiftedCountPrerequisites } from "./count-lifted-prerequisite.js";
|
|
6
|
+
import { proveLiftedCountComposition } from "./count-lifted-strategy.js";
|
|
7
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
8
|
+
import { workLedger } from "./work-admission.js";
|
|
9
|
+
import { prepareGuardCountContext } from "./count-guard-context.js";
|
|
10
|
+
import { proveCountRowComposition } from "./count-row-composition.js";
|
|
11
|
+
import { proveCountGuardComposition } from "./count-guard-composition.js";
|
|
12
|
+
import { clock, fullRate, fullWork, late, withDeadline } from "../kernel/prove.js";
|
|
13
|
+
import { env } from "./solver.js";
|
|
14
|
+
// Omitting the optional argument keeps legacy callers legal. Supplying an exact
|
|
15
|
+
// argument (including undefined/null at runtime) must never select that path.
|
|
16
|
+
export function assertLiftedWorkLease(plan) {
|
|
17
|
+
if (!plan || typeof plan !== 'object' || Array.isArray(plan) || !plan.lease || !completeWorkProfile.enabled || !workLedger.inBudget())
|
|
18
|
+
throw new Error('exact lifted dispatch requires a live FULL lease plan');
|
|
19
|
+
}
|
|
20
|
+
// Install only conservative count definitions, once before the family's attempts.
|
|
21
|
+
// Candidate generation is already finished: no extra law or trusted fact is added.
|
|
22
|
+
export function prepareCountStrategyMachine(m, family, until, observe) {
|
|
23
|
+
return withDeadline(until, () => {
|
|
24
|
+
let machine = m;
|
|
25
|
+
for (const law of family) {
|
|
26
|
+
if (late(until))
|
|
27
|
+
break;
|
|
28
|
+
const context = prepareGuardCountContext(machine, law, family);
|
|
29
|
+
if (context)
|
|
30
|
+
machine = context.machine;
|
|
31
|
+
}
|
|
32
|
+
const added = Object.keys(machine.counts ?? {}).filter(name => !m.counts?.[name]).length;
|
|
33
|
+
observe?.({ added });
|
|
34
|
+
return machine;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const liftedSelected = (m, family, law) => env.GDP_COUNT_LIFTED === '1' && family.includes(law) && discoverLiftedCountGuard(m, law, family) && (env.GDP_COUNT_LIFTED_PREREQUISITES !== '1' || discoverLiftedCountPrerequisites(m, law, family).length > 0);
|
|
38
|
+
// Shape discovery is scheduling only; it does not authorize a proof or a premise.
|
|
39
|
+
export function countStrategyKind(m, family, law) {
|
|
40
|
+
if (discoverRowAgreement(m, law))
|
|
41
|
+
return 'row';
|
|
42
|
+
if (liftedSelected(m, family, law))
|
|
43
|
+
return 'lifted';
|
|
44
|
+
if (prepareGuardCountContext(m, law, family))
|
|
45
|
+
return 'guard';
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
// Structural dispatch only; this admits no proof or premise.
|
|
49
|
+
export function selectedCountStrategies(m, family) {
|
|
50
|
+
return family.filter(law => !!countStrategyKind(m, family, law));
|
|
51
|
+
}
|
|
52
|
+
// The caller owns allocation (for example the tier budget); every law and case
|
|
53
|
+
// consumes this one absolute end. Unused pool time is never reserved here.
|
|
54
|
+
export function proveCountStrategyPool(m, family, until, request, observe, workAllowance = Math.max(0, until - clock())) {
|
|
55
|
+
return withDeadline(until, () => {
|
|
56
|
+
const proofs = new Map(), declined = [];
|
|
57
|
+
if (late(until))
|
|
58
|
+
return { proofs, declined };
|
|
59
|
+
const selected = family.map(law => ({ law, kind: countStrategyKind(m, family, law) })).filter(row => row.kind);
|
|
60
|
+
selected.sort((a, b) => Number(a.kind === 'row') - Number(b.kind === 'row'));
|
|
61
|
+
if (env.GDP_COUNT_LIFTED_PREREQUISITES === '1') {
|
|
62
|
+
const ranked = selected.filter(row => row.kind === 'lifted').map(row => ({ ...row, size: discoverLiftedCountPrerequisites(m, row.law, family)[0]?.bodyNodes ?? 0 })).sort((a, b) => b.size - a.size);
|
|
63
|
+
let next = 0;
|
|
64
|
+
for (let i = 0; i < selected.length; i++)
|
|
65
|
+
if (selected[i].kind === 'lifted')
|
|
66
|
+
selected[i] = ranked[next++];
|
|
67
|
+
}
|
|
68
|
+
for (const { law } of selected) {
|
|
69
|
+
if (late(until))
|
|
70
|
+
break;
|
|
71
|
+
const start = fullWork();
|
|
72
|
+
const proof = proveCountStrategies(m, family, law, until, request, event => observe?.({ law: law.name, end: until, ...event }), workAllowance);
|
|
73
|
+
if (proof)
|
|
74
|
+
proofs.set(law.name, proof);
|
|
75
|
+
else
|
|
76
|
+
declined.push(law.name);
|
|
77
|
+
observe?.({ stage: 'pool-law', law: law.name, end: until, checked: !!proof, units: (fullWork() - start) / fullRate });
|
|
78
|
+
}
|
|
79
|
+
return { proofs, declined };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export function proveCountStrategies(m, family, law, until, request, observe, workAllowance = Math.max(0, until - clock()), shapeFamily, liftedBudget) {
|
|
83
|
+
if (arguments.length >= 9)
|
|
84
|
+
assertLiftedWorkLease(liftedBudget);
|
|
85
|
+
return countStrategies(m, family, law, until, request, observe, workAllowance, undefined, shapeFamily, liftedBudget);
|
|
86
|
+
}
|
|
87
|
+
// Internal construction path: an explicit proposal, never a checked verdict.
|
|
88
|
+
export function proposeCountStrategiesForClosing(m, family, law, until, request, observe, workAllowance = Math.max(0, until - clock()), shapeFamily, liftedBudget) {
|
|
89
|
+
if (arguments.length >= 9)
|
|
90
|
+
assertLiftedWorkLease(liftedBudget);
|
|
91
|
+
return countStrategies(m, family, law, until, request, observe, workAllowance, finalCountStepDeferralEnabled() ? familyStepProposal : undefined, shapeFamily, liftedBudget);
|
|
92
|
+
}
|
|
93
|
+
// The recipe ID is authority to select only this non-lifted constructor. These
|
|
94
|
+
// entry points can never silently dispatch the numeric lifted legacy path.
|
|
95
|
+
export function proveCountStrategyKind(kind, m, family, law, until, request, observe, workAllowance = Math.max(0, until - clock()), shapeFamily) {
|
|
96
|
+
return countStrategies(m, family, law, until, request, observe, workAllowance, undefined, shapeFamily, undefined, kind);
|
|
97
|
+
}
|
|
98
|
+
export function proposeCountStrategyKindForClosing(kind, m, family, law, until, request, observe, workAllowance = Math.max(0, until - clock()), shapeFamily) {
|
|
99
|
+
return countStrategies(m, family, law, until, request, observe, workAllowance, finalCountStepDeferralEnabled() ? familyStepProposal : undefined, shapeFamily, undefined, kind);
|
|
100
|
+
}
|
|
101
|
+
function countStrategies(m, family, law, until, request, observe, workAllowance, familyProposal, shapeFamily, liftedBudget, requestedKind) {
|
|
102
|
+
// The segmented-owner path remains explicit/unactivated in the controller.
|
|
103
|
+
// Discovery is non-case body work; do not wrap the lifted callback (and its
|
|
104
|
+
// cases) in that body segment. Row/guard cannot enter a lifted owner plan.
|
|
105
|
+
if (liftedBudget?.lease?.owners) {
|
|
106
|
+
if (!liftedBudget.lease.owners.ownsBank(workLedger))
|
|
107
|
+
throw new Error('lifted owners require the native work ledger');
|
|
108
|
+
const selected = liftedBudget.lease.owners.body(() => {
|
|
109
|
+
assertLiftedWorkLease(liftedBudget);
|
|
110
|
+
if (countStrategyKind(m, family, law) !== 'lifted')
|
|
111
|
+
return false;
|
|
112
|
+
observe?.({ strategy: 'lifted', stage: 'selected' });
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
return selected ? proveLiftedCountComposition(m, family, law, Infinity, request, event => observe?.({ strategy: 'lifted', ...event }), liftedBudget) : undefined;
|
|
116
|
+
}
|
|
117
|
+
// The exact path is explicit and requires the caller's live inherited bank.
|
|
118
|
+
// A missing/invalid plan never silently re-enters the numeric legacy path.
|
|
119
|
+
if (liftedBudget) {
|
|
120
|
+
assertLiftedWorkLease(liftedBudget);
|
|
121
|
+
if (countStrategyKind(m, family, law) !== 'lifted')
|
|
122
|
+
return;
|
|
123
|
+
until = Infinity;
|
|
124
|
+
}
|
|
125
|
+
return withDeadline(until, () => {
|
|
126
|
+
if (late(until))
|
|
127
|
+
return;
|
|
128
|
+
if (requestedKind !== undefined) {
|
|
129
|
+
const actualKind = countStrategyKind(m, family, law);
|
|
130
|
+
if ((requestedKind !== 'row' && requestedKind !== 'guard') || actualKind !== requestedKind) {
|
|
131
|
+
observe?.({ strategy: requestedKind, stage: 'decline', reason: 'strategy-kind-mismatch', actualKind: actualKind ?? 'none' });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const leafUnits = liftedBudget ? Infinity : strategyLeafUnits(workAllowance);
|
|
136
|
+
if (requestedKind === 'row' || requestedKind === undefined && discoverRowAgreement(m, law)) {
|
|
137
|
+
observe?.({ strategy: 'row', stage: 'search-budget', workAllowance, leafUnits });
|
|
138
|
+
return proveCountRowComposition(m, family, law, until, request, e => observe?.({ strategy: 'row', ...e }), { framePremisesOnly: true, leafUnits, deferRowChecks: env.GDP_COUNT_ROW_DEFER_CHECKS === '1', reindexFactsOnly: env.GDP_COUNT_REINDEX_FACTS_ONLY === '1', familyProposal, shapeFamily });
|
|
139
|
+
}
|
|
140
|
+
if (requestedKind === undefined && liftedSelected(m, family, law)) {
|
|
141
|
+
observe?.({ strategy: 'lifted', stage: 'selected' });
|
|
142
|
+
return proveLiftedCountComposition(m, family, law, until, request, event => observe?.({ strategy: 'lifted', ...event }), liftedBudget ?? workAllowance);
|
|
143
|
+
}
|
|
144
|
+
const context = prepareGuardCountContext(m, law, family);
|
|
145
|
+
if (!context)
|
|
146
|
+
return;
|
|
147
|
+
const original = m.counts ?? {}, extended = context.machine.counts ?? {};
|
|
148
|
+
if (Object.keys(original).length !== Object.keys(extended).length || Object.entries(extended).some(([name, count]) => JSON.stringify(original[name]) !== JSON.stringify(count))) {
|
|
149
|
+
observe?.({ strategy: 'guard', stage: 'decline', reason: 'unadmitted count definitions' });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
observe?.({ strategy: 'guard', stage: 'search-budget', workAllowance, leafUnits });
|
|
153
|
+
return proveCountGuardComposition({ ...context, machine: m }, family, law, until, request, e => observe?.({ strategy: 'guard', ...e }), { caseOrder: 'cost', minimalView: true, leafUnits, reindexFactsOnly: env.GDP_COUNT_REINDEX_FACTS_ONLY === '1', familyProposal });
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function recordCountStrategyPremises(family, proof) {
|
|
2
|
+
if (new Set(family.map(law => law.name)).size !== family.length)
|
|
3
|
+
throw Error('ambiguous strategy premise name');
|
|
4
|
+
const premises = family.filter(law => {
|
|
5
|
+
const arity = law.forall ? 1 + (law.keys?.length ?? 0) : 0;
|
|
6
|
+
if (!Object.hasOwn(proof.instances, law.name))
|
|
7
|
+
return arity === 0;
|
|
8
|
+
const values = proof.instances[law.name];
|
|
9
|
+
if (arity ? values.length % arity !== 0 : values.length !== 0)
|
|
10
|
+
throw Error('malformed strategy premise tuple: ' + law.name);
|
|
11
|
+
return arity === 0 || values.length > 0;
|
|
12
|
+
});
|
|
13
|
+
return { ...proof, premises: Object.freeze(premises.map(law => law.name)) };
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type FamilyStepProposal } from './count-final-step.js';
|
|
3
|
+
import { type CountStageObserver } from './count-stage-trace.js';
|
|
4
|
+
import { type WorkAmount } from './work-amount.js';
|
|
5
|
+
import { type CountFundingOwners } from './count-disjoint-funding.js';
|
|
6
|
+
import { type LiftedWorkSliceObserver, type LiftedWorkTrace } from './count-lifted-budget.js';
|
|
7
|
+
import { type CountCert, type CountDecl, type Goal, type Instances } from '../kernel/kernel.js';
|
|
8
|
+
export type CountStrategyOptions = {
|
|
9
|
+
familyProposal?: FamilyStepProposal;
|
|
10
|
+
deferToComposition?: boolean;
|
|
11
|
+
deferIntermediateChecks?: boolean;
|
|
12
|
+
deferOwnedReplacementLemmas?: boolean;
|
|
13
|
+
batchOwnedReplacementPruning?: boolean;
|
|
14
|
+
deferOwnedReplacementReplay?: boolean;
|
|
15
|
+
slicedLemmas?: boolean;
|
|
16
|
+
deferRowChecks?: boolean;
|
|
17
|
+
minimize?: boolean;
|
|
18
|
+
reindexFactsOnly?: boolean;
|
|
19
|
+
emitterFramePool?: boolean;
|
|
20
|
+
minimalView?: boolean;
|
|
21
|
+
leafUnits?: number;
|
|
22
|
+
leafWork?: WorkAmount;
|
|
23
|
+
workSliceObserver?: LiftedWorkSliceObserver;
|
|
24
|
+
workSliceTrace?: LiftedWorkTrace;
|
|
25
|
+
workOwners?: CountFundingOwners;
|
|
26
|
+
caseKey?: string;
|
|
27
|
+
trace?: (event: Record<string, unknown>) => void;
|
|
28
|
+
tailTrace?: CountStageObserver;
|
|
29
|
+
};
|
|
30
|
+
export declare function strategyLeafUnits(workAllowance: number): number;
|
|
31
|
+
export declare const strategyLeafUntil: (until: number, options: CountStrategyOptions) => number;
|
|
32
|
+
export declare const deferIntermediateCountChecks: (options: CountStrategyOptions) => boolean;
|
|
33
|
+
export declare const deferOwnedReplacementChecks: (options: CountStrategyOptions) => boolean;
|
|
34
|
+
export type CountStrategyProof = {
|
|
35
|
+
instances: Instances;
|
|
36
|
+
certs: Record<string, CountCert>;
|
|
37
|
+
status?: 'unchecked';
|
|
38
|
+
premises?: readonly string[];
|
|
39
|
+
};
|
|
40
|
+
export type CountRequestBuilder = (goal: Goal, declarations: CountDecl[]) => Pick<CountCert, 'reads' | 'insts' | 'picks'>;
|
|
41
|
+
export declare function finishCountStrategy(m: Machine, family: Law[], law: Law, instances: Instances, zeroMap: string, stepCert: CountCert, until: number, requestFor: CountRequestBuilder, observe?: (stage: string, checked: boolean) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { countsForReads } from "./count-facts.js";
|
|
2
|
+
import { deferFinalCountStep } from "./count-final-step.js";
|
|
3
|
+
import { countStageTrace } from "./count-stage-trace.js";
|
|
4
|
+
import { checkMC, countedObligations, mcGoal } from "../kernel/kernel.js";
|
|
5
|
+
import { clock, grow, pastWall } from "../kernel/prove.js";
|
|
6
|
+
// Calibration-independent: W is the original enclosing work allowance, not
|
|
7
|
+
// a case's remaining share. INIT and final checking do not use this cap.
|
|
8
|
+
export function strategyLeafUnits(workAllowance) {
|
|
9
|
+
if (!Number.isFinite(workAllowance) || workAllowance < 0)
|
|
10
|
+
throw new RangeError('invalid strategy work allowance');
|
|
11
|
+
return workAllowance / 120;
|
|
12
|
+
}
|
|
13
|
+
export const strategyLeafUntil = (until, options) => Math.min(until, clock() + Math.max(0, options.leafUnits ?? Infinity));
|
|
14
|
+
// UNCHECKED is construction metadata, never a receipt or public acceptance.
|
|
15
|
+
export const deferIntermediateCountChecks = (options) => options.deferToComposition === true && options.deferIntermediateChecks === true;
|
|
16
|
+
// Search-only deferral: every retained lemma remains subject to the final native checker.
|
|
17
|
+
export const deferOwnedReplacementChecks = (options) => deferIntermediateCountChecks(options) && options.deferOwnedReplacementLemmas === true;
|
|
18
|
+
export function finishCountStrategy(m, family, law, instances, zeroMap, stepCert, until, requestFor, observe, options = {}) {
|
|
19
|
+
const index = family.indexOf(law);
|
|
20
|
+
if (index < 0 || clock() >= until || pastWall())
|
|
21
|
+
return;
|
|
22
|
+
if (options.deferToComposition)
|
|
23
|
+
return { instances, certs: { [law.name + ' @step']: stepCert }, ...(deferIntermediateCountChecks(options) ? { status: 'unchecked' } : {}) };
|
|
24
|
+
const trace = countStageTrace(options.tailTrace, 'strategy-finish-total');
|
|
25
|
+
try {
|
|
26
|
+
trace.mark('final-obligation-build', 'untrusted-assembly');
|
|
27
|
+
const packets = countedObligations(m, family, { [law.name]: instances }, index), step = packets.at(-1);
|
|
28
|
+
if (!step)
|
|
29
|
+
return;
|
|
30
|
+
const deferred = deferFinalCountStep(options.familyProposal);
|
|
31
|
+
if (deferred)
|
|
32
|
+
observe?.('step-proposal', false);
|
|
33
|
+
else {
|
|
34
|
+
trace.mark('native-step-check', 'trusted-check');
|
|
35
|
+
const stepChecked = checkMC(step.goal.hyps, step.decls, stepCert);
|
|
36
|
+
observe?.('step-check', stepChecked);
|
|
37
|
+
if (!stepChecked)
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const certs = { [step.goal.name]: stepCert };
|
|
41
|
+
for (const initial of packets.slice(0, -1)) {
|
|
42
|
+
trace.mark('initial-request-build', 'untrusted-assembly');
|
|
43
|
+
if (clock() >= until || pastWall())
|
|
44
|
+
return;
|
|
45
|
+
const base = requestFor(initial.goal, initial.decls), counts = countsForReads(initial.decls, base.reads), target = base.reads.find(r => r[1].replace(/#$/, '') === zeroMap);
|
|
46
|
+
const count = counts?.find(c => c.v === target?.[0]);
|
|
47
|
+
if (!target || !count)
|
|
48
|
+
return;
|
|
49
|
+
const scope = JSON.stringify([m, family, initial.goal, base]), fresh = (n) => `countInitial$${n}`;
|
|
50
|
+
let i = 0;
|
|
51
|
+
while (scope.includes(JSON.stringify(fresh(i))))
|
|
52
|
+
i++;
|
|
53
|
+
const request = { reads: base.reads, insts: [{ wit: fresh(i), below: count.below, terms: [[1, target[0]]], unit: 0 }], picks: [] };
|
|
54
|
+
trace.mark('initial-goal-build', 'untrusted-assembly');
|
|
55
|
+
const goal = mcGoal(initial.goal.hyps, initial.decls, request);
|
|
56
|
+
trace.mark('initial-search', 'untrusted-search');
|
|
57
|
+
const result = goal && grow(goal, new Map(), { nodes: 0, until });
|
|
58
|
+
if (!result || !('tree' in result)) {
|
|
59
|
+
observe?.('initial-search', false);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const cert = { ...request, tree: result.tree };
|
|
63
|
+
trace.mark('native-init-check', 'trusted-check');
|
|
64
|
+
const initialChecked = checkMC(initial.goal.hyps, initial.decls, cert);
|
|
65
|
+
observe?.('initial-check', initialChecked);
|
|
66
|
+
if (!initialChecked)
|
|
67
|
+
return;
|
|
68
|
+
certs[initial.goal.name] = cert;
|
|
69
|
+
}
|
|
70
|
+
trace.mark('certificate-return', 'untrusted-assembly');
|
|
71
|
+
return clock() < until && !pastWall() ? { instances, certs, ...(deferred ? { status: 'unchecked' } : {}) } : undefined;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
trace.finish();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { searchNow as countedSearchNow } from "./wall.js";
|
|
1
2
|
// Private untrusted count-candidate scheduling. Every emitted tuple instantiates a whole
|
|
2
3
|
// original PRE law; every CountInst is reified by mcGoal and the final closed family is
|
|
3
4
|
// checked by checkCountedLaws. No coordinate projection is an equality premise.
|
|
@@ -156,7 +157,7 @@ export function candidateWork() {
|
|
|
156
157
|
const tick = () => {
|
|
157
158
|
if (state.exhausted || state.deadline)
|
|
158
159
|
return false;
|
|
159
|
-
if (
|
|
160
|
+
if (countedSearchNow() >= wallAt()) {
|
|
160
161
|
state.deadline = true;
|
|
161
162
|
return false;
|
|
162
163
|
}
|
|
@@ -598,7 +599,7 @@ export const instId = (i, rs) => { const rd = new Map(rs.map(r => [r[0], [r[1],
|
|
|
598
599
|
export const ids = (c) => { const rd = new Map(c.reads.map(r => [r[0], [r[1], keyId(r[2])]])); return [...(c.picks ?? []).map(p => 'p' + json([rd.get(p[0]), p[1].map(keyId)])), ...c.insts.map(i => 'i' + instId(i, c.reads))]; };
|
|
599
600
|
function requireValue(x, message) { if (x === undefined)
|
|
600
601
|
throw new UnsupportedCountProposal('unresolved reservation: ' + message); return x; }
|
|
601
|
-
const reservationOpen = () => { if (
|
|
602
|
+
const reservationOpen = () => { if (countedSearchNow() >= wallAt())
|
|
602
603
|
throw new UnsupportedCountProposal('reservation deadline'); };
|
|
603
604
|
// A lexical free-variable walk, not sourceNames: local quantified binders and a
|
|
604
605
|
// declaration's formal parameters do not grant scope to a retained read key.
|
|
@@ -821,8 +822,29 @@ export function reservePool(goal, decls, pool, previous, previousDecls, chosen,
|
|
|
821
822
|
const forbidden = sourceNames([{ ...goal, hyps: undefined }, decls, full.reads, [...previous.insts, ...full.insts].map(i => i.below)], reservationOpen);
|
|
822
823
|
for (const n of reservationHypNames(goal.hyps))
|
|
823
824
|
forbidden.add(n);
|
|
824
|
-
if (owner.reserved.has(wit) || forbidden.has(wit))
|
|
825
|
-
|
|
825
|
+
if (owner.reserved.has(wit) || forbidden.has(wit)) {
|
|
826
|
+
// Before acquisition the spelling belongs only to the proposal: a source
|
|
827
|
+
// name is not its binder. Never rewrite the source or a selected pick.
|
|
828
|
+
// Once leased, free HYPS may already mean this witness; those must refuse.
|
|
829
|
+
if ((prior && reservationFree(goal.hyps).has(wit)) || names((previous.picks ?? []).filter((_, i) => chosen.has(oldIds[i])), reservationOpen).has(wit))
|
|
830
|
+
throw new UnsupportedCountProposal('reservation owned witness capture/source');
|
|
831
|
+
const from = wit;
|
|
832
|
+
for (const n of sourceNames([previous, full, goal, decls], reservationOpen))
|
|
833
|
+
fresh.add(n);
|
|
834
|
+
for (const n of owner.reserved)
|
|
835
|
+
fresh.add(n);
|
|
836
|
+
for (const l of [...owner.leases.values(), ...leases.values()])
|
|
837
|
+
fresh.add(l.wit);
|
|
838
|
+
do {
|
|
839
|
+
reservationOpen();
|
|
840
|
+
wit = 'w$' + state.next++;
|
|
841
|
+
} while (fresh.has(wit));
|
|
842
|
+
// Optional picks have no retained meaning: alpha-rename their bound
|
|
843
|
+
// witness occurrences together. A selected pick was refused above.
|
|
844
|
+
full.picks = (full.picks ?? []).map((p, i) => chosen.has(fullIds[i]) ? p : [p[0], p[1].map(t => substE(t, { vars: { [from]: x(wit) }, maps: {}, flags: {} }))]);
|
|
845
|
+
fresh.add(wit);
|
|
846
|
+
renamed.push({ key, from, to: wit, reason: 'source-freshness' });
|
|
847
|
+
}
|
|
826
848
|
if ([...owner.leases, ...leases].some(([id, l]) => id !== key && l.wit === wit) || full.insts.some(i => i.wit === wit && 'i' + instId(i, full.reads) !== key))
|
|
827
849
|
throw new UnsupportedCountProposal('reservation different witness owner');
|
|
828
850
|
if (reservationIdentity(rebound, full.reads, decls) !== identity)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type CountTierBudget = Readonly<{
|
|
2
|
+
active: boolean;
|
|
3
|
+
workAllowance: number;
|
|
4
|
+
generationUntil: number;
|
|
5
|
+
strategyFloor: number;
|
|
6
|
+
ordinaryFloor: number;
|
|
7
|
+
strategyUntil: number | undefined;
|
|
8
|
+
until: number;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function countTierBudget(start: number, until: number, selectedStrategies: number): CountTierBudget;
|
|
11
|
+
export declare function remainingCountTierBudget(start: number, requested: number, selected: number): CountTierBudget;
|
|
12
|
+
export declare function strategyPhase<T>(budget: CountTierBudget | undefined, attemptEnd: number, run: (end: number) => T): T | undefined;
|
|
13
|
+
export declare function isLocalCountExpiration(error: unknown, enclosingEnd: number): boolean;
|
|
14
|
+
export declare function ordinaryTierShare(budget: CountTierBudget, now: number, pending: ReadonlySet<string>): number;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Counted-unit reservations, not wall-clock timers. A strategy floor is not
|
|
2
|
+
// a per-law or pool cap: the unreserved remainder and unused generation flow
|
|
3
|
+
// to strategies, while an ordinary-work floor remains protected.
|
|
4
|
+
import { attemptShare } from "./support-budget.js";
|
|
5
|
+
import { BudgetExpired, budgetEnd, clock, withDeadline } from "../kernel/prove.js";
|
|
6
|
+
import { inProxySearch } from "./search-policy.js";
|
|
7
|
+
import { workLedger } from "./work-admission.js";
|
|
8
|
+
export function countTierBudget(start, until, selectedStrategies) {
|
|
9
|
+
if (!Number.isSafeInteger(selectedStrategies) || selectedStrategies < 0)
|
|
10
|
+
throw new RangeError('invalid strategy count');
|
|
11
|
+
// No dispatcher hit: no reservation and precisely the existing split.
|
|
12
|
+
if (!selectedStrategies)
|
|
13
|
+
return Object.freeze({ active: false, workAllowance: Math.max(0, until - start), generationUntil: until, strategyFloor: 0, ordinaryFloor: 0, strategyUntil: undefined, until });
|
|
14
|
+
if (!Number.isFinite(start) || !Number.isFinite(until))
|
|
15
|
+
throw new RangeError('tiered work requires finite counted endpoints');
|
|
16
|
+
const width = Math.max(0, until - start), ordinaryFloor = width * 3 / 10;
|
|
17
|
+
return Object.freeze({ active: true, workAllowance: width, generationUntil: Math.min(until, start + width / 4), strategyFloor: width * 7 / 20, ordinaryFloor, strategyUntil: until - ordinaryFloor, until });
|
|
18
|
+
}
|
|
19
|
+
// The public caller has already spent work on normalization and preflight.
|
|
20
|
+
// Never regrant its original duration after that work.
|
|
21
|
+
export function remainingCountTierBudget(start, requested, selected) {
|
|
22
|
+
const plan = countTierBudget(start, Math.min(start + requested, budgetEnd()), selected);
|
|
23
|
+
if (!plan.active)
|
|
24
|
+
return plan;
|
|
25
|
+
// Include fixed public preflight in the original generation quarter.
|
|
26
|
+
const originalStart = plan.until - requested;
|
|
27
|
+
return Object.freeze({ ...plan, generationUntil: Math.min(plan.generationUntil, originalStart + requested / 4) });
|
|
28
|
+
}
|
|
29
|
+
// One endpoint shared by every STEP refinement and every retry. Expiration
|
|
30
|
+
// returns to ordinary INIT/STEP completion; it does not cancel that reserve.
|
|
31
|
+
export function strategyPhase(budget, attemptEnd, run) {
|
|
32
|
+
if (!budget?.active)
|
|
33
|
+
return run(attemptEnd);
|
|
34
|
+
const end = Math.min(attemptEnd, budget.strategyUntil ?? attemptEnd);
|
|
35
|
+
if (clock() >= end)
|
|
36
|
+
return undefined;
|
|
37
|
+
try {
|
|
38
|
+
const result = withDeadline(end, () => run(end)), now = clock();
|
|
39
|
+
// Equality does not throw BudgetExpired. Only a local-cap unknown hands
|
|
40
|
+
// back the ordinary reserve; proofs and genuine refutations stay results.
|
|
41
|
+
if (now >= end && now <= budgetEnd() && result !== null && typeof result === 'object' &&
|
|
42
|
+
'stuck' in result && result.stuck === 'unknown' && !('proof' in result) &&
|
|
43
|
+
!('refuted' in result && result.refuted))
|
|
44
|
+
return undefined;
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (inProxySearch() && workLedger.capacityRefusal(error))
|
|
49
|
+
throw error;
|
|
50
|
+
if (!(error instanceof BudgetExpired) || clock() < end || clock() > budgetEnd())
|
|
51
|
+
throw error;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// A local full-work deadline throws the same exception as the public budget.
|
|
56
|
+
// Only the former is an unknown attempt: preserve the enclosing phase's end,
|
|
57
|
+
// captured before per-law/subset scopes, and never swallow outer cancellation.
|
|
58
|
+
export function isLocalCountExpiration(error, enclosingEnd) {
|
|
59
|
+
return !(inProxySearch() && workLedger.capacityRefusal(error))
|
|
60
|
+
&& error instanceof BudgetExpired && clock() < Math.min(enclosingEnd, budgetEnd());
|
|
61
|
+
}
|
|
62
|
+
export function ordinaryTierShare(budget, now, pending) {
|
|
63
|
+
return attemptShare(budget.until - now, pending);
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type C, type E } from './machine.js';
|
|
2
|
+
import { type Count, type CountDecl, type LinCut, type MapRead } from '../kernel/kernel.js';
|
|
3
|
+
export declare function checkedReversePrefix(counts: Count[], cut: LinCut): LinCut | undefined;
|
|
4
|
+
export declare function replayReversePrefix(counts: Count[], cut: LinCut, until: number): LinCut | undefined;
|
|
5
|
+
export declare class UnwrittenCountPrefix {
|
|
6
|
+
private decls;
|
|
7
|
+
private reads;
|
|
8
|
+
private guards;
|
|
9
|
+
private written;
|
|
10
|
+
private rowBound;
|
|
11
|
+
private search;
|
|
12
|
+
private options;
|
|
13
|
+
private cache;
|
|
14
|
+
readonly stats: {
|
|
15
|
+
proofs: number;
|
|
16
|
+
hits: number;
|
|
17
|
+
refusals: number;
|
|
18
|
+
};
|
|
19
|
+
constructor(decls: CountDecl[], reads: MapRead[], guards: C[], written: E, rowBound: E, search?: 'grow' | 'cdcl', options?: {
|
|
20
|
+
deferCheck?: boolean;
|
|
21
|
+
leafUnits?: number;
|
|
22
|
+
});
|
|
23
|
+
prove(post: string, pre: string, rows: E[], sign: 1 | -1, until: number): LinCut | undefined;
|
|
24
|
+
}
|