tla-ts 0.0.9-dev.8298a52 → 0.0.10-dev.28c823e4b
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 +7 -0
- package/dist/compile.cjs +3 -3
- package/dist/compile.js +3 -3
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +52 -52
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +105 -10
- package/dist/index.d.ts +105 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +4 -23
- package/src/bags.ts +99 -102
- package/src/builtins.ts +40 -78
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +564 -366
- package/src/cli/options.ts +10 -5
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +18 -11
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +640 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +525 -216
- package/src/cli/typescript.ts +0 -3
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +237 -119
- package/src/errors.ts +56 -56
- package/src/evaluate.ts +543 -341
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +38 -31
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +255 -139
- package/src/levels.ts +8 -17
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +77 -117
- package/src/liveness.ts +106 -62
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +24 -33
- package/src/parallel.ts +48 -40
- package/src/parser.ts +565 -282
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +1 -16
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +12 -112
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generator.ts +149 -252
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +41 -61
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +495 -155
- package/src/simulate.ts +685 -0
- package/src/spec-description.ts +176 -69
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +254 -69
- package/src/state-graph.ts +50 -24
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +260 -91
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +110 -44
- package/src/tlc/order.ts +37 -60
- package/src/tlc/random.ts +33 -45
- package/src/tlc/replay.ts +549 -217
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +76 -41
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +269 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +8 -21
- package/src/typescript/collections.ts +0 -15
- package/src/typescript/compile.ts +0 -5
- package/src/typescript/context.ts +0 -12
- package/src/typescript/emit.ts +0 -1
- package/src/typescript/expressions.ts +0 -12
- package/src/typescript/formula.ts +4 -12
- package/src/typescript/functions.ts +6 -17
- package/src/typescript/model.ts +10 -11
- package/src/typescript/names.ts +0 -2
- package/src/typescript/program.ts +0 -3
- package/src/typescript/properties.ts +6 -8
- package/src/typescript/scope.ts +0 -5
- package/src/typescript/steps.ts +0 -10
- package/src/typescript/types.ts +1 -8
- package/src/values.ts +749 -330
- package/src/worker.ts +7 -8
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { gzipSync } from "node:zlib";
|
|
2
|
+
import { defineStateOperator, getValue, overrideWithJava } from "../builtins";
|
|
3
|
+
import type { Builtin } from "../evaluate";
|
|
4
|
+
import { getPath, type FileSystem } from "../json";
|
|
5
|
+
import {
|
|
6
|
+
getFunctionClass,
|
|
7
|
+
getModelValues,
|
|
8
|
+
isSetValue,
|
|
9
|
+
toFiniteFunction,
|
|
10
|
+
toFiniteSet,
|
|
11
|
+
type Value,
|
|
12
|
+
} from "../values";
|
|
13
|
+
|
|
14
|
+
const TAGS = {
|
|
15
|
+
boolean: 0,
|
|
16
|
+
integer: 1,
|
|
17
|
+
string: 3,
|
|
18
|
+
record: 4,
|
|
19
|
+
set: 5,
|
|
20
|
+
tuple: 7,
|
|
21
|
+
function: 9,
|
|
22
|
+
modelValue: 21,
|
|
23
|
+
interval: 23,
|
|
24
|
+
handle: 26,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const serializeValue = (value: Value) => {
|
|
28
|
+
const bytes: number[] = [];
|
|
29
|
+
const objectHandles = new Map<object, number>();
|
|
30
|
+
const nameHandles = new Map<string, number>();
|
|
31
|
+
let handleCount = 0;
|
|
32
|
+
const modelValues = getModelValues();
|
|
33
|
+
const writeByte = (byte: number) => bytes.push(byte & 0xff);
|
|
34
|
+
const writeShort = (short: number) => {
|
|
35
|
+
writeByte(short >> 8);
|
|
36
|
+
writeByte(short);
|
|
37
|
+
};
|
|
38
|
+
const writeInt = (int: number) => {
|
|
39
|
+
writeShort(int >> 16);
|
|
40
|
+
writeShort(int);
|
|
41
|
+
};
|
|
42
|
+
const writeNat = (nat: number) => (nat > 0x7fff ? writeInt(-nat) : writeShort(nat));
|
|
43
|
+
const writeString = (text: string) => {
|
|
44
|
+
writeByte(TAGS.string);
|
|
45
|
+
writeInt(0);
|
|
46
|
+
writeInt(-1);
|
|
47
|
+
writeInt(text.length);
|
|
48
|
+
text.split("").forEach((unit) => writeByte(unit.charCodeAt(0)));
|
|
49
|
+
};
|
|
50
|
+
const writeHandle = (index: number) => {
|
|
51
|
+
writeByte(TAGS.handle);
|
|
52
|
+
writeNat(index);
|
|
53
|
+
};
|
|
54
|
+
const write = (inner: Value): void => {
|
|
55
|
+
if (typeof inner === "boolean") {
|
|
56
|
+
writeByte(TAGS.boolean);
|
|
57
|
+
writeByte(inner ? 1 : 0);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (typeof inner === "number") {
|
|
61
|
+
writeByte(TAGS.integer);
|
|
62
|
+
writeInt(inner);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (typeof inner === "string") {
|
|
66
|
+
handleCount++;
|
|
67
|
+
writeString(inner);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (inner.kind === "ModelValue") {
|
|
71
|
+
writeByte(TAGS.modelValue);
|
|
72
|
+
writeShort(modelValues.indexOf(inner));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (inner.kind === "Interval") {
|
|
76
|
+
writeByte(TAGS.interval);
|
|
77
|
+
writeInt(inner.low);
|
|
78
|
+
writeInt(inner.high);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const handle = objectHandles.get(inner);
|
|
82
|
+
if (handle !== undefined) {
|
|
83
|
+
writeHandle(handle);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
objectHandles.set(inner, handleCount++);
|
|
87
|
+
if (isSetValue(inner)) {
|
|
88
|
+
const elements = toFiniteSet(inner).elements;
|
|
89
|
+
writeByte(TAGS.set);
|
|
90
|
+
writeInt(elements.length);
|
|
91
|
+
elements.forEach(write);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const functionValue = toFiniteFunction(inner);
|
|
95
|
+
const functionClass = getFunctionClass(inner);
|
|
96
|
+
if (functionClass === "tuple") {
|
|
97
|
+
writeByte(TAGS.tuple);
|
|
98
|
+
writeNat(functionValue.range.length);
|
|
99
|
+
functionValue.range.forEach(write);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (functionClass === "record") {
|
|
103
|
+
writeByte(TAGS.record);
|
|
104
|
+
writeInt(functionValue.domain.length);
|
|
105
|
+
functionValue.domain.forEach((name, index) => {
|
|
106
|
+
const fieldName = String(name);
|
|
107
|
+
const nameHandle = nameHandles.get(fieldName);
|
|
108
|
+
if (nameHandle === undefined) {
|
|
109
|
+
nameHandles.set(fieldName, handleCount++);
|
|
110
|
+
writeString(fieldName);
|
|
111
|
+
} else {
|
|
112
|
+
writeHandle(nameHandle);
|
|
113
|
+
}
|
|
114
|
+
write(functionValue.range[index]);
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
writeByte(TAGS.function);
|
|
119
|
+
writeNat(functionValue.domain.length);
|
|
120
|
+
writeByte(1);
|
|
121
|
+
functionValue.domain.forEach((key, index) => {
|
|
122
|
+
write(key);
|
|
123
|
+
write(functionValue.range[index]);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
write(value);
|
|
127
|
+
return gzipSync(Uint8Array.from(bytes));
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const createTlcTraceOperators = (files: FileSystem): Builtin[] => [
|
|
131
|
+
overrideWithJava(
|
|
132
|
+
defineStateOperator("_TLCTraceSerialize", 2, (args) => {
|
|
133
|
+
const path = getPath(getValue(args, 1, "_TLCTraceSerialize"));
|
|
134
|
+
files.writeFile?.(path, serializeValue(getValue(args, 0, "_TLCTraceSerialize")));
|
|
135
|
+
return true;
|
|
136
|
+
}),
|
|
137
|
+
"public static final tlc2.value.IValue tlc2.module._TLCTrace.ioSerialize(tlc2.value.IValue,tlc2.value.impl.StringValue) throws java.io.IOException",
|
|
138
|
+
),
|
|
139
|
+
];
|
package/src/tlc/version.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
|
|
3
|
-
// The TLC whose output tla-ts reproduces: the 1.7.4 release, or the master builds that tla-ts
|
|
4
|
-
// follows for any other tla2tools.jar.
|
|
5
3
|
export type TlcVersion = "1.7.4" | "master";
|
|
6
4
|
|
|
7
5
|
const MANIFEST = "META-INF/MANIFEST.MF";
|
|
8
6
|
|
|
9
|
-
//
|
|
10
|
-
// node:worker_threads, so only a run with a jar imports it.
|
|
7
|
+
// fflate loads node:worker_threads, so only a run with a jar imports it.
|
|
11
8
|
export const getTlcVersion = async (jar: string | undefined): Promise<TlcVersion> => {
|
|
12
9
|
if (jar === undefined || !existsSync(jar)) return "master";
|
|
13
10
|
const fflate = await import("fflate");
|
package/src/transfer.ts
CHANGED
|
@@ -19,7 +19,6 @@ const SET_TAG = 5;
|
|
|
19
19
|
const FUNCTION_TAG = 6;
|
|
20
20
|
const INTERVAL_FUNCTION_TAG = 7;
|
|
21
21
|
|
|
22
|
-
// A function's TLC class follows its tag, so a worker words errors about it as TLC does.
|
|
23
22
|
const FUNCTION_CLASSES: (FunctionClass | undefined)[] = [undefined, "lambda", "tuple", "record"];
|
|
24
23
|
|
|
25
24
|
export interface EncodedStates {
|
|
@@ -34,16 +33,18 @@ interface StateEncoder {
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
export const createStateEncoder = (): StateEncoder => {
|
|
37
|
-
|
|
36
|
+
let words = new Int32Array(1024);
|
|
37
|
+
let length = 0;
|
|
38
|
+
let count = 0;
|
|
38
39
|
const strings: string[] = [];
|
|
39
40
|
const stringIndexes = new Map<string, number>();
|
|
40
41
|
const pushWord = (word: number) => {
|
|
41
|
-
if (
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (length === words.length) {
|
|
43
|
+
const grown = new Int32Array(words.length * 2);
|
|
44
|
+
grown.set(words);
|
|
45
|
+
words = grown;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
words[length++] = word;
|
|
47
48
|
};
|
|
48
49
|
const pushString = (value: string) => {
|
|
49
50
|
const known = stringIndexes.get(value);
|
|
@@ -96,19 +97,15 @@ export const createStateEncoder = (): StateEncoder => {
|
|
|
96
97
|
};
|
|
97
98
|
return {
|
|
98
99
|
encode: (state) => {
|
|
99
|
-
const start =
|
|
100
|
+
const start = length;
|
|
100
101
|
if (state.every(encodeValue)) {
|
|
101
|
-
|
|
102
|
+
count++;
|
|
102
103
|
return true;
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
length = start;
|
|
105
106
|
return false;
|
|
106
107
|
},
|
|
107
|
-
finish: () => ({
|
|
108
|
-
words: buffer.words.slice(0, buffer.length),
|
|
109
|
-
strings,
|
|
110
|
-
count: buffer.count,
|
|
111
|
-
}),
|
|
108
|
+
finish: () => ({ words: words.slice(0, length), strings, count }),
|
|
112
109
|
};
|
|
113
110
|
};
|
|
114
111
|
|
|
@@ -116,27 +113,27 @@ export const createStateDecoder =
|
|
|
116
113
|
(width: number) =>
|
|
117
114
|
(encoded: EncodedStates): Value[][] => {
|
|
118
115
|
const words = encoded.words;
|
|
119
|
-
|
|
116
|
+
let cursor = 0;
|
|
120
117
|
const decodeElements = (length: number) => Array.from({ length }, () => decodeValue());
|
|
121
118
|
const decodeValue = (): Value => {
|
|
122
|
-
const tag = words[cursor
|
|
119
|
+
const tag = words[cursor++];
|
|
123
120
|
if (tag === FALSE_TAG) return false;
|
|
124
121
|
if (tag === TRUE_TAG) return true;
|
|
125
|
-
if (tag === INTEGER_TAG) return words[cursor
|
|
126
|
-
if (tag === STRING_TAG) return encoded.strings[words[cursor
|
|
127
|
-
if (tag === MODEL_VALUE_TAG) return createModelValue(encoded.strings[words[cursor
|
|
128
|
-
if (tag === SET_TAG) return createSortedSet(decodeElements(words[cursor
|
|
129
|
-
const functionClass = FUNCTION_CLASSES[words[cursor
|
|
122
|
+
if (tag === INTEGER_TAG) return words[cursor++];
|
|
123
|
+
if (tag === STRING_TAG) return encoded.strings[words[cursor++]];
|
|
124
|
+
if (tag === MODEL_VALUE_TAG) return createModelValue(encoded.strings[words[cursor++]]);
|
|
125
|
+
if (tag === SET_TAG) return createSortedSet(decodeElements(words[cursor++]));
|
|
126
|
+
const functionClass = FUNCTION_CLASSES[words[cursor++]];
|
|
130
127
|
if (tag === INTERVAL_FUNCTION_TAG) {
|
|
131
|
-
const low = words[cursor
|
|
132
|
-
const length = words[cursor
|
|
128
|
+
const low = words[cursor++];
|
|
129
|
+
const length = words[cursor++];
|
|
133
130
|
const domain = getFunctionDomain({ kind: "Interval", low, high: low + length - 1 });
|
|
134
131
|
return setFunctionClass(
|
|
135
132
|
createSortedFunction(domain, decodeElements(length)),
|
|
136
133
|
functionClass,
|
|
137
134
|
);
|
|
138
135
|
}
|
|
139
|
-
const length = words[cursor
|
|
136
|
+
const length = words[cursor++];
|
|
140
137
|
const domain = decodeElements(length);
|
|
141
138
|
return setFunctionClass(createSortedFunction(domain, decodeElements(length)), functionClass);
|
|
142
139
|
};
|
|
@@ -9,14 +9,13 @@ import {
|
|
|
9
9
|
} from "./context";
|
|
10
10
|
import { TlaTypeScriptError } from "../errors";
|
|
11
11
|
import { translateExpression, translateKey } from "./expressions";
|
|
12
|
-
import { and, DISABLED, type Formula, letIn,
|
|
12
|
+
import { and, createText, DISABLED, type Formula, letIn, wrap, wrapEquated } from "./formula";
|
|
13
13
|
import { translateIf, translateSwitch, translateThrow } from "./functions";
|
|
14
14
|
import { bindPattern, bindValues, type Scope } from "./scope";
|
|
15
15
|
import { getKind } from "./types";
|
|
16
16
|
|
|
17
17
|
interface Path {
|
|
18
18
|
scope: Scope;
|
|
19
|
-
// State variables and mutable locals, which assignments may change.
|
|
20
19
|
mutable: Set<ts.Symbol>;
|
|
21
20
|
isAssigned: boolean;
|
|
22
21
|
}
|
|
@@ -24,7 +23,6 @@ interface Path {
|
|
|
24
23
|
interface Target {
|
|
25
24
|
symbol: ts.Symbol;
|
|
26
25
|
current: string;
|
|
27
|
-
// The path to the changed part, as an EXCEPT selector such as .field[2].
|
|
28
26
|
selector: string;
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -34,12 +32,9 @@ interface Removed {
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
interface Frame {
|
|
37
|
-
// What follows the statements once they complete.
|
|
38
35
|
next: (path: Path) => Formula;
|
|
39
|
-
// What a return statement does: end the action, or leave an inlined helper.
|
|
40
36
|
exit: (path: Path) => Formula;
|
|
41
37
|
breakTo: ((path: Path) => Formula) | undefined;
|
|
42
|
-
// Helpers being inlined, to reject recursion.
|
|
43
38
|
inlining: Set<ts.Declaration>;
|
|
44
39
|
}
|
|
45
40
|
|
|
@@ -54,7 +49,6 @@ const INCREMENT_OPERATORS = new Map<ts.SyntaxKind, string>([
|
|
|
54
49
|
[ts.SyntaxKind.MinusMinusToken, "-"],
|
|
55
50
|
]);
|
|
56
51
|
|
|
57
|
-
// The current value of an assignment target, and how to replace it.
|
|
58
52
|
const getTarget = (node: ts.Expression, path: Path, context: Context): Target => {
|
|
59
53
|
if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node)) {
|
|
60
54
|
return getTarget(node.expression, path, context);
|
|
@@ -113,8 +107,6 @@ const assign = (
|
|
|
113
107
|
};
|
|
114
108
|
};
|
|
115
109
|
|
|
116
|
-
// Assigns a value to a target, or to each target in a destructuring pattern. Every value is read
|
|
117
|
-
// before any target changes, so [a, b] = [b, a] swaps.
|
|
118
110
|
const assignPattern = (
|
|
119
111
|
target: ts.Expression,
|
|
120
112
|
source: ts.Expression | undefined,
|
|
@@ -169,7 +161,6 @@ const assignPattern = (
|
|
|
169
161
|
return assign(target, path, context, () => value);
|
|
170
162
|
};
|
|
171
163
|
|
|
172
|
-
// The value that a call like queue.shift() returns, before it changes the queue.
|
|
173
164
|
const getRemovedValue = (
|
|
174
165
|
node: ts.Expression,
|
|
175
166
|
path: Path,
|
|
@@ -192,7 +183,6 @@ const getRemovedValue = (
|
|
|
192
183
|
};
|
|
193
184
|
};
|
|
194
185
|
|
|
195
|
-
// The path after an assignment, such as x = 1, x += 1, or x++.
|
|
196
186
|
const getAssignedPath = (expression: ts.Expression, path: Path, context: Context) => {
|
|
197
187
|
if (ts.isPostfixUnaryExpression(expression) || ts.isPrefixUnaryExpression(expression)) {
|
|
198
188
|
const operator = INCREMENT_OPERATORS.get(expression.operator);
|
|
@@ -236,11 +226,11 @@ const translateCallStatement = (
|
|
|
236
226
|
const isConsole = receiver.getText() === "console";
|
|
237
227
|
if (isConsole && method === "log") {
|
|
238
228
|
const value = values.length === 1 ? values[0] : `<<${values.join(", ")}>>`;
|
|
239
|
-
return and([
|
|
229
|
+
return and([createText(`PrintT(${value})`), continueWith(path)]);
|
|
240
230
|
}
|
|
241
231
|
if (isConsole && method === "assert") {
|
|
242
232
|
const message = values[1] ?? JSON.stringify("Assertion failed");
|
|
243
|
-
return and([
|
|
233
|
+
return and([createText(`Assert(${values[0]}, ${message})`), continueWith(path)]);
|
|
244
234
|
}
|
|
245
235
|
if (MUTATING_METHODS.has(method)) {
|
|
246
236
|
const kind = getKind(receiver, context);
|
|
@@ -255,7 +245,6 @@ const translateCallStatement = (
|
|
|
255
245
|
);
|
|
256
246
|
}
|
|
257
247
|
}
|
|
258
|
-
// A helper that changes state runs inline, as part of the action.
|
|
259
248
|
const helper = getTopLevelDeclaration(getSymbol(expression.expression, context.checker));
|
|
260
249
|
const helperFunction = getFunction(helper);
|
|
261
250
|
if (helper === undefined || helperFunction?.body === undefined) {
|
|
@@ -306,7 +295,6 @@ const translateExpressionStatement = (
|
|
|
306
295
|
return continueWith(assigned);
|
|
307
296
|
};
|
|
308
297
|
|
|
309
|
-
// Binds each declared local to a LET definition. A let can change later, and a const can't.
|
|
310
298
|
const translateDeclarations = (
|
|
311
299
|
declarations: readonly ts.VariableDeclaration[],
|
|
312
300
|
path: Path,
|
|
@@ -386,7 +374,9 @@ const translateStatements = (
|
|
|
386
374
|
if (frame.breakTo === undefined) throw new TlaTypeScriptError("Unsupported break", statement);
|
|
387
375
|
return frame.breakTo(path);
|
|
388
376
|
}
|
|
389
|
-
if (ts.isThrowStatement(statement))
|
|
377
|
+
if (ts.isThrowStatement(statement)) {
|
|
378
|
+
return createText(translateThrow(statement, path.scope, context));
|
|
379
|
+
}
|
|
390
380
|
if (ts.isSwitchStatement(statement)) {
|
|
391
381
|
return translateSwitch(
|
|
392
382
|
statement,
|
|
@@ -413,8 +403,6 @@ const translateStatements = (
|
|
|
413
403
|
throw new TlaTypeScriptError(`Unsupported statement: ${statement.getText()}`, statement);
|
|
414
404
|
};
|
|
415
405
|
|
|
416
|
-
// An action's body as a TLA+ action: each path that assigns a state variable becomes a step, and
|
|
417
|
-
// every other path disables the action.
|
|
418
406
|
export const translateAction = (
|
|
419
407
|
statements: readonly ts.Statement[],
|
|
420
408
|
scope: Scope,
|
|
@@ -430,9 +418,9 @@ export const translateAction = (
|
|
|
430
418
|
return and([
|
|
431
419
|
...assignments
|
|
432
420
|
.filter((assignment) => assignment.value !== assignment.name)
|
|
433
|
-
.map((assignment) =>
|
|
421
|
+
.map((assignment) => createText(`${assignment.name}' = ${wrapEquated(assignment.value)}`)),
|
|
434
422
|
...(unchanged.length > 0
|
|
435
|
-
? [
|
|
423
|
+
? [createText(`UNCHANGED <<${unchanged.map((assignment) => assignment.name).join(", ")}>>`)]
|
|
436
424
|
: []),
|
|
437
425
|
]);
|
|
438
426
|
};
|
|
@@ -456,7 +444,6 @@ const getRoot = (node: ts.Expression): ts.Expression => {
|
|
|
456
444
|
: node;
|
|
457
445
|
};
|
|
458
446
|
|
|
459
|
-
// Whether a function assigns a state variable, directly or through a helper it calls.
|
|
460
447
|
export const writesState = (
|
|
461
448
|
node: ts.Node,
|
|
462
449
|
context: Context,
|
|
@@ -16,11 +16,9 @@ import { getKind, type Kind } from "./types";
|
|
|
16
16
|
|
|
17
17
|
interface Unordered {
|
|
18
18
|
set: string;
|
|
19
|
-
// Whether map() built the set, so that it may have fewer elements than the array would.
|
|
20
19
|
isMapped: boolean;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
// Methods that read their array once, so that sharing it with a LET gains nothing.
|
|
24
22
|
const SINGLE_USE_METHODS = new Set(["concat", "with", "filter"]);
|
|
25
23
|
|
|
26
24
|
interface Element {
|
|
@@ -47,7 +45,6 @@ const rejectIndex = (callback: ts.Expression, message: string, context: Context)
|
|
|
47
45
|
}
|
|
48
46
|
};
|
|
49
47
|
|
|
50
|
-
// Binds a callback's element parameter to a fresh variable, which a quantifier then binds.
|
|
51
48
|
const bindElement = (callback: ts.Expression, scope: Scope, context: Context): Element => {
|
|
52
49
|
const parameter = getCallback(callback, context).parameters[0];
|
|
53
50
|
if (parameter === undefined) return { variable: context.names.getFresh("element"), scope };
|
|
@@ -60,8 +57,6 @@ const bindElement = (callback: ts.Expression, scope: Scope, context: Context): E
|
|
|
60
57
|
return { variable, scope: bindNames(scope, [{ name: variable, symbol }]) };
|
|
61
58
|
};
|
|
62
59
|
|
|
63
|
-
// Binds a callback's (element, index) parameters for the TLA+ index of a sequence, which counts
|
|
64
|
-
// from 1 where JavaScript counts from 0.
|
|
65
60
|
const bindIndexed = (
|
|
66
61
|
callback: ts.Expression,
|
|
67
62
|
element: string | undefined,
|
|
@@ -101,7 +96,6 @@ const getElements = (value: string, context: Context) =>
|
|
|
101
96
|
return `{${sequence}[${index}] : ${index} \\in DOMAIN ${sequence}}`;
|
|
102
97
|
});
|
|
103
98
|
|
|
104
|
-
// A set built from a Set, Map, or object, whose element order TLA+ doesn't keep.
|
|
105
99
|
const translateUnordered = (
|
|
106
100
|
node: ts.Expression,
|
|
107
101
|
scope: Scope,
|
|
@@ -161,7 +155,6 @@ const translateUnordered = (
|
|
|
161
155
|
: { set: `{${body} : ${element.variable} \\in ${wrap(source.set)}}`, isMapped: true };
|
|
162
156
|
};
|
|
163
157
|
|
|
164
|
-
// The elements of a set, an array, or an iterator over a collection, as a TLA+ set.
|
|
165
158
|
export const translateSet = (node: ts.Expression, scope: Scope, context: Context) => {
|
|
166
159
|
const unordered = translateUnordered(node, scope, context);
|
|
167
160
|
if (unordered !== undefined) return unordered.set;
|
|
@@ -172,7 +165,6 @@ export const translateSet = (node: ts.Expression, scope: Scope, context: Context
|
|
|
172
165
|
return getElements(value, context);
|
|
173
166
|
};
|
|
174
167
|
|
|
175
|
-
// The number of elements in a collection, or undefined if the receiver isn't one.
|
|
176
168
|
export const translateSize = (node: ts.Expression, scope: Scope, context: Context) => {
|
|
177
169
|
const unordered = translateUnordered(node, scope, context);
|
|
178
170
|
if (unordered?.isMapped) {
|
|
@@ -190,7 +182,6 @@ export const translateSize = (node: ts.Expression, scope: Scope, context: Contex
|
|
|
190
182
|
return undefined;
|
|
191
183
|
};
|
|
192
184
|
|
|
193
|
-
// [x \in S |-> e] from source.map((x) => [x, e]), as new Map() and Object.fromEntries() take it.
|
|
194
185
|
export const translateFunctionConstructor = (
|
|
195
186
|
node: ts.Expression,
|
|
196
187
|
scope: Scope,
|
|
@@ -230,7 +221,6 @@ export const translateFunctionConstructor = (
|
|
|
230
221
|
return `[${element.variable} \\in ${source} |-> ${value}]`;
|
|
231
222
|
};
|
|
232
223
|
|
|
233
|
-
// A sequence from Array.from({ length: n }, callback) or new Array(n).fill(value).
|
|
234
224
|
export const translateArrayConstructor = (node: MethodCall, scope: Scope, context: Context) => {
|
|
235
225
|
const receiver = node.expression.expression;
|
|
236
226
|
const method = node.expression.name.text;
|
|
@@ -268,7 +258,6 @@ export const translateArrayConstructor = (node: MethodCall, scope: Scope, contex
|
|
|
268
258
|
return `[${index} \\in 1..${translateLength(length)} |-> ${translateExpression(node.arguments[0], scope, context)}]`;
|
|
269
259
|
};
|
|
270
260
|
|
|
271
|
-
// The first index in a sequence whose element passes a test, or undefined if none does.
|
|
272
261
|
const translateFirstIndex = (
|
|
273
262
|
sequence: string,
|
|
274
263
|
callback: ts.Expression,
|
|
@@ -302,7 +291,6 @@ const translateSequenceOperation = (
|
|
|
302
291
|
const wrapped = wrap(sequence);
|
|
303
292
|
const isNegative = (inner: ts.Expression): inner is ts.PrefixUnaryExpression =>
|
|
304
293
|
ts.isPrefixUnaryExpression(inner) && inner.operator === ts.SyntaxKind.MinusToken;
|
|
305
|
-
// An index that may count back from the end, as slice() and at() take it.
|
|
306
294
|
const getOffset = (inner: ts.Expression) =>
|
|
307
295
|
isNegative(inner) ? `Len(${sequence}) - ${wrap(translate(inner.operand))}` : translate(inner);
|
|
308
296
|
const orUndefined = (exists: string, value: string) => {
|
|
@@ -532,8 +520,6 @@ export const MUTATING_METHODS = new Set(
|
|
|
532
520
|
[...UPDATES.values()].flatMap((updates) => [...updates.keys()]),
|
|
533
521
|
);
|
|
534
522
|
|
|
535
|
-
// The value of a collection after a mutating method call, or undefined if the method doesn't
|
|
536
|
-
// mutate.
|
|
537
523
|
export const getUpdatedValue = (
|
|
538
524
|
current: string,
|
|
539
525
|
kind: Kind,
|
|
@@ -556,7 +542,6 @@ export const translateMethod = (
|
|
|
556
542
|
if (unordered !== undefined) {
|
|
557
543
|
return translateUnorderedMethod(node, unordered, scope, context, isDefined);
|
|
558
544
|
}
|
|
559
|
-
// A mutating method on a fresh copy, such as new Set(s).add(x), returns the updated copy.
|
|
560
545
|
const isCopy =
|
|
561
546
|
ts.isNewExpression(receiver) &&
|
|
562
547
|
receiver.arguments?.length === 1 &&
|
|
@@ -13,7 +13,6 @@ import { createStateScope } from "./scope";
|
|
|
13
13
|
import { translateStep } from "./steps";
|
|
14
14
|
import { getDomain } from "./types";
|
|
15
15
|
|
|
16
|
-
// A state variable starts at its initializer, or at every value of its type without one.
|
|
17
16
|
const translateInitial = (variable: Variable, context: Context) => {
|
|
18
17
|
const initializer = variable.declaration.initializer;
|
|
19
18
|
if (initializer === undefined) {
|
|
@@ -24,8 +23,6 @@ const translateInitial = (variable: Variable, context: Context) => {
|
|
|
24
23
|
return `${variable.name} = ${indent(wrapEquated(value), " ")}`;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
// An exported function is a property if a tag says so, an action if it changes state, and an
|
|
28
|
-
// invariant if it returns a boolean.
|
|
29
26
|
const translateExported = (
|
|
30
27
|
definition: Exported,
|
|
31
28
|
model: Model,
|
|
@@ -53,8 +50,6 @@ const translateExported = (
|
|
|
53
50
|
return translateInvariant(definition, sections, context);
|
|
54
51
|
};
|
|
55
52
|
|
|
56
|
-
// Compiles a TypeScript file into a TLA+ spec and the config that checks it. Imports resolve
|
|
57
|
-
// relative to fileName, and the module takes its name, so die-hard.ts is the module DieHard.
|
|
58
53
|
export const compile = (source: string, fileName = "spec.ts"): CompiledSpec => {
|
|
59
54
|
const program = createProgram(source, fileName.replaceAll("\\", "/"));
|
|
60
55
|
const context = createContext(program.checker);
|
|
@@ -3,7 +3,6 @@ import { createNames, type Names } from "./names";
|
|
|
3
3
|
|
|
4
4
|
export interface Definition {
|
|
5
5
|
name: string;
|
|
6
|
-
// The operator's parameters as TLA+ declares them, such as "x" or "F(_)".
|
|
7
6
|
parameters: string[];
|
|
8
7
|
readsState: boolean;
|
|
9
8
|
}
|
|
@@ -12,16 +11,11 @@ export interface Context {
|
|
|
12
11
|
checker: ts.TypeChecker;
|
|
13
12
|
names: Names;
|
|
14
13
|
variables: Map<ts.Symbol, string>;
|
|
15
|
-
// Helper functions and constants, compiled when first referenced.
|
|
16
14
|
definitions: Map<ts.Declaration, Definition>;
|
|
17
|
-
// Helpers being compiled or inlined, to detect recursion.
|
|
18
15
|
inProgress: Set<ts.Node>;
|
|
19
16
|
recursive: Set<ts.Declaration>;
|
|
20
|
-
// Rendered definitions, each after the definitions it uses.
|
|
21
17
|
output: string[];
|
|
22
|
-
// String literals of @symmetric types, which become model values.
|
|
23
18
|
modelValues: Map<string, string>;
|
|
24
|
-
// Model values and helper operators that the spec uses.
|
|
25
19
|
prelude: Set<"Null" | "Undefined" | "Rem" | "Quot">;
|
|
26
20
|
}
|
|
27
21
|
|
|
@@ -58,8 +52,6 @@ export const getSymbol = (node: ts.Node, checker: ts.TypeChecker) => {
|
|
|
58
52
|
export const isMethodCall = (node: ts.Node): node is MethodCall =>
|
|
59
53
|
ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression);
|
|
60
54
|
|
|
61
|
-
// The declaration of a constant or function at the top level of a module, which becomes a TLA+
|
|
62
|
-
// definition.
|
|
63
55
|
export const getTopLevelDeclaration = (symbol: ts.Symbol | undefined) => {
|
|
64
56
|
const declaration = symbol?.valueDeclaration;
|
|
65
57
|
if (declaration === undefined) return undefined;
|
|
@@ -74,7 +66,6 @@ export const getTopLevelDeclaration = (symbol: ts.Symbol | undefined) => {
|
|
|
74
66
|
return isTopLevelConst ? declaration : undefined;
|
|
75
67
|
};
|
|
76
68
|
|
|
77
|
-
// The function a node is, or that a variable declaration initializes.
|
|
78
69
|
export const getFunction = (node: ts.Node | undefined): FunctionNode | undefined => {
|
|
79
70
|
if (node === undefined) return undefined;
|
|
80
71
|
if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
@@ -83,17 +74,14 @@ export const getFunction = (node: ts.Node | undefined): FunctionNode | undefined
|
|
|
83
74
|
return ts.isVariableDeclaration(node) ? getFunction(node.initializer) : undefined;
|
|
84
75
|
};
|
|
85
76
|
|
|
86
|
-
// The function that a callee or callback names: one written in place, or one declared elsewhere.
|
|
87
77
|
export const getCallee = (node: ts.Expression, context: Context) =>
|
|
88
78
|
getFunction(node) ?? getFunction(getSymbol(node, context.checker)?.valueDeclaration);
|
|
89
79
|
|
|
90
80
|
export const translateString = (value: string, context: Context) =>
|
|
91
81
|
context.modelValues.get(value) ?? JSON.stringify(value);
|
|
92
82
|
|
|
93
|
-
// A name, a number, a string, or the @ of an EXCEPT, which costs nothing to repeat.
|
|
94
83
|
const isTrivial = (value: string) => /^(@|[A-Za-z_]\w*'?|-?\d+|"[^"\\]*")$/.test(value);
|
|
95
84
|
|
|
96
|
-
// Binds a value that an expression repeats to a LET definition, so that TLC evaluates it once.
|
|
97
85
|
export const share = (
|
|
98
86
|
value: string,
|
|
99
87
|
base: string,
|
package/src/typescript/emit.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Context } from "./context";
|
|
|
2
2
|
import { TlaTypeScriptError } from "../errors";
|
|
3
3
|
import type { Model } from "./model";
|
|
4
4
|
|
|
5
|
-
// The parts of a spec and its config, in the order that the model declares them.
|
|
6
5
|
export interface Sections {
|
|
7
6
|
init: string[];
|
|
8
7
|
actions: string[];
|
|
@@ -51,7 +51,6 @@ const LOGICAL_OPERATORS = new Map([
|
|
|
51
51
|
[ts.SyntaxKind.BarBarToken, "\\/"],
|
|
52
52
|
]);
|
|
53
53
|
|
|
54
|
-
// The key of an element access, which counts from 1 in a sequence where JavaScript counts from 0.
|
|
55
54
|
export const translateKey = (node: ts.ElementAccessExpression, scope: Scope, context: Context) => {
|
|
56
55
|
const key = node.argumentExpression;
|
|
57
56
|
if (getKind(node.expression, context) !== "sequence") {
|
|
@@ -63,7 +62,6 @@ export const translateKey = (node: ts.ElementAccessExpression, scope: Scope, con
|
|
|
63
62
|
};
|
|
64
63
|
|
|
65
64
|
const translateArrayLiteral = (node: ts.ArrayLiteralExpression, scope: Scope, context: Context) => {
|
|
66
|
-
// Runs of plain elements become tuples, and each spread array stays a sequence of its own.
|
|
67
65
|
const parts = node.elements.reduce<(string | string[])[]>((result, element) => {
|
|
68
66
|
if (!ts.isSpreadElement(element)) {
|
|
69
67
|
const value = translateExpression(element, scope, context);
|
|
@@ -126,7 +124,6 @@ const translateObjectLiteral = (
|
|
|
126
124
|
}),
|
|
127
125
|
);
|
|
128
126
|
}
|
|
129
|
-
// { ...base, a: 1 } updates fields that base already has with EXCEPT.
|
|
130
127
|
const base = node.properties[0];
|
|
131
128
|
const updates = node.properties.slice(1);
|
|
132
129
|
if (ts.isSpreadAssignment(base) && spreads.length === 1) {
|
|
@@ -149,7 +146,6 @@ const translateObjectLiteral = (
|
|
|
149
146
|
return `[${wrap(value)} EXCEPT ${changes.join(", ")}]`;
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
|
-
// Otherwise each field takes its value from the last member that sets it.
|
|
153
149
|
return formatRecord(
|
|
154
150
|
checker
|
|
155
151
|
.getTypeAtLocation(node)
|
|
@@ -255,7 +251,6 @@ const translateCall = (
|
|
|
255
251
|
return constructed ?? translateMethod(node, scope, context, isDefined);
|
|
256
252
|
};
|
|
257
253
|
|
|
258
|
-
// A value as a string, as JavaScript converts it in a template or beside a string in +.
|
|
259
254
|
const translateToString = (node: ts.Expression, scope: Scope, context: Context) => {
|
|
260
255
|
const value = translateExpression(node, scope, context);
|
|
261
256
|
return getKind(node, context) === "string" ? value : `ToString(${value})`;
|
|
@@ -325,7 +320,6 @@ const translateBinary = (node: ts.BinaryExpression, scope: Scope, context: Conte
|
|
|
325
320
|
return `${translate(node.left)} ${operator} ${translate(node.right)}`;
|
|
326
321
|
};
|
|
327
322
|
|
|
328
|
-
// A field of the state before the step, which is the variable's unprimed value.
|
|
329
323
|
const getPreviousVariable = (name: string, node: ts.Node, context: Context) => {
|
|
330
324
|
const variable = [...context.variables].find((entry) => entry[0].name === name);
|
|
331
325
|
if (variable === undefined) throw new TlaTypeScriptError(`Unknown variable: ${name}`, node);
|
|
@@ -343,7 +337,6 @@ const translateEnumMember = (node: ts.Node, symbol: ts.Symbol, context: Context)
|
|
|
343
337
|
throw new TlaTypeScriptError("Unsupported enum member", node);
|
|
344
338
|
};
|
|
345
339
|
|
|
346
|
-
// The value that an enum or a top-level declaration gives a name.
|
|
347
340
|
const translateDeclared = (
|
|
348
341
|
node: ts.Node,
|
|
349
342
|
symbol: ts.Symbol | undefined,
|
|
@@ -355,7 +348,6 @@ const translateDeclared = (
|
|
|
355
348
|
}
|
|
356
349
|
const declaration = getTopLevelDeclaration(symbol);
|
|
357
350
|
if (declaration === undefined) return undefined;
|
|
358
|
-
// A function passes as its operator's name, and a constant as its value.
|
|
359
351
|
return getFunction(declaration) === undefined
|
|
360
352
|
? translateHelperCall(declaration, undefined, scope, context)
|
|
361
353
|
: getDefinition(declaration, context).name;
|
|
@@ -428,8 +420,6 @@ export const translateCondition = (node: ts.Expression, scope: Scope, context: C
|
|
|
428
420
|
return translateExpression(node, scope, context);
|
|
429
421
|
};
|
|
430
422
|
|
|
431
|
-
// Negates a condition, cancelling ! and turning a negated || into a conjunction of guards, so that
|
|
432
|
-
// TLC sees the same formula as a hand-written spec and counts the same successors.
|
|
433
423
|
export const translateNegatedCondition = (
|
|
434
424
|
node: ts.Expression,
|
|
435
425
|
scope: Scope,
|
|
@@ -449,8 +439,6 @@ export const translateNegatedCondition = (
|
|
|
449
439
|
return `~${wrap(translateCondition(node, scope, context))}`;
|
|
450
440
|
};
|
|
451
441
|
|
|
452
|
-
// An expression as a TLA+ expression. Under a non-null assertion, isDefined skips the check that a
|
|
453
|
-
// lookup such as map.get(key) found a value.
|
|
454
442
|
export const translateExpression = (
|
|
455
443
|
node: ts.Expression,
|
|
456
444
|
scope: Scope,
|