tla-ts 0.0.4-dev.66582d4 → 0.0.4-dev.702eb98
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 +26 -141
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +37 -1
- package/dist/index.d.ts +37 -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 +515 -0
- package/dist/prove.js +515 -0
- package/dist/run-cli.cjs +30 -47
- package/dist/run-cli.js +30 -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 +280 -80
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +258 -37
- package/src/{obligation-anon.ts → obligations/anon.ts} +13 -7
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +2 -2
- package/src/{obligation-expression.ts → obligations/expression.ts} +54 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +134 -61
- package/src/{obligations.ts → obligations/index.ts} +26 -12
- package/src/{obligation-levels.ts → obligations/levels.ts} +12 -2
- package/src/{obligation-module.ts → obligations/module.ts} +46 -20
- package/src/obligations/pickle.ts +100 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +5 -59
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
- package/src/{obligation-source.ts → obligations/source.ts} +91 -35
- package/src/obligations/temporal.ts +319 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
- package/src/parallel-worker.ts +2 -18
- package/src/parallel.ts +10 -43
- package/src/prove/decide-pool.ts +100 -0
- package/src/prove/deciders.ts +27 -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 +477 -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 +520 -0
- package/src/prove/prep/defs.ts +27 -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 +552 -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 +29 -0
- package/src/prove/prove.ts +417 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +256 -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 +210 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +665 -0
- package/src/prove/smt/encode.ts +169 -0
- package/src/prove/smt/extensionality.ts +63 -0
- package/src/prove/smt/flatten.ts +127 -0
- package/src/prove/smt/format.ts +143 -0
- package/src/prove/smt/instances.ts +182 -0
- package/src/prove/smt/rewrite.ts +784 -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 +97 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +13 -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 +444 -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 +78 -35
- package/src/standard-modules.ts +5 -2
- package/src/successors.ts +25 -6
- 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/{obligation-format.ts → obligations/format.ts} +0 -0
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,
|
|
@@ -578,15 +590,19 @@ interface LazyFunction {
|
|
|
578
590
|
scope: Scope | undefined;
|
|
579
591
|
}
|
|
580
592
|
|
|
581
|
-
|
|
593
|
+
// The function keeps its parameters, body and scope itself, since a WeakMap entry for each
|
|
594
|
+
// short-lived function makes every garbage collection slower.
|
|
595
|
+
interface KeptLazyFunctionValue extends LazyFunctionValue {
|
|
596
|
+
lambda: LazyFunction;
|
|
597
|
+
}
|
|
582
598
|
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
};
|
|
599
|
+
const isKeptLazyFunction = (value: Value): value is KeptLazyFunctionValue =>
|
|
600
|
+
typeof value === "object" && value.kind === "LazyFunction" && "lambda" in value;
|
|
601
|
+
|
|
602
|
+
const keepLambda = (lambda: LazyFunction) => Object.assign(lambda.value, { lambda });
|
|
587
603
|
|
|
588
604
|
export const getLazyFunction = (value: Value) =>
|
|
589
|
-
|
|
605
|
+
isKeptLazyFunction(value) ? value.lambda : undefined;
|
|
590
606
|
|
|
591
607
|
// Tool.getFcnContext: the scope of a lazy function's body for the arguments of an application. It
|
|
592
608
|
// ignores arguments beyond the parameters.
|
|
@@ -835,7 +851,7 @@ const forceThunk = (thunk: Thunk, context: Context) => {
|
|
|
835
851
|
const isSameState = thunk.state === context.state && thunk.next === context.next;
|
|
836
852
|
if (isSameState && thunk.cache !== undefined) return thunk.cache;
|
|
837
853
|
const value = evaluate(thunk.expression, withScope(context, thunk.scope));
|
|
838
|
-
if (isSameState) thunk.cache = value;
|
|
854
|
+
if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
|
|
839
855
|
return value;
|
|
840
856
|
};
|
|
841
857
|
|
|
@@ -956,6 +972,7 @@ const createThunk = (expression: Expression, context: Context): Thunk => ({
|
|
|
956
972
|
state: context.state,
|
|
957
973
|
next: context.next,
|
|
958
974
|
cache: undefined,
|
|
975
|
+
isStreamed: false,
|
|
959
976
|
});
|
|
960
977
|
|
|
961
978
|
export const findGlobalName = (name: string, environment: Environment): GlobalName | undefined => {
|
|
@@ -1015,6 +1032,7 @@ export const bindOperatorArguments = (
|
|
|
1015
1032
|
closure: Closure,
|
|
1016
1033
|
args: Expression[],
|
|
1017
1034
|
context: Context,
|
|
1035
|
+
binders?: ArgumentBinder[],
|
|
1018
1036
|
): Scope | undefined => {
|
|
1019
1037
|
if (args.length !== closure.params.length) {
|
|
1020
1038
|
throw new TlaEvaluationError(
|
|
@@ -1027,18 +1045,36 @@ export const bindOperatorArguments = (
|
|
|
1027
1045
|
const binding: Binding =
|
|
1028
1046
|
param.arity > 0
|
|
1029
1047
|
? { kind: "Operator", operator: evaluateOperatorArgument(args[index], context) }
|
|
1030
|
-
: getArgumentBinder(args[index], context.environment)(context);
|
|
1048
|
+
: (binders?.[index] ?? getArgumentBinder(args[index], context.environment))(context);
|
|
1031
1049
|
scope = { name: param.name, binding, parent: scope };
|
|
1032
1050
|
}
|
|
1033
1051
|
return scope;
|
|
1034
1052
|
};
|
|
1035
1053
|
|
|
1036
|
-
|
|
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
|
+
) => {
|
|
1037
1067
|
if (operator.kind === "Closure") {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
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);
|
|
1042
1078
|
}
|
|
1043
1079
|
if (operator.kind === "Operator") return operator.call(args.map((arg) => evaluate(arg, context)));
|
|
1044
1080
|
if (operator.isLazy) return operator.evaluate(getLazyArguments(args, context), context);
|
|
@@ -1052,10 +1088,16 @@ const callOperator = (operator: Operator, args: Expression[], context: Context)
|
|
|
1052
1088
|
);
|
|
1053
1089
|
};
|
|
1054
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
|
+
|
|
1055
1097
|
export const bindDefinitions = (
|
|
1056
1098
|
definitions: Definition[],
|
|
1057
1099
|
context: Context,
|
|
1058
|
-
reevaluated?:
|
|
1100
|
+
reevaluated?: ReevaluatedDefinitions,
|
|
1059
1101
|
): Scope | undefined =>
|
|
1060
1102
|
definitions.reduce<Scope | undefined>((scope, definition) => {
|
|
1061
1103
|
const node: Scope = {
|
|
@@ -1077,10 +1119,11 @@ export const bindDefinitions = (
|
|
|
1077
1119
|
state: context.state,
|
|
1078
1120
|
next: context.next,
|
|
1079
1121
|
cache: undefined,
|
|
1122
|
+
isStreamed: false,
|
|
1080
1123
|
};
|
|
1081
1124
|
return node;
|
|
1082
1125
|
}
|
|
1083
|
-
if (definition.params.length > 0 || reevaluated?.has(definition)) {
|
|
1126
|
+
if (definition.params.length > 0 || reevaluated?.impure.has(definition)) {
|
|
1084
1127
|
node.binding = {
|
|
1085
1128
|
kind: "Operator",
|
|
1086
1129
|
operator: {
|
|
@@ -1100,6 +1143,7 @@ export const bindDefinitions = (
|
|
|
1100
1143
|
state: context.state,
|
|
1101
1144
|
next: context.next,
|
|
1102
1145
|
cache: undefined,
|
|
1146
|
+
isStreamed: reevaluated?.streamed.has(definition) ?? false,
|
|
1103
1147
|
};
|
|
1104
1148
|
return node;
|
|
1105
1149
|
}, context.scope);
|
|
@@ -1216,14 +1260,15 @@ const STREAMED_SET: Impurity = {
|
|
|
1216
1260
|
// TLC's next-state generator does not bind LET definitions to values, so each reference to one
|
|
1217
1261
|
// evaluates it again: one that calls an impure builtin repeats its effects, and a set one builds
|
|
1218
1262
|
// with UNION or \cup starts out uncached.
|
|
1219
|
-
export const getReevaluatedDefinitions = (
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
),
|
|
1226
|
-
)
|
|
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
|
+
});
|
|
1227
1272
|
|
|
1228
1273
|
export const isImpure = (environment: Environment) =>
|
|
1229
1274
|
[...environment.definitions.values()].some((definition) =>
|
|
@@ -1375,9 +1420,14 @@ const isStateCached = (expression: Expression, environment: Environment) =>
|
|
|
1375
1420
|
getReadVariables(expression, environment) !== undefined &&
|
|
1376
1421
|
!hasFreeLocals(expression, NO_BOUND_NAMES);
|
|
1377
1422
|
|
|
1378
|
-
//
|
|
1423
|
+
// A set filter TLC evaluates lazily, with how to rebuild it so that its predicate runs in another
|
|
1379
1424
|
// environment.
|
|
1380
|
-
|
|
1425
|
+
interface RebindableFilteredSet extends FilteredSetValue {
|
|
1426
|
+
rebind: (environment: Environment) => Value;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
const isRebindableFilteredSet = (value: Value): value is RebindableFilteredSet =>
|
|
1430
|
+
typeof value === "object" && value.kind === "FilteredSet" && "rebind" in value;
|
|
1381
1431
|
|
|
1382
1432
|
// TLC's CallStackTool rebinds the lazy values its evaluations return, so their later evaluation
|
|
1383
1433
|
// records its call stack too.
|
|
@@ -1398,11 +1448,7 @@ const traceEvaluator =
|
|
|
1398
1448
|
setTrace.callStack = callStack;
|
|
1399
1449
|
try {
|
|
1400
1450
|
const computed = evaluator(context);
|
|
1401
|
-
const rebind
|
|
1402
|
-
typeof computed === "object" && computed.kind === "FilteredSet"
|
|
1403
|
-
? filteredSetRebinders.get(computed)
|
|
1404
|
-
: undefined;
|
|
1405
|
-
const value = rebind ? rebind(environment) : computed;
|
|
1451
|
+
const value = isRebindableFilteredSet(computed) ? computed.rebind(environment) : computed;
|
|
1406
1452
|
callStack.values.set(expression, value);
|
|
1407
1453
|
if (typeof value === "object" && value.kind !== "FilteredSet" && isSourced(expression)) {
|
|
1408
1454
|
callStack.sources.set(value, expression);
|
|
@@ -1506,7 +1552,7 @@ export const getEvaluator = (expression: Expression, environment: Environment):
|
|
|
1506
1552
|
|
|
1507
1553
|
const entryEvaluators = new WeakMap<Expression, Evaluator>();
|
|
1508
1554
|
|
|
1509
|
-
const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1555
|
+
export const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1510
1556
|
if (environment.callStack) return getEvaluator(expression, environment);
|
|
1511
1557
|
const cached = entryEvaluators.get(expression);
|
|
1512
1558
|
if (cached) return cached;
|
|
@@ -1680,52 +1726,180 @@ export const compileArgumentScope = (
|
|
|
1680
1726
|
};
|
|
1681
1727
|
|
|
1682
1728
|
interface MemoizedCall {
|
|
1729
|
+
sources: (Expression | undefined)[];
|
|
1683
1730
|
args: Value[];
|
|
1684
1731
|
value: Value;
|
|
1685
1732
|
}
|
|
1686
1733
|
|
|
1687
1734
|
const MEMOIZED_CALL_LIMIT = 1 << 16;
|
|
1688
1735
|
|
|
1689
|
-
|
|
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>();
|
|
1690
1754
|
|
|
1691
|
-
const
|
|
1755
|
+
const getCallMemos = (closure: Closure) => {
|
|
1692
1756
|
const cached = callMemos.get(closure);
|
|
1693
1757
|
if (cached) return cached;
|
|
1694
|
-
const
|
|
1695
|
-
callMemos.set(closure,
|
|
1696
|
-
return
|
|
1758
|
+
const memos = { constant: createCallMemo(), state: createCallMemo() };
|
|
1759
|
+
callMemos.set(closure, memos);
|
|
1760
|
+
return memos;
|
|
1697
1761
|
};
|
|
1698
1762
|
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
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));
|
|
1704
1829
|
}
|
|
1705
|
-
return
|
|
1830
|
+
return true;
|
|
1706
1831
|
};
|
|
1707
1832
|
|
|
1708
|
-
|
|
1709
|
-
|
|
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
|
+
};
|
|
1710
1862
|
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
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
|
+
};
|
|
1883
|
+
|
|
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) => {
|
|
1714
1887
|
const definition = getDefinition(expression.operator, environment);
|
|
1715
|
-
|
|
1888
|
+
const isMemoizable =
|
|
1716
1889
|
definition?.kind === "Operator" &&
|
|
1717
1890
|
definition.params.length > 0 &&
|
|
1718
1891
|
definition.params.every((param) => param.arity === 0) &&
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
);
|
|
1892
|
+
!isImpureDefinition(definition, environment);
|
|
1893
|
+
if (!isMemoizable) return undefined;
|
|
1894
|
+
if (isConstantLevel(definition, environment)) return "constant";
|
|
1895
|
+
return isStatePure(definition, environment) ? "state" : undefined;
|
|
1722
1896
|
};
|
|
1723
1897
|
|
|
1724
1898
|
const compileClosureCall = (
|
|
1725
1899
|
closure: Closure,
|
|
1726
1900
|
args: Expression[],
|
|
1727
1901
|
environment: Environment,
|
|
1728
|
-
|
|
1902
|
+
memoizedLevel: "constant" | "state" | undefined,
|
|
1729
1903
|
): Evaluator => {
|
|
1730
1904
|
const bindArguments = compileArgumentScope(closure, args, environment);
|
|
1731
1905
|
const compiled = { body: undefined as Evaluator | undefined };
|
|
@@ -1739,23 +1913,49 @@ const compileClosureCall = (
|
|
|
1739
1913
|
isKeepLazy: context.isKeepLazy,
|
|
1740
1914
|
});
|
|
1741
1915
|
};
|
|
1742
|
-
if (!
|
|
1743
|
-
|
|
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 };
|
|
1744
1922
|
return (context) => {
|
|
1745
|
-
const scope = bindArguments(context);
|
|
1746
|
-
const values = getArgumentValues(scope, args.length);
|
|
1747
1923
|
// A call TLC evaluates with EvalControl.KeepLazy builds what a memoized one wouldn't.
|
|
1748
|
-
if (
|
|
1749
|
-
|
|
1750
|
-
|
|
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;
|
|
1751
1944
|
const bucket = memo.calls.get(hash);
|
|
1752
|
-
const known = bucket
|
|
1753
|
-
if (known)
|
|
1754
|
-
|
|
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);
|
|
1755
1954
|
if (memo.size < MEMOIZED_CALL_LIMIT) {
|
|
1756
1955
|
memo.size++;
|
|
1757
|
-
|
|
1758
|
-
|
|
1956
|
+
const call = { sources, args: keyArgs, value };
|
|
1957
|
+
if (bucket) bucket.push(call);
|
|
1958
|
+
else memo.calls.set(hash, [call]);
|
|
1759
1959
|
}
|
|
1760
1960
|
return value;
|
|
1761
1961
|
};
|
|
@@ -1783,8 +1983,10 @@ const compileApply = (
|
|
|
1783
1983
|
: resolveGlobalOperator(expression.operator, environment);
|
|
1784
1984
|
if (global?.kind === "Closure") {
|
|
1785
1985
|
// The replay records the evaluation of each call, which TLC repeats.
|
|
1786
|
-
const
|
|
1787
|
-
|
|
1986
|
+
const memoizedLevel = environment.callStack
|
|
1987
|
+
? undefined
|
|
1988
|
+
: getMemoizedLevel(expression, environment);
|
|
1989
|
+
return compileClosureCall(global, args, environment, memoizedLevel);
|
|
1788
1990
|
}
|
|
1789
1991
|
if (global?.kind === "Builtin" && global.name === "DOMAIN") {
|
|
1790
1992
|
const operand = getEvaluator(args[0], environment);
|
|
@@ -1817,9 +2019,11 @@ const compileApply = (
|
|
|
1817
2019
|
);
|
|
1818
2020
|
};
|
|
1819
2021
|
}
|
|
2022
|
+
const called = { entry: undefined as CalledBody | undefined };
|
|
2023
|
+
const binders = args.map((arg) => getArgumentBinder(arg, environment));
|
|
1820
2024
|
return (context) => {
|
|
1821
2025
|
const operator = resolveOperator(expression.operator, context);
|
|
1822
|
-
if (operator) return callOperator(operator, args, context);
|
|
2026
|
+
if (operator) return callOperator(operator, args, context, called, binders);
|
|
1823
2027
|
const definition = environment.definitions.get(expression.operator);
|
|
1824
2028
|
if (definition?.kind === "Function") {
|
|
1825
2029
|
throw new TlaEvaluationError(`${expression.operator} is a function; apply it with brackets`);
|
|
@@ -2069,22 +2273,18 @@ const compileSetComprehension = (
|
|
|
2069
2273
|
base: Value,
|
|
2070
2274
|
context: Context,
|
|
2071
2275
|
evaluator: Evaluator,
|
|
2072
|
-
):
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
};
|
|
2079
|
-
filteredSetRebinders.set(filtered, (tracing) =>
|
|
2276
|
+
): RebindableFilteredSet => ({
|
|
2277
|
+
kind: "FilteredSet",
|
|
2278
|
+
base,
|
|
2279
|
+
test: createTest(evaluator, context),
|
|
2280
|
+
source,
|
|
2281
|
+
rebind: (tracing) =>
|
|
2080
2282
|
createFiltered(
|
|
2081
2283
|
base,
|
|
2082
2284
|
{ ...context, environment: tracing },
|
|
2083
2285
|
getEvaluator(expression.predicate, tracing),
|
|
2084
2286
|
),
|
|
2085
|
-
|
|
2086
|
-
return filtered;
|
|
2087
|
-
};
|
|
2287
|
+
});
|
|
2088
2288
|
return (context) => {
|
|
2089
2289
|
const base = set(context);
|
|
2090
2290
|
// TLC filters any value it can't enumerate lazily, and fails only when it uses the result.
|
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";
|