tla-ts 0.0.4-dev.2be6058 → 0.0.4-dev.2da24e1
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 +37 -126
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +996 -0
- package/dist/prove.js +996 -0
- package/dist/run-cli.cjs +37 -47
- package/dist/run-cli.js +37 -47
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +38 -44
- package/dist/transfer.js +38 -44
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/check.ts +1 -0
- package/src/codegen.ts +26 -7
- package/src/errors.ts +86 -0
- package/src/evaluate.ts +255 -56
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +247 -69
- package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
- package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
- package/src/{obligations.ts → obligations/index.ts} +32 -16
- package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
- package/src/{obligation-module.ts → obligations/module.ts} +113 -121
- package/src/obligations/pickle.ts +98 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/{obligation-source.ts → obligations/source.ts} +154 -99
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/ocaml-marshal.ts +166 -0
- package/src/parallel-worker.ts +2 -18
- package/src/parallel.ts +10 -43
- package/src/prove/decide-pool.ts +95 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/first-order.ts +78 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +446 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +547 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +441 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +363 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +402 -0
- package/src/prove/isabelle/pure/name.ts +110 -0
- package/src/prove/isabelle/pure/net.ts +262 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +650 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +156 -0
- package/src/prove/isabelle/pure/simplifier.ts +112 -0
- package/src/prove/isabelle/pure/table.ts +208 -0
- package/src/prove/isabelle/pure/tactic.ts +276 -0
- package/src/prove/isabelle/pure/tactical.ts +347 -0
- package/src/prove/isabelle/pure/term-ord.ts +159 -0
- package/src/prove/isabelle/pure/term.ts +808 -0
- package/src/prove/isabelle/pure/thm.ts +806 -0
- package/src/prove/isabelle/pure/type.ts +133 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +508 -0
- package/src/prove/prep/defs.ts +33 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +529 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +22 -0
- package/src/prove/prove.ts +498 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +255 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +209 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +164 -0
- package/src/prove/smt/extensionality.ts +65 -0
- package/src/prove/smt/flatten.ts +112 -0
- package/src/prove/smt/format.ts +154 -0
- package/src/prove/smt/instances.ts +181 -0
- package/src/prove/smt/rewrite.ts +772 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +147 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +18 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +379 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +181 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/run-cli.ts +283 -81
- package/src/standard-modules.ts +5 -2
- package/src/successors.ts +25 -6
- package/src/tlapm-cache.ts +236 -0
- package/src/tlc-random.ts +55 -32
- package/src/tlc-version.ts +8 -7
- package/src/values.ts +97 -47
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
package/src/evaluate.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { CheckerRuntime } from "./runtime";
|
|
|
21
21
|
import { getReadVariables } from "./dependencies";
|
|
22
22
|
import { contextualApplications, mapChildren, substitutedExpressions } from "./instances";
|
|
23
23
|
import { prettyPrint } from "./pretty-print";
|
|
24
|
-
import { isEnabled } from "./successors";
|
|
24
|
+
import { getReadLocals, isEnabled } from "./successors";
|
|
25
25
|
import {
|
|
26
26
|
applyFunction,
|
|
27
27
|
describeMissingArgument,
|
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
markLambdaFunction,
|
|
55
55
|
isReducibleSet,
|
|
56
56
|
isSetValue,
|
|
57
|
+
isSettledValue,
|
|
57
58
|
MAXIMUM_INTEGER,
|
|
58
59
|
MINIMUM_INTEGER,
|
|
59
60
|
toFiniteFunction,
|
|
@@ -113,6 +114,9 @@ export interface Thunk {
|
|
|
113
114
|
state: State | undefined;
|
|
114
115
|
next: State | undefined;
|
|
115
116
|
cache: Value | undefined;
|
|
117
|
+
// Whether the expression may build a set that streams until TLC caches it, so that the thunk
|
|
118
|
+
// caches only a settled value.
|
|
119
|
+
isStreamed: boolean;
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
type Binding = { kind: "Value"; value: Value } | Thunk | { kind: "Operator"; operator: Operator };
|
|
@@ -380,7 +384,15 @@ export const expectFunction = (value: Value, application: Expression) => {
|
|
|
380
384
|
};
|
|
381
385
|
|
|
382
386
|
export const toKeepLazyContext = (context: Context): Context =>
|
|
383
|
-
context.isKeepLazy
|
|
387
|
+
context.isKeepLazy
|
|
388
|
+
? context
|
|
389
|
+
: {
|
|
390
|
+
environment: context.environment,
|
|
391
|
+
scope: context.scope,
|
|
392
|
+
state: context.state,
|
|
393
|
+
next: context.next,
|
|
394
|
+
isKeepLazy: true,
|
|
395
|
+
};
|
|
384
396
|
|
|
385
397
|
const withScope = (context: Context, scope: Scope | undefined): Context => ({
|
|
386
398
|
environment: context.environment,
|
|
@@ -839,7 +851,7 @@ const forceThunk = (thunk: Thunk, context: Context) => {
|
|
|
839
851
|
const isSameState = thunk.state === context.state && thunk.next === context.next;
|
|
840
852
|
if (isSameState && thunk.cache !== undefined) return thunk.cache;
|
|
841
853
|
const value = evaluate(thunk.expression, withScope(context, thunk.scope));
|
|
842
|
-
if (isSameState) thunk.cache = value;
|
|
854
|
+
if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
|
|
843
855
|
return value;
|
|
844
856
|
};
|
|
845
857
|
|
|
@@ -960,6 +972,7 @@ const createThunk = (expression: Expression, context: Context): Thunk => ({
|
|
|
960
972
|
state: context.state,
|
|
961
973
|
next: context.next,
|
|
962
974
|
cache: undefined,
|
|
975
|
+
isStreamed: false,
|
|
963
976
|
});
|
|
964
977
|
|
|
965
978
|
export const findGlobalName = (name: string, environment: Environment): GlobalName | undefined => {
|
|
@@ -1019,6 +1032,7 @@ export const bindOperatorArguments = (
|
|
|
1019
1032
|
closure: Closure,
|
|
1020
1033
|
args: Expression[],
|
|
1021
1034
|
context: Context,
|
|
1035
|
+
binders?: ArgumentBinder[],
|
|
1022
1036
|
): Scope | undefined => {
|
|
1023
1037
|
if (args.length !== closure.params.length) {
|
|
1024
1038
|
throw new TlaEvaluationError(
|
|
@@ -1031,18 +1045,36 @@ export const bindOperatorArguments = (
|
|
|
1031
1045
|
const binding: Binding =
|
|
1032
1046
|
param.arity > 0
|
|
1033
1047
|
? { kind: "Operator", operator: evaluateOperatorArgument(args[index], context) }
|
|
1034
|
-
: getArgumentBinder(args[index], context.environment)(context);
|
|
1048
|
+
: (binders?.[index] ?? getArgumentBinder(args[index], context.environment))(context);
|
|
1035
1049
|
scope = { name: param.name, binding, parent: scope };
|
|
1036
1050
|
}
|
|
1037
1051
|
return scope;
|
|
1038
1052
|
};
|
|
1039
1053
|
|
|
1040
|
-
|
|
1054
|
+
// The body a call site last called and its evaluator, as a site mostly calls one closure.
|
|
1055
|
+
interface CalledBody {
|
|
1056
|
+
body: Expression;
|
|
1057
|
+
evaluator: Evaluator;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
const callOperator = (
|
|
1061
|
+
operator: Operator,
|
|
1062
|
+
args: Expression[],
|
|
1063
|
+
context: Context,
|
|
1064
|
+
called: { entry: CalledBody | undefined },
|
|
1065
|
+
binders: ArgumentBinder[],
|
|
1066
|
+
) => {
|
|
1041
1067
|
if (operator.kind === "Closure") {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1068
|
+
const bodyContext = withScope(context, bindOperatorArguments(operator, args, context, binders));
|
|
1069
|
+
if (context.environment.callStack) return evaluate(operator.body, bodyContext);
|
|
1070
|
+
const entry =
|
|
1071
|
+
called.entry?.body === operator.body
|
|
1072
|
+
? called.entry
|
|
1073
|
+
: (called.entry = {
|
|
1074
|
+
body: operator.body,
|
|
1075
|
+
evaluator: getEntryEvaluator(operator.body, context.environment),
|
|
1076
|
+
});
|
|
1077
|
+
return entry.evaluator(bodyContext);
|
|
1046
1078
|
}
|
|
1047
1079
|
if (operator.kind === "Operator") return operator.call(args.map((arg) => evaluate(arg, context)));
|
|
1048
1080
|
if (operator.isLazy) return operator.evaluate(getLazyArguments(args, context), context);
|
|
@@ -1056,10 +1088,16 @@ const callOperator = (operator: Operator, args: Expression[], context: Context)
|
|
|
1056
1088
|
);
|
|
1057
1089
|
};
|
|
1058
1090
|
|
|
1091
|
+
// The LET definitions that a reference evaluates again, and those that cache only a settled value.
|
|
1092
|
+
interface ReevaluatedDefinitions {
|
|
1093
|
+
impure: ReadonlySet<Definition>;
|
|
1094
|
+
streamed: ReadonlySet<Definition>;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1059
1097
|
export const bindDefinitions = (
|
|
1060
1098
|
definitions: Definition[],
|
|
1061
1099
|
context: Context,
|
|
1062
|
-
reevaluated?:
|
|
1100
|
+
reevaluated?: ReevaluatedDefinitions,
|
|
1063
1101
|
): Scope | undefined =>
|
|
1064
1102
|
definitions.reduce<Scope | undefined>((scope, definition) => {
|
|
1065
1103
|
const node: Scope = {
|
|
@@ -1081,10 +1119,11 @@ export const bindDefinitions = (
|
|
|
1081
1119
|
state: context.state,
|
|
1082
1120
|
next: context.next,
|
|
1083
1121
|
cache: undefined,
|
|
1122
|
+
isStreamed: false,
|
|
1084
1123
|
};
|
|
1085
1124
|
return node;
|
|
1086
1125
|
}
|
|
1087
|
-
if (definition.params.length > 0 || reevaluated?.has(definition)) {
|
|
1126
|
+
if (definition.params.length > 0 || reevaluated?.impure.has(definition)) {
|
|
1088
1127
|
node.binding = {
|
|
1089
1128
|
kind: "Operator",
|
|
1090
1129
|
operator: {
|
|
@@ -1104,6 +1143,7 @@ export const bindDefinitions = (
|
|
|
1104
1143
|
state: context.state,
|
|
1105
1144
|
next: context.next,
|
|
1106
1145
|
cache: undefined,
|
|
1146
|
+
isStreamed: reevaluated?.streamed.has(definition) ?? false,
|
|
1107
1147
|
};
|
|
1108
1148
|
return node;
|
|
1109
1149
|
}, context.scope);
|
|
@@ -1220,14 +1260,15 @@ const STREAMED_SET: Impurity = {
|
|
|
1220
1260
|
// TLC's next-state generator does not bind LET definitions to values, so each reference to one
|
|
1221
1261
|
// evaluates it again: one that calls an impure builtin repeats its effects, and a set one builds
|
|
1222
1262
|
// with UNION or \cup starts out uncached.
|
|
1223
|
-
export const getReevaluatedDefinitions = (
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
),
|
|
1230
|
-
)
|
|
1263
|
+
export const getReevaluatedDefinitions = (
|
|
1264
|
+
definitions: Definition[],
|
|
1265
|
+
environment: Environment,
|
|
1266
|
+
): ReevaluatedDefinitions => ({
|
|
1267
|
+
impure: new Set(definitions.filter((definition) => isImpureDefinition(definition, environment))),
|
|
1268
|
+
streamed: new Set(
|
|
1269
|
+
definitions.filter((definition) => isImpureDefinition(definition, environment, STREAMED_SET)),
|
|
1270
|
+
),
|
|
1271
|
+
});
|
|
1231
1272
|
|
|
1232
1273
|
export const isImpure = (environment: Environment) =>
|
|
1233
1274
|
[...environment.definitions.values()].some((definition) =>
|
|
@@ -1511,7 +1552,7 @@ export const getEvaluator = (expression: Expression, environment: Environment):
|
|
|
1511
1552
|
|
|
1512
1553
|
const entryEvaluators = new WeakMap<Expression, Evaluator>();
|
|
1513
1554
|
|
|
1514
|
-
const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1555
|
+
export const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1515
1556
|
if (environment.callStack) return getEvaluator(expression, environment);
|
|
1516
1557
|
const cached = entryEvaluators.get(expression);
|
|
1517
1558
|
if (cached) return cached;
|
|
@@ -1685,52 +1726,180 @@ export const compileArgumentScope = (
|
|
|
1685
1726
|
};
|
|
1686
1727
|
|
|
1687
1728
|
interface MemoizedCall {
|
|
1729
|
+
sources: (Expression | undefined)[];
|
|
1688
1730
|
args: Value[];
|
|
1689
1731
|
value: Value;
|
|
1690
1732
|
}
|
|
1691
1733
|
|
|
1692
1734
|
const MEMOIZED_CALL_LIMIT = 1 << 16;
|
|
1693
1735
|
|
|
1694
|
-
|
|
1736
|
+
// A call site that finds fewer than half its calls in a state's memo after this many new ones
|
|
1737
|
+
// stops paying for the lookups.
|
|
1738
|
+
const MEMOIZED_TRIAL_CALLS = 1 << 10;
|
|
1739
|
+
|
|
1740
|
+
interface CallMemo {
|
|
1741
|
+
calls: Map<number, MemoizedCall[]>;
|
|
1742
|
+
size: number;
|
|
1743
|
+
state: Context["state"];
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
interface CallMemos {
|
|
1747
|
+
constant: CallMemo;
|
|
1748
|
+
state: CallMemo;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
const createCallMemo = (): CallMemo => ({ calls: new Map(), size: 0, state: undefined });
|
|
1752
|
+
|
|
1753
|
+
const callMemos = new WeakMap<Closure, CallMemos>();
|
|
1695
1754
|
|
|
1696
|
-
const
|
|
1755
|
+
const getCallMemos = (closure: Closure) => {
|
|
1697
1756
|
const cached = callMemos.get(closure);
|
|
1698
1757
|
if (cached) return cached;
|
|
1699
|
-
const
|
|
1700
|
-
callMemos.set(closure,
|
|
1701
|
-
return
|
|
1758
|
+
const memos = { constant: createCallMemo(), state: createCallMemo() };
|
|
1759
|
+
callMemos.set(closure, memos);
|
|
1760
|
+
return memos;
|
|
1702
1761
|
};
|
|
1703
1762
|
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1763
|
+
const readsExceptAt = (expression: Expression): boolean =>
|
|
1764
|
+
expression.kind === "ExceptAt" || getChildren(expression).some(readsExceptAt);
|
|
1765
|
+
|
|
1766
|
+
// The locals an argument expression reads, when the state and their values decide its value. An @
|
|
1767
|
+
// reads the value its EXCEPT binds.
|
|
1768
|
+
const argumentLocals = new WeakMap<Expression, string[] | false>();
|
|
1769
|
+
|
|
1770
|
+
const getArgumentLocals = (expression: Expression, environment: Environment) => {
|
|
1771
|
+
const cached = argumentLocals.get(expression);
|
|
1772
|
+
if (cached !== undefined) return cached;
|
|
1773
|
+
const locals =
|
|
1774
|
+
getReadVariables(expression, environment) !== undefined &&
|
|
1775
|
+
getReadLocals(expression, NO_BOUND_NAMES);
|
|
1776
|
+
const unique = locals && [
|
|
1777
|
+
...new Set(readsExceptAt(expression) ? [...locals, EXCEPT_AT] : locals),
|
|
1778
|
+
];
|
|
1779
|
+
argumentLocals.set(expression, unique ?? false);
|
|
1780
|
+
return unique ?? false;
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
// Hashing a lazy set or function would enumerate it, which TLC does only when it has to.
|
|
1784
|
+
const isEagerValue = (value: Value) =>
|
|
1785
|
+
typeof value !== "object" ||
|
|
1786
|
+
value.kind === "ModelValue" ||
|
|
1787
|
+
value.kind === "Set" ||
|
|
1788
|
+
value.kind === "Function" ||
|
|
1789
|
+
value.kind === "Interval";
|
|
1790
|
+
|
|
1791
|
+
// The key of the call being looked up, copied into the memo only when the call is new. Counts
|
|
1792
|
+
// mark its ends, since shortening an array is slow.
|
|
1793
|
+
const callKey = {
|
|
1794
|
+
sources: [] as (Expression | undefined)[],
|
|
1795
|
+
sourceCount: 0,
|
|
1796
|
+
args: [] as Value[],
|
|
1797
|
+
argCount: 0,
|
|
1798
|
+
hash: 0,
|
|
1799
|
+
isStateKeyed: false,
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
// A model value's rank tells it apart without hashing its name.
|
|
1803
|
+
const getKeyHash = (value: Value) =>
|
|
1804
|
+
typeof value === "object" && value.kind === "ModelValue" ? value.rank : getValueHash(value);
|
|
1805
|
+
|
|
1806
|
+
const pushKeyValue = (value: Value) => {
|
|
1807
|
+
if (!isEagerValue(value)) return false;
|
|
1808
|
+
callKey.sources[callKey.sourceCount++] = undefined;
|
|
1809
|
+
callKey.args[callKey.argCount++] = value;
|
|
1810
|
+
callKey.hash = combineHash(callKey.hash, getKeyHash(value));
|
|
1811
|
+
return true;
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1814
|
+
// An argument TLC has not evaluated yet stands for its expression and the values of the locals it
|
|
1815
|
+
// reads, so a call keeps the laziness of its arguments.
|
|
1816
|
+
const pushKeyExpression = (
|
|
1817
|
+
expression: Expression,
|
|
1818
|
+
locals: string[] | false,
|
|
1819
|
+
scope: Scope | undefined,
|
|
1820
|
+
) => {
|
|
1821
|
+
if (!locals) return false;
|
|
1822
|
+
callKey.sources[callKey.sourceCount++] = expression;
|
|
1823
|
+
callKey.isStateKeyed = true;
|
|
1824
|
+
for (let index = 0; index < locals.length; index++) {
|
|
1825
|
+
const local = lookupScope(scope, locals[index]);
|
|
1826
|
+
if (local?.kind !== "Value" || !isEagerValue(local.value)) return false;
|
|
1827
|
+
callKey.args[callKey.argCount++] = local.value;
|
|
1828
|
+
callKey.hash = combineHash(callKey.hash, getKeyHash(local.value));
|
|
1709
1829
|
}
|
|
1710
|
-
return
|
|
1830
|
+
return true;
|
|
1711
1831
|
};
|
|
1712
1832
|
|
|
1713
|
-
|
|
1714
|
-
|
|
1833
|
+
// Each argument adds to the key what compileArgumentBinder would bind its parameter to.
|
|
1834
|
+
const compileArgumentKey = (
|
|
1835
|
+
argument: Expression,
|
|
1836
|
+
environment: Environment,
|
|
1837
|
+
): ((context: Context) => boolean) => {
|
|
1838
|
+
const isLiteral =
|
|
1839
|
+
argument.kind === "String" || (argument.kind === "Number" && isTlcInteger(argument.value));
|
|
1840
|
+
if (isLiteral) return () => pushKeyValue(argument.value);
|
|
1841
|
+
if (argument.kind === "Identifier") {
|
|
1842
|
+
const global = isLocallyResolved(argument)
|
|
1843
|
+
? undefined
|
|
1844
|
+
: findGlobalName(argument.name, environment);
|
|
1845
|
+
if (global?.kind === "Value") return () => pushKeyValue(global.value);
|
|
1846
|
+
if (global === undefined) {
|
|
1847
|
+
return (context) => {
|
|
1848
|
+
const binding = lookupScope(context.scope, argument.name);
|
|
1849
|
+
if (binding?.kind === "Value") return pushKeyValue(binding.value);
|
|
1850
|
+
if (binding?.kind !== "Thunk" || binding.state !== context.state) return false;
|
|
1851
|
+
return pushKeyExpression(
|
|
1852
|
+
binding.expression,
|
|
1853
|
+
getArgumentLocals(binding.expression, environment),
|
|
1854
|
+
binding.scope,
|
|
1855
|
+
);
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
const locals = getArgumentLocals(argument, environment);
|
|
1860
|
+
return (context) => pushKeyExpression(argument, locals, context.scope);
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
const isKnownCall = (call: MemoizedCall) => {
|
|
1864
|
+
if (call.args.length !== callKey.argCount || call.sources.length !== callKey.sourceCount) {
|
|
1865
|
+
return false;
|
|
1866
|
+
}
|
|
1867
|
+
for (let index = 0; index < callKey.sourceCount; index++) {
|
|
1868
|
+
if (call.sources[index] !== callKey.sources[index]) return false;
|
|
1869
|
+
}
|
|
1870
|
+
for (let index = 0; index < callKey.argCount; index++) {
|
|
1871
|
+
if (!isSameValue(call.args[index], callKey.args[index])) return false;
|
|
1872
|
+
}
|
|
1873
|
+
return true;
|
|
1874
|
+
};
|
|
1875
|
+
|
|
1876
|
+
const findCall = (bucket: MemoizedCall[] | undefined) => {
|
|
1877
|
+
if (bucket === undefined) return undefined;
|
|
1878
|
+
for (let index = 0; index < bucket.length; index++) {
|
|
1879
|
+
if (isKnownCall(bucket[index])) return bucket[index];
|
|
1880
|
+
}
|
|
1881
|
+
return undefined;
|
|
1882
|
+
};
|
|
1715
1883
|
|
|
1716
|
-
//
|
|
1717
|
-
// so its calls
|
|
1718
|
-
const
|
|
1884
|
+
// An operator without side effects yields the same value for the same arguments, a state-level one
|
|
1885
|
+
// in the same state, so its calls share one result.
|
|
1886
|
+
const getMemoizedLevel = (expression: Expression & { kind: "Apply" }, environment: Environment) => {
|
|
1719
1887
|
const definition = getDefinition(expression.operator, environment);
|
|
1720
|
-
|
|
1888
|
+
const isMemoizable =
|
|
1721
1889
|
definition?.kind === "Operator" &&
|
|
1722
1890
|
definition.params.length > 0 &&
|
|
1723
1891
|
definition.params.every((param) => param.arity === 0) &&
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
);
|
|
1892
|
+
!isImpureDefinition(definition, environment);
|
|
1893
|
+
if (!isMemoizable) return undefined;
|
|
1894
|
+
if (isConstantLevel(definition, environment)) return "constant";
|
|
1895
|
+
return isStatePure(definition, environment) ? "state" : undefined;
|
|
1727
1896
|
};
|
|
1728
1897
|
|
|
1729
1898
|
const compileClosureCall = (
|
|
1730
1899
|
closure: Closure,
|
|
1731
1900
|
args: Expression[],
|
|
1732
1901
|
environment: Environment,
|
|
1733
|
-
|
|
1902
|
+
memoizedLevel: "constant" | "state" | undefined,
|
|
1734
1903
|
): Evaluator => {
|
|
1735
1904
|
const bindArguments = compileArgumentScope(closure, args, environment);
|
|
1736
1905
|
const compiled = { body: undefined as Evaluator | undefined };
|
|
@@ -1744,23 +1913,49 @@ const compileClosureCall = (
|
|
|
1744
1913
|
isKeepLazy: context.isKeepLazy,
|
|
1745
1914
|
});
|
|
1746
1915
|
};
|
|
1747
|
-
if (!
|
|
1748
|
-
|
|
1916
|
+
if (!memoizedLevel || args.length !== closure.params.length) {
|
|
1917
|
+
return (context) => evaluateBody(bindArguments(context), context);
|
|
1918
|
+
}
|
|
1919
|
+
const memos = getCallMemos(closure);
|
|
1920
|
+
const keys = args.map((arg) => compileArgumentKey(arg, environment));
|
|
1921
|
+
const usage = { hits: 0, misses: 0 };
|
|
1749
1922
|
return (context) => {
|
|
1750
|
-
const scope = bindArguments(context);
|
|
1751
|
-
const values = getArgumentValues(scope, args.length);
|
|
1752
1923
|
// A call TLC evaluates with EvalControl.KeepLazy builds what a memoized one wouldn't.
|
|
1753
|
-
if (
|
|
1754
|
-
|
|
1755
|
-
|
|
1924
|
+
if (context.isKeepLazy) return evaluateBody(bindArguments(context), context);
|
|
1925
|
+
callKey.sourceCount = 0;
|
|
1926
|
+
callKey.argCount = 0;
|
|
1927
|
+
callKey.hash = args.length;
|
|
1928
|
+
callKey.isStateKeyed = false;
|
|
1929
|
+
for (let index = 0; index < keys.length; index++) {
|
|
1930
|
+
if (!keys[index](context)) return evaluateBody(bindArguments(context), context);
|
|
1931
|
+
}
|
|
1932
|
+
const isStateKeyed = memoizedLevel === "state" || callKey.isStateKeyed;
|
|
1933
|
+
if (isStateKeyed && usage.misses > MEMOIZED_TRIAL_CALLS && usage.hits < usage.misses) {
|
|
1934
|
+
return evaluateBody(bindArguments(context), context);
|
|
1935
|
+
}
|
|
1936
|
+
const memo = isStateKeyed ? memos.state : memos.constant;
|
|
1937
|
+
if (isStateKeyed && memo.state !== context.state) {
|
|
1938
|
+
memo.state = context.state;
|
|
1939
|
+
memo.calls.clear();
|
|
1940
|
+
memo.size = 0;
|
|
1941
|
+
}
|
|
1942
|
+
// A small integer key keeps the Map from boxing it.
|
|
1943
|
+
const hash = callKey.hash & 0x3fffffff;
|
|
1756
1944
|
const bucket = memo.calls.get(hash);
|
|
1757
|
-
const known = bucket
|
|
1758
|
-
if (known)
|
|
1759
|
-
|
|
1945
|
+
const known = findCall(bucket);
|
|
1946
|
+
if (known) {
|
|
1947
|
+
if (isStateKeyed) usage.hits++;
|
|
1948
|
+
return known.value;
|
|
1949
|
+
}
|
|
1950
|
+
if (isStateKeyed) usage.misses++;
|
|
1951
|
+
const sources = callKey.sources.slice(0, callKey.sourceCount);
|
|
1952
|
+
const keyArgs = callKey.args.slice(0, callKey.argCount);
|
|
1953
|
+
const value = evaluateBody(bindArguments(context), context);
|
|
1760
1954
|
if (memo.size < MEMOIZED_CALL_LIMIT) {
|
|
1761
1955
|
memo.size++;
|
|
1762
|
-
|
|
1763
|
-
|
|
1956
|
+
const call = { sources, args: keyArgs, value };
|
|
1957
|
+
if (bucket) bucket.push(call);
|
|
1958
|
+
else memo.calls.set(hash, [call]);
|
|
1764
1959
|
}
|
|
1765
1960
|
return value;
|
|
1766
1961
|
};
|
|
@@ -1788,8 +1983,10 @@ const compileApply = (
|
|
|
1788
1983
|
: resolveGlobalOperator(expression.operator, environment);
|
|
1789
1984
|
if (global?.kind === "Closure") {
|
|
1790
1985
|
// The replay records the evaluation of each call, which TLC repeats.
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1986
|
+
const memoizedLevel = environment.callStack
|
|
1987
|
+
? undefined
|
|
1988
|
+
: getMemoizedLevel(expression, environment);
|
|
1989
|
+
return compileClosureCall(global, args, environment, memoizedLevel);
|
|
1793
1990
|
}
|
|
1794
1991
|
if (global?.kind === "Builtin" && global.name === "DOMAIN") {
|
|
1795
1992
|
const operand = getEvaluator(args[0], environment);
|
|
@@ -1822,9 +2019,11 @@ const compileApply = (
|
|
|
1822
2019
|
);
|
|
1823
2020
|
};
|
|
1824
2021
|
}
|
|
2022
|
+
const called = { entry: undefined as CalledBody | undefined };
|
|
2023
|
+
const binders = args.map((arg) => getArgumentBinder(arg, environment));
|
|
1825
2024
|
return (context) => {
|
|
1826
2025
|
const operator = resolveOperator(expression.operator, context);
|
|
1827
|
-
if (operator) return callOperator(operator, args, context);
|
|
2026
|
+
if (operator) return callOperator(operator, args, context, called, binders);
|
|
1828
2027
|
const definition = environment.definitions.get(expression.operator);
|
|
1829
2028
|
if (definition?.kind === "Function") {
|
|
1830
2029
|
throw new TlaEvaluationError(`${expression.operator} is a function; apply it with brackets`);
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,16 @@ export {
|
|
|
18
18
|
} from "./errors";
|
|
19
19
|
export { check } from "./parallel";
|
|
20
20
|
export { parseModule } from "./parser";
|
|
21
|
+
export { prove } from "./prove/prove";
|
|
22
|
+
export type {
|
|
23
|
+
ProofObligation,
|
|
24
|
+
ProofStatus,
|
|
25
|
+
ProveOptions,
|
|
26
|
+
ProveResult,
|
|
27
|
+
ProvedObligation,
|
|
28
|
+
TrivialObligation,
|
|
29
|
+
UnprovedObligation,
|
|
30
|
+
} from "./prove/prove";
|
|
21
31
|
export type { Module } from "./ast";
|
|
22
32
|
export { formatValue } from "./values";
|
|
23
33
|
export type { Value } from "./values";
|