tla-ts 0.0.4-dev.0be9567 → 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 +33 -1
- package/dist/index.d.ts +33 -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/errors.ts +86 -0
- package/src/evaluate.ts +54 -19
- 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/successors.ts +24 -5
- 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 +47 -4
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
package/dist/worker.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license tla-ts
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Aiden Bai
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=/* @__PURE__ */ new WeakMap,n=(e,n)=>(e instanceof Error&&!t.has(e)&&t.set(e,n),e),r=e=>t.get(e),i=t=>{try{return t()}catch(t){throw n(t,e.error)}},a=e=>{let t=i(e);return t&&{branches:t.branches,addInitialState:(e,n,r)=>i(()=>t.addInitialState(e,n,r)),addState:(e,n,r,a)=>i(()=>t.addState(e,n,r,a)),findViolation:()=>i(()=>t.findViolation()),getViolatedProperties:(e,n)=>i(()=>t.getViolatedProperties(e,n))}},o=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,s=o(`java.lang.RuntimeException`),c=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var l=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},u=class extends l{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},d=class extends u{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},f=class extends d{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const p=(e,t=!1,n,r=[])=>new u(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
10
|
+
|
|
11
|
+
`),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),m=(e,t)=>p([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),h=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
|
|
12
|
+
`)}`,g=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,_=(e,t)=>p([{location:g(t),message:e}]);var v=class extends l{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends l{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
|
|
13
|
+
of an incorrect recursive function definition that caused TLC to enter
|
|
14
|
+
an infinite loop when trying to compute the function or its application
|
|
15
|
+
to an element in its putative domain.`;var x=class extends y{constructor(){super(b)}},S=class extends y{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},C=class extends y{variable;constructor(e,t){super(e),this.variable=t}},w=class extends y{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},T=class extends y{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},E=class extends l{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},D=class extends E{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},O=class extends l{constructor(e,t){super(e,t),this.name=`TlaProverError`}},k=class extends l{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},A=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},j=class extends l{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},M=class extends l{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},N=class extends l{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},P=class extends l{constructor(e){super(e),this.name=`SmtInvariantError`}},F=class extends l{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},I=class extends l{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},L=class extends l{constructor(e,t){super(e,t),this.name=`SmtParseError`}},R=class extends j{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const z=t=>r(t)??(t instanceof u?e.specParseError:t instanceof v?e.configParseError:t instanceof y?e.specEvaluationFailure:e.error);var B=class extends l{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},V=class extends l{constructor(e){super(e),this.name=`PcalRuntimeError`}},H=class extends l{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const U=`node:worker_threads`,W=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,G=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
|
|
16
|
+
/* @vite-ignore */
|
|
17
|
+
/* webpackIgnore: true */
|
|
18
|
+
U))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},K=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
19
|
+
/* @vite-ignore */
|
|
20
|
+
/* webpackIgnore: true */
|
|
21
|
+
U)).parentPort;Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return o}});
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license tla-ts
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Aiden Bai
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=/* @__PURE__ */ new WeakMap,n=(e,n)=>(e instanceof Error&&!t.has(e)&&t.set(e,n),e),r=e=>t.get(e),i=t=>{try{return t()}catch(t){throw n(t,e.error)}},a=e=>{let t=i(e);return t&&{branches:t.branches,addInitialState:(e,n,r)=>i(()=>t.addInitialState(e,n,r)),addState:(e,n,r,a)=>i(()=>t.addState(e,n,r,a)),findViolation:()=>i(()=>t.findViolation()),getViolatedProperties:(e,n)=>i(()=>t.getViolatedProperties(e,n))}},o=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,s=o(`java.lang.RuntimeException`),c=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var l=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},u=class extends l{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},d=class extends u{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},f=class extends d{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const p=(e,t=!1,n,r=[])=>new u(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
10
|
+
|
|
11
|
+
`),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),m=(e,t)=>p([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),h=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
|
|
12
|
+
`)}`,g=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,_=(e,t)=>p([{location:g(t),message:e}]);var v=class extends l{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends l{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
|
|
13
|
+
of an incorrect recursive function definition that caused TLC to enter
|
|
14
|
+
an infinite loop when trying to compute the function or its application
|
|
15
|
+
to an element in its putative domain.`;var x=class extends y{constructor(){super(b)}},S=class extends y{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},C=class extends y{variable;constructor(e,t){super(e),this.variable=t}},w=class extends y{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},T=class extends y{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},E=class extends l{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},D=class extends E{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},O=class extends l{constructor(e,t){super(e,t),this.name=`TlaProverError`}},k=class extends l{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},A=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},j=class extends l{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},M=class extends l{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},N=class extends l{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},P=class extends l{constructor(e){super(e),this.name=`SmtInvariantError`}},F=class extends l{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},I=class extends l{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},L=class extends l{constructor(e,t){super(e,t),this.name=`SmtParseError`}},R=class extends j{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const z=t=>r(t)??(t instanceof u?e.specParseError:t instanceof v?e.configParseError:t instanceof y?e.specEvaluationFailure:e.error);var B=class extends l{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},V=class extends l{constructor(e){super(e),this.name=`PcalRuntimeError`}},H=class extends l{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const U=`node:worker_threads`,W=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,G=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
|
|
16
|
+
/* @vite-ignore */
|
|
17
|
+
/* webpackIgnore: true */
|
|
18
|
+
U))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},K=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
19
|
+
/* @vite-ignore */
|
|
20
|
+
/* webpackIgnore: true */
|
|
21
|
+
U)).parentPort;export{k as A,c as B,E as C,u as D,x as E,_ as F,r as H,g as I,h as L,s as M,m as N,C as O,p as P,z as R,w as S,d as T,n as U,e as V,a as W,T as _,H as a,R as b,I as c,P as d,L as f,y as g,l as h,F as i,D as j,j as k,b as l,v as m,W as n,B as o,M as p,G as r,V as s,K as t,N as u,S as v,O as w,f as x,A as y,o as z};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tla-ts",
|
|
3
|
-
"version": "0.0.4-dev.
|
|
3
|
+
"version": "0.0.4-dev.2da24e1",
|
|
4
4
|
"description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formal verification",
|
|
@@ -60,23 +60,32 @@
|
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^22",
|
|
62
62
|
"publint": "^0.3.0",
|
|
63
|
-
"tsx": "^4.21.0",
|
|
64
63
|
"typescript": "^7.0.2",
|
|
65
64
|
"vite-plus": "latest"
|
|
66
65
|
},
|
|
67
66
|
"scripts": {
|
|
68
67
|
"build": "NODE_ENV=production vp pack",
|
|
69
68
|
"dev": "NODE_ENV=development vp pack --watch",
|
|
70
|
-
"bench": "pnpm build &&
|
|
71
|
-
"bench:corpus": "pnpm build &&
|
|
72
|
-
"
|
|
73
|
-
"conformance
|
|
74
|
-
"conformance:
|
|
75
|
-
"conformance:
|
|
76
|
-
"conformance:
|
|
77
|
-
"conformance:
|
|
78
|
-
"conformance:
|
|
79
|
-
"conformance:
|
|
69
|
+
"bench": "pnpm build && bun scripts/run.ts benchmark",
|
|
70
|
+
"bench:corpus": "pnpm build && bun scripts/run.ts benchmark-corpus",
|
|
71
|
+
"bench:prove": "pnpm build && bun scripts/run.ts prove-benchmark",
|
|
72
|
+
"conformance": "bun scripts/run.ts conformance",
|
|
73
|
+
"conformance:fetch": "bun scripts/run.ts fetch-corpora",
|
|
74
|
+
"conformance:fingerprint": "bun scripts/run.ts fingerprint-conformance",
|
|
75
|
+
"conformance:isabelle": "bun scripts/run.ts isabelle-conformance",
|
|
76
|
+
"conformance:isabelle-encode": "bun scripts/run.ts isabelle-encode-conformance",
|
|
77
|
+
"conformance:sany": "bun scripts/run.ts proof-conformance",
|
|
78
|
+
"conformance:ptl": "bun scripts/run.ts ptl-conformance",
|
|
79
|
+
"conformance:smt": "bun scripts/run.ts smt-conformance",
|
|
80
|
+
"conformance:record": "bun scripts/run.ts record-tlc",
|
|
81
|
+
"conformance:record-sany": "bun scripts/run.ts record-sany",
|
|
82
|
+
"conformance:record-statechart": "bun scripts/run.ts record-statechart",
|
|
83
|
+
"conformance:record-proofs": "bun scripts/run.ts record-proofs",
|
|
84
|
+
"conformance:record-tlapm": "bun scripts/run.ts record-tlapm",
|
|
85
|
+
"conformance:smt-encode": "bun scripts/run.ts smt-encode-conformance",
|
|
86
|
+
"conformance:prove": "pnpm build && bun scripts/run.ts prove-conformance",
|
|
87
|
+
"conformance:tlapm": "bun scripts/run.ts tlapm-conformance",
|
|
88
|
+
"conformance:zenon": "bun scripts/run.ts zenon-conformance",
|
|
80
89
|
"publint": "publint",
|
|
81
90
|
"test": "vp test",
|
|
82
91
|
"typecheck": "tsc --noEmit"
|
package/src/check.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -251,6 +251,39 @@ export class TlapmBugError extends TlaProofError {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
// A backend can't take an obligation, which tlapm reports as not tried.
|
|
255
|
+
export class TlaProverError extends TlaError {
|
|
256
|
+
constructor(message: string, cause?: unknown) {
|
|
257
|
+
super(message, cause);
|
|
258
|
+
this.name = "TlaProverError";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Zenon gives up on a .znn file the way the OCaml Zenon raises an exception and prints no proof.
|
|
263
|
+
export class TlaZenonError extends TlaError {
|
|
264
|
+
constructor(message: string, cause?: unknown) {
|
|
265
|
+
super(message, cause);
|
|
266
|
+
this.name = "TlaZenonError";
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// The exceptions Isabelle raises: ERROR for a rejected theory or a failed proof, TERM, TYPE and THM
|
|
271
|
+
// for an ill-formed term, type or theorem, and Interrupt when the time limit runs out.
|
|
272
|
+
export type IsabelleException = "ERROR" | "TERM" | "TYPE" | "THM" | "Interrupt";
|
|
273
|
+
|
|
274
|
+
// Isabelle's tactics raise and handle these as control flow, often millions of times per proof, and
|
|
275
|
+
// decideIsabelle answers "unknown" for any that escape. So unlike an Error, it skips the stack trace.
|
|
276
|
+
export class TlaIsabelleError {
|
|
277
|
+
readonly name = "TlaIsabelleError";
|
|
278
|
+
readonly exception: IsabelleException;
|
|
279
|
+
readonly message: string;
|
|
280
|
+
|
|
281
|
+
constructor(exception: IsabelleException, message: string) {
|
|
282
|
+
this.exception = exception;
|
|
283
|
+
this.message = message;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
254
287
|
export class TlaUnsupportedError extends TlaError {
|
|
255
288
|
constructor(message: string, cause?: unknown) {
|
|
256
289
|
super(message, cause);
|
|
@@ -258,6 +291,59 @@ export class TlaUnsupportedError extends TlaError {
|
|
|
258
291
|
}
|
|
259
292
|
}
|
|
260
293
|
|
|
294
|
+
// The SMT solver met input outside the SMT-LIB subset that tlapm emits, or a numeral too large for
|
|
295
|
+
// its exact arithmetic. The solver answers unknown.
|
|
296
|
+
export class SmtUnsupportedError extends TlaError {
|
|
297
|
+
constructor(message: string, cause?: unknown) {
|
|
298
|
+
super(message, cause);
|
|
299
|
+
this.name = "SmtUnsupportedError";
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// The SMT solver ran past its time limit, or its signal aborted, in the middle of a rewrite. The
|
|
304
|
+
// solver answers unknown.
|
|
305
|
+
export class SmtCanceledError extends TlaError {
|
|
306
|
+
constructor() {
|
|
307
|
+
super("the SMT solver was canceled");
|
|
308
|
+
this.name = "SmtCanceledError";
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// The SMT solver broke one of its own invariants, a bug in the port rather than in the input. It
|
|
313
|
+
// keeps its name, and index.ts doesn't export it.
|
|
314
|
+
export class SmtInvariantError extends TlaError {
|
|
315
|
+
constructor(message: string) {
|
|
316
|
+
super(message);
|
|
317
|
+
this.name = "SmtInvariantError";
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// nlsat reached a case Z3 leaves unimplemented, where Z3 exits the process. nra answers unknown
|
|
322
|
+
// instead. index.ts doesn't export it.
|
|
323
|
+
export class NlsatUnsupportedError extends TlaError {
|
|
324
|
+
constructor(reason: string) {
|
|
325
|
+
super(`nlsat does not implement ${reason}`);
|
|
326
|
+
this.name = "NlsatUnsupportedError";
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// mem_out: the pdd manager needed a node past its limit outside an operation. Grobner catches it
|
|
331
|
+
// and gives up on the round. index.ts doesn't export it.
|
|
332
|
+
export class PddMemoryOutError extends TlaError {
|
|
333
|
+
constructor() {
|
|
334
|
+
super("the pdd manager ran out of nodes");
|
|
335
|
+
this.name = "PddMemoryOutError";
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// The SMT-LIB input is malformed: a syntax error, an undeclared symbol, or an ill-sorted application.
|
|
340
|
+
export class SmtParseError extends TlaError {
|
|
341
|
+
constructor(message: string, cause?: unknown) {
|
|
342
|
+
super(message, cause);
|
|
343
|
+
this.name = "SmtParseError";
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
261
347
|
// An exception that TLC's Java code throws and nothing catches, with the stack trace it prints, after
|
|
262
348
|
// what the frames that the exception unwinds print about it.
|
|
263
349
|
export class TlaJavaException extends TlaUnsupportedError {
|
package/src/evaluate.ts
CHANGED
|
@@ -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 };
|
|
@@ -847,7 +851,7 @@ const forceThunk = (thunk: Thunk, context: Context) => {
|
|
|
847
851
|
const isSameState = thunk.state === context.state && thunk.next === context.next;
|
|
848
852
|
if (isSameState && thunk.cache !== undefined) return thunk.cache;
|
|
849
853
|
const value = evaluate(thunk.expression, withScope(context, thunk.scope));
|
|
850
|
-
if (isSameState) thunk.cache = value;
|
|
854
|
+
if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
|
|
851
855
|
return value;
|
|
852
856
|
};
|
|
853
857
|
|
|
@@ -968,6 +972,7 @@ const createThunk = (expression: Expression, context: Context): Thunk => ({
|
|
|
968
972
|
state: context.state,
|
|
969
973
|
next: context.next,
|
|
970
974
|
cache: undefined,
|
|
975
|
+
isStreamed: false,
|
|
971
976
|
});
|
|
972
977
|
|
|
973
978
|
export const findGlobalName = (name: string, environment: Environment): GlobalName | undefined => {
|
|
@@ -1027,6 +1032,7 @@ export const bindOperatorArguments = (
|
|
|
1027
1032
|
closure: Closure,
|
|
1028
1033
|
args: Expression[],
|
|
1029
1034
|
context: Context,
|
|
1035
|
+
binders?: ArgumentBinder[],
|
|
1030
1036
|
): Scope | undefined => {
|
|
1031
1037
|
if (args.length !== closure.params.length) {
|
|
1032
1038
|
throw new TlaEvaluationError(
|
|
@@ -1039,18 +1045,36 @@ export const bindOperatorArguments = (
|
|
|
1039
1045
|
const binding: Binding =
|
|
1040
1046
|
param.arity > 0
|
|
1041
1047
|
? { kind: "Operator", operator: evaluateOperatorArgument(args[index], context) }
|
|
1042
|
-
: getArgumentBinder(args[index], context.environment)(context);
|
|
1048
|
+
: (binders?.[index] ?? getArgumentBinder(args[index], context.environment))(context);
|
|
1043
1049
|
scope = { name: param.name, binding, parent: scope };
|
|
1044
1050
|
}
|
|
1045
1051
|
return scope;
|
|
1046
1052
|
};
|
|
1047
1053
|
|
|
1048
|
-
|
|
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
|
+
) => {
|
|
1049
1067
|
if (operator.kind === "Closure") {
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
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);
|
|
1054
1078
|
}
|
|
1055
1079
|
if (operator.kind === "Operator") return operator.call(args.map((arg) => evaluate(arg, context)));
|
|
1056
1080
|
if (operator.isLazy) return operator.evaluate(getLazyArguments(args, context), context);
|
|
@@ -1064,10 +1088,16 @@ const callOperator = (operator: Operator, args: Expression[], context: Context)
|
|
|
1064
1088
|
);
|
|
1065
1089
|
};
|
|
1066
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
|
+
|
|
1067
1097
|
export const bindDefinitions = (
|
|
1068
1098
|
definitions: Definition[],
|
|
1069
1099
|
context: Context,
|
|
1070
|
-
reevaluated?:
|
|
1100
|
+
reevaluated?: ReevaluatedDefinitions,
|
|
1071
1101
|
): Scope | undefined =>
|
|
1072
1102
|
definitions.reduce<Scope | undefined>((scope, definition) => {
|
|
1073
1103
|
const node: Scope = {
|
|
@@ -1089,10 +1119,11 @@ export const bindDefinitions = (
|
|
|
1089
1119
|
state: context.state,
|
|
1090
1120
|
next: context.next,
|
|
1091
1121
|
cache: undefined,
|
|
1122
|
+
isStreamed: false,
|
|
1092
1123
|
};
|
|
1093
1124
|
return node;
|
|
1094
1125
|
}
|
|
1095
|
-
if (definition.params.length > 0 || reevaluated?.has(definition)) {
|
|
1126
|
+
if (definition.params.length > 0 || reevaluated?.impure.has(definition)) {
|
|
1096
1127
|
node.binding = {
|
|
1097
1128
|
kind: "Operator",
|
|
1098
1129
|
operator: {
|
|
@@ -1112,6 +1143,7 @@ export const bindDefinitions = (
|
|
|
1112
1143
|
state: context.state,
|
|
1113
1144
|
next: context.next,
|
|
1114
1145
|
cache: undefined,
|
|
1146
|
+
isStreamed: reevaluated?.streamed.has(definition) ?? false,
|
|
1115
1147
|
};
|
|
1116
1148
|
return node;
|
|
1117
1149
|
}, context.scope);
|
|
@@ -1228,14 +1260,15 @@ const STREAMED_SET: Impurity = {
|
|
|
1228
1260
|
// TLC's next-state generator does not bind LET definitions to values, so each reference to one
|
|
1229
1261
|
// evaluates it again: one that calls an impure builtin repeats its effects, and a set one builds
|
|
1230
1262
|
// with UNION or \cup starts out uncached.
|
|
1231
|
-
export const getReevaluatedDefinitions = (
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
),
|
|
1238
|
-
)
|
|
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
|
+
});
|
|
1239
1272
|
|
|
1240
1273
|
export const isImpure = (environment: Environment) =>
|
|
1241
1274
|
[...environment.definitions.values()].some((definition) =>
|
|
@@ -1519,7 +1552,7 @@ export const getEvaluator = (expression: Expression, environment: Environment):
|
|
|
1519
1552
|
|
|
1520
1553
|
const entryEvaluators = new WeakMap<Expression, Evaluator>();
|
|
1521
1554
|
|
|
1522
|
-
const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1555
|
+
export const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1523
1556
|
if (environment.callStack) return getEvaluator(expression, environment);
|
|
1524
1557
|
const cached = entryEvaluators.get(expression);
|
|
1525
1558
|
if (cached) return cached;
|
|
@@ -1986,9 +2019,11 @@ const compileApply = (
|
|
|
1986
2019
|
);
|
|
1987
2020
|
};
|
|
1988
2021
|
}
|
|
2022
|
+
const called = { entry: undefined as CalledBody | undefined };
|
|
2023
|
+
const binders = args.map((arg) => getArgumentBinder(arg, environment));
|
|
1989
2024
|
return (context) => {
|
|
1990
2025
|
const operator = resolveOperator(expression.operator, context);
|
|
1991
|
-
if (operator) return callOperator(operator, args, context);
|
|
2026
|
+
if (operator) return callOperator(operator, args, context, called, binders);
|
|
1992
2027
|
const definition = environment.definitions.get(expression.operator);
|
|
1993
2028
|
if (definition?.kind === "Function") {
|
|
1994
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";
|