tla-ts 0.0.9 → 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 +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -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 +2 -2
- 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 +3 -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 +599 -388
- package/src/cli/options.ts +11 -6
- 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 +538 -220
- package/src/cli/typescript.ts +23 -0
- 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 +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +596 -339
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- 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 +82 -119
- package/src/liveness.ts +112 -64
- 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 +29 -39
- package/src/parallel.ts +53 -44
- 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 +23 -34
- 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 +263 -94
- 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 +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +780 -337
- package/src/worker.ts +7 -8
package/src/environment.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type OperatorParam,
|
|
10
10
|
type SourceLocation,
|
|
11
11
|
} from "./ast";
|
|
12
|
-
import {
|
|
12
|
+
import type { ModuleOperator } from "./check";
|
|
13
13
|
import type { ConfigValue, ModelConfig } from "./config";
|
|
14
14
|
import type { FileSystem } from "./json";
|
|
15
15
|
import {
|
|
@@ -19,17 +19,23 @@ import {
|
|
|
19
19
|
formatSanyWarnings,
|
|
20
20
|
TlaConfigError,
|
|
21
21
|
TlaEvaluationError,
|
|
22
|
+
TlaFeatureUnsupportedError,
|
|
22
23
|
TlaModuleError,
|
|
23
24
|
TlaSyntaxError,
|
|
25
|
+
UNEXPECTED_EXCEPTION,
|
|
24
26
|
type SanyError,
|
|
25
27
|
} from "./errors";
|
|
26
28
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
27
29
|
import {
|
|
30
|
+
bindOperatorArguments,
|
|
28
31
|
createBigNumberError,
|
|
29
32
|
createRealNumberError,
|
|
30
33
|
evaluate,
|
|
31
34
|
getDefinition,
|
|
32
35
|
type Builtin,
|
|
36
|
+
type BuiltinArgument,
|
|
37
|
+
type Closure,
|
|
38
|
+
type Context,
|
|
33
39
|
type Environment,
|
|
34
40
|
} from "./evaluate";
|
|
35
41
|
import {
|
|
@@ -60,10 +66,10 @@ import {
|
|
|
60
66
|
} from "./resolve";
|
|
61
67
|
import { createRuntime } from "./runtime";
|
|
62
68
|
import { getSanyStandardModules } from "./sany/modules";
|
|
63
|
-
import { USER_STANDARD_MODULES } from "./tlc/jar-data";
|
|
64
69
|
import { getSanyParseError } from "./sany/parse-error";
|
|
65
70
|
import {
|
|
66
71
|
CORE_OPERATORS,
|
|
72
|
+
getJavaOverrides,
|
|
67
73
|
getStandardModule,
|
|
68
74
|
getTraceSpecArithmetic,
|
|
69
75
|
STANDARD_DEPENDENCIES,
|
|
@@ -78,9 +84,9 @@ import { createTlcOrder, type TlcOrder } from "./tlc/order";
|
|
|
78
84
|
import {
|
|
79
85
|
isTlcInteger,
|
|
80
86
|
createModelValue,
|
|
81
|
-
createSet,
|
|
82
87
|
formatValue,
|
|
83
88
|
valuesEqual,
|
|
89
|
+
toFiniteSet,
|
|
84
90
|
type Value,
|
|
85
91
|
markNormalized,
|
|
86
92
|
} from "./values";
|
|
@@ -89,34 +95,32 @@ import type { TlcVersion } from "./tlc/version";
|
|
|
89
95
|
interface EnvironmentOptions {
|
|
90
96
|
source: string;
|
|
91
97
|
loadModule: ((name: string) => string | undefined) | undefined;
|
|
92
|
-
// The TLC orders of the same spec, when the caller already reads them.
|
|
93
98
|
order?: TlcOrder;
|
|
94
99
|
loadClass?: (name: string) => Uint8Array | undefined;
|
|
95
100
|
print: (text: string) => void;
|
|
96
101
|
files: FileSystem;
|
|
97
102
|
seed?: bigint;
|
|
98
|
-
// Links the modules without a model, as SANY does, so a declared constant needs no value.
|
|
99
|
-
isUnconfigured?: boolean;
|
|
100
103
|
isTool?: boolean;
|
|
101
|
-
|
|
102
|
-
// methods then compute the arithmetic of Naturals.
|
|
103
|
-
isTraceRecorded?: boolean;
|
|
104
|
+
traceFile?: string;
|
|
104
105
|
isSanyReported?: boolean;
|
|
105
106
|
isWarningEnabled?: boolean;
|
|
106
107
|
version?: TlcVersion;
|
|
108
|
+
moduleOperators?: ModuleOperator[];
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
interface
|
|
111
|
+
export interface ResolvedModuleOperator extends ModuleOperator {
|
|
112
|
+
key: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface Specification {
|
|
110
116
|
environment: Environment;
|
|
111
117
|
assumptions: Assumption[];
|
|
112
118
|
variableLocations: SourceLocation[];
|
|
113
119
|
instanceActions: Map<string, InstanceAction>;
|
|
114
|
-
// The definitions TLC computes when it starts, in the order it computes them.
|
|
115
120
|
startupDefinitions: Definition[];
|
|
116
|
-
rootConstants: Declaration[];
|
|
117
|
-
rootSymbols: Symbols;
|
|
118
|
-
// The methods of the modules' classes, in the order TLC loads the classes.
|
|
119
121
|
javaOverrides: JavaOverride[];
|
|
122
|
+
moduleOperators: ResolvedModuleOperator[];
|
|
123
|
+
rootName: string;
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
export interface InstanceAction {
|
|
@@ -124,13 +128,15 @@ export interface InstanceAction {
|
|
|
124
128
|
location: SourceLocation;
|
|
125
129
|
}
|
|
126
130
|
|
|
131
|
+
const ANNOTATED_OVERRIDE_MODULES = new Set(["IOUtils", "Json", "TLCExt"]);
|
|
132
|
+
|
|
127
133
|
const toValue = (value: ConfigValue): Value => {
|
|
128
134
|
switch (value.kind) {
|
|
129
135
|
case "Number":
|
|
130
|
-
// TLC
|
|
136
|
+
// Deviation from TLC: ModelConfig#parseValue lets Integer.parseInt fail on a number too big, where tla-ts reports it as TLC reports such a number in a module.
|
|
131
137
|
if (!isTlcInteger(value.value)) {
|
|
132
138
|
throw setExitCode(
|
|
133
|
-
new TlaModuleError(`
|
|
139
|
+
new TlaModuleError(`TLC can't handle a number this big.\n${value.value}`),
|
|
134
140
|
EXIT_STATUS.error,
|
|
135
141
|
);
|
|
136
142
|
}
|
|
@@ -141,7 +147,25 @@ const toValue = (value: ConfigValue): Value => {
|
|
|
141
147
|
case "ModelValue":
|
|
142
148
|
return createModelValue(value.name);
|
|
143
149
|
case "Set":
|
|
144
|
-
return
|
|
150
|
+
return toFiniteSet({ kind: "MixedSet", elements: value.elements.map(toValue) });
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const toConstantValue = (value: ConfigValue) => {
|
|
155
|
+
try {
|
|
156
|
+
return toValue(value);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (
|
|
159
|
+
!(error instanceof TlaEvaluationError) ||
|
|
160
|
+
error instanceof TlaModuleError ||
|
|
161
|
+
error instanceof TlaFeatureUnsupportedError
|
|
162
|
+
) {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
throw setExitCode(
|
|
166
|
+
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`),
|
|
167
|
+
EXIT_STATUS.error,
|
|
168
|
+
);
|
|
145
169
|
}
|
|
146
170
|
};
|
|
147
171
|
|
|
@@ -157,8 +181,6 @@ interface LinkedModule {
|
|
|
157
181
|
facts: Set<string>;
|
|
158
182
|
}
|
|
159
183
|
|
|
160
|
-
// errors and warnings collect what SANY reports for the module, and levelChecks the level checks of
|
|
161
|
-
// the modules in its file, which SANY runs only when it reports no error.
|
|
162
184
|
interface ModuleScope {
|
|
163
185
|
id: string;
|
|
164
186
|
symbols: Symbols;
|
|
@@ -178,8 +200,6 @@ const getDeclarations = (linked: LinkedModule): Declaration[] => [
|
|
|
178
200
|
})),
|
|
179
201
|
];
|
|
180
202
|
|
|
181
|
-
// Parses the module SANY reads from the file name.tla. A module SANY's parser rejects fails as it
|
|
182
|
-
// does in TLC: SANY's message, then a fatal error that names the module.
|
|
183
203
|
const parseModuleFile = (source: string, name: string, order: TlcOrder) => {
|
|
184
204
|
try {
|
|
185
205
|
return order.parseModule(source);
|
|
@@ -212,12 +232,9 @@ const getModuleRedefinition = (module: Module, existing: Module): SanyError | un
|
|
|
212
232
|
message: `Multiply-defined module '${module.name}': this definition or declaration conflicts \nwith the one at ${formatRange(existing.location.range)}.`,
|
|
213
233
|
};
|
|
214
234
|
|
|
215
|
-
// Context.kindOfNode names a definition or a parameter a definition, and any other symbol a
|
|
216
|
-
// declaration.
|
|
217
235
|
const getNodeWord = (kind: SymbolKind) =>
|
|
218
236
|
["Builtin", "Definition", "Instance", "Parameter"].includes(kind) ? "definition" : "declaration";
|
|
219
237
|
|
|
220
|
-
// The Java class of the node SANY binds a symbol to.
|
|
221
238
|
const getNodeClass = (kind: SymbolKind) =>
|
|
222
239
|
kind === "Theorem" ? "ThmOrAssumpDefNode" : getNodeWord(kind);
|
|
223
240
|
|
|
@@ -306,9 +323,9 @@ export const createEnvironment = (
|
|
|
306
323
|
const root = order.parseModule(options.source);
|
|
307
324
|
const definitions = new Map<string, Definition>();
|
|
308
325
|
const parameterized = new Map<string, boolean>();
|
|
309
|
-
// The definition each instance copy came from, and the instance parameters the copy adds.
|
|
310
326
|
const copySources = new Map<string, { source: string; prefix: number }>();
|
|
311
327
|
const substitutedDefinitions = new Set<Definition>();
|
|
328
|
+
const instanceParams = new Set<OperatorParam>();
|
|
312
329
|
const builtins = new Map<string, Builtin>(
|
|
313
330
|
CORE_OPERATORS.map((operator) => [operator.name, operator]),
|
|
314
331
|
);
|
|
@@ -318,13 +335,10 @@ export const createEnvironment = (
|
|
|
318
335
|
runtime.isTool = options.isTool ?? false;
|
|
319
336
|
runtime.version = options.version ?? "master";
|
|
320
337
|
const linkedModules = new Map<string, LinkedModule>();
|
|
321
|
-
const nestedModules = new Map<string, LinkedModule>();
|
|
322
|
-
// Each module by name, from the time its level checks run.
|
|
323
338
|
const checkedModules = new Map<string, LinkedModule>();
|
|
324
339
|
const linkOrder: LinkedModule[] = [];
|
|
325
340
|
const dependencies = new Map<string, Set<string>>();
|
|
326
341
|
const loading: Set<string>[] = [];
|
|
327
|
-
// The top-level modules being linked, to report a cycle of EXTENDS or INSTANCE.
|
|
328
342
|
const linking: string[] = [];
|
|
329
343
|
|
|
330
344
|
const useModule = (name: string, used: Iterable<string>) =>
|
|
@@ -332,8 +346,8 @@ export const createEnvironment = (
|
|
|
332
346
|
closure.add(name);
|
|
333
347
|
[...used].forEach((dependency) => closure.add(dependency));
|
|
334
348
|
});
|
|
335
|
-
|
|
336
|
-
const createName = (name: string) => `${name}#${copyCount
|
|
349
|
+
let copyCount = 0;
|
|
350
|
+
const createName = (name: string) => `${name}#${copyCount++}`;
|
|
337
351
|
const instanceChecks: InstanceCheck[] = [];
|
|
338
352
|
const warnings: SanyError[] = [];
|
|
339
353
|
const checkInstance = createInstanceChecker((name) => {
|
|
@@ -360,8 +374,6 @@ export const createEnvironment = (
|
|
|
360
374
|
if (cached) return cached;
|
|
361
375
|
const standardModule = getStandardModule(name, options.print, runtime, options.files, builtins);
|
|
362
376
|
if (!standardModule) return undefined;
|
|
363
|
-
// TLC loads the modules a standard module instantiates too, and the Java methods of each
|
|
364
|
-
// replace the operators of every module, as those of Integers replace those of Naturals.
|
|
365
377
|
STANDARD_DEPENDENCIES.get(name)?.forEach(addStandardModule);
|
|
366
378
|
const exported: Symbols = new Map();
|
|
367
379
|
standardModule.extends.forEach((extended) =>
|
|
@@ -384,19 +396,18 @@ export const createEnvironment = (
|
|
|
384
396
|
};
|
|
385
397
|
|
|
386
398
|
const getStandardSymbols = (name: string) => {
|
|
387
|
-
|
|
388
|
-
if (
|
|
399
|
+
const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
|
|
400
|
+
if (
|
|
401
|
+
name === "TLCExt" ||
|
|
402
|
+
[name, ...dependencies].some((module) => options.loadModule?.(module) !== undefined)
|
|
403
|
+
)
|
|
389
404
|
return undefined;
|
|
390
405
|
const symbols = addStandardModule(name);
|
|
391
|
-
const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
|
|
392
406
|
if (symbols) useModule(name, dependencies);
|
|
393
|
-
// TLC loads the Java class of each module a standard module uses, so one that uses Integers
|
|
394
|
-
// overrides the arithmetic of Naturals.
|
|
395
407
|
if (symbols && dependencies.includes("Integers")) addStandardModule("Integers");
|
|
396
408
|
return symbols;
|
|
397
409
|
};
|
|
398
410
|
|
|
399
|
-
// Like TLC, reject a decimal or a big integer anywhere in a module, even where nothing evaluates it.
|
|
400
411
|
const rejectModuleLiterals = (module: Module): Module => {
|
|
401
412
|
rejectLiterals([
|
|
402
413
|
...module.definitions.flatMap((definition) =>
|
|
@@ -418,7 +429,7 @@ export const createEnvironment = (
|
|
|
418
429
|
const loadModule = (name: string, importer: string) => {
|
|
419
430
|
const source =
|
|
420
431
|
options.loadModule?.(name) ??
|
|
421
|
-
|
|
432
|
+
getSanyStandardModules(runtime.version).get(name) ??
|
|
422
433
|
extractModule(options.source, name);
|
|
423
434
|
if (source === undefined) throw createMissingModuleError(name, importer);
|
|
424
435
|
const module = parseModuleFile(source, name, order);
|
|
@@ -478,14 +489,49 @@ export const createEnvironment = (
|
|
|
478
489
|
return cached;
|
|
479
490
|
}
|
|
480
491
|
const top = linkTopLevel(loadModule(name, importer));
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
: undefined
|
|
486
|
-
|
|
492
|
+
const replaced = new Map<string, Definition>();
|
|
493
|
+
const evaluateReplaced = (
|
|
494
|
+
operator: string,
|
|
495
|
+
args: BuiltinArgument[],
|
|
496
|
+
context: Context | undefined,
|
|
497
|
+
) => {
|
|
498
|
+
const definition = replaced.get(operator);
|
|
499
|
+
const expressions = args.flatMap((arg) =>
|
|
500
|
+
typeof arg === "object" && arg.kind === "Operator" && arg.expression
|
|
501
|
+
? [arg.expression]
|
|
502
|
+
: [],
|
|
503
|
+
);
|
|
504
|
+
if (definition?.kind !== "Operator" || !context || expressions.length !== args.length) {
|
|
505
|
+
throw new TlaEvaluationError(`No definition of ${operator} to fall back to`);
|
|
506
|
+
}
|
|
507
|
+
const closure: Closure = {
|
|
508
|
+
kind: "Closure",
|
|
509
|
+
name: definition.name,
|
|
510
|
+
params: definition.params,
|
|
511
|
+
body: definition.body,
|
|
512
|
+
scope: undefined,
|
|
513
|
+
};
|
|
514
|
+
return evaluate(definition.body, {
|
|
515
|
+
environment: context.environment,
|
|
516
|
+
scope: bindOperatorArguments(closure, expressions, context),
|
|
517
|
+
state: context.state,
|
|
518
|
+
next: context.next,
|
|
519
|
+
isKeepLazy: context.isKeepLazy,
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
getJavaOverrides(
|
|
523
|
+
name,
|
|
524
|
+
options.print,
|
|
525
|
+
runtime,
|
|
526
|
+
options.files,
|
|
527
|
+
builtins,
|
|
528
|
+
evaluateReplaced,
|
|
529
|
+
)?.forEach((operator) => {
|
|
487
530
|
const symbol = top.linked.visible.get(operator.name);
|
|
488
|
-
if (symbol?.kind !== "Definition"
|
|
531
|
+
if (symbol?.kind !== "Definition") return;
|
|
532
|
+
if (symbol.arity !== operator.arity && ANNOTATED_OVERRIDE_MODULES.has(name)) return;
|
|
533
|
+
const definition = definitions.get(symbol.key);
|
|
534
|
+
if (definition) replaced.set(operator.name, definition);
|
|
489
535
|
builtins.set(symbol.key, operator);
|
|
490
536
|
definitions.delete(symbol.key);
|
|
491
537
|
});
|
|
@@ -509,7 +555,7 @@ export const createEnvironment = (
|
|
|
509
555
|
unit.facts.add(instance.name === undefined ? name : `${instance.name}!${name}`),
|
|
510
556
|
);
|
|
511
557
|
const declarations = getDeclarations(linked);
|
|
512
|
-
const suffix = `#${copyCount
|
|
558
|
+
const suffix = `#${copyCount++}`;
|
|
513
559
|
const renamed = new Map(instance.params.map((param) => [param.name, `${param.name}${suffix}`]));
|
|
514
560
|
const substitutions = resolveSubstitutions(
|
|
515
561
|
resolveInstanceSubexpressions(instance, module),
|
|
@@ -524,13 +570,23 @@ export const createEnvironment = (
|
|
|
524
570
|
substitutions,
|
|
525
571
|
location: instance.location,
|
|
526
572
|
});
|
|
573
|
+
const params = instance.params.map((param) => ({ ...param, name: `${param.name}${suffix}` }));
|
|
574
|
+
params.forEach((param) => instanceParams.add(param));
|
|
575
|
+
const substitutionRange = instance.definitionRange
|
|
576
|
+
? {
|
|
577
|
+
...instance.definitionRange,
|
|
578
|
+
start: { line: instance.location.line, column: instance.location.column },
|
|
579
|
+
}
|
|
580
|
+
: instance.instanceRange;
|
|
527
581
|
const instantiation = createInstantiation({
|
|
528
|
-
params
|
|
582
|
+
params,
|
|
529
583
|
substitutions: new Map(
|
|
530
584
|
[...substitutions].map(([name, expression]) => [name, renameLocals(expression, renamed)]),
|
|
531
585
|
),
|
|
532
586
|
variables: new Set(linked.variables),
|
|
533
587
|
getDefinition: (key) => definitions.get(key),
|
|
588
|
+
getOuterDefinition: (name) =>
|
|
589
|
+
module.definitions.find((definition) => definition.name === name),
|
|
534
590
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
535
591
|
addDefinition: (source, name, create) => {
|
|
536
592
|
const key = createName(`${name}@${module.name}`);
|
|
@@ -545,6 +601,13 @@ export const createEnvironment = (
|
|
|
545
601
|
return key;
|
|
546
602
|
},
|
|
547
603
|
createName,
|
|
604
|
+
...(declarations.length > 0 && {
|
|
605
|
+
frame: {
|
|
606
|
+
kind: "Identifier",
|
|
607
|
+
name: instance.name ?? instance.module,
|
|
608
|
+
location: { ...substitutionRange.start, range: substitutionRange },
|
|
609
|
+
},
|
|
610
|
+
}),
|
|
548
611
|
});
|
|
549
612
|
return getInstanceSymbols(instance, linked.exported, declarations, (key, name) => {
|
|
550
613
|
const copy =
|
|
@@ -567,9 +630,6 @@ export const createEnvironment = (
|
|
|
567
630
|
]),
|
|
568
631
|
);
|
|
569
632
|
|
|
570
|
-
// The names an INSTANCE adds for the definitions of the module it instantiates, each with the key
|
|
571
|
-
// that getKey gives it. SANY binds a copy of a definition that depends on the parameters at the
|
|
572
|
-
// INSTANCE.
|
|
573
633
|
const getInstanceSymbols = (
|
|
574
634
|
instance: Instance,
|
|
575
635
|
exported: Symbols,
|
|
@@ -636,7 +696,7 @@ export const createEnvironment = (
|
|
|
636
696
|
});
|
|
637
697
|
|
|
638
698
|
const createArgumentParams = (arity: number) =>
|
|
639
|
-
Array.from({ length: arity }, (
|
|
699
|
+
Array.from({ length: arity }, (_value, index) => ({ name: `argument${index}`, arity: 0 }));
|
|
640
700
|
|
|
641
701
|
const getSubstitutionBody = (
|
|
642
702
|
replacement: Expression,
|
|
@@ -685,7 +745,7 @@ export const createEnvironment = (
|
|
|
685
745
|
});
|
|
686
746
|
}
|
|
687
747
|
const linked = nested ?? getLinkedModule(instance.module, instancer);
|
|
688
|
-
const suffix = `#${copyCount
|
|
748
|
+
const suffix = `#${copyCount++}`;
|
|
689
749
|
const explicitSubstitutions = new Map(
|
|
690
750
|
instance.substitutions.map((item) => [item.name, item.expression]),
|
|
691
751
|
);
|
|
@@ -742,6 +802,7 @@ export const createEnvironment = (
|
|
|
742
802
|
),
|
|
743
803
|
variables: new Set(linked.variables),
|
|
744
804
|
getDefinition: (key) => definitions.get(key),
|
|
805
|
+
getOuterDefinition: () => undefined,
|
|
745
806
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
746
807
|
addDefinition: (_source, name, create) => {
|
|
747
808
|
const key = `${name}${KEY_SEPARATOR}${instance.module}${suffix}.${copies.length}`;
|
|
@@ -796,12 +857,9 @@ export const createEnvironment = (
|
|
|
796
857
|
]),
|
|
797
858
|
...scope.symbols,
|
|
798
859
|
]);
|
|
799
|
-
// Where an INSTANCE first made each name it adds visible.
|
|
800
860
|
const importedAt = new Map<string, SourceLocation>();
|
|
801
861
|
const extendsReport: ModuleReport = { location: MODULE_START, errors: [], warnings: [] };
|
|
802
862
|
const reports = [extendsReport];
|
|
803
|
-
// Context.mergeExtendContext keeps the first of the symbols the extended modules share by name,
|
|
804
|
-
// and warns of two definitions or two declarations but rejects a definition and a declaration.
|
|
805
863
|
const mergeExtended = (symbols: Symbols) =>
|
|
806
864
|
symbols.forEach((symbol, name) => {
|
|
807
865
|
const current = exported.get(name);
|
|
@@ -836,8 +894,12 @@ export const createEnvironment = (
|
|
|
836
894
|
const modules = new Map<string, LinkedModule>();
|
|
837
895
|
const extended: LinkedModule[] = [];
|
|
838
896
|
const constants = [...parsed.constants];
|
|
839
|
-
const
|
|
840
|
-
|
|
897
|
+
const declaredVariables = parsed.variables.filter(
|
|
898
|
+
(variable, index) =>
|
|
899
|
+
parsed.variables.findIndex((other) => other.name === variable.name) === index,
|
|
900
|
+
);
|
|
901
|
+
const variables = declaredVariables.map((variable) => variable.name);
|
|
902
|
+
const variableLocations = declaredVariables.map((variable) => variable.location);
|
|
841
903
|
parsed.extends.forEach((name) => {
|
|
842
904
|
const nested = scope.modules.get(name);
|
|
843
905
|
const standardSymbols = nested ? undefined : getStandardSymbols(name);
|
|
@@ -847,12 +909,16 @@ export const createEnvironment = (
|
|
|
847
909
|
}
|
|
848
910
|
const linked = nested ?? getLinkedModule(name, parsed.name);
|
|
849
911
|
constants.push(
|
|
850
|
-
...linked.constants.filter(
|
|
851
|
-
|
|
912
|
+
...linked.constants.filter(
|
|
913
|
+
(constant) =>
|
|
914
|
+
constants.every((existing) => existing.name !== constant.name) &&
|
|
915
|
+
!variables.includes(constant.name),
|
|
852
916
|
),
|
|
853
917
|
);
|
|
854
918
|
linked.variables.forEach((variable, index) => {
|
|
855
|
-
|
|
919
|
+
const isDeclared =
|
|
920
|
+
variables.includes(variable) || constants.some((constant) => constant.name === variable);
|
|
921
|
+
if (isDeclared) return;
|
|
856
922
|
variables.push(variable);
|
|
857
923
|
variableLocations.push(linked.variableLocations[index]);
|
|
858
924
|
});
|
|
@@ -887,14 +953,12 @@ export const createEnvironment = (
|
|
|
887
953
|
parsed === root ? definition.name : `${definition.name}${KEY_SEPARATOR}${scope.id}`;
|
|
888
954
|
const instanced = new Map<Instance, Symbols>();
|
|
889
955
|
const getVisibleModules = () => new Map([...scope.modules, ...modules]);
|
|
890
|
-
const isInstancedAfterDefinition = (nested: Module) => {
|
|
891
|
-
const first = parsed.instances.find((instance) => instance.module === nested.name);
|
|
892
|
-
return first !== undefined && isBefore(nested.location, first.location);
|
|
893
|
-
};
|
|
894
956
|
const getLetModule = (instance: Instance) => {
|
|
895
957
|
const ownModule = parsed.modules.find((nested) => nested.name === instance.module);
|
|
896
958
|
if (!ownModule) return getVisibleModules().get(instance.module);
|
|
897
|
-
return
|
|
959
|
+
return isBefore(ownModule.location, instance.location)
|
|
960
|
+
? modules.get(ownModule.name)
|
|
961
|
+
: undefined;
|
|
898
962
|
};
|
|
899
963
|
const getUnit = (module: Module): ModuleUnit => ({
|
|
900
964
|
imported: visible,
|
|
@@ -927,7 +991,6 @@ export const createEnvironment = (
|
|
|
927
991
|
reports,
|
|
928
992
|
warnings: scope.warnings,
|
|
929
993
|
});
|
|
930
|
-
// SANY keeps the first of two symbols of a name.
|
|
931
994
|
const getSymbolsBefore = (location: SourceLocation): Symbols =>
|
|
932
995
|
[
|
|
933
996
|
...declarations
|
|
@@ -946,8 +1009,6 @@ export const createEnvironment = (
|
|
|
946
1009
|
(symbols, [name, symbol]) => (symbols.has(name) ? symbols : symbols.set(name, symbol)),
|
|
947
1010
|
new Map(visible),
|
|
948
1011
|
);
|
|
949
|
-
// Generator.generateModule reports the errors of a nested module and goes on, and then
|
|
950
|
-
// SymbolTable.addModule reports a module already defined.
|
|
951
1012
|
const linkNested = (nested: Module) => {
|
|
952
1013
|
const visibleModules = getVisibleModules();
|
|
953
1014
|
const existing = visibleModules.get(nested.name);
|
|
@@ -967,7 +1028,6 @@ export const createEnvironment = (
|
|
|
967
1028
|
});
|
|
968
1029
|
if (redefinition) report.errors.push(redefinition);
|
|
969
1030
|
if (!existing) modules.set(nested.name, linked);
|
|
970
|
-
if (!nestedModules.has(nested.name)) nestedModules.set(nested.name, linked);
|
|
971
1031
|
};
|
|
972
1032
|
[
|
|
973
1033
|
...parsed.instances.map((instance) => ({
|
|
@@ -1009,7 +1069,6 @@ export const createEnvironment = (
|
|
|
1009
1069
|
parameterized.set(key, !isParameterFree);
|
|
1010
1070
|
const symbol = getDefinitionSymbol(definition);
|
|
1011
1071
|
const importedLocation = importedAt.get(definition.name);
|
|
1012
|
-
// SANY binds the name of a fact to a fact the module imports before it.
|
|
1013
1072
|
if (
|
|
1014
1073
|
symbol.kind === "Theorem" &&
|
|
1015
1074
|
visible.get(definition.name)?.kind === "Theorem" &&
|
|
@@ -1035,8 +1094,6 @@ export const createEnvironment = (
|
|
|
1035
1094
|
]),
|
|
1036
1095
|
};
|
|
1037
1096
|
if (!checkedModules.has(parsed.name)) checkedModules.set(parsed.name, linked);
|
|
1038
|
-
// SANY checks the instances of a module with its definitions and theorems, so it reports their
|
|
1039
|
-
// errors together.
|
|
1040
1097
|
const checks = instanceChecks
|
|
1041
1098
|
.splice(firstCheck)
|
|
1042
1099
|
.map((check) => ({ location: check.location, check: () => checkInstance(check) }));
|
|
@@ -1058,12 +1115,37 @@ export const createEnvironment = (
|
|
|
1058
1115
|
};
|
|
1059
1116
|
|
|
1060
1117
|
const linkedRoot = linkTopLevel(root).linked;
|
|
1118
|
+
const traceFile = options.traceFile;
|
|
1119
|
+
const traceOperators: ModuleOperator[] =
|
|
1120
|
+
traceFile === undefined
|
|
1121
|
+
? []
|
|
1122
|
+
: [
|
|
1123
|
+
{
|
|
1124
|
+
kind: "postcondition",
|
|
1125
|
+
module: "_TLCTrace",
|
|
1126
|
+
operator: "_TLCTraceSilent",
|
|
1127
|
+
constants: { _TLCTraceFile: traceFile },
|
|
1128
|
+
},
|
|
1129
|
+
];
|
|
1130
|
+
const moduleOperators = [...(options.moduleOperators ?? []), ...traceOperators].map(
|
|
1131
|
+
(operator): ResolvedModuleOperator => {
|
|
1132
|
+
const symbol = getLinkedModule(operator.module, root.name).visible.get(operator.operator);
|
|
1133
|
+
return { ...operator, key: symbol?.kind === "Definition" ? symbol.key : undefined };
|
|
1134
|
+
},
|
|
1135
|
+
);
|
|
1136
|
+
linkOrder.push(...linkOrder.splice(linkOrder.indexOf(linkedRoot), 1));
|
|
1061
1137
|
if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
|
|
1062
1138
|
const getRootKey = (name: string) => linkedRoot.visible.get(name)?.key ?? name;
|
|
1063
1139
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
1064
1140
|
const definition = definitions.get(symbol.key);
|
|
1065
1141
|
if (definition && symbol.key !== name) definitions.set(name, definition);
|
|
1066
1142
|
});
|
|
1143
|
+
moduleOperators.forEach((operator) => {
|
|
1144
|
+
const definition = operator.key === undefined ? undefined : definitions.get(operator.key);
|
|
1145
|
+
if (operator.kind !== "postcondition" && definition) {
|
|
1146
|
+
definitions.set(operator.operator, definition);
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1067
1149
|
|
|
1068
1150
|
const assumptions: Assumption[] = [];
|
|
1069
1151
|
const addAssumptions = (linked: LinkedModule, visited: Set<LinkedModule>) => {
|
|
@@ -1076,17 +1158,29 @@ export const createEnvironment = (
|
|
|
1076
1158
|
const declaredConstants = linkedRoot.constants.map((constant) => constant.name);
|
|
1077
1159
|
const variables = linkedRoot.variables;
|
|
1078
1160
|
|
|
1079
|
-
const
|
|
1161
|
+
const moduleSymbols = new Map([
|
|
1162
|
+
...standardExports,
|
|
1163
|
+
...[...linkedModules].map(([name, linked]): [string, Symbols] => [name, linked.visible]),
|
|
1164
|
+
[root.name, linkedRoot.visible],
|
|
1165
|
+
]);
|
|
1166
|
+
const getScopedSymbol = (item: { name: string; module?: string }) => {
|
|
1167
|
+
const symbol = moduleSymbols.get(item.module ?? "")?.get(item.name);
|
|
1168
|
+
return symbol?.kind === "Definition" ? symbol : undefined;
|
|
1169
|
+
};
|
|
1170
|
+
const getSubstitutedKeys = (item: { name: string; module?: string }) => {
|
|
1080
1171
|
if (item.module === undefined) return [item.name, getRootKey(item.name)];
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
return [linked?.visible.get(item.name)?.key ?? item.name];
|
|
1172
|
+
const symbol = getScopedSymbol(item);
|
|
1173
|
+
return symbol ? [symbol.key] : [];
|
|
1084
1174
|
};
|
|
1175
|
+
const getScopedKeys = (item: { name: string; module?: string }) =>
|
|
1176
|
+
item.module === root.name ? [] : getSubstitutedKeys(item);
|
|
1085
1177
|
const getKeyArity = (key: string) => {
|
|
1086
1178
|
const definition = definitions.get(key);
|
|
1087
1179
|
return definition?.kind === "Operator"
|
|
1088
1180
|
? definition.params.length
|
|
1089
|
-
: (linkedRoot.constants.find((constant) => constant.name === key)?.arity ??
|
|
1181
|
+
: (linkedRoot.constants.find((constant) => constant.name === key)?.arity ??
|
|
1182
|
+
builtins.get(key)?.arity ??
|
|
1183
|
+
0);
|
|
1090
1184
|
};
|
|
1091
1185
|
const constants = new Map<string, Value>();
|
|
1092
1186
|
const operatorKeys = new Set<string>();
|
|
@@ -1099,7 +1193,7 @@ export const createEnvironment = (
|
|
|
1099
1193
|
config.constants
|
|
1100
1194
|
.filter((assignment) => assignment.args === undefined)
|
|
1101
1195
|
.forEach((assignment) => {
|
|
1102
|
-
const value =
|
|
1196
|
+
const value = toConstantValue(assignment.value);
|
|
1103
1197
|
markNormalized(value);
|
|
1104
1198
|
getScopedKeys(assignment).forEach((key) => {
|
|
1105
1199
|
const arity = getKeyArity(key);
|
|
@@ -1135,20 +1229,38 @@ export const createEnvironment = (
|
|
|
1135
1229
|
});
|
|
1136
1230
|
tables.forEach((table) =>
|
|
1137
1231
|
getScopedKeys(table).forEach((key) =>
|
|
1138
|
-
setOperator(
|
|
1139
|
-
key,
|
|
1140
|
-
createOperatorTable(table.name, getKeyArity(key) || table.rows[0][0].length, table.rows),
|
|
1141
|
-
),
|
|
1232
|
+
setOperator(key, createOperatorTable(table.name, getKeyArity(key), table.rows)),
|
|
1142
1233
|
),
|
|
1143
1234
|
);
|
|
1144
1235
|
const substitutions = new Map(
|
|
1145
1236
|
config.substitutions.flatMap((substitution) =>
|
|
1146
|
-
|
|
1237
|
+
getSubstitutedKeys(substitution).map((key): [string, string] => [
|
|
1147
1238
|
key,
|
|
1148
1239
|
getRootKey(substitution.target),
|
|
1149
1240
|
]),
|
|
1150
1241
|
),
|
|
1151
1242
|
);
|
|
1243
|
+
[...substitutions.keys()].forEach((key) => constants.delete(key));
|
|
1244
|
+
const checkSubstitutionTarget = (name: string, target: string, arity: number | undefined) => {
|
|
1245
|
+
const targetKey = getRootKey(target);
|
|
1246
|
+
const definition = definitions.get(targetKey);
|
|
1247
|
+
const isDefined =
|
|
1248
|
+
definition !== undefined ||
|
|
1249
|
+
builtins.has(targetKey) ||
|
|
1250
|
+
constants.has(targetKey) ||
|
|
1251
|
+
declaredConstants.includes(target) ||
|
|
1252
|
+
variables.includes(target);
|
|
1253
|
+
if (!isDefined) {
|
|
1254
|
+
throw new TlaConfigError(
|
|
1255
|
+
`The configuration file substitutes for ${name} with the undefined identifier ${target}.`,
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
if (definition?.kind === "Operator" && definition.params.length !== arity) {
|
|
1259
|
+
throw new TlaConfigError(
|
|
1260
|
+
`The configuration file substitutes for ${name} with ${target} of different number of arguments.`,
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1152
1264
|
config.substitutions
|
|
1153
1265
|
.filter((substitution) => substitution.module === undefined)
|
|
1154
1266
|
.forEach((substitution) => {
|
|
@@ -1164,32 +1276,43 @@ export const createEnvironment = (
|
|
|
1164
1276
|
`In the configuration file, the identifier ${target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
|
|
1165
1277
|
);
|
|
1166
1278
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
(linkedRoot.constants.find((constant) => constant.name === name)?.arity ??
|
|
1184
|
-
linkedRoot.visible.get(name)?.arity)
|
|
1185
|
-
) {
|
|
1279
|
+
checkSubstitutionTarget(
|
|
1280
|
+
name,
|
|
1281
|
+
target,
|
|
1282
|
+
linkedRoot.constants.find((constant) => constant.name === name)?.arity ??
|
|
1283
|
+
linkedRoot.visible.get(name)?.arity,
|
|
1284
|
+
);
|
|
1285
|
+
});
|
|
1286
|
+
const scopedSubstitutions = config.substitutions.filter(
|
|
1287
|
+
(substitution) => substitution.module !== undefined,
|
|
1288
|
+
);
|
|
1289
|
+
[...moduleSymbols.keys()].forEach((name) => {
|
|
1290
|
+
const inModule = scopedSubstitutions.filter((substitution) => substitution.module === name);
|
|
1291
|
+
inModule.forEach((substitution) => {
|
|
1292
|
+
const symbol = getScopedSymbol(substitution);
|
|
1293
|
+
if (!symbol) return;
|
|
1294
|
+
if (inModule.some((other) => other.name === substitution.target)) {
|
|
1186
1295
|
throw new TlaConfigError(
|
|
1187
|
-
`
|
|
1296
|
+
`In the configuration file, the identifier ${substitution.target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
|
|
1188
1297
|
);
|
|
1189
1298
|
}
|
|
1299
|
+
checkSubstitutionTarget(substitution.name, substitution.target, symbol.arity);
|
|
1190
1300
|
});
|
|
1191
|
-
|
|
1192
|
-
|
|
1301
|
+
const missing = inModule.find((substitution) => !getScopedSymbol(substitution));
|
|
1302
|
+
if (missing) {
|
|
1303
|
+
throw new TlaConfigError(
|
|
1304
|
+
`In the configuration file, the identifier ${missing.name} does not appear in the specification.`,
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
const unknownModule = scopedSubstitutions.find(
|
|
1309
|
+
(substitution) => !moduleSymbols.has(substitution.module ?? ""),
|
|
1310
|
+
);
|
|
1311
|
+
if (unknownModule) {
|
|
1312
|
+
throw new TlaConfigError(
|
|
1313
|
+
`In the configuration file, the module name ${unknownModule.module} is not a module in the specification.`,
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1193
1316
|
const scopedKeys = new Set(
|
|
1194
1317
|
[...config.constants, ...config.substitutions]
|
|
1195
1318
|
.filter((item) => item.module !== undefined)
|
|
@@ -1220,11 +1343,16 @@ export const createEnvironment = (
|
|
|
1220
1343
|
if (symbol.key === key && name !== key) definitions.set(name, alias);
|
|
1221
1344
|
});
|
|
1222
1345
|
});
|
|
1346
|
+
moduleOperators.forEach((operator) =>
|
|
1347
|
+
getLinkedModule(operator.module, root.name).constants.forEach((constant) => {
|
|
1348
|
+
const value = operator.constants?.[constant.name];
|
|
1349
|
+
if (value !== undefined) constants.set(constant.name, value);
|
|
1350
|
+
}),
|
|
1351
|
+
);
|
|
1223
1352
|
const unassigned = declaredConstants.filter(
|
|
1224
1353
|
(name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
|
|
1225
1354
|
);
|
|
1226
|
-
if (unassigned.length > 0
|
|
1227
|
-
// TLC reports the first constant it finds unassigned in SANY's order of declarations.
|
|
1355
|
+
if (unassigned.length > 0) {
|
|
1228
1356
|
const name =
|
|
1229
1357
|
order.getDeclarationOrder("constant").find((constant) => unassigned.includes(constant)) ??
|
|
1230
1358
|
unassigned[0];
|
|
@@ -1233,7 +1361,7 @@ export const createEnvironment = (
|
|
|
1233
1361
|
);
|
|
1234
1362
|
}
|
|
1235
1363
|
|
|
1236
|
-
if (
|
|
1364
|
+
if (traceFile !== undefined) {
|
|
1237
1365
|
builtins.forEach((builtin, name) => {
|
|
1238
1366
|
const replacement = getTraceSpecArithmetic(builtin);
|
|
1239
1367
|
if (replacement) builtins.set(name, replacement);
|
|
@@ -1264,13 +1392,11 @@ export const createEnvironment = (
|
|
|
1264
1392
|
facts,
|
|
1265
1393
|
startupValues: Array.from({ length: facts.ids.size }, (): Value | undefined => undefined),
|
|
1266
1394
|
substitutedDefinitions,
|
|
1395
|
+
instanceParams,
|
|
1267
1396
|
evaluators: new WeakMap(),
|
|
1268
1397
|
entryEvaluators: new WeakMap(),
|
|
1269
1398
|
definitionEvaluators: new WeakMap(),
|
|
1270
1399
|
};
|
|
1271
|
-
// TLC evaluates a substitute at startup and rejects it only when that fails and the level bound it
|
|
1272
|
-
// computes is above constant. The bound counts the operators that TLC's Java code overrides with
|
|
1273
|
-
// a minimum level as state-level, so the analyzer takes them for variables.
|
|
1274
1400
|
const analyzer = createLevelAnalyzer({
|
|
1275
1401
|
constants: new Set(constants.keys()),
|
|
1276
1402
|
variables: new Set([
|
|
@@ -1298,17 +1424,13 @@ export const createEnvironment = (
|
|
|
1298
1424
|
? getEvaluationError(definition.body)
|
|
1299
1425
|
: undefined;
|
|
1300
1426
|
if (error) {
|
|
1301
|
-
// TLC's SpecProcessor adds the message of a TLCRuntimeException, not of an EvalException.
|
|
1302
1427
|
const addendum = isEvalException(error) ? "" : ` - specifically: ${error.message}`;
|
|
1303
1428
|
throw new TlaConfigError(
|
|
1304
1429
|
`The configuration file substitutes constant ${name} with non-constant ${target}${addendum}`,
|
|
1305
1430
|
);
|
|
1306
1431
|
}
|
|
1307
1432
|
});
|
|
1308
|
-
// TLC 1.7.4 processes the whole spec before it creates its model checker, which TLCGet reads.
|
|
1309
1433
|
if (runtime.version !== "1.7.4") runtime.isStarted = true;
|
|
1310
|
-
// TLC computes the constant definitions of each module in the order SANY finishes the modules,
|
|
1311
|
-
// except those of a module that an INSTANCE gives parameters to.
|
|
1312
1434
|
const instantiated = new Set(
|
|
1313
1435
|
linkOrder.flatMap((linked) => linked.module.instances.map((instance) => instance.module)),
|
|
1314
1436
|
);
|
|
@@ -1330,8 +1452,8 @@ export const createEnvironment = (
|
|
|
1330
1452
|
},
|
|
1331
1453
|
),
|
|
1332
1454
|
),
|
|
1333
|
-
rootConstants: linkedRoot.constants,
|
|
1334
|
-
rootSymbols: linkedRoot.visible,
|
|
1335
1455
|
javaOverrides: linkOrder.flatMap((linked) => javaOverrides.get(linked.module.name) ?? []),
|
|
1456
|
+
moduleOperators,
|
|
1457
|
+
rootName: root.name,
|
|
1336
1458
|
};
|
|
1337
1459
|
};
|