tla-ts 0.0.9 → 0.0.10-dev.63a6693bd
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 +29 -29
- package/dist/deciders.js +42 -42
- 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 +117 -37
- 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 +48 -62
- package/src/bags.ts +99 -102
- package/src/builtins.ts +28 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +599 -754
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +19 -12
- package/src/cli/tlapm.ts +14 -25
- package/src/cli/tlc-arguments.ts +652 -0
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +309 -658
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +196 -74
- package/src/config.ts +140 -109
- package/src/coverage.ts +830 -0
- package/src/dependencies.ts +14 -53
- package/src/dfid.ts +618 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +169 -335
- package/src/errors.ts +71 -55
- package/src/evaluate.ts +598 -340
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +126 -21
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +46 -58
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +103 -153
- package/src/liveness.ts +150 -109
- package/src/obligations/action.ts +8 -39
- package/src/obligations/anonymize.ts +88 -82
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +20 -21
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +46 -49
- package/src/obligations/index.ts +2 -13
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +28 -53
- package/src/obligations/normalize.ts +7 -25
- 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 +42 -58
- package/src/obligations/source.ts +48 -78
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +13 -19
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +30 -60
- package/src/parallel.ts +57 -71
- package/src/parser.ts +584 -316
- 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 +8 -13
- package/src/prover/deciders.ts +3 -7
- 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 +114 -115
- package/src/prover/isabelle/isar/method.ts +29 -53
- 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 +26 -36
- package/src/prover/isabelle/isar/type-check.ts +17 -31
- package/src/prover/isabelle/provers/blast/blast.ts +17 -104
- 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 +28 -51
- package/src/prover/isabelle/pure/bicompose.ts +25 -38
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +3 -17
- package/src/prover/isabelle/pure/drule.ts +33 -42
- 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 +2 -15
- 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 +17 -62
- package/src/prover/isabelle/pure/rewriter.ts +31 -67
- 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 +3 -32
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +48 -47
- 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 +27 -47
- 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 +17 -24
- package/src/prover/isabelle/tla/context.ts +15 -18
- package/src/prover/isabelle/tla/logic.ts +14 -32
- package/src/prover/isabelle/tla/simpdata.ts +46 -43
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +14 -54
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +2 -21
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +33 -39
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +87 -100
- 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 +20 -28
- package/src/prover/smt/data.ts +433 -424
- package/src/prover/smt/encode.ts +43 -52
- 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 +663 -667
- 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 -165
- package/src/prover/smt/solver/auf-solver.ts +8 -44
- 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 +7 -64
- 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 +4 -35
- 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 +1 -6
- 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 +7 -100
- 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 +9 -102
- 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 +36 -135
- 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 +18 -58
- 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 +3 -37
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +15 -32
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +23 -88
- package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
- package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +10 -69
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
- package/src/prover/smt/solver/nlsat/solver.ts +18 -90
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
- 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 -52
- 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 +27 -47
- package/src/prover/smt/solver/quantifier-manager.ts +2 -13
- 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 +80 -131
- 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 +1 -7
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
- 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 +45 -40
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +21 -20
- package/src/prover/verdict.ts +7 -2
- package/src/prover/zenon/check/check.ts +1 -11
- 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 +1 -6
- package/src/prover/zenon/check/relations.ts +2 -14
- package/src/prover/zenon/check/rewrites.ts +2 -21
- package/src/prover/zenon/check/sets.ts +40 -61
- package/src/prover/zenon/check/terms.ts +1 -19
- 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 +2 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +8 -26
- package/src/prover/zenon/index-table.ts +26 -57
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +36 -64
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +2 -20
- package/src/prover/zenon/mltoll.ts +66 -104
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +4 -12
- 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 +5 -31
- package/src/prover/zenon/tla/functions.ts +59 -31
- package/src/prover/zenon/tla/llproof.ts +67 -76
- package/src/prover/zenon/tla/records.ts +57 -33
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +83 -53
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +66 -64
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +67 -184
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +191 -2764
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +58 -77
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +5 -43
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +49 -76
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +35 -117
- package/src/search.ts +541 -163
- package/src/simulate.ts +709 -0
- package/src/spec-description.ts +192 -100
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +264 -95
- package/src/state-graph.ts +52 -31
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +266 -99
- 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 +125 -54
- package/src/tlc/order.ts +39 -69
- package/src/tlc/random.ts +37 -49
- package/src/tlc/replay.ts +553 -228
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +78 -44
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +249 -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 +479 -0
- package/src/typescript/collections.ts +614 -0
- package/src/typescript/compile.ts +63 -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 +154 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +162 -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 +167 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -484
- package/src/worker.ts +7 -8
package/src/environment.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getChildren,
|
|
3
|
+
getDefinitionExpressions,
|
|
4
|
+
getReferencedName,
|
|
3
5
|
type Assumption,
|
|
4
6
|
type Declaration,
|
|
5
7
|
type Definition,
|
|
@@ -9,8 +11,9 @@ import {
|
|
|
9
11
|
type OperatorParam,
|
|
10
12
|
type SourceLocation,
|
|
11
13
|
} from "./ast";
|
|
12
|
-
import {
|
|
13
|
-
import type {
|
|
14
|
+
import type { ModuleOperator } from "./check";
|
|
15
|
+
import type { ModelConfig } from "./config";
|
|
16
|
+
import { applyConfig, type CopySource } from "./environment-config";
|
|
14
17
|
import type { FileSystem } from "./json";
|
|
15
18
|
import {
|
|
16
19
|
createSanyError,
|
|
@@ -19,21 +22,24 @@ import {
|
|
|
19
22
|
formatSanyWarnings,
|
|
20
23
|
TlaConfigError,
|
|
21
24
|
TlaEvaluationError,
|
|
22
|
-
TlaModuleError,
|
|
23
25
|
TlaSyntaxError,
|
|
24
26
|
type SanyError,
|
|
25
27
|
} from "./errors";
|
|
26
|
-
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
27
28
|
import {
|
|
29
|
+
bindOperatorArguments,
|
|
28
30
|
createBigNumberError,
|
|
29
31
|
createRealNumberError,
|
|
30
32
|
evaluate,
|
|
31
33
|
getDefinition,
|
|
34
|
+
getDefinitionClosure,
|
|
32
35
|
type Builtin,
|
|
36
|
+
type BuiltinArgument,
|
|
37
|
+
type Context,
|
|
33
38
|
type Environment,
|
|
34
39
|
} from "./evaluate";
|
|
35
40
|
import {
|
|
36
41
|
createInstantiation,
|
|
42
|
+
createLocalAlias,
|
|
37
43
|
createLocalArguments,
|
|
38
44
|
createLocalIdentifier,
|
|
39
45
|
getEnabledVariableName,
|
|
@@ -60,13 +66,14 @@ 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,
|
|
67
|
-
|
|
72
|
+
getJavaOverrides,
|
|
73
|
+
getStandardOperators,
|
|
68
74
|
getTraceSpecArithmetic,
|
|
69
75
|
STANDARD_DEPENDENCIES,
|
|
76
|
+
STANDARD_EXTENDS,
|
|
70
77
|
} from "./standard-modules";
|
|
71
78
|
import { getStandardRange, STANDARD_LEVELS } from "./standard-definitions";
|
|
72
79
|
import { resolveInstanceSubexpressions, resolveModuleSubexpressions } from "./subexpressions";
|
|
@@ -75,48 +82,38 @@ import { createInstanceChecker, type InstanceCheck } from "./substitution-levels
|
|
|
75
82
|
import { isEvalException } from "./tlc/messages";
|
|
76
83
|
import { createDefinitionFacts } from "./dependencies";
|
|
77
84
|
import { createTlcOrder, type TlcOrder } from "./tlc/order";
|
|
78
|
-
import {
|
|
79
|
-
isTlcInteger,
|
|
80
|
-
createModelValue,
|
|
81
|
-
createSet,
|
|
82
|
-
formatValue,
|
|
83
|
-
valuesEqual,
|
|
84
|
-
type Value,
|
|
85
|
-
markNormalized,
|
|
86
|
-
} from "./values";
|
|
85
|
+
import { isTlcInteger, type Value } from "./values";
|
|
87
86
|
import type { TlcVersion } from "./tlc/version";
|
|
88
87
|
|
|
89
88
|
interface EnvironmentOptions {
|
|
90
89
|
source: string;
|
|
91
90
|
loadModule: ((name: string) => string | undefined) | undefined;
|
|
92
|
-
// The TLC orders of the same spec, when the caller already reads them.
|
|
93
91
|
order?: TlcOrder;
|
|
94
92
|
loadClass?: (name: string) => Uint8Array | undefined;
|
|
95
93
|
print: (text: string) => void;
|
|
96
94
|
files: FileSystem;
|
|
97
95
|
seed?: bigint;
|
|
98
|
-
// Links the modules without a model, as SANY does, so a declared constant needs no value.
|
|
99
|
-
isUnconfigured?: boolean;
|
|
100
96
|
isTool?: boolean;
|
|
101
|
-
|
|
102
|
-
// methods then compute the arithmetic of Naturals.
|
|
103
|
-
isTraceRecorded?: boolean;
|
|
97
|
+
traceFile?: string;
|
|
104
98
|
isSanyReported?: boolean;
|
|
105
99
|
isWarningEnabled?: boolean;
|
|
106
100
|
version?: TlcVersion;
|
|
101
|
+
moduleOperators?: ModuleOperator[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface ResolvedModuleOperator extends ModuleOperator {
|
|
105
|
+
key: string | undefined;
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
interface Specification {
|
|
108
|
+
export interface Specification {
|
|
110
109
|
environment: Environment;
|
|
111
110
|
assumptions: Assumption[];
|
|
112
111
|
variableLocations: SourceLocation[];
|
|
113
112
|
instanceActions: Map<string, InstanceAction>;
|
|
114
|
-
// The definitions TLC computes when it starts, in the order it computes them.
|
|
115
113
|
startupDefinitions: Definition[];
|
|
116
|
-
rootConstants: Declaration[];
|
|
117
|
-
rootSymbols: Symbols;
|
|
118
|
-
// The methods of the modules' classes, in the order TLC loads the classes.
|
|
119
114
|
javaOverrides: JavaOverride[];
|
|
115
|
+
moduleOperators: ResolvedModuleOperator[];
|
|
116
|
+
rootName: string;
|
|
120
117
|
}
|
|
121
118
|
|
|
122
119
|
export interface InstanceAction {
|
|
@@ -124,28 +121,9 @@ export interface InstanceAction {
|
|
|
124
121
|
location: SourceLocation;
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
const
|
|
128
|
-
switch (value.kind) {
|
|
129
|
-
case "Number":
|
|
130
|
-
// TLC fails with an unexpected exception on a configuration number too big for it.
|
|
131
|
-
if (!isTlcInteger(value.value)) {
|
|
132
|
-
throw setExitCode(
|
|
133
|
-
new TlaModuleError(`Integer overflow: ${value.value} is outside TLC's 32-bit range`),
|
|
134
|
-
EXIT_STATUS.error,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
return value.value;
|
|
138
|
-
case "String":
|
|
139
|
-
case "Boolean":
|
|
140
|
-
return value.value;
|
|
141
|
-
case "ModelValue":
|
|
142
|
-
return createModelValue(value.name);
|
|
143
|
-
case "Set":
|
|
144
|
-
return createSet(value.elements.map(toValue));
|
|
145
|
-
}
|
|
146
|
-
};
|
|
124
|
+
const ANNOTATED_OVERRIDE_MODULES = new Set(["IOUtils", "Json", "TLCExt"]);
|
|
147
125
|
|
|
148
|
-
interface LinkedModule {
|
|
126
|
+
export interface LinkedModule {
|
|
149
127
|
module: Module;
|
|
150
128
|
constants: Declaration[];
|
|
151
129
|
variables: string[];
|
|
@@ -157,8 +135,6 @@ interface LinkedModule {
|
|
|
157
135
|
facts: Set<string>;
|
|
158
136
|
}
|
|
159
137
|
|
|
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
138
|
interface ModuleScope {
|
|
163
139
|
id: string;
|
|
164
140
|
symbols: Symbols;
|
|
@@ -178,8 +154,6 @@ const getDeclarations = (linked: LinkedModule): Declaration[] => [
|
|
|
178
154
|
})),
|
|
179
155
|
];
|
|
180
156
|
|
|
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
157
|
const parseModuleFile = (source: string, name: string, order: TlcOrder) => {
|
|
184
158
|
try {
|
|
185
159
|
return order.parseModule(source);
|
|
@@ -212,12 +186,9 @@ const getModuleRedefinition = (module: Module, existing: Module): SanyError | un
|
|
|
212
186
|
message: `Multiply-defined module '${module.name}': this definition or declaration conflicts \nwith the one at ${formatRange(existing.location.range)}.`,
|
|
213
187
|
};
|
|
214
188
|
|
|
215
|
-
// Context.kindOfNode names a definition or a parameter a definition, and any other symbol a
|
|
216
|
-
// declaration.
|
|
217
189
|
const getNodeWord = (kind: SymbolKind) =>
|
|
218
190
|
["Builtin", "Definition", "Instance", "Parameter"].includes(kind) ? "definition" : "declaration";
|
|
219
191
|
|
|
220
|
-
// The Java class of the node SANY binds a symbol to.
|
|
221
192
|
const getNodeClass = (kind: SymbolKind) =>
|
|
222
193
|
kind === "Theorem" ? "ThmOrAssumpDefNode" : getNodeWord(kind);
|
|
223
194
|
|
|
@@ -236,42 +207,14 @@ const createLocalFunction = (definition: Definition, key: string): Definition =>
|
|
|
236
207
|
location: definition.location,
|
|
237
208
|
});
|
|
238
209
|
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
return
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
evaluate: (args) => {
|
|
246
|
-
const row = rows.find((candidate) => {
|
|
247
|
-
if (candidate[0].length !== args.length) {
|
|
248
|
-
throw new TlaEvaluationError(
|
|
249
|
-
`Attempted to apply the operator ${table}\nwith wrong number of arguments.`,
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
return candidate[0].every((value, index) => {
|
|
253
|
-
const argument = args[index];
|
|
254
|
-
return (
|
|
255
|
-
!(typeof argument === "object" && argument.kind === "Operator") &&
|
|
256
|
-
valuesEqual(value, argument)
|
|
257
|
-
);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
if (row) return row[1];
|
|
261
|
-
throw new TlaEvaluationError(
|
|
262
|
-
`Attempted to apply operator:\n${table}\nto arguments (${args.map((argument) => (typeof argument === "object" && argument.kind === "Operator" ? argument.name : formatValue(argument))).join(", ")}), which is undefined.`,
|
|
263
|
-
);
|
|
264
|
-
},
|
|
265
|
-
evaluateUnary: undefined,
|
|
266
|
-
evaluateBinary: undefined,
|
|
267
|
-
};
|
|
210
|
+
const mentionsName = (expression: Expression, names: Set<string>): boolean => {
|
|
211
|
+
const name = getReferencedName(expression);
|
|
212
|
+
return (
|
|
213
|
+
(name !== undefined && names.has(name)) ||
|
|
214
|
+
getChildren(expression).some((child) => mentionsName(child, names))
|
|
215
|
+
);
|
|
268
216
|
};
|
|
269
217
|
|
|
270
|
-
const mentionsName = (expression: Expression, names: Set<string>): boolean =>
|
|
271
|
-
(expression.kind === "Identifier" && names.has(expression.name)) ||
|
|
272
|
-
(expression.kind === "Apply" && names.has(expression.operator)) ||
|
|
273
|
-
getChildren(expression).some((child) => mentionsName(child, names));
|
|
274
|
-
|
|
275
218
|
const getVariableIndex = (variables: string[], declared: string[]) => {
|
|
276
219
|
const index = new Map(variables.map((name, position) => [name, position]));
|
|
277
220
|
new Set(declared).forEach((name) =>
|
|
@@ -306,9 +249,9 @@ export const createEnvironment = (
|
|
|
306
249
|
const root = order.parseModule(options.source);
|
|
307
250
|
const definitions = new Map<string, Definition>();
|
|
308
251
|
const parameterized = new Map<string, boolean>();
|
|
309
|
-
|
|
310
|
-
const copySources = new Map<string, { source: string; prefix: number }>();
|
|
252
|
+
const copySources = new Map<string, CopySource>();
|
|
311
253
|
const substitutedDefinitions = new Set<Definition>();
|
|
254
|
+
const instanceParams = new Set<OperatorParam>();
|
|
312
255
|
const builtins = new Map<string, Builtin>(
|
|
313
256
|
CORE_OPERATORS.map((operator) => [operator.name, operator]),
|
|
314
257
|
);
|
|
@@ -318,13 +261,10 @@ export const createEnvironment = (
|
|
|
318
261
|
runtime.isTool = options.isTool ?? false;
|
|
319
262
|
runtime.version = options.version ?? "master";
|
|
320
263
|
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
264
|
const checkedModules = new Map<string, LinkedModule>();
|
|
324
265
|
const linkOrder: LinkedModule[] = [];
|
|
325
266
|
const dependencies = new Map<string, Set<string>>();
|
|
326
267
|
const loading: Set<string>[] = [];
|
|
327
|
-
// The top-level modules being linked, to report a cycle of EXTENDS or INSTANCE.
|
|
328
268
|
const linking: string[] = [];
|
|
329
269
|
|
|
330
270
|
const useModule = (name: string, used: Iterable<string>) =>
|
|
@@ -332,8 +272,8 @@ export const createEnvironment = (
|
|
|
332
272
|
closure.add(name);
|
|
333
273
|
[...used].forEach((dependency) => closure.add(dependency));
|
|
334
274
|
});
|
|
335
|
-
|
|
336
|
-
const createName = (name: string) => `${name}#${copyCount
|
|
275
|
+
let copyCount = 0;
|
|
276
|
+
const createName = (name: string) => `${name}#${copyCount++}`;
|
|
337
277
|
const instanceChecks: InstanceCheck[] = [];
|
|
338
278
|
const warnings: SanyError[] = [];
|
|
339
279
|
const checkInstance = createInstanceChecker((name) => {
|
|
@@ -358,18 +298,16 @@ export const createEnvironment = (
|
|
|
358
298
|
const addStandardModule = (name: string): Symbols | undefined => {
|
|
359
299
|
const cached = standardExports.get(name);
|
|
360
300
|
if (cached) return cached;
|
|
361
|
-
const
|
|
362
|
-
if (!
|
|
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.
|
|
301
|
+
const operators = getStandardOperators(name, options.print, runtime, options.files, builtins);
|
|
302
|
+
if (!operators) return undefined;
|
|
365
303
|
STANDARD_DEPENDENCIES.get(name)?.forEach(addStandardModule);
|
|
366
304
|
const exported: Symbols = new Map();
|
|
367
|
-
|
|
305
|
+
STANDARD_EXTENDS.get(name)?.forEach((extended) =>
|
|
368
306
|
addStandardModule(extended)?.forEach((symbol, symbolName) =>
|
|
369
307
|
exported.set(symbolName, symbol),
|
|
370
308
|
),
|
|
371
309
|
);
|
|
372
|
-
|
|
310
|
+
operators.forEach((operator) => {
|
|
373
311
|
builtins.set(operator.name, operator);
|
|
374
312
|
exported.set(operator.name, {
|
|
375
313
|
key: operator.name,
|
|
@@ -384,26 +322,21 @@ export const createEnvironment = (
|
|
|
384
322
|
};
|
|
385
323
|
|
|
386
324
|
const getStandardSymbols = (name: string) => {
|
|
387
|
-
|
|
388
|
-
if (
|
|
325
|
+
const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
|
|
326
|
+
if (
|
|
327
|
+
name === "TLCExt" ||
|
|
328
|
+
[name, ...dependencies].some((module) => options.loadModule?.(module) !== undefined)
|
|
329
|
+
)
|
|
389
330
|
return undefined;
|
|
390
331
|
const symbols = addStandardModule(name);
|
|
391
|
-
const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
|
|
392
332
|
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
333
|
if (symbols && dependencies.includes("Integers")) addStandardModule("Integers");
|
|
396
334
|
return symbols;
|
|
397
335
|
};
|
|
398
336
|
|
|
399
|
-
// Like TLC, reject a decimal or a big integer anywhere in a module, even where nothing evaluates it.
|
|
400
337
|
const rejectModuleLiterals = (module: Module): Module => {
|
|
401
338
|
rejectLiterals([
|
|
402
|
-
...module.definitions.flatMap(
|
|
403
|
-
definition.kind === "Function"
|
|
404
|
-
? [...definition.bounds.map((bound) => bound.set), definition.body]
|
|
405
|
-
: [definition.body],
|
|
406
|
-
),
|
|
339
|
+
...module.definitions.flatMap(getDefinitionExpressions),
|
|
407
340
|
...module.assumptions.map((assumption) => assumption.expression),
|
|
408
341
|
...module.theorems.flatMap((theorem) =>
|
|
409
342
|
theorem.statement.kind === "AssumeProve" ? [] : [theorem.statement],
|
|
@@ -418,7 +351,7 @@ export const createEnvironment = (
|
|
|
418
351
|
const loadModule = (name: string, importer: string) => {
|
|
419
352
|
const source =
|
|
420
353
|
options.loadModule?.(name) ??
|
|
421
|
-
|
|
354
|
+
getSanyStandardModules(runtime.version).get(name) ??
|
|
422
355
|
extractModule(options.source, name);
|
|
423
356
|
if (source === undefined) throw createMissingModuleError(name, importer);
|
|
424
357
|
const module = parseModuleFile(source, name, order);
|
|
@@ -478,14 +411,42 @@ export const createEnvironment = (
|
|
|
478
411
|
return cached;
|
|
479
412
|
}
|
|
480
413
|
const top = linkTopLevel(loadModule(name, importer));
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
: undefined
|
|
486
|
-
|
|
414
|
+
const replaced = new Map<string, Definition>();
|
|
415
|
+
const evaluateReplaced = (
|
|
416
|
+
operator: string,
|
|
417
|
+
args: BuiltinArgument[],
|
|
418
|
+
context: Context | undefined,
|
|
419
|
+
) => {
|
|
420
|
+
const definition = replaced.get(operator);
|
|
421
|
+
const expressions = args.flatMap((arg) =>
|
|
422
|
+
typeof arg === "object" && arg.kind === "Operator" && arg.expression
|
|
423
|
+
? [arg.expression]
|
|
424
|
+
: [],
|
|
425
|
+
);
|
|
426
|
+
if (definition?.kind !== "Operator" || !context || expressions.length !== args.length) {
|
|
427
|
+
throw new TlaEvaluationError(`No definition of ${operator} to fall back to`);
|
|
428
|
+
}
|
|
429
|
+
return evaluate(definition.body, {
|
|
430
|
+
environment: context.environment,
|
|
431
|
+
scope: bindOperatorArguments(getDefinitionClosure(definition), expressions, context),
|
|
432
|
+
state: context.state,
|
|
433
|
+
next: context.next,
|
|
434
|
+
isKeepLazy: context.isKeepLazy,
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
getJavaOverrides(
|
|
438
|
+
name,
|
|
439
|
+
options.print,
|
|
440
|
+
runtime,
|
|
441
|
+
options.files,
|
|
442
|
+
builtins,
|
|
443
|
+
evaluateReplaced,
|
|
444
|
+
)?.forEach((operator) => {
|
|
487
445
|
const symbol = top.linked.visible.get(operator.name);
|
|
488
|
-
if (symbol?.kind !== "Definition"
|
|
446
|
+
if (symbol?.kind !== "Definition") return;
|
|
447
|
+
if (symbol.arity !== operator.arity && ANNOTATED_OVERRIDE_MODULES.has(name)) return;
|
|
448
|
+
const definition = definitions.get(symbol.key);
|
|
449
|
+
if (definition) replaced.set(operator.name, definition);
|
|
489
450
|
builtins.set(symbol.key, operator);
|
|
490
451
|
definitions.delete(symbol.key);
|
|
491
452
|
});
|
|
@@ -509,7 +470,7 @@ export const createEnvironment = (
|
|
|
509
470
|
unit.facts.add(instance.name === undefined ? name : `${instance.name}!${name}`),
|
|
510
471
|
);
|
|
511
472
|
const declarations = getDeclarations(linked);
|
|
512
|
-
const suffix = `#${copyCount
|
|
473
|
+
const suffix = `#${copyCount++}`;
|
|
513
474
|
const renamed = new Map(instance.params.map((param) => [param.name, `${param.name}${suffix}`]));
|
|
514
475
|
const substitutions = resolveSubstitutions(
|
|
515
476
|
resolveInstanceSubexpressions(instance, module),
|
|
@@ -524,13 +485,23 @@ export const createEnvironment = (
|
|
|
524
485
|
substitutions,
|
|
525
486
|
location: instance.location,
|
|
526
487
|
});
|
|
488
|
+
const params = instance.params.map((param) => ({ ...param, name: `${param.name}${suffix}` }));
|
|
489
|
+
params.forEach((param) => instanceParams.add(param));
|
|
490
|
+
const substitutionRange = instance.definitionRange
|
|
491
|
+
? {
|
|
492
|
+
...instance.definitionRange,
|
|
493
|
+
start: { line: instance.location.line, column: instance.location.column },
|
|
494
|
+
}
|
|
495
|
+
: instance.instanceRange;
|
|
527
496
|
const instantiation = createInstantiation({
|
|
528
|
-
params
|
|
497
|
+
params,
|
|
529
498
|
substitutions: new Map(
|
|
530
499
|
[...substitutions].map(([name, expression]) => [name, renameLocals(expression, renamed)]),
|
|
531
500
|
),
|
|
532
501
|
variables: new Set(linked.variables),
|
|
533
502
|
getDefinition: (key) => definitions.get(key),
|
|
503
|
+
getOuterDefinition: (name) =>
|
|
504
|
+
module.definitions.find((definition) => definition.name === name),
|
|
534
505
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
535
506
|
addDefinition: (source, name, create) => {
|
|
536
507
|
const key = createName(`${name}@${module.name}`);
|
|
@@ -545,6 +516,13 @@ export const createEnvironment = (
|
|
|
545
516
|
return key;
|
|
546
517
|
},
|
|
547
518
|
createName,
|
|
519
|
+
...(declarations.length > 0 && {
|
|
520
|
+
frame: {
|
|
521
|
+
kind: "Identifier",
|
|
522
|
+
name: instance.name ?? instance.module,
|
|
523
|
+
location: { ...substitutionRange.start, range: substitutionRange },
|
|
524
|
+
},
|
|
525
|
+
}),
|
|
548
526
|
});
|
|
549
527
|
return getInstanceSymbols(instance, linked.exported, declarations, (key, name) => {
|
|
550
528
|
const copy =
|
|
@@ -567,9 +545,6 @@ export const createEnvironment = (
|
|
|
567
545
|
]),
|
|
568
546
|
);
|
|
569
547
|
|
|
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
548
|
const getInstanceSymbols = (
|
|
574
549
|
instance: Instance,
|
|
575
550
|
exported: Symbols,
|
|
@@ -611,32 +586,8 @@ export const createEnvironment = (
|
|
|
611
586
|
);
|
|
612
587
|
};
|
|
613
588
|
|
|
614
|
-
const createLocalAlias = (
|
|
615
|
-
name: string,
|
|
616
|
-
key: string,
|
|
617
|
-
params: OperatorParam[],
|
|
618
|
-
forwarded: OperatorParam[],
|
|
619
|
-
location: SourceLocation,
|
|
620
|
-
): Definition => ({
|
|
621
|
-
kind: "Operator",
|
|
622
|
-
name,
|
|
623
|
-
params,
|
|
624
|
-
body:
|
|
625
|
-
forwarded.length === 0
|
|
626
|
-
? { kind: "Identifier", name: key, location }
|
|
627
|
-
: {
|
|
628
|
-
kind: "Apply",
|
|
629
|
-
operator: key,
|
|
630
|
-
args: createLocalArguments(forwarded, location),
|
|
631
|
-
location,
|
|
632
|
-
},
|
|
633
|
-
isLocal: true,
|
|
634
|
-
isRecursive: false,
|
|
635
|
-
location,
|
|
636
|
-
});
|
|
637
|
-
|
|
638
589
|
const createArgumentParams = (arity: number) =>
|
|
639
|
-
Array.from({ length: arity }, (
|
|
590
|
+
Array.from({ length: arity }, (_value, index) => ({ name: `argument${index}`, arity: 0 }));
|
|
640
591
|
|
|
641
592
|
const getSubstitutionBody = (
|
|
642
593
|
replacement: Expression,
|
|
@@ -685,7 +636,7 @@ export const createEnvironment = (
|
|
|
685
636
|
});
|
|
686
637
|
}
|
|
687
638
|
const linked = nested ?? getLinkedModule(instance.module, instancer);
|
|
688
|
-
const suffix = `#${copyCount
|
|
639
|
+
const suffix = `#${copyCount++}`;
|
|
689
640
|
const explicitSubstitutions = new Map(
|
|
690
641
|
instance.substitutions.map((item) => [item.name, item.expression]),
|
|
691
642
|
);
|
|
@@ -742,6 +693,7 @@ export const createEnvironment = (
|
|
|
742
693
|
),
|
|
743
694
|
variables: new Set(linked.variables),
|
|
744
695
|
getDefinition: (key) => definitions.get(key),
|
|
696
|
+
getOuterDefinition: () => undefined,
|
|
745
697
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
746
698
|
addDefinition: (_source, name, create) => {
|
|
747
699
|
const key = `${name}${KEY_SEPARATOR}${instance.module}${suffix}.${copies.length}`;
|
|
@@ -796,12 +748,9 @@ export const createEnvironment = (
|
|
|
796
748
|
]),
|
|
797
749
|
...scope.symbols,
|
|
798
750
|
]);
|
|
799
|
-
// Where an INSTANCE first made each name it adds visible.
|
|
800
751
|
const importedAt = new Map<string, SourceLocation>();
|
|
801
752
|
const extendsReport: ModuleReport = { location: MODULE_START, errors: [], warnings: [] };
|
|
802
753
|
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
754
|
const mergeExtended = (symbols: Symbols) =>
|
|
806
755
|
symbols.forEach((symbol, name) => {
|
|
807
756
|
const current = exported.get(name);
|
|
@@ -836,8 +785,12 @@ export const createEnvironment = (
|
|
|
836
785
|
const modules = new Map<string, LinkedModule>();
|
|
837
786
|
const extended: LinkedModule[] = [];
|
|
838
787
|
const constants = [...parsed.constants];
|
|
839
|
-
const
|
|
840
|
-
|
|
788
|
+
const declaredVariables = parsed.variables.filter(
|
|
789
|
+
(variable, index) =>
|
|
790
|
+
parsed.variables.findIndex((other) => other.name === variable.name) === index,
|
|
791
|
+
);
|
|
792
|
+
const variables = declaredVariables.map((variable) => variable.name);
|
|
793
|
+
const variableLocations = declaredVariables.map((variable) => variable.location);
|
|
841
794
|
parsed.extends.forEach((name) => {
|
|
842
795
|
const nested = scope.modules.get(name);
|
|
843
796
|
const standardSymbols = nested ? undefined : getStandardSymbols(name);
|
|
@@ -847,12 +800,16 @@ export const createEnvironment = (
|
|
|
847
800
|
}
|
|
848
801
|
const linked = nested ?? getLinkedModule(name, parsed.name);
|
|
849
802
|
constants.push(
|
|
850
|
-
...linked.constants.filter(
|
|
851
|
-
|
|
803
|
+
...linked.constants.filter(
|
|
804
|
+
(constant) =>
|
|
805
|
+
constants.every((existing) => existing.name !== constant.name) &&
|
|
806
|
+
!variables.includes(constant.name),
|
|
852
807
|
),
|
|
853
808
|
);
|
|
854
809
|
linked.variables.forEach((variable, index) => {
|
|
855
|
-
|
|
810
|
+
const isDeclared =
|
|
811
|
+
variables.includes(variable) || constants.some((constant) => constant.name === variable);
|
|
812
|
+
if (isDeclared) return;
|
|
856
813
|
variables.push(variable);
|
|
857
814
|
variableLocations.push(linked.variableLocations[index]);
|
|
858
815
|
});
|
|
@@ -887,14 +844,12 @@ export const createEnvironment = (
|
|
|
887
844
|
parsed === root ? definition.name : `${definition.name}${KEY_SEPARATOR}${scope.id}`;
|
|
888
845
|
const instanced = new Map<Instance, Symbols>();
|
|
889
846
|
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
847
|
const getLetModule = (instance: Instance) => {
|
|
895
848
|
const ownModule = parsed.modules.find((nested) => nested.name === instance.module);
|
|
896
849
|
if (!ownModule) return getVisibleModules().get(instance.module);
|
|
897
|
-
return
|
|
850
|
+
return isBefore(ownModule.location, instance.location)
|
|
851
|
+
? modules.get(ownModule.name)
|
|
852
|
+
: undefined;
|
|
898
853
|
};
|
|
899
854
|
const getUnit = (module: Module): ModuleUnit => ({
|
|
900
855
|
imported: visible,
|
|
@@ -927,7 +882,6 @@ export const createEnvironment = (
|
|
|
927
882
|
reports,
|
|
928
883
|
warnings: scope.warnings,
|
|
929
884
|
});
|
|
930
|
-
// SANY keeps the first of two symbols of a name.
|
|
931
885
|
const getSymbolsBefore = (location: SourceLocation): Symbols =>
|
|
932
886
|
[
|
|
933
887
|
...declarations
|
|
@@ -946,8 +900,6 @@ export const createEnvironment = (
|
|
|
946
900
|
(symbols, [name, symbol]) => (symbols.has(name) ? symbols : symbols.set(name, symbol)),
|
|
947
901
|
new Map(visible),
|
|
948
902
|
);
|
|
949
|
-
// Generator.generateModule reports the errors of a nested module and goes on, and then
|
|
950
|
-
// SymbolTable.addModule reports a module already defined.
|
|
951
903
|
const linkNested = (nested: Module) => {
|
|
952
904
|
const visibleModules = getVisibleModules();
|
|
953
905
|
const existing = visibleModules.get(nested.name);
|
|
@@ -967,7 +919,6 @@ export const createEnvironment = (
|
|
|
967
919
|
});
|
|
968
920
|
if (redefinition) report.errors.push(redefinition);
|
|
969
921
|
if (!existing) modules.set(nested.name, linked);
|
|
970
|
-
if (!nestedModules.has(nested.name)) nestedModules.set(nested.name, linked);
|
|
971
922
|
};
|
|
972
923
|
[
|
|
973
924
|
...parsed.instances.map((instance) => ({
|
|
@@ -1009,7 +960,6 @@ export const createEnvironment = (
|
|
|
1009
960
|
parameterized.set(key, !isParameterFree);
|
|
1010
961
|
const symbol = getDefinitionSymbol(definition);
|
|
1011
962
|
const importedLocation = importedAt.get(definition.name);
|
|
1012
|
-
// SANY binds the name of a fact to a fact the module imports before it.
|
|
1013
963
|
if (
|
|
1014
964
|
symbol.kind === "Theorem" &&
|
|
1015
965
|
visible.get(definition.name)?.kind === "Theorem" &&
|
|
@@ -1035,8 +985,6 @@ export const createEnvironment = (
|
|
|
1035
985
|
]),
|
|
1036
986
|
};
|
|
1037
987
|
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
988
|
const checks = instanceChecks
|
|
1041
989
|
.splice(firstCheck)
|
|
1042
990
|
.map((check) => ({ location: check.location, check: () => checkInstance(check) }));
|
|
@@ -1058,12 +1006,36 @@ export const createEnvironment = (
|
|
|
1058
1006
|
};
|
|
1059
1007
|
|
|
1060
1008
|
const linkedRoot = linkTopLevel(root).linked;
|
|
1009
|
+
const traceFile = options.traceFile;
|
|
1010
|
+
const traceOperators: ModuleOperator[] =
|
|
1011
|
+
traceFile === undefined
|
|
1012
|
+
? []
|
|
1013
|
+
: [
|
|
1014
|
+
{
|
|
1015
|
+
kind: "postcondition",
|
|
1016
|
+
module: "_TLCTrace",
|
|
1017
|
+
operator: "_TLCTraceSilent",
|
|
1018
|
+
constants: { _TLCTraceFile: traceFile },
|
|
1019
|
+
},
|
|
1020
|
+
];
|
|
1021
|
+
const moduleOperators = [...(options.moduleOperators ?? []), ...traceOperators].map(
|
|
1022
|
+
(operator): ResolvedModuleOperator => {
|
|
1023
|
+
const symbol = getLinkedModule(operator.module, root.name).visible.get(operator.operator);
|
|
1024
|
+
return { ...operator, key: symbol?.kind === "Definition" ? symbol.key : undefined };
|
|
1025
|
+
},
|
|
1026
|
+
);
|
|
1027
|
+
linkOrder.push(...linkOrder.splice(linkOrder.indexOf(linkedRoot), 1));
|
|
1061
1028
|
if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
|
|
1062
|
-
const getRootKey = (name: string) => linkedRoot.visible.get(name)?.key ?? name;
|
|
1063
1029
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
1064
1030
|
const definition = definitions.get(symbol.key);
|
|
1065
1031
|
if (definition && symbol.key !== name) definitions.set(name, definition);
|
|
1066
1032
|
});
|
|
1033
|
+
moduleOperators.forEach((operator) => {
|
|
1034
|
+
const definition = operator.key === undefined ? undefined : definitions.get(operator.key);
|
|
1035
|
+
if (operator.kind !== "postcondition" && definition) {
|
|
1036
|
+
definitions.set(operator.operator, definition);
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1067
1039
|
|
|
1068
1040
|
const assumptions: Assumption[] = [];
|
|
1069
1041
|
const addAssumptions = (linked: LinkedModule, visited: Set<LinkedModule>) => {
|
|
@@ -1076,164 +1048,32 @@ export const createEnvironment = (
|
|
|
1076
1048
|
const declaredConstants = linkedRoot.constants.map((constant) => constant.name);
|
|
1077
1049
|
const variables = linkedRoot.variables;
|
|
1078
1050
|
|
|
1079
|
-
const
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
operatorKeys.add(key);
|
|
1098
|
-
};
|
|
1099
|
-
config.constants
|
|
1100
|
-
.filter((assignment) => assignment.args === undefined)
|
|
1101
|
-
.forEach((assignment) => {
|
|
1102
|
-
const value = toValue(assignment.value);
|
|
1103
|
-
markNormalized(value);
|
|
1104
|
-
getScopedKeys(assignment).forEach((key) => {
|
|
1105
|
-
const arity = getKeyArity(key);
|
|
1106
|
-
if (arity === 0) constants.set(key, value);
|
|
1107
|
-
else
|
|
1108
|
-
setOperator(key, {
|
|
1109
|
-
kind: "Builtin",
|
|
1110
|
-
name: key,
|
|
1111
|
-
arity,
|
|
1112
|
-
evaluate: () => value,
|
|
1113
|
-
evaluateUnary: undefined,
|
|
1114
|
-
evaluateBinary: undefined,
|
|
1115
|
-
isLazy: true,
|
|
1116
|
-
});
|
|
1117
|
-
});
|
|
1118
|
-
});
|
|
1119
|
-
const tables = new Map<string, { name: string; module?: string; rows: [Value[], Value][] }>();
|
|
1120
|
-
config.constants.forEach((assignment) => {
|
|
1121
|
-
if (assignment.args === undefined) return;
|
|
1122
|
-
const tableKey = `${assignment.module ?? ""}!${assignment.name}`;
|
|
1123
|
-
const table = tables.get(tableKey) ?? {
|
|
1124
|
-
name: assignment.name,
|
|
1125
|
-
module: assignment.module,
|
|
1126
|
-
rows: [],
|
|
1127
|
-
};
|
|
1128
|
-
if (table.rows.length > 0 && table.rows[0][0].length !== assignment.args.length) {
|
|
1129
|
-
throw new TlaConfigError(
|
|
1130
|
-
`The arity of the operator ${assignment.name} is inconsistent in the configuration file.`,
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
table.rows.push([assignment.args.map(toValue), toValue(assignment.value)]);
|
|
1134
|
-
tables.set(tableKey, table);
|
|
1135
|
-
});
|
|
1136
|
-
tables.forEach((table) =>
|
|
1137
|
-
getScopedKeys(table).forEach((key) =>
|
|
1138
|
-
setOperator(
|
|
1139
|
-
key,
|
|
1140
|
-
createOperatorTable(table.name, getKeyArity(key) || table.rows[0][0].length, table.rows),
|
|
1051
|
+
const applied = applyConfig(config, {
|
|
1052
|
+
root: linkedRoot,
|
|
1053
|
+
moduleSymbols: new Map([
|
|
1054
|
+
...standardExports,
|
|
1055
|
+
...[...linkedModules].map(([name, linked]): [string, Symbols] => [name, linked.visible]),
|
|
1056
|
+
[root.name, linkedRoot.visible],
|
|
1057
|
+
]),
|
|
1058
|
+
definitions,
|
|
1059
|
+
builtins,
|
|
1060
|
+
copySources,
|
|
1061
|
+
operatorConstants: new Map(
|
|
1062
|
+
moduleOperators.flatMap((operator) =>
|
|
1063
|
+
getLinkedModule(operator.module, root.name).constants.flatMap(
|
|
1064
|
+
(constant): [string, Value][] => {
|
|
1065
|
+
const value = operator.constants?.[constant.name];
|
|
1066
|
+
return value === undefined ? [] : [[constant.name, value]];
|
|
1067
|
+
},
|
|
1068
|
+
),
|
|
1141
1069
|
),
|
|
1142
1070
|
),
|
|
1143
|
-
|
|
1144
|
-
const substitutions = new Map(
|
|
1145
|
-
config.substitutions.flatMap((substitution) =>
|
|
1146
|
-
getScopedKeys(substitution).map((key): [string, string] => [
|
|
1147
|
-
key,
|
|
1148
|
-
getRootKey(substitution.target),
|
|
1149
|
-
]),
|
|
1150
|
-
),
|
|
1151
|
-
);
|
|
1152
|
-
config.substitutions
|
|
1153
|
-
.filter((substitution) => substitution.module === undefined)
|
|
1154
|
-
.forEach((substitution) => {
|
|
1155
|
-
const name = substitution.name;
|
|
1156
|
-
const target = substitution.target;
|
|
1157
|
-
if (!declaredConstants.includes(name) && !linkedRoot.visible.has(name)) {
|
|
1158
|
-
throw new TlaConfigError(
|
|
1159
|
-
`In the configuration file, the identifier ${name} does not appear in the specification.`,
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
if (config.substitutions.some((other) => other.name === target)) {
|
|
1163
|
-
throw new TlaConfigError(
|
|
1164
|
-
`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
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
const targetKey = getRootKey(target);
|
|
1168
|
-
const definition = definitions.get(targetKey);
|
|
1169
|
-
const isDefined =
|
|
1170
|
-
definition !== undefined ||
|
|
1171
|
-
builtins.has(targetKey) ||
|
|
1172
|
-
constants.has(targetKey) ||
|
|
1173
|
-
declaredConstants.includes(target) ||
|
|
1174
|
-
variables.includes(target);
|
|
1175
|
-
if (!isDefined) {
|
|
1176
|
-
throw new TlaConfigError(
|
|
1177
|
-
`The configuration file substitutes for ${name} with the undefined identifier ${target}.`,
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
if (
|
|
1181
|
-
definition?.kind === "Operator" &&
|
|
1182
|
-
definition.params.length !==
|
|
1183
|
-
(linkedRoot.constants.find((constant) => constant.name === name)?.arity ??
|
|
1184
|
-
linkedRoot.visible.get(name)?.arity)
|
|
1185
|
-
) {
|
|
1186
|
-
throw new TlaConfigError(
|
|
1187
|
-
`The configuration file substitutes for ${name} with ${target} of different number of arguments.`,
|
|
1188
|
-
);
|
|
1189
|
-
}
|
|
1190
|
-
});
|
|
1191
|
-
// TLC sets a module-scoped entry on the body of the module's definition, which every instance of
|
|
1192
|
-
// the module shares.
|
|
1193
|
-
const scopedKeys = new Set(
|
|
1194
|
-
[...config.constants, ...config.substitutions]
|
|
1195
|
-
.filter((item) => item.module !== undefined)
|
|
1196
|
-
.flatMap(getScopedKeys),
|
|
1197
|
-
);
|
|
1198
|
-
const getOverride = (
|
|
1199
|
-
key: string,
|
|
1200
|
-
prefix: number,
|
|
1201
|
-
): { key: string; prefix: number } | undefined => {
|
|
1202
|
-
if (scopedKeys.has(key)) return { key, prefix };
|
|
1203
|
-
const copy = copySources.get(key);
|
|
1204
|
-
return copy && getOverride(copy.source, prefix + copy.prefix);
|
|
1205
|
-
};
|
|
1206
|
-
copySources.forEach((copy, key) => {
|
|
1207
|
-
const override = getOverride(copy.source, copy.prefix);
|
|
1208
|
-
const definition = definitions.get(key);
|
|
1209
|
-
if (!override || !definition) return;
|
|
1210
|
-
const params = definition.kind === "Operator" ? definition.params : [];
|
|
1211
|
-
const alias = createLocalAlias(
|
|
1212
|
-
key,
|
|
1213
|
-
override.key,
|
|
1214
|
-
params,
|
|
1215
|
-
params.slice(override.prefix),
|
|
1216
|
-
definition.location,
|
|
1217
|
-
);
|
|
1218
|
-
definitions.set(key, alias);
|
|
1219
|
-
linkedRoot.visible.forEach((symbol, name) => {
|
|
1220
|
-
if (symbol.key === key && name !== key) definitions.set(name, alias);
|
|
1221
|
-
});
|
|
1071
|
+
order,
|
|
1222
1072
|
});
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1225
|
-
);
|
|
1226
|
-
if (unassigned.length > 0 && !options.isUnconfigured) {
|
|
1227
|
-
// TLC reports the first constant it finds unassigned in SANY's order of declarations.
|
|
1228
|
-
const name =
|
|
1229
|
-
order.getDeclarationOrder("constant").find((constant) => unassigned.includes(constant)) ??
|
|
1230
|
-
unassigned[0];
|
|
1231
|
-
throw new TlaConfigError(
|
|
1232
|
-
`The constant parameter ${name} is not assigned a value by the configuration file.`,
|
|
1233
|
-
);
|
|
1234
|
-
}
|
|
1073
|
+
const constants = applied.constants;
|
|
1074
|
+
const substitutions = applied.substitutions;
|
|
1235
1075
|
|
|
1236
|
-
if (
|
|
1076
|
+
if (traceFile !== undefined) {
|
|
1237
1077
|
builtins.forEach((builtin, name) => {
|
|
1238
1078
|
const replacement = getTraceSpecArithmetic(builtin);
|
|
1239
1079
|
if (replacement) builtins.set(name, replacement);
|
|
@@ -1264,13 +1104,11 @@ export const createEnvironment = (
|
|
|
1264
1104
|
facts,
|
|
1265
1105
|
startupValues: Array.from({ length: facts.ids.size }, (): Value | undefined => undefined),
|
|
1266
1106
|
substitutedDefinitions,
|
|
1107
|
+
instanceParams,
|
|
1267
1108
|
evaluators: new WeakMap(),
|
|
1268
1109
|
entryEvaluators: new WeakMap(),
|
|
1269
1110
|
definitionEvaluators: new WeakMap(),
|
|
1270
1111
|
};
|
|
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
1112
|
const analyzer = createLevelAnalyzer({
|
|
1275
1113
|
constants: new Set(constants.keys()),
|
|
1276
1114
|
variables: new Set([
|
|
@@ -1298,17 +1136,13 @@ export const createEnvironment = (
|
|
|
1298
1136
|
? getEvaluationError(definition.body)
|
|
1299
1137
|
: undefined;
|
|
1300
1138
|
if (error) {
|
|
1301
|
-
// TLC's SpecProcessor adds the message of a TLCRuntimeException, not of an EvalException.
|
|
1302
1139
|
const addendum = isEvalException(error) ? "" : ` - specifically: ${error.message}`;
|
|
1303
1140
|
throw new TlaConfigError(
|
|
1304
1141
|
`The configuration file substitutes constant ${name} with non-constant ${target}${addendum}`,
|
|
1305
1142
|
);
|
|
1306
1143
|
}
|
|
1307
1144
|
});
|
|
1308
|
-
// TLC 1.7.4 processes the whole spec before it creates its model checker, which TLCGet reads.
|
|
1309
1145
|
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
1146
|
const instantiated = new Set(
|
|
1313
1147
|
linkOrder.flatMap((linked) => linked.module.instances.map((instance) => instance.module)),
|
|
1314
1148
|
);
|
|
@@ -1330,8 +1164,8 @@ export const createEnvironment = (
|
|
|
1330
1164
|
},
|
|
1331
1165
|
),
|
|
1332
1166
|
),
|
|
1333
|
-
rootConstants: linkedRoot.constants,
|
|
1334
|
-
rootSymbols: linkedRoot.visible,
|
|
1335
1167
|
javaOverrides: linkOrder.flatMap((linked) => javaOverrides.get(linked.module.name) ?? []),
|
|
1168
|
+
moduleOperators,
|
|
1169
|
+
rootName: root.name,
|
|
1336
1170
|
};
|
|
1337
1171
|
};
|