tla-ts 0.0.10-dev.b4a856304 → 0.0.10-dev.c92e6a4ea
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 +2 -1
- package/dist/compile.cjs +6 -6
- package/dist/compile.js +10 -10
- package/dist/deciders.cjs +41 -37
- package/dist/deciders.js +57 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +2683 -427
- package/dist/prove.js +2681 -425
- package/dist/run.cjs +45 -44
- package/dist/run.js +45 -44
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +44 -41
- package/dist/transfer.js +45 -42
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +41 -41
- package/src/bags.ts +2 -5
- package/src/builtins.ts +5 -21
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +268 -0
- package/src/check.ts +578 -757
- package/src/cli/options.ts +6 -31
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +27 -62
- package/src/cli/shared.ts +1 -5
- package/src/cli/tlapm.ts +433 -70
- package/src/cli/tlc-arguments.ts +246 -240
- package/src/cli/tlc-output.ts +686 -0
- package/src/cli/tlc-usage.ts +3 -5
- package/src/cli/tlc.ts +59 -707
- package/src/cli/xml-exporter.ts +23 -33
- package/src/codegen.ts +5 -10
- package/src/coverage.ts +3 -10
- package/src/dependencies.ts +30 -14
- package/src/dfid.ts +16 -16
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +73 -338
- package/src/errors.ts +33 -5
- package/src/evaluate.ts +34 -107
- package/src/exit-codes.ts +3 -0
- package/src/fingerprints.ts +65 -1
- package/src/instances.ts +47 -10
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -9
- package/src/json-reader.ts +1 -2
- package/src/json.ts +8 -18
- package/src/levels.ts +46 -57
- package/src/lexer.ts +76 -85
- package/src/liveness-checker.ts +634 -306
- package/src/liveness.ts +104 -120
- package/src/obligations/action.ts +14 -17
- package/src/obligations/anonymize.ts +37 -16
- package/src/obligations/enabled-axioms.ts +218 -0
- package/src/obligations/equality.ts +1 -3
- package/src/obligations/expression.ts +36 -8
- package/src/obligations/format.ts +0 -2
- package/src/obligations/generate.ts +66 -54
- package/src/obligations/index.ts +38 -8
- package/src/obligations/levels.ts +24 -11
- package/src/obligations/module.ts +28 -41
- package/src/obligations/normalize.ts +26 -14
- package/src/obligations/operators.ts +0 -2
- package/src/obligations/pragma.ts +53 -16
- package/src/obligations/printer.ts +43 -13
- package/src/obligations/proof.ts +3 -2
- package/src/obligations/regroup.ts +0 -2
- package/src/obligations/simplify.ts +55 -50
- package/src/obligations/source.ts +118 -74
- package/src/obligations/subexpression.ts +45 -18
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +5 -7
- package/src/obligations/tuples.ts +0 -2
- package/src/parallel-worker.ts +17 -31
- package/src/parallel.ts +55 -80
- package/src/parser.ts +722 -385
- package/src/pcal/ast.ts +53 -65
- package/src/pcal/parse.ts +144 -191
- package/src/pcal/tokenize.ts +91 -115
- package/src/pcal/translate.ts +83 -98
- package/src/pcal/validate.ts +48 -50
- package/src/pretty-print.ts +7 -7
- package/src/prover/decide-pool.ts +3 -3
- package/src/prover/deciders.ts +12 -9
- package/src/prover/isabelle/decide.ts +3 -25
- package/src/prover/isabelle/encode.ts +72 -42
- package/src/prover/isabelle/isar/attrib.ts +250 -0
- package/src/prover/isabelle/isar/context.ts +335 -0
- package/src/prover/isabelle/isar/induct.ts +382 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +158 -7
- package/src/prover/isabelle/isar/method.ts +509 -212
- package/src/prover/isabelle/isar/proof.ts +570 -14
- package/src/prover/isabelle/isar/rule-cases.ts +224 -0
- package/src/prover/isabelle/isar/theory.ts +487 -76
- package/src/prover/isabelle/isar/toplevel.ts +331 -0
- package/src/prover/isabelle/isar/type-check.ts +89 -14
- package/src/prover/isabelle/provers/blast/blast.ts +7 -65
- package/src/prover/isabelle/provers/blast/branch.ts +0 -2
- package/src/prover/isabelle/provers/blast/prove.ts +0 -2
- package/src/prover/isabelle/provers/blast/rules.ts +0 -2
- package/src/prover/isabelle/provers/blast/state.ts +0 -2
- package/src/prover/isabelle/provers/blast/term.ts +0 -2
- package/src/prover/isabelle/provers/clasimp.ts +0 -2
- package/src/prover/isabelle/provers/classical.ts +45 -20
- package/src/prover/isabelle/provers/hypsubst.ts +17 -28
- package/src/prover/isabelle/pure/bicompose.ts +9 -27
- package/src/prover/isabelle/pure/consts.ts +0 -2
- package/src/prover/isabelle/pure/conv.ts +2 -10
- package/src/prover/isabelle/pure/drule.ts +72 -6
- package/src/prover/isabelle/pure/envir.ts +0 -2
- package/src/prover/isabelle/pure/goal.ts +1 -3
- package/src/prover/isabelle/pure/logic.ts +1 -3
- package/src/prover/isabelle/pure/name.ts +0 -2
- package/src/prover/isabelle/pure/net.ts +0 -2
- package/src/prover/isabelle/pure/object-logic.ts +13 -7
- package/src/prover/isabelle/pure/pattern.ts +0 -2
- package/src/prover/isabelle/pure/raw-simplifier.ts +4 -15
- package/src/prover/isabelle/pure/rewriter.ts +6 -17
- package/src/prover/isabelle/pure/search.ts +0 -2
- package/src/prover/isabelle/pure/seq.ts +0 -2
- package/src/prover/isabelle/pure/simplifier.ts +26 -7
- package/src/prover/isabelle/pure/table.ts +2 -3
- package/src/prover/isabelle/pure/tactic.ts +0 -2
- package/src/prover/isabelle/pure/tactical.ts +42 -37
- package/src/prover/isabelle/pure/term-ord.ts +0 -2
- package/src/prover/isabelle/pure/term.ts +0 -2
- package/src/prover/isabelle/pure/thm.ts +14 -13
- package/src/prover/isabelle/pure/type.ts +0 -2
- package/src/prover/isabelle/pure/unify.ts +0 -2
- package/src/prover/isabelle/pure/variable.ts +0 -2
- package/src/prover/isabelle/tla/classical-setup.ts +18 -16
- package/src/prover/isabelle/tla/context.ts +58 -11
- package/src/prover/isabelle/tla/logic-data.ts +1 -1
- package/src/prover/isabelle/tla/logic.ts +49 -21
- package/src/prover/isabelle/tla/simpdata.ts +1 -12
- package/src/prover/isabelle/tools/intuitionistic.ts +28 -12
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +30 -31
- package/src/prover/prep/enabled-axioms.ts +11 -2
- package/src/prover/prep/fingerprint.ts +2 -5
- package/src/prover/prep/methods.ts +181 -51
- package/src/prover/prep/normalize.ts +38 -9
- package/src/prover/prove.ts +395 -94
- package/src/prover/ptl/decide.ts +95 -50
- package/src/prover/ptl/encode.ts +2 -3
- package/src/prover/ptl/tableau.ts +28 -2
- package/src/prover/smt/arithmetic.ts +310 -0
- package/src/prover/smt/axioms.ts +12 -8
- package/src/prover/smt/context.ts +43 -8
- package/src/prover/smt/data.ts +498 -379
- package/src/prover/smt/encode.ts +148 -57
- package/src/prover/smt/extensionality.ts +5 -3
- package/src/prover/smt/flatten.ts +4 -6
- package/src/prover/smt/format.ts +28 -4
- package/src/prover/smt/instances.ts +7 -1
- package/src/prover/smt/layout.ts +91 -0
- package/src/prover/smt/rewrite.ts +1021 -618
- package/src/prover/smt/simplify.ts +441 -0
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +61 -0
- package/src/prover/smt/solver/ackr-helper.ts +179 -0
- package/src/prover/smt/solver/ackr-model-converter.ts +105 -0
- package/src/prover/smt/solver/act-cache.ts +0 -1
- package/src/prover/smt/solver/add-bounds-tactic.ts +59 -0
- package/src/prover/smt/solver/aig-tactic.ts +52 -0
- package/src/prover/smt/solver/aig.ts +889 -0
- package/src/prover/smt/solver/arith-rewriter.ts +613 -6
- package/src/prover/smt/solver/arith-terms.ts +121 -0
- package/src/prover/smt/solver/array-decl-plugin.ts +175 -0
- package/src/prover/smt/solver/array-rewriter.ts +309 -0
- package/src/prover/smt/solver/asserted-formulas.ts +87 -16
- package/src/prover/smt/solver/ast-lt.ts +166 -12
- package/src/prover/smt/solver/ast-util.ts +160 -2
- package/src/prover/smt/solver/ast.ts +1427 -41
- package/src/prover/smt/solver/auf-solver.ts +2 -6
- package/src/prover/smt/solver/bit-blast-tactic.ts +582 -0
- package/src/prover/smt/solver/bit-blaster.ts +871 -0
- package/src/prover/smt/solver/bound-manager.ts +196 -0
- package/src/prover/smt/solver/bound-simplifier.ts +600 -0
- package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
- package/src/prover/smt/solver/bv-decl-plugin.ts +338 -0
- package/src/prover/smt/solver/bv-divrem-bounds.ts +95 -0
- package/src/prover/smt/solver/bv-rewriter.ts +1901 -0
- package/src/prover/smt/solver/bv1-blast.ts +214 -0
- package/src/prover/smt/solver/bv2fpa-converter.ts +174 -0
- package/src/prover/smt/solver/bv2int-rewriter.ts +544 -0
- package/src/prover/smt/solver/bv2real-rewriter.ts +533 -0
- package/src/prover/smt/solver/card2bv.ts +110 -0
- package/src/prover/smt/solver/case-split-queue.ts +0 -2
- package/src/prover/smt/solver/cg-table.ts +39 -25
- package/src/prover/smt/solver/check-logic.ts +330 -0
- package/src/prover/smt/solver/clause.ts +0 -1
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +278 -0
- package/src/prover/smt/solver/conflict-resolution.ts +78 -2
- package/src/prover/smt/solver/context.ts +516 -115
- package/src/prover/smt/solver/ctx-simplify.ts +20 -10
- package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
- package/src/prover/smt/solver/datatype-decl-plugin.ts +572 -0
- package/src/prover/smt/solver/datatype-rewriter.ts +82 -0
- package/src/prover/smt/solver/demodulator.ts +786 -0
- package/src/prover/smt/solver/dependent-expr-state.ts +81 -0
- package/src/prover/smt/solver/der.ts +38 -10
- package/src/prover/smt/solver/diff-neq.ts +206 -0
- package/src/prover/smt/solver/distribute-forall.ts +57 -0
- package/src/prover/smt/solver/dom-simplify.ts +511 -0
- package/src/prover/smt/solver/dt2bv-tactic.ts +260 -0
- package/src/prover/smt/solver/dyn-ack.ts +0 -1
- package/src/prover/smt/solver/e-matching.ts +7 -8
- package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +545 -0
- package/src/prover/smt/solver/enode.ts +100 -3
- package/src/prover/smt/solver/eq2bv-tactic.ts +218 -0
- package/src/prover/smt/solver/euf/arith-axioms.ts +403 -0
- package/src/prover/smt/solver/euf/arith-internalize.ts +653 -0
- package/src/prover/smt/solver/euf/arith-solver.ts +889 -0
- package/src/prover/smt/solver/euf/array-axioms.ts +527 -0
- package/src/prover/smt/solver/euf/array-internalize.ts +428 -0
- package/src/prover/smt/solver/euf/array-solver.ts +306 -0
- package/src/prover/smt/solver/euf/bv-ackerman.ts +162 -0
- package/src/prover/smt/solver/euf/bv-internalize.ts +748 -0
- package/src/prover/smt/solver/euf/bv-solver.ts +449 -0
- package/src/prover/smt/solver/euf/dt-solver.ts +618 -0
- package/src/prover/smt/solver/euf/egraph.ts +908 -0
- package/src/prover/smt/solver/euf/euf-solver.ts +1205 -0
- package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
- package/src/prover/smt/solver/euf/mam.ts +1050 -0
- package/src/prover/smt/solver/euf/q-ematch.ts +830 -0
- package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
- package/src/prover/smt/solver/euf/q-model-fixer.ts +296 -0
- package/src/prover/smt/solver/euf/q-solver.ts +361 -0
- package/src/prover/smt/solver/euf/th-solver.ts +335 -0
- package/src/prover/smt/solver/euf/th-solvers.ts +30 -0
- package/src/prover/smt/solver/expr-ref.ts +0 -1
- package/src/prover/smt/solver/expr-safe-replace.ts +26 -2
- package/src/prover/smt/solver/expr2polynomial.ts +146 -0
- package/src/prover/smt/solver/factor.ts +141 -0
- package/src/prover/smt/solver/fd-solver.ts +265 -0
- package/src/prover/smt/solver/fingerprints.ts +15 -15
- package/src/prover/smt/solver/fix-dl-var.ts +148 -0
- package/src/prover/smt/solver/flat-literals.ts +0 -1
- package/src/prover/smt/solver/fm-tactic.ts +884 -0
- package/src/prover/smt/solver/fpa-decl-plugin.ts +618 -0
- package/src/prover/smt/solver/fpa-rewriter.ts +640 -0
- package/src/prover/smt/solver/fpa2bv-converter.ts +2249 -0
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +348 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
- package/src/prover/smt/solver/goal.ts +175 -15
- package/src/prover/smt/solver/goal2nlsat.ts +189 -0
- package/src/prover/smt/solver/guard-set.ts +219 -0
- package/src/prover/smt/solver/hash.ts +0 -1
- package/src/prover/smt/solver/hashtable.ts +30 -16
- package/src/prover/smt/solver/inf-eps.ts +63 -0
- package/src/prover/smt/solver/inj-axiom.ts +101 -0
- package/src/prover/smt/solver/internalizer.ts +110 -38
- package/src/prover/smt/solver/lackr.ts +381 -0
- package/src/prover/smt/solver/lbool.ts +0 -1
- package/src/prover/smt/solver/lia2card.ts +268 -0
- package/src/prover/smt/solver/lia2pb.ts +154 -0
- package/src/prover/smt/solver/literal.ts +0 -1
- package/src/prover/smt/solver/logic-tactics.ts +345 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +0 -1
- package/src/prover/smt/solver/lp/constraints.ts +0 -1
- package/src/prover/smt/solver/lp/containers.ts +7 -2
- package/src/prover/smt/solver/lp/core-solver.ts +18 -3
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -4
- package/src/prover/smt/solver/lp/dep-intervals.ts +0 -3
- package/src/prover/smt/solver/lp/dependency.ts +0 -2
- package/src/prover/smt/solver/lp/dioph-eq.ts +1 -10
- package/src/prover/smt/solver/lp/explanation.ts +0 -1
- package/src/prover/smt/solver/lp/gomory.ts +0 -1
- package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -2
- package/src/prover/smt/solver/lp/hnf.ts +0 -3
- package/src/prover/smt/solver/lp/int-cube.ts +3 -4
- package/src/prover/smt/solver/lp/int-solver.ts +0 -2
- package/src/prover/smt/solver/lp/lar-solver.ts +40 -4
- package/src/prover/smt/solver/lp/lar-term.ts +0 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +0 -1
- package/src/prover/smt/solver/lp/maximize-term.ts +59 -10
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -3
- package/src/prover/smt/solver/lp/nex.ts +2 -2
- package/src/prover/smt/solver/lp/nla-backoff.ts +0 -2
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -3
- package/src/prover/smt/solver/lp/nla-core.ts +67 -16
- package/src/prover/smt/solver/lp/nla-divisions.ts +0 -2
- package/src/prover/smt/solver/lp/nla-emonics.ts +0 -1
- package/src/prover/smt/solver/lp/nla-factorization.ts +0 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +165 -83
- package/src/prover/smt/solver/lp/nla-horner.ts +0 -2
- package/src/prover/smt/solver/lp/nla-intervals.ts +0 -1
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +0 -2
- package/src/prover/smt/solver/lp/nla-monotone.ts +0 -1
- package/src/prover/smt/solver/lp/nla-order.ts +0 -2
- package/src/prover/smt/solver/lp/nla-patcher.ts +0 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +220 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +0 -2
- package/src/prover/smt/solver/lp/nla-throttle.ts +0 -1
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +324 -0
- package/src/prover/smt/solver/lp/nla-types.ts +0 -2
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +0 -1
- package/src/prover/smt/solver/lp/nra-solver.ts +122 -64
- package/src/prover/smt/solver/lp/numeric-pair.ts +0 -1
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -21
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -41
- package/src/prover/smt/solver/lp/pdd.ts +725 -289
- package/src/prover/smt/solver/lp/random-updater.ts +0 -2
- package/src/prover/smt/solver/lp/static-matrix.ts +0 -1
- package/src/prover/smt/solver/lp/union-find.ts +7 -2
- package/src/prover/smt/solver/macro-finder.ts +530 -0
- package/src/prover/smt/solver/mam-compiler.ts +122 -90
- package/src/prover/smt/solver/mam-interpreter.ts +0 -1
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +17 -0
- package/src/prover/smt/solver/max-cliques.ts +105 -0
- package/src/prover/smt/solver/maxcore.ts +309 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +8 -6
- package/src/prover/smt/solver/maxlex.ts +115 -0
- package/src/prover/smt/solver/maxsmt-base.ts +105 -0
- package/src/prover/smt/solver/maxsmt.ts +92 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +467 -0
- package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +101 -0
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +287 -0
- package/src/prover/smt/solver/mbp/mbp-qel.ts +48 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +271 -0
- package/src/prover/smt/solver/mbp/mbp-term-graph.ts +606 -0
- package/src/prover/smt/solver/model-based-opt.ts +844 -0
- package/src/prover/smt/solver/model-checker.ts +18 -27
- package/src/prover/smt/solver/model-evaluator.ts +188 -12
- package/src/prover/smt/solver/model-finder.ts +12 -18
- package/src/prover/smt/solver/model-generator.ts +56 -29
- package/src/prover/smt/solver/model-macro-solver.ts +49 -46
- package/src/prover/smt/solver/model-printer.ts +214 -0
- package/src/prover/smt/solver/mpf.ts +711 -0
- package/src/prover/smt/solver/mus.ts +51 -0
- package/src/prover/smt/solver/muz/dl-context.ts +404 -0
- package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +97 -0
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +167 -0
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +125 -0
- package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +299 -0
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +455 -0
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +340 -0
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +163 -0
- package/src/prover/smt/solver/muz/dl-rule-set.ts +273 -0
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +123 -0
- package/src/prover/smt/solver/muz/dl-rule.ts +496 -0
- package/src/prover/smt/solver/muz/hnf.ts +201 -0
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +201 -0
- package/src/prover/smt/solver/muz/rule-properties.ts +337 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +1406 -0
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +52 -0
- package/src/prover/smt/solver/muz/spacer-generalizers.ts +241 -0
- package/src/prover/smt/solver/muz/spacer-manager.ts +127 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +218 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +333 -0
- package/src/prover/smt/solver/muz/spacer-util.ts +282 -0
- package/src/prover/smt/solver/muz/substitution.ts +203 -0
- package/src/prover/smt/solver/nla2bv-tactic.ts +285 -0
- package/src/prover/smt/solver/nlqsat.ts +484 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +125 -12
- package/src/prover/smt/solver/nlsat/atoms.ts +20 -6
- package/src/prover/smt/solver/nlsat/evaluator.ts +0 -1
- package/src/prover/smt/solver/nlsat/explain.ts +63 -23
- package/src/prover/smt/solver/nlsat/interval-set.ts +1 -2
- package/src/prover/smt/solver/nlsat/levelwise.ts +3 -9
- package/src/prover/smt/solver/nlsat/mpbq.ts +45 -1
- package/src/prover/smt/solver/nlsat/polynomial.ts +13 -6
- package/src/prover/smt/solver/nlsat/solver.ts +236 -45
- package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
- package/src/prover/smt/solver/nlsat/transcendentals.ts +367 -0
- package/src/prover/smt/solver/nlsat/types.ts +0 -2
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +0 -2
- package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
- package/src/prover/smt/solver/nnf.ts +105 -23
- package/src/prover/smt/solver/normalize-bounds.ts +53 -0
- package/src/prover/smt/solver/occf.ts +97 -0
- package/src/prover/smt/solver/opt-context.ts +787 -0
- package/src/prover/smt/solver/opt-nlsat.ts +375 -0
- package/src/prover/smt/solver/opt-pareto.ts +282 -0
- package/src/prover/smt/solver/opt-preprocess.ts +101 -0
- package/src/prover/smt/solver/opt-solver.ts +308 -0
- package/src/prover/smt/solver/opt-value.ts +55 -0
- package/src/prover/smt/solver/optsmt.ts +692 -0
- package/src/prover/smt/solver/parallel-tactic.ts +299 -0
- package/src/prover/smt/solver/pattern-inference.ts +19 -11
- package/src/prover/smt/solver/pb-rewriter.ts +284 -0
- package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
- package/src/prover/smt/solver/poly-rewriter.ts +202 -57
- package/src/prover/smt/solver/probes.ts +512 -0
- package/src/prover/smt/solver/propagate-values.ts +37 -21
- package/src/prover/smt/solver/proto-model.ts +648 -19
- package/src/prover/smt/solver/pull-quant.ts +28 -12
- package/src/prover/smt/solver/purify-arith.ts +632 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +1098 -0
- package/src/prover/smt/solver/qe-lite-der.ts +2 -3
- package/src/prover/smt/solver/qe-lite-fm.ts +3 -4
- package/src/prover/smt/solver/qe-lite.ts +37 -17
- package/src/prover/smt/solver/qe-mbp.ts +270 -0
- package/src/prover/smt/solver/qe.ts +1498 -0
- package/src/prover/smt/solver/qel.ts +25 -0
- package/src/prover/smt/solver/qi-queue.ts +0 -1
- package/src/prover/smt/solver/qsat.ts +814 -0
- package/src/prover/smt/solver/quant-hoist.ts +196 -0
- package/src/prover/smt/solver/quant-tactics.ts +16 -56
- package/src/prover/smt/solver/quantifier-analyzer.ts +19 -20
- package/src/prover/smt/solver/quantifier-manager.ts +8 -16
- package/src/prover/smt/solver/quasi-macros.ts +243 -0
- package/src/prover/smt/solver/random-gen.ts +0 -1
- package/src/prover/smt/solver/rational.ts +45 -1
- package/src/prover/smt/solver/recfun-decl-plugin.ts +261 -0
- package/src/prover/smt/solver/recfun-rewriter.ts +107 -0
- package/src/prover/smt/solver/reduce-args.ts +225 -0
- package/src/prover/smt/solver/reduce-bv-size.ts +119 -0
- package/src/prover/smt/solver/ref-vector.ts +0 -1
- package/src/prover/smt/solver/relevancy.ts +1 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +77 -10
- package/src/prover/smt/solver/rewriter.ts +475 -36
- package/src/prover/smt/solver/rlimit.ts +38 -2
- package/src/prover/smt/solver/sat/asymm-branch.ts +325 -0
- package/src/prover/smt/solver/sat/big.ts +177 -0
- package/src/prover/smt/solver/sat/clause-use-list.ts +71 -0
- package/src/prover/smt/solver/sat/clause.ts +203 -0
- package/src/prover/smt/solver/sat/cleaner.ts +94 -0
- package/src/prover/smt/solver/sat/config.ts +122 -0
- package/src/prover/smt/solver/sat/consequences.ts +203 -0
- package/src/prover/smt/solver/sat/elim-eqs.ts +142 -0
- package/src/prover/smt/solver/sat/goal2sat.ts +526 -0
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +378 -0
- package/src/prover/smt/solver/sat/model-converter.ts +136 -0
- package/src/prover/smt/solver/sat/pb-constraint.ts +261 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +1577 -0
- package/src/prover/smt/solver/sat/probing.ts +170 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +43 -0
- package/src/prover/smt/solver/sat/sat2goal.ts +165 -0
- package/src/prover/smt/solver/sat/scc.ts +142 -0
- package/src/prover/smt/solver/sat/simplifier.ts +1618 -0
- package/src/prover/smt/solver/sat/solver.ts +2127 -0
- package/src/prover/smt/solver/sat/var-queue.ts +117 -0
- package/src/prover/smt/solver/sat/watch-list.ts +140 -0
- package/src/prover/smt/solver/search-tree.ts +284 -0
- package/src/prover/smt/solver/seq-axioms.ts +1010 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
- package/src/prover/smt/solver/seq-derive.ts +1298 -0
- package/src/prover/smt/solver/seq-eq-approx.ts +236 -0
- package/src/prover/smt/solver/seq-eq-solver.ts +439 -0
- package/src/prover/smt/solver/seq-factory.ts +89 -0
- package/src/prover/smt/solver/seq-monadic.ts +728 -0
- package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
- package/src/prover/smt/solver/seq-re-rewriter.ts +1170 -0
- package/src/prover/smt/solver/seq-re-util.ts +758 -0
- package/src/prover/smt/solver/seq-regex-bisim.ts +144 -0
- package/src/prover/smt/solver/seq-regex-live.ts +200 -0
- package/src/prover/smt/solver/seq-rewriter.ts +2402 -0
- package/src/prover/smt/solver/seq-skolem.ts +317 -0
- package/src/prover/smt/solver/seq-subset.ts +165 -0
- package/src/prover/smt/solver/seq-view-witness.ts +353 -0
- package/src/prover/smt/solver/smt-consequences.ts +297 -0
- package/src/prover/smt/solver/smt-kernel.ts +83 -0
- package/src/prover/smt/solver/smt-logics.ts +66 -0
- package/src/prover/smt/solver/smt-setup.ts +496 -0
- package/src/prover/smt/solver/smt2-printer.ts +765 -0
- package/src/prover/smt/solver/smtlib-parser.ts +3126 -316
- package/src/prover/smt/solver/smtlib-script.ts +1631 -0
- package/src/prover/smt/solver/solve-eqs.ts +929 -0
- package/src/prover/smt/solver/solver.ts +113 -22
- package/src/prover/smt/solver/static-features.ts +314 -0
- package/src/prover/smt/solver/sticky-generations.ts +0 -1
- package/src/prover/smt/solver/tactic.ts +1986 -0
- package/src/prover/smt/solver/term-enumeration.ts +205 -0
- package/src/prover/smt/solver/theory-array.ts +1240 -0
- package/src/prover/smt/solver/theory-bv.ts +1200 -0
- package/src/prover/smt/solver/theory-char.ts +355 -0
- package/src/prover/smt/solver/theory-datatype.ts +598 -0
- package/src/prover/smt/solver/theory-finite-set.ts +30 -0
- package/src/prover/smt/solver/theory-fpa.ts +389 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +53 -2
- package/src/prover/smt/solver/theory-lra-bounds.ts +31 -6
- package/src/prover/smt/solver/theory-lra-final-check.ts +56 -70
- package/src/prover/smt/solver/theory-lra-internalize.ts +94 -27
- package/src/prover/smt/solver/theory-lra-model.ts +20 -35
- package/src/prover/smt/solver/theory-lra-propagate.ts +24 -26
- package/src/prover/smt/solver/theory-lra-state.ts +6 -22
- package/src/prover/smt/solver/theory-lra.ts +188 -1
- package/src/prover/smt/solver/theory-pb.ts +934 -0
- package/src/prover/smt/solver/theory-polymorphism.ts +58 -0
- package/src/prover/smt/solver/theory-recfun.ts +307 -0
- package/src/prover/smt/solver/theory-seq-regex.ts +867 -0
- package/src/prover/smt/solver/theory-seq-solve.ts +1373 -0
- package/src/prover/smt/solver/theory-seq-state.ts +871 -0
- package/src/prover/smt/solver/theory-seq.ts +961 -0
- package/src/prover/smt/solver/theory.ts +189 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +485 -0
- package/src/prover/smt/solver/var-subst.ts +36 -14
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/smt/types.ts +146 -0
- package/src/prover/tlapm/cache.ts +50 -19
- package/src/prover/tlapm/tlapm.ts +15 -9
- package/src/prover/tlapm-library.ts +3208 -0
- package/src/prover/verdict.ts +9 -0
- package/src/prover/zenon/check/check.ts +1 -2
- package/src/prover/zenon/check/records.ts +1 -1
- package/src/prover/zenon/check/relations.ts +2 -1
- package/src/prover/zenon/check/rewrites.ts +2 -15
- package/src/prover/zenon/check/sets.ts +40 -58
- package/src/prover/zenon/check/terms.ts +1 -2
- package/src/prover/zenon/decide.ts +10 -7
- package/src/prover/zenon/encode.ts +0 -2
- package/src/prover/zenon/eqrel.ts +2 -2
- package/src/prover/zenon/equality-rules.ts +24 -2
- package/src/prover/zenon/expr.ts +28 -2
- package/src/prover/zenon/index-table.ts +11 -21
- package/src/prover/zenon/isar-case.ts +0 -2
- package/src/prover/zenon/isar.ts +35 -37
- package/src/prover/zenon/llproof.ts +2 -13
- package/src/prover/zenon/mltoll.ts +12 -30
- package/src/prover/zenon/node.ts +20 -5
- package/src/prover/zenon/parse.ts +9 -8
- package/src/prover/zenon/phrase.ts +0 -2
- package/src/prover/zenon/proof.ts +0 -2
- package/src/prover/zenon/propositional-rules.ts +0 -2
- package/src/prover/zenon/rules.ts +2 -3
- package/src/prover/zenon/search.ts +11 -19
- package/src/prover/zenon/tla/functions.ts +2 -4
- package/src/prover/zenon/tla/llproof.ts +9 -13
- package/src/prover/zenon/tla/records.ts +1 -8
- package/src/prover/zenon/tla/rewrites.ts +0 -2
- package/src/prover/zenon/tla/sets.ts +22 -22
- package/src/prover/zenon/tla/terms.ts +0 -2
- package/src/prover/zenon/tla/tla.ts +7 -8
- package/src/randomization.ts +1 -4
- package/src/resolve.ts +67 -143
- package/src/runtime.ts +17 -18
- package/src/sany/builtins.ts +1 -3
- 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 +160 -2683
- package/src/sany/levels.ts +5 -11
- package/src/sany/lexer.ts +57 -60
- package/src/sany/linter.ts +0 -3
- package/src/sany/nodes.ts +6 -13
- package/src/sany/report.ts +3 -6
- package/src/sany/selectors.ts +35 -38
- package/src/sany/xml.ts +23 -55
- package/src/search.ts +244 -53
- package/src/simulate.ts +202 -184
- package/src/spec-description.ts +56 -82
- package/src/standard-definitions.ts +4 -3
- package/src/standard-modules.ts +17 -44
- package/src/state-graph.ts +3 -17
- package/src/subexpressions.ts +38 -47
- package/src/substitution-levels.ts +5 -4
- package/src/successors.ts +20 -43
- package/src/symmetry.ts +6 -21
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +96 -30
- package/src/tlc/jar-data.ts +0 -1
- package/src/tlc/messages.ts +22 -36
- package/src/tlc/order.ts +36 -50
- package/src/tlc/random.ts +22 -34
- package/src/tlc/replay.ts +21 -48
- package/src/tlc/summary.ts +64 -58
- package/src/tlc/tlc-operators.ts +6 -17
- package/src/tlc/tlcext-operators.ts +70 -29
- package/src/tlc/trace-spec.ts +26 -51
- package/src/tlc/value-stream.ts +9 -13
- package/src/tlc/version.ts +0 -1
- package/src/typed-tier.ts +6535 -0
- package/src/typescript/actions.ts +2 -4
- package/src/typescript/collections.ts +34 -20
- package/src/typescript/compile.ts +1 -3
- package/src/typescript/formula.ts +5 -3
- package/src/typescript/model.ts +4 -5
- package/src/typescript/steps.ts +20 -18
- package/src/values.ts +136 -338
- package/src/prover/isabelle/isar/statement.ts +0 -52
- package/src/prover/smt/solver/z3-license.txt +0 -10
- package/src/prover/tlaps-module.ts +0 -510
- package/src/prover/zenon/LICENSE +0 -32
package/src/values.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
TlaModuleError,
|
|
7
7
|
TlaSetBoundError,
|
|
8
8
|
} from "./errors";
|
|
9
|
+
import { getJavaHashCode } from "./java-hash";
|
|
9
10
|
import { prettyPrint } from "./pretty-print";
|
|
10
11
|
import { isEvalException } from "./tlc/messages";
|
|
11
12
|
import type { TlcVersion } from "./tlc/version";
|
|
@@ -28,16 +29,13 @@ interface LazySet {
|
|
|
28
29
|
export interface SetValue {
|
|
29
30
|
kind: "Set";
|
|
30
31
|
elements: Value[];
|
|
31
|
-
// A set enumeration's unsorted elements, duplicates included, until TLC normalizes it.
|
|
32
32
|
writtenElements: Value[] | undefined;
|
|
33
|
-
// Once normalized, TLC checks membership by binary search with compareTo, not with equals.
|
|
34
33
|
isNormalized: boolean;
|
|
35
34
|
hash: number;
|
|
36
35
|
fingerprint: number;
|
|
37
36
|
isFingerprinted: boolean;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
// TLC sorts a set enumeration only when it has to, so it checks membership element by element.
|
|
41
39
|
export interface MixedSetValue extends LazySet {
|
|
42
40
|
kind: "MixedSet";
|
|
43
41
|
elements: Value[];
|
|
@@ -51,7 +49,6 @@ export interface FunctionValue {
|
|
|
51
49
|
fingerprint: number;
|
|
52
50
|
writtenKeys: Value[] | undefined;
|
|
53
51
|
functionClass: FunctionClass | undefined;
|
|
54
|
-
// The set a lambda ranges over, which TLC's DOMAIN returns until it builds the function.
|
|
55
52
|
lambdaDomain: Value | undefined;
|
|
56
53
|
isFingerprinted: boolean;
|
|
57
54
|
}
|
|
@@ -101,7 +98,6 @@ export interface SetOperationValue extends LazySet {
|
|
|
101
98
|
right: Value;
|
|
102
99
|
}
|
|
103
100
|
|
|
104
|
-
// TLC prints a set filter as its bound names and the location of its predicate.
|
|
105
101
|
interface FilteredSetSource {
|
|
106
102
|
names: string;
|
|
107
103
|
predicate: string;
|
|
@@ -114,7 +110,6 @@ export interface FilteredSetValue extends LazySet {
|
|
|
114
110
|
source?: FilteredSetSource;
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
// UNION S when some element of S isn't a set enumeration. TLC enumerates it only when it has to.
|
|
118
113
|
export interface UnionValue extends LazySet {
|
|
119
114
|
kind: "Union";
|
|
120
115
|
base: Value;
|
|
@@ -130,12 +125,10 @@ export interface LazyFunctionSource {
|
|
|
130
125
|
body: string;
|
|
131
126
|
}
|
|
132
127
|
|
|
133
|
-
// enumerated is the FcnRcdValue TLC converts the function to once it compares or fingerprints it.
|
|
134
128
|
export interface LazyFunctionValue {
|
|
135
129
|
kind: "LazyFunction";
|
|
136
130
|
domain: Value;
|
|
137
131
|
apply: (argument: Value) => Value;
|
|
138
|
-
// The length of each bound's tuple pattern, or undefined for a name.
|
|
139
132
|
boundTupleLengths?: (number | undefined)[];
|
|
140
133
|
source?: LazyFunctionSource;
|
|
141
134
|
functionClass?: FunctionClass;
|
|
@@ -189,16 +182,14 @@ export const MAXIMUM_INTEGER = 2147483647;
|
|
|
189
182
|
const DEFAULT_SET_BOUND = 1000000;
|
|
190
183
|
const VALUE_VEC_CAPACITY = 10;
|
|
191
184
|
|
|
192
|
-
|
|
185
|
+
let setBound = DEFAULT_SET_BOUND;
|
|
193
186
|
|
|
194
|
-
export const getSetBound = () => setBound
|
|
187
|
+
export const getSetBound = () => setBound;
|
|
195
188
|
|
|
196
|
-
|
|
197
|
-
// its room reaches the bound.
|
|
198
|
-
export const getMaximumSetSize = () => Math.max(setBound.size, VALUE_VEC_CAPACITY);
|
|
189
|
+
export const getMaximumSetSize = () => Math.max(setBound, VALUE_VEC_CAPACITY);
|
|
199
190
|
|
|
200
191
|
export const getSetBoundMessage = () =>
|
|
201
|
-
`Attempted to construct a set with too many elements (>${setBound
|
|
192
|
+
`Attempted to construct a set with too many elements (>${setBound}).`;
|
|
202
193
|
|
|
203
194
|
export const addBoundedElement = (elements: Value[], element: Value) => {
|
|
204
195
|
if (elements.length === getMaximumSetSize()) throw new TlaSetBoundError(getSetBoundMessage());
|
|
@@ -210,7 +201,6 @@ export const isBeyondSetBound = (value: Value): value is IntervalValue =>
|
|
|
210
201
|
value.kind === "Interval" &&
|
|
211
202
|
value.high - value.low >= getMaximumSetSize();
|
|
212
203
|
|
|
213
|
-
// TLC steps through an interval without building its elements.
|
|
214
204
|
export const forEachElement = (
|
|
215
205
|
elements: IntervalValue | Value[],
|
|
216
206
|
visit: (element: Value) => void,
|
|
@@ -252,13 +242,10 @@ export const describeKind = (value: Value) => {
|
|
|
252
242
|
export const isTlcInteger = (value: number) =>
|
|
253
243
|
Number.isInteger(value) && value <= MAXIMUM_INTEGER && value >= MINIMUM_INTEGER;
|
|
254
244
|
|
|
255
|
-
|
|
256
|
-
// fingerprint it. It searches the function in that order, and ToString, Assert, and error
|
|
257
|
-
// messages show it, unless every key is an integer.
|
|
258
|
-
const writtenOrderUse = { isUsed: false };
|
|
245
|
+
let isWrittenOrderUsed = false;
|
|
259
246
|
|
|
260
247
|
const setWrittenOrder = (functionValue: FunctionValue, keys: Value[]) => {
|
|
261
|
-
|
|
248
|
+
isWrittenOrderUsed = true;
|
|
262
249
|
functionValue.writtenKeys = keys;
|
|
263
250
|
return functionValue;
|
|
264
251
|
};
|
|
@@ -274,7 +261,6 @@ export const getWrittenPairs = (functionValue: FunctionValue): [Value, Value][]
|
|
|
274
261
|
functionValue.range[functionValue.domain.indexOf(key)],
|
|
275
262
|
]);
|
|
276
263
|
|
|
277
|
-
// TLC sorts a function whose keys are all integers to check whether it is a tuple.
|
|
278
264
|
export const getPrintedPairs = (functionValue: FunctionValue): [Value, Value][] =>
|
|
279
265
|
functionValue.domain.every((key) => typeof key === "number")
|
|
280
266
|
? functionValue.domain.map((key, index) => [key, functionValue.range[index]])
|
|
@@ -283,7 +269,6 @@ export const getPrintedPairs = (functionValue: FunctionValue): [Value, Value][]
|
|
|
283
269
|
export const createWrittenRecord = (names: Value[], range: Value[], writtenNames: Value[]) =>
|
|
284
270
|
setWrittenOrder(createSortedRecord(names, range), writtenNames);
|
|
285
271
|
|
|
286
|
-
// TLC sorts a value it compares, even with itself, so a hashed or fingerprinted value is sorted.
|
|
287
272
|
const forgetWrittenOrder = (value: Value): void => {
|
|
288
273
|
if (typeof value !== "object" || (value.kind !== "Function" && value.kind !== "Set")) return;
|
|
289
274
|
if (value.hash !== 0 || value.fingerprint !== 0) return;
|
|
@@ -294,12 +279,11 @@ const forgetWrittenOrder = (value: Value): void => {
|
|
|
294
279
|
|
|
295
280
|
const isRecordDomain = (domain: Value[]) => domain.every((key) => typeof key === "string");
|
|
296
281
|
|
|
297
|
-
// TLC compares a record only with a record, so this can fail before the sizes decide.
|
|
298
282
|
const isRecordMismatch = (left: Value[], right: Value[]) =>
|
|
299
283
|
left.length > 0 && right.length > 0 && isRecordDomain(left) !== isRecordDomain(right);
|
|
300
284
|
|
|
301
285
|
const compareFunctions = (left: FunctionValue, right: FunctionValue) => {
|
|
302
|
-
if (
|
|
286
|
+
if (isWrittenOrderUsed) {
|
|
303
287
|
left.writtenKeys = undefined;
|
|
304
288
|
right.writtenKeys = undefined;
|
|
305
289
|
}
|
|
@@ -371,25 +355,21 @@ const checkModelValueTypes = (left: Value, right: Value, isEquality: boolean) =>
|
|
|
371
355
|
interface StringOrder {
|
|
372
356
|
ranks: Record<string, number>;
|
|
373
357
|
size: number;
|
|
374
|
-
// A parallel search's workers rank the strings they create in different orders, so the search
|
|
375
|
-
// notes the first string it orders against another string ranked from this rank on.
|
|
376
358
|
searchRank: number | undefined;
|
|
377
359
|
unorderedString: string | undefined;
|
|
378
360
|
}
|
|
379
361
|
|
|
380
|
-
|
|
381
|
-
const stringOrder: StringOrder = {
|
|
362
|
+
const createStringOrder = (): StringOrder => ({
|
|
382
363
|
ranks: Object.create(null),
|
|
383
364
|
size: 0,
|
|
384
365
|
searchRank: undefined,
|
|
385
366
|
unorderedString: undefined,
|
|
386
|
-
};
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
const stringOrder = createStringOrder();
|
|
387
370
|
|
|
388
371
|
export const setStringOrder = (texts: Iterable<string>) => {
|
|
389
|
-
|
|
390
|
-
stringOrder.size = 0;
|
|
391
|
-
stringOrder.searchRank = undefined;
|
|
392
|
-
stringOrder.unorderedString = undefined;
|
|
372
|
+
Object.assign(stringOrder, createStringOrder());
|
|
393
373
|
modelValues.clear();
|
|
394
374
|
for (const text of texts) rankString(text);
|
|
395
375
|
};
|
|
@@ -400,8 +380,7 @@ export const freezeStringOrder = () => {
|
|
|
400
380
|
|
|
401
381
|
export const getUnorderedString = () => stringOrder.unorderedString;
|
|
402
382
|
|
|
403
|
-
|
|
404
|
-
const valueVersion = { is174: false };
|
|
383
|
+
let isVersion174 = false;
|
|
405
384
|
|
|
406
385
|
const printing = { isExpanded: true, isViewPrinted: false };
|
|
407
386
|
|
|
@@ -413,13 +392,12 @@ export interface ValueOptions {
|
|
|
413
392
|
}
|
|
414
393
|
|
|
415
394
|
export const setValueOptions = (options: ValueOptions) => {
|
|
416
|
-
|
|
417
|
-
setBound
|
|
395
|
+
isVersion174 = options.version === "1.7.4";
|
|
396
|
+
setBound = options.maxSetSize ?? DEFAULT_SET_BOUND;
|
|
418
397
|
printing.isExpanded = options.isLazyValueExpanded ?? true;
|
|
419
398
|
printing.isViewPrinted = options.isViewPrinted ?? false;
|
|
420
399
|
};
|
|
421
400
|
|
|
422
|
-
// TLC evaluates the VIEW of a state it prints as it prints it.
|
|
423
401
|
const viewTexts = new WeakMap<Record<string, Value>, () => string>();
|
|
424
402
|
|
|
425
403
|
export const setViewText = (state: Record<string, Value>, getText: () => string) => {
|
|
@@ -427,7 +405,6 @@ export const setViewText = (state: Record<string, Value>, getText: () => string)
|
|
|
427
405
|
return state;
|
|
428
406
|
};
|
|
429
407
|
|
|
430
|
-
// TLC prints by its _format only the state an ALIAS gives.
|
|
431
408
|
const aliasNames = new WeakMap<Record<string, Value>, string>();
|
|
432
409
|
|
|
433
410
|
export const setAliasName = (state: Record<string, Value>, alias: string) => {
|
|
@@ -480,8 +457,6 @@ const createComparisonError = (left: Value, right: Value) =>
|
|
|
480
457
|
: `Attempted to compare ${describeKind(left)} ${formatValue(left)} with ${describeKind(right)} ${formatValue(right)}`,
|
|
481
458
|
);
|
|
482
459
|
|
|
483
|
-
// TLC's Nat, Int, STRING, Seq(S), and Any compare only with each other and with model values,
|
|
484
|
-
// and fail with any other set, worded by the class of the left operand.
|
|
485
460
|
const compareOverriddenSets = (
|
|
486
461
|
left: Value,
|
|
487
462
|
right: Value,
|
|
@@ -510,9 +485,8 @@ const compareAny = (other: Value): never => {
|
|
|
510
485
|
throw new TlaModuleError(`Attempted to compare ANY with the value\n${formatValue(other)}`);
|
|
511
486
|
};
|
|
512
487
|
|
|
513
|
-
// TLC enumerates a lambda to compare it, even with itself.
|
|
514
488
|
const compareWithItself = (value: Value) => {
|
|
515
|
-
if (
|
|
489
|
+
if (isWrittenOrderUsed) forgetWrittenOrder(value);
|
|
516
490
|
if (value === ANY_SET) compareAny(value);
|
|
517
491
|
if (typeof value === "object" && value.kind === "LazyFunction") toFiniteFunction(value);
|
|
518
492
|
};
|
|
@@ -550,7 +524,6 @@ export const compareValues = (left: Value, right: Value): number => {
|
|
|
550
524
|
if (isLeftSet !== isSetValue(right)) {
|
|
551
525
|
throw createComparisonError(left, right);
|
|
552
526
|
}
|
|
553
|
-
// The sizes decide first, so an interval of another size never needs its elements.
|
|
554
527
|
if (leftKind === "Interval" && rightKind === "Set") {
|
|
555
528
|
const difference = getCardinality(left) - right.elements.length;
|
|
556
529
|
if (difference !== 0) return difference;
|
|
@@ -573,10 +546,8 @@ export const compareValues = (left: Value, right: Value): number => {
|
|
|
573
546
|
|
|
574
547
|
const modelValues = new Map<string, ModelValue>();
|
|
575
548
|
|
|
576
|
-
// ModelValue's index is a short.
|
|
577
549
|
const MAXIMUM_MODEL_VALUES = 32768;
|
|
578
550
|
|
|
579
|
-
// setStringOrder clears the model values, so each check ranks and creates its own.
|
|
580
551
|
export const createModelValue = (name: string): ModelValue => {
|
|
581
552
|
const known = modelValues.get(name);
|
|
582
553
|
if (known) return known;
|
|
@@ -627,18 +598,15 @@ export const createSortedFunction = (domain: Value[], range: Value[]): FunctionV
|
|
|
627
598
|
isFingerprinted: false,
|
|
628
599
|
});
|
|
629
600
|
|
|
630
|
-
// TLC words a failed application by the function's Java class: FcnLambdaValue, TupleValue,
|
|
631
|
-
// RecordValue, or FcnRcdValue.
|
|
632
601
|
export type FunctionClass = "lambda" | "tuple" | "record";
|
|
633
602
|
|
|
634
|
-
|
|
635
|
-
const lambdaPresence = { isPresent: false };
|
|
603
|
+
let hasLambda = false;
|
|
636
604
|
|
|
637
605
|
export const setFunctionClass = <FunctionLike extends FunctionValue | LazyFunctionValue>(
|
|
638
606
|
functionValue: FunctionLike,
|
|
639
607
|
functionClass: FunctionClass | undefined,
|
|
640
608
|
) => {
|
|
641
|
-
if (functionClass === "lambda")
|
|
609
|
+
if (functionClass === "lambda") hasLambda = true;
|
|
642
610
|
if (functionClass !== undefined) functionValue.functionClass = functionClass;
|
|
643
611
|
return functionValue;
|
|
644
612
|
};
|
|
@@ -652,17 +620,14 @@ export const markLambdaFunction = <FunctionLike extends FunctionValue | LazyFunc
|
|
|
652
620
|
functionValue: FunctionLike,
|
|
653
621
|
) => setFunctionClass(functionValue, "lambda");
|
|
654
622
|
|
|
655
|
-
// TLC caches a lazy set as the receiver of compareTo, equals, size, and fingerPrint, not as
|
|
656
|
-
// their argument, and enumerates the sets an uncached one combines, duplicates and all.
|
|
657
623
|
const isCachedSet = (value: ObjectValue) => isLazySet(value) && value.isCached === true;
|
|
658
624
|
|
|
659
|
-
|
|
660
|
-
const streamedSetPresence = { isPresent: false };
|
|
625
|
+
let hasStreamedSet = false;
|
|
661
626
|
|
|
662
627
|
export const markStreamedSet = <Streamed extends UnionValue | SetOperationValue>(
|
|
663
628
|
value: Streamed,
|
|
664
629
|
) => {
|
|
665
|
-
|
|
630
|
+
hasStreamedSet = true;
|
|
666
631
|
return value;
|
|
667
632
|
};
|
|
668
633
|
|
|
@@ -677,7 +642,7 @@ const STREAMING_KINDS = new Set<ObjectValue["kind"]>([
|
|
|
677
642
|
|
|
678
643
|
const cacheSet = (value: Value) => {
|
|
679
644
|
if (
|
|
680
|
-
|
|
645
|
+
hasStreamedSet &&
|
|
681
646
|
typeof value === "object" &&
|
|
682
647
|
isLazySet(value) &&
|
|
683
648
|
STREAMING_KINDS.has(value.kind)
|
|
@@ -686,11 +651,8 @@ const cacheSet = (value: Value) => {
|
|
|
686
651
|
}
|
|
687
652
|
};
|
|
688
653
|
|
|
689
|
-
// Fingerprinting caches the FcnRcdValue a lambda enumerates to, so it is no longer a lambda.
|
|
690
654
|
export const markFingerprinted = (value: Value): void => {
|
|
691
|
-
if ((!
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
655
|
+
if ((!hasLambda && !hasStreamedSet) || typeof value !== "object") return;
|
|
694
656
|
if (value.kind === "ModelValue" || value.kind === "Interval" || value.kind === "InfiniteSet") {
|
|
695
657
|
return;
|
|
696
658
|
}
|
|
@@ -724,7 +686,6 @@ export const valuesEqual = (left: Value, right: Value): boolean => {
|
|
|
724
686
|
if (left.kind === "Function" && right.kind === "Function")
|
|
725
687
|
return compareFunctions(left, right) === 0;
|
|
726
688
|
if (left.kind === "Set" && right.kind === "Set") return compareSets(left, right) === 0;
|
|
727
|
-
// The sizes decide first, so an interval of another size never needs its elements.
|
|
728
689
|
if (left.kind === "Interval" && right.kind === "Set") {
|
|
729
690
|
if (getCardinality(left) !== right.elements.length) return false;
|
|
730
691
|
}
|
|
@@ -732,7 +693,6 @@ export const valuesEqual = (left: Value, right: Value): boolean => {
|
|
|
732
693
|
if (left.elements.length !== getCardinality(right)) return false;
|
|
733
694
|
}
|
|
734
695
|
if (isModelValue(left) || isModelValue(right)) {
|
|
735
|
-
// TLC enumerates a lambda, which can fail, before it compares it.
|
|
736
696
|
if (left.kind === "LazyFunction") toFiniteFunction(left);
|
|
737
697
|
checkModelValueTypes(left, right, true);
|
|
738
698
|
return isModelValue(left) && isModelValue(right) && left.name === right.name;
|
|
@@ -786,7 +746,6 @@ export const valuesEqual = (left: Value, right: Value): boolean => {
|
|
|
786
746
|
return compareValues(left, right) === 0;
|
|
787
747
|
};
|
|
788
748
|
|
|
789
|
-
// TLC words errors by each function's Java class, so a stand-in must match each function's class.
|
|
790
749
|
const createSameValueCheck = (isClassSensitive: boolean) => {
|
|
791
750
|
const areSameValues = (left: Value[], right: Value[]) => {
|
|
792
751
|
if (left === right) return true;
|
|
@@ -826,7 +785,6 @@ const canonicalizeElements = (elements: Value[], canonicalize: (value: Value) =>
|
|
|
826
785
|
}
|
|
827
786
|
};
|
|
828
787
|
|
|
829
|
-
// So that the states it keeps share their values.
|
|
830
788
|
export const createCanonicalizer = () => {
|
|
831
789
|
const canonicalValues = new Map<number, Value | Value[]>();
|
|
832
790
|
const canonicalize = (value: Value): Value => {
|
|
@@ -860,15 +818,12 @@ export const createCanonicalizer = () => {
|
|
|
860
818
|
};
|
|
861
819
|
};
|
|
862
820
|
|
|
863
|
-
// These follow TLC's compareTo and equals, which word a failure by the left operand's class,
|
|
864
|
-
// so a failed comparison above runs again through them to fail as TLC does.
|
|
865
821
|
interface TlcFunction {
|
|
866
822
|
domain: Value[];
|
|
867
823
|
range: Value[];
|
|
868
824
|
low: number | undefined;
|
|
869
825
|
}
|
|
870
826
|
|
|
871
|
-
// TLC compares a domain it keeps as an interval apart from one it keeps as an array.
|
|
872
827
|
const getIntervalLow = (value: Value, domain: Value[]) =>
|
|
873
828
|
domain.length === 0 || getFunctionClass(value) === "tuple" ? 1 : getDomainInterval(domain)?.low;
|
|
874
829
|
|
|
@@ -885,30 +840,14 @@ const toTlcFunction = (value: Value) => {
|
|
|
885
840
|
const toTlcRecord = (value: Value) => {
|
|
886
841
|
if (!isFunctionValue(value)) return undefined;
|
|
887
842
|
const functionValue = toFiniteFunction(value);
|
|
888
|
-
return functionValue.domain
|
|
843
|
+
return isRecordDomain(functionValue.domain) ? functionValue : undefined;
|
|
889
844
|
};
|
|
890
845
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
checkModelValueTypes(other, modelValue, false);
|
|
846
|
+
const compareModelValueWith = (modelValue: ModelValue, other: Value, isEquality: boolean) => {
|
|
847
|
+
checkModelValueTypes(other, modelValue, isEquality);
|
|
894
848
|
return 1;
|
|
895
849
|
};
|
|
896
850
|
|
|
897
|
-
const equalsModelValueWith = (modelValue: ModelValue, other: Value) => {
|
|
898
|
-
checkModelValueTypes(other, modelValue, true);
|
|
899
|
-
return false;
|
|
900
|
-
};
|
|
901
|
-
|
|
902
|
-
const compareModelValue = (left: ModelValue, right: Value) => {
|
|
903
|
-
if (left.type !== undefined) checkModelValueTypes(left, right, false);
|
|
904
|
-
return isModelValue(right) ? left.rank - right.rank : -1;
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
const equalsModelValue = (left: ModelValue, right: Value) => {
|
|
908
|
-
if (left.type !== undefined) checkModelValueTypes(left, right, true);
|
|
909
|
-
return isModelValue(right) && left.name === right.name;
|
|
910
|
-
};
|
|
911
|
-
|
|
912
851
|
const SCALAR_KINDS = {
|
|
913
852
|
number: { name: "integer", other: "non-integer", equality: "check equality of" },
|
|
914
853
|
string: { name: "string", other: "non-string", equality: "check equality of" },
|
|
@@ -927,31 +866,40 @@ const describeScalarMismatch = (
|
|
|
927
866
|
return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${formatValue(left)} with ${kind.other}:\n${formatValue(right)}`;
|
|
928
867
|
};
|
|
929
868
|
|
|
930
|
-
const
|
|
869
|
+
const getComparisonVerb = (isEquality: boolean) => (isEquality ? "check equality of" : "compare");
|
|
870
|
+
|
|
871
|
+
const compareTlcFunctions = (
|
|
872
|
+
functionValue: TlcFunction,
|
|
873
|
+
left: Value,
|
|
874
|
+
right: Value,
|
|
875
|
+
isEquality: boolean,
|
|
876
|
+
) => {
|
|
931
877
|
const other = toTlcFunction(right);
|
|
932
878
|
if (!other) {
|
|
933
|
-
if (isModelValue(right)) return compareModelValueWith(right, left);
|
|
879
|
+
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
934
880
|
throw new TlaEvaluationError(
|
|
935
|
-
`Attempted to
|
|
881
|
+
`Attempted to ${getComparisonVerb(isEquality)} the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
936
882
|
);
|
|
937
883
|
}
|
|
938
884
|
if (functionValue.range.length !== other.range.length)
|
|
939
885
|
return functionValue.range.length - other.range.length;
|
|
940
|
-
const compareRanges = () => compareElementsLikeTlc(functionValue.range, other.range);
|
|
886
|
+
const compareRanges = () => compareElementsLikeTlc(functionValue.range, other.range, isEquality);
|
|
941
887
|
if (functionValue.low !== undefined && functionValue.range.length === 0) return 0;
|
|
942
888
|
if (functionValue.low !== undefined && other.low !== undefined) {
|
|
943
889
|
return functionValue.low === other.low ? compareRanges() : functionValue.low - other.low;
|
|
944
890
|
}
|
|
945
891
|
const intervalLow = functionValue.low ?? other.low;
|
|
946
892
|
if (intervalLow === undefined) {
|
|
947
|
-
return
|
|
893
|
+
return (
|
|
894
|
+
compareElementsLikeTlc(functionValue.domain, other.domain, isEquality) || compareRanges()
|
|
895
|
+
);
|
|
948
896
|
}
|
|
949
897
|
const keys = functionValue.low === undefined ? functionValue.domain : other.domain;
|
|
950
898
|
for (let index = 0; index < keys.length; index++) {
|
|
951
899
|
const key = keys[index];
|
|
952
900
|
if (typeof key !== "number") {
|
|
953
901
|
throw new TlaEvaluationError(
|
|
954
|
-
`Attempted to compare integer with non-integer${functionValue.low
|
|
902
|
+
`Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${formatValue(key)}.`,
|
|
955
903
|
);
|
|
956
904
|
}
|
|
957
905
|
const difference =
|
|
@@ -961,46 +909,50 @@ const compareTlcFunctions = (functionValue: TlcFunction, left: Value, right: Val
|
|
|
961
909
|
return compareRanges();
|
|
962
910
|
};
|
|
963
911
|
|
|
964
|
-
const compareElementsLikeTlc = (left: Value[], right: Value[]) => {
|
|
912
|
+
const compareElementsLikeTlc = (left: Value[], right: Value[], isEquality: boolean) => {
|
|
965
913
|
for (let index = 0; index < left.length; index++) {
|
|
966
|
-
const comparison =
|
|
914
|
+
const comparison = compareOrEqualLikeTlc(left[index], right[index], isEquality);
|
|
967
915
|
if (comparison !== 0) return comparison;
|
|
968
916
|
}
|
|
969
917
|
return 0;
|
|
970
918
|
};
|
|
971
919
|
|
|
972
|
-
const compareFunctionLikeTlc = (
|
|
920
|
+
const compareFunctionLikeTlc = (
|
|
921
|
+
left: FunctionValue | LazyFunctionValue,
|
|
922
|
+
right: Value,
|
|
923
|
+
isEquality: boolean,
|
|
924
|
+
) => {
|
|
973
925
|
const functionValue = toFiniteFunction(left);
|
|
974
926
|
if (getFunctionClass(left) === "tuple") {
|
|
975
927
|
const tuple = isFunctionValue(right) ? getSequenceElements(right) : undefined;
|
|
976
|
-
if (!tuple) return compareTlcFunctions({ ...functionValue, low: 1 }, left, right);
|
|
928
|
+
if (!tuple) return compareTlcFunctions({ ...functionValue, low: 1 }, left, right, isEquality);
|
|
977
929
|
return (
|
|
978
930
|
functionValue.range.length - tuple.length ||
|
|
979
|
-
compareElementsLikeTlc(functionValue.range, tuple)
|
|
931
|
+
compareElementsLikeTlc(functionValue.range, tuple, isEquality)
|
|
980
932
|
);
|
|
981
933
|
}
|
|
982
934
|
if (getFunctionClass(left) === "record") {
|
|
983
935
|
const record = toTlcRecord(right);
|
|
984
936
|
if (!record) {
|
|
985
|
-
if (isModelValue(right)) return compareModelValueWith(right, left);
|
|
937
|
+
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
986
938
|
throw new TlaEvaluationError(
|
|
987
|
-
`Attempted to
|
|
939
|
+
`Attempted to ${getComparisonVerb(isEquality)} record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
|
|
988
940
|
);
|
|
989
941
|
}
|
|
990
942
|
return (
|
|
991
943
|
functionValue.domain.length - record.domain.length ||
|
|
992
|
-
compareElementsLikeTlc(functionValue.domain, record.domain) ||
|
|
993
|
-
compareElementsLikeTlc(functionValue.range, record.range)
|
|
944
|
+
compareElementsLikeTlc(functionValue.domain, record.domain, isEquality) ||
|
|
945
|
+
compareElementsLikeTlc(functionValue.range, record.range, isEquality)
|
|
994
946
|
);
|
|
995
947
|
}
|
|
996
948
|
return compareTlcFunctions(
|
|
997
949
|
{ ...functionValue, low: getIntervalLow(left, functionValue.domain) },
|
|
998
950
|
left,
|
|
999
951
|
right,
|
|
952
|
+
isEquality,
|
|
1000
953
|
);
|
|
1001
954
|
};
|
|
1002
955
|
|
|
1003
|
-
// TLC compares a lazy or Java-overridden set through its own class before it compares elements.
|
|
1004
956
|
const isComparedByClass = (left: ObjectValue, right: Value) =>
|
|
1005
957
|
isOverriddenSet(left) ||
|
|
1006
958
|
isOverriddenSet(right) ||
|
|
@@ -1017,130 +969,48 @@ const getSetElementsLikeTlc = (left: SetValue | MixedSetValue, right: Value) =>
|
|
|
1017
969
|
return { elements: toFiniteSet(left).elements, otherElements: toFiniteSet(other).elements };
|
|
1018
970
|
};
|
|
1019
971
|
|
|
1020
|
-
const compareSetLikeTlc = (left: ObjectValue, right: Value): number => {
|
|
1021
|
-
if (isComparedByClass(left, right))
|
|
1022
|
-
|
|
972
|
+
const compareSetLikeTlc = (left: ObjectValue, right: Value, isEquality: boolean): number => {
|
|
973
|
+
if (isComparedByClass(left, right)) {
|
|
974
|
+
if (!isEquality) return compareValues(left, right);
|
|
975
|
+
return valuesEqual(left, right) ? 0 : 1;
|
|
976
|
+
}
|
|
977
|
+
if (!isEnumeratedSet(left)) return compareSetLikeTlc(toFiniteSet(left), right, isEquality);
|
|
1023
978
|
if (!isSetValue(right)) {
|
|
1024
|
-
if (isModelValue(right)) return compareModelValueWith(right, left);
|
|
979
|
+
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
1025
980
|
throw new TlaEvaluationError(
|
|
1026
|
-
`Attempted to
|
|
981
|
+
`Attempted to ${getComparisonVerb(isEquality)} the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
1027
982
|
);
|
|
1028
983
|
}
|
|
1029
984
|
const sets = getSetElementsLikeTlc(left, right);
|
|
1030
985
|
return (
|
|
1031
986
|
sets.elements.length - sets.otherElements.length ||
|
|
1032
|
-
compareElementsLikeTlc(sets.elements, sets.otherElements)
|
|
987
|
+
compareElementsLikeTlc(sets.elements, sets.otherElements, isEquality)
|
|
1033
988
|
);
|
|
1034
989
|
};
|
|
1035
990
|
|
|
1036
|
-
const
|
|
991
|
+
const compareOrEqualLikeTlc = (left: Value, right: Value, isEquality: boolean): number => {
|
|
1037
992
|
if (typeof left !== "object") {
|
|
1038
|
-
if (typeof right === typeof left)
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
}
|
|
1042
|
-
if (left.kind === "ModelValue") return compareModelValue(left, right);
|
|
1043
|
-
if (isFunctionValue(left)) return compareFunctionLikeTlc(left, right);
|
|
1044
|
-
return compareSetLikeTlc(left, right);
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
|
-
const equalsElementsLikeTlc = (left: Value[], right: Value[]) =>
|
|
1048
|
-
left.every((element, index) => equalsLikeTlc(element, right[index]));
|
|
1049
|
-
|
|
1050
|
-
const equalsTlcFunctions = (functionValue: TlcFunction, left: Value, right: Value) => {
|
|
1051
|
-
const other = toTlcFunction(right);
|
|
1052
|
-
if (!other) {
|
|
1053
|
-
if (isModelValue(right)) return equalsModelValueWith(right, left);
|
|
1054
|
-
throw new TlaEvaluationError(
|
|
1055
|
-
`Attempted to check equality of the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
1056
|
-
);
|
|
1057
|
-
}
|
|
1058
|
-
if (functionValue.range.length !== other.range.length) return false;
|
|
1059
|
-
if (functionValue.low !== undefined && other.low !== undefined) {
|
|
1060
|
-
return (
|
|
1061
|
-
(functionValue.range.length === 0 || functionValue.low === other.low) &&
|
|
1062
|
-
equalsElementsLikeTlc(functionValue.range, other.range)
|
|
1063
|
-
);
|
|
1064
|
-
}
|
|
1065
|
-
const intervalLow = functionValue.low ?? other.low;
|
|
1066
|
-
if (intervalLow === undefined) {
|
|
1067
|
-
return (
|
|
1068
|
-
equalsElementsLikeTlc(functionValue.domain, other.domain) &&
|
|
1069
|
-
equalsElementsLikeTlc(functionValue.range, other.range)
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
const keys = functionValue.low === undefined ? functionValue.domain : other.domain;
|
|
1073
|
-
return (
|
|
1074
|
-
keys.every((key, index) => {
|
|
1075
|
-
if (typeof key !== "number") {
|
|
1076
|
-
throw new TlaEvaluationError(
|
|
1077
|
-
`Attempted to compare an integer with non-integer:\n${formatValue(key)}.`,
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
return key === intervalLow + index;
|
|
1081
|
-
}) && equalsElementsLikeTlc(functionValue.range, other.range)
|
|
1082
|
-
);
|
|
1083
|
-
};
|
|
1084
|
-
|
|
1085
|
-
const equalsFunctionLikeTlc = (left: FunctionValue | LazyFunctionValue, right: Value) => {
|
|
1086
|
-
const functionValue = toFiniteFunction(left);
|
|
1087
|
-
if (getFunctionClass(left) === "tuple") {
|
|
1088
|
-
const tuple = isFunctionValue(right) ? getSequenceElements(right) : undefined;
|
|
1089
|
-
if (!tuple) return equalsTlcFunctions({ ...functionValue, low: 1 }, left, right);
|
|
1090
|
-
return (
|
|
1091
|
-
functionValue.range.length === tuple.length &&
|
|
1092
|
-
equalsElementsLikeTlc(functionValue.range, tuple)
|
|
1093
|
-
);
|
|
1094
|
-
}
|
|
1095
|
-
if (getFunctionClass(left) === "record") {
|
|
1096
|
-
const record = toTlcRecord(right);
|
|
1097
|
-
if (!record) {
|
|
1098
|
-
if (isModelValue(right)) return equalsModelValueWith(right, left);
|
|
1099
|
-
throw new TlaEvaluationError(
|
|
1100
|
-
`Attempted to check equality of record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
|
|
1101
|
-
);
|
|
993
|
+
if (typeof right === typeof left) {
|
|
994
|
+
if (!isEquality) return compareValues(left, right);
|
|
995
|
+
return left === right ? 0 : 1;
|
|
1102
996
|
}
|
|
1103
|
-
return (
|
|
1104
|
-
|
|
1105
|
-
equalsElementsLikeTlc(functionValue.domain, record.domain) &&
|
|
1106
|
-
equalsElementsLikeTlc(functionValue.range, record.range)
|
|
1107
|
-
);
|
|
997
|
+
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
998
|
+
throw new TlaEvaluationError(describeScalarMismatch(left, right, isEquality));
|
|
1108
999
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
right
|
|
1113
|
-
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
|
-
const equalsSetLikeTlc = (left: ObjectValue, right: Value): boolean => {
|
|
1117
|
-
if (isComparedByClass(left, right)) return valuesEqual(left, right);
|
|
1118
|
-
if (!isEnumeratedSet(left)) return equalsSetLikeTlc(toFiniteSet(left), right);
|
|
1119
|
-
if (!isSetValue(right)) {
|
|
1120
|
-
if (isModelValue(right)) return equalsModelValueWith(right, left);
|
|
1121
|
-
throw new TlaEvaluationError(
|
|
1122
|
-
`Attempted to check equality of the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
1123
|
-
);
|
|
1000
|
+
if (left.kind === "ModelValue") {
|
|
1001
|
+
if (left.type !== undefined) checkModelValueTypes(left, right, isEquality);
|
|
1002
|
+
if (!isModelValue(right)) return -1;
|
|
1003
|
+
if (!isEquality) return left.rank - right.rank;
|
|
1004
|
+
return left.name === right.name ? 0 : 1;
|
|
1124
1005
|
}
|
|
1125
|
-
|
|
1126
|
-
return (
|
|
1127
|
-
sets.elements.length === sets.otherElements.length &&
|
|
1128
|
-
equalsElementsLikeTlc(sets.elements, sets.otherElements)
|
|
1129
|
-
);
|
|
1006
|
+
if (isFunctionValue(left)) return compareFunctionLikeTlc(left, right, isEquality);
|
|
1007
|
+
return compareSetLikeTlc(left, right, isEquality);
|
|
1130
1008
|
};
|
|
1131
1009
|
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
if (isModelValue(right)) return equalsModelValueWith(right, left);
|
|
1136
|
-
throw new TlaEvaluationError(describeScalarMismatch(left, right, true));
|
|
1137
|
-
}
|
|
1138
|
-
if (left.kind === "ModelValue") return equalsModelValue(left, right);
|
|
1139
|
-
if (isFunctionValue(left)) return equalsFunctionLikeTlc(left, right);
|
|
1140
|
-
return equalsSetLikeTlc(left, right);
|
|
1141
|
-
};
|
|
1010
|
+
const compareLikeTlc = (left: Value, right: Value) => compareOrEqualLikeTlc(left, right, false);
|
|
1011
|
+
|
|
1012
|
+
const equalsLikeTlc = (left: Value, right: Value) => compareOrEqualLikeTlc(left, right, true) === 0;
|
|
1142
1013
|
|
|
1143
|
-
// TLC's ValueVec.sort, which inserts each element into the sorted prefix by binary search.
|
|
1144
1014
|
const sortLikeTlc = (elements: Value[]) => {
|
|
1145
1015
|
const sorted: Value[] = [];
|
|
1146
1016
|
for (const element of elements) {
|
|
@@ -1159,17 +1029,17 @@ const callTracedMethod = <Result>(receiver: Value, method: () => Result) => {
|
|
|
1159
1029
|
return result;
|
|
1160
1030
|
};
|
|
1161
1031
|
|
|
1162
|
-
// A binary search with compareTo, which ends where the element is or would go.
|
|
1163
1032
|
const searchLikeTlc = (element: Value, sorted: Value[]) => {
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1033
|
+
let low = 0;
|
|
1034
|
+
let high = sorted.length;
|
|
1035
|
+
while (low < high) {
|
|
1036
|
+
const middle = low + ((high - low) >> 1);
|
|
1167
1037
|
const comparison = callTracedMethod(element, () => compareLikeTlc(element, sorted[middle]));
|
|
1168
1038
|
if (comparison === 0) return { index: middle, isFound: true };
|
|
1169
|
-
if (comparison < 0)
|
|
1170
|
-
else
|
|
1039
|
+
if (comparison < 0) high = middle;
|
|
1040
|
+
else low = middle + 1;
|
|
1171
1041
|
}
|
|
1172
|
-
return { index:
|
|
1042
|
+
return { index: low, isFound: false };
|
|
1173
1043
|
};
|
|
1174
1044
|
|
|
1175
1045
|
const isElementOfLikeTlc = (element: Value, elements: Value[]) =>
|
|
@@ -1192,7 +1062,6 @@ export const markNormalized = (value: Value): void => {
|
|
|
1192
1062
|
}
|
|
1193
1063
|
};
|
|
1194
1064
|
|
|
1195
|
-
// TLC's Value.normalize sorts a set enumeration, and the sets a lazy set it hasn't cached combines.
|
|
1196
1065
|
export const normalizeShallowly = (value: Value): void => {
|
|
1197
1066
|
if (typeof value !== "object" || isCachedSet(value)) return;
|
|
1198
1067
|
switch (value.kind) {
|
|
@@ -1241,7 +1110,6 @@ const isAscendingIntegers = (elements: Value[]) => {
|
|
|
1241
1110
|
};
|
|
1242
1111
|
|
|
1243
1112
|
export const createSet = (elements: Value[]): SetValue => {
|
|
1244
|
-
// TLC's sort compares each element after the first with those before it.
|
|
1245
1113
|
for (let index = 1; index < elements.length; index++) cacheSet(elements[index]);
|
|
1246
1114
|
if (elements.length < 2 || isStrictlySorted(elements)) return createSortedSet(elements);
|
|
1247
1115
|
const sorted = [...elements].sort(compareValues);
|
|
@@ -1252,7 +1120,6 @@ export const createSet = (elements: Value[]): SetValue => {
|
|
|
1252
1120
|
return createSortedSet(unique);
|
|
1253
1121
|
};
|
|
1254
1122
|
|
|
1255
|
-
// TLC builds a set enumeration unsorted, so one whose elements it can't compare still evaluates.
|
|
1256
1123
|
export const createEnumeratedSet = (elements: Value[]): SetValue | MixedSetValue => {
|
|
1257
1124
|
if (isAscendingIntegers(elements)) return createSortedSet(elements);
|
|
1258
1125
|
const set = computeLikeTlcOnFailure<Value[], undefined, SetValue | MixedSetValue>(
|
|
@@ -1394,20 +1261,15 @@ const longIntervalDomains = new Map<number, WeakRef<Value[]>>();
|
|
|
1394
1261
|
const intervalValues: IntervalValue[] = [];
|
|
1395
1262
|
const intervalArrays = new WeakMap<Value[], IntervalValue>();
|
|
1396
1263
|
|
|
1397
|
-
// Every function over 1..n shares one domain array per length, so the array's identity records
|
|
1398
|
-
// the interval. Callers must not mutate the returned array. Longer domains are held weakly: a
|
|
1399
|
-
// sequence that grows one element at a time would otherwise keep an array of every length it
|
|
1400
|
-
// passed through, n * n / 2 numbers in all.
|
|
1401
1264
|
const getIntervalDomain = (length: number): Value[] => {
|
|
1402
1265
|
const cached = intervalDomains[length] ?? longIntervalDomains.get(length)?.deref();
|
|
1403
1266
|
if (cached) return cached;
|
|
1404
|
-
const domain = Array.from({ length }, (
|
|
1267
|
+
const domain = Array.from({ length }, (_value, index) => index + 1);
|
|
1405
1268
|
if (length > MAX_SHARED_INTERVAL_LENGTH) longIntervalDomains.set(length, new WeakRef(domain));
|
|
1406
1269
|
else intervalDomains[length] = domain;
|
|
1407
1270
|
return domain;
|
|
1408
1271
|
};
|
|
1409
1272
|
|
|
1410
|
-
// The caller only iterates the elements, so they need not record the interval for DOMAIN.
|
|
1411
1273
|
export const getIntervalElements = (value: IntervalValue): Value[] => {
|
|
1412
1274
|
getCardinality(value);
|
|
1413
1275
|
if (value.low === 1 && value.high >= 1) return getIntervalDomain(value.high);
|
|
@@ -1422,7 +1284,6 @@ const isIntervalDomain = (domain: Value[]) =>
|
|
|
1422
1284
|
domain === longIntervalDomains.get(domain.length)?.deref())) ||
|
|
1423
1285
|
intervalArrays.has(domain);
|
|
1424
1286
|
|
|
1425
|
-
// A set such as (1..2) \cap S, whose elements are the shared array, gets a copy.
|
|
1426
1287
|
export const getFunctionDomain = (set: Value): Value[] => {
|
|
1427
1288
|
const elements = toFiniteSet(set).elements;
|
|
1428
1289
|
return isIntervalDomain(elements) && !(typeof set === "object" && set.kind === "Interval")
|
|
@@ -1576,25 +1437,24 @@ const advanceCombination = (indices: number[], length: number) => {
|
|
|
1576
1437
|
return false;
|
|
1577
1438
|
};
|
|
1578
1439
|
|
|
1579
|
-
// TLC enumerates SUBSET S lazily, by size and then in the order of S, so a quantifier that
|
|
1580
|
-
// finds its witness early never builds the rest.
|
|
1581
1440
|
export const getLazySubsets = (value: Value): Value[] | undefined => {
|
|
1582
1441
|
if (typeof value !== "object" || value.kind !== "Subset" || isOverriddenSet(value.base)) {
|
|
1583
1442
|
return undefined;
|
|
1584
1443
|
}
|
|
1585
1444
|
const base = toFiniteSet(value.base).elements;
|
|
1586
1445
|
if (base.length <= MAXIMUM_BUILT_SUBSET_BASE) return undefined;
|
|
1587
|
-
|
|
1446
|
+
let cursorIndex = -1;
|
|
1447
|
+
let indices = [0];
|
|
1588
1448
|
const getSubset = (index: number) => {
|
|
1589
|
-
if (index <=
|
|
1590
|
-
while (
|
|
1591
|
-
if (
|
|
1592
|
-
else if (!advanceCombination(
|
|
1593
|
-
|
|
1449
|
+
if (index <= cursorIndex) cursorIndex = -1;
|
|
1450
|
+
while (cursorIndex < index) {
|
|
1451
|
+
if (cursorIndex === -1) indices = [];
|
|
1452
|
+
else if (!advanceCombination(indices, base.length)) {
|
|
1453
|
+
indices = Array.from({ length: indices.length + 1 }, (_value, position) => position);
|
|
1594
1454
|
}
|
|
1595
|
-
|
|
1455
|
+
cursorIndex++;
|
|
1596
1456
|
}
|
|
1597
|
-
return createSortedSet(
|
|
1457
|
+
return createSortedSet(indices.map((baseIndex) => base[baseIndex]));
|
|
1598
1458
|
};
|
|
1599
1459
|
const length = 2 ** base.length;
|
|
1600
1460
|
const isIndex = (property: string | symbol) =>
|
|
@@ -1613,7 +1473,7 @@ export const getLazySubsets = (value: Value): Value[] | undefined => {
|
|
|
1613
1473
|
const getSortedSubsets = (base: Value[]) => {
|
|
1614
1474
|
const subsets: Value[] = [];
|
|
1615
1475
|
for (let size = 0; size <= base.length; size++) {
|
|
1616
|
-
const indices = Array.from({ length: size }, (
|
|
1476
|
+
const indices = Array.from({ length: size }, (_value, index) => index);
|
|
1617
1477
|
do {
|
|
1618
1478
|
subsets.push(createSortedSet(indices.map((index) => base[index])));
|
|
1619
1479
|
} while (advanceCombination(indices, base.length));
|
|
@@ -1621,8 +1481,6 @@ const getSortedSubsets = (base: Value[]) => {
|
|
|
1621
1481
|
return subsets;
|
|
1622
1482
|
};
|
|
1623
1483
|
|
|
1624
|
-
// TLC enumerates the sets in turn and stops at the first empty one. Later versions decide
|
|
1625
|
-
// that the set is empty before they enumerate it.
|
|
1626
1484
|
const getComponentElements = (
|
|
1627
1485
|
sets: Value[],
|
|
1628
1486
|
getElements: (set: Value) => Value[],
|
|
@@ -1656,7 +1514,6 @@ const enumerateSet = (
|
|
|
1656
1514
|
return elements;
|
|
1657
1515
|
}
|
|
1658
1516
|
case "Subset": {
|
|
1659
|
-
// TLC sizes the set before it enumerates it, and enumerates a set of size 0 as {{}}.
|
|
1660
1517
|
if (getCardinality(value.base) === 0) return getSortedSubsets([]);
|
|
1661
1518
|
if (!isSetValue(value.base)) {
|
|
1662
1519
|
throw new TlaEvaluationError(
|
|
@@ -1670,15 +1527,14 @@ const enumerateSet = (
|
|
|
1670
1527
|
return getSortedSubsets(base);
|
|
1671
1528
|
}
|
|
1672
1529
|
case "FunctionSet": {
|
|
1673
|
-
if (!
|
|
1530
|
+
if (!isVersion174 && isEmptySet(value)) return [];
|
|
1674
1531
|
if (isOverriddenSet(value.domain)) {
|
|
1675
1532
|
throw new TlaEvaluationError(
|
|
1676
1533
|
`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${formatValue(value.domain)}\ncannot be enumerated.`,
|
|
1677
1534
|
);
|
|
1678
1535
|
}
|
|
1679
1536
|
const domain = getFunctionDomain(value.domain);
|
|
1680
|
-
|
|
1681
|
-
if ((domain.length > 0 || valueVersion.is174) && isOverriddenSet(value.range)) {
|
|
1537
|
+
if ((domain.length > 0 || isVersion174) && isOverriddenSet(value.range)) {
|
|
1682
1538
|
throw new TlaEvaluationError(
|
|
1683
1539
|
`Attempted to enumerate a set of the form [D -> R],but the range R:\n${formatValue(value.range)}\ncannot be enumerated.`,
|
|
1684
1540
|
);
|
|
@@ -1689,7 +1545,7 @@ const enumerateSet = (
|
|
|
1689
1545
|
);
|
|
1690
1546
|
}
|
|
1691
1547
|
case "RecordSet": {
|
|
1692
|
-
if (!
|
|
1548
|
+
if (!isVersion174 && isEmptySet(value)) return [];
|
|
1693
1549
|
const fields = getComponentElements(
|
|
1694
1550
|
value.sets,
|
|
1695
1551
|
getElements,
|
|
@@ -1701,7 +1557,7 @@ const enumerateSet = (
|
|
|
1701
1557
|
);
|
|
1702
1558
|
}
|
|
1703
1559
|
case "ProductSet": {
|
|
1704
|
-
if (!
|
|
1560
|
+
if (!isVersion174 && isEmptySet(value)) return [];
|
|
1705
1561
|
const factors = getComponentElements(
|
|
1706
1562
|
value.factors,
|
|
1707
1563
|
getElements,
|
|
@@ -1799,8 +1655,6 @@ export const toFiniteSet = (value: Value): SetValue => {
|
|
|
1799
1655
|
return set;
|
|
1800
1656
|
};
|
|
1801
1657
|
|
|
1802
|
-
// TLC's enumerator of a set sorts the set enumerations it streams, and fails on a set it can't
|
|
1803
|
-
// enumerate, before it yields an element, so S \cup T fails on T before it streams S.
|
|
1804
1658
|
const openStream = (value: Value): void => {
|
|
1805
1659
|
if (typeof value !== "object" || isCachedSet(value)) return;
|
|
1806
1660
|
switch (value.kind) {
|
|
@@ -1849,8 +1703,6 @@ const listUnionLikeTlc = (union: SetOperationValue) => {
|
|
|
1849
1703
|
return [...left, ...right];
|
|
1850
1704
|
};
|
|
1851
1705
|
|
|
1852
|
-
// EnumerableValue#elements(NORMALIZED) sorts a union outside its methods, so a failed comparison
|
|
1853
|
-
// isn't a fingerprint failure.
|
|
1854
1706
|
export const getNormalizedSetElements = (value: Value) => {
|
|
1855
1707
|
if (
|
|
1856
1708
|
typeof value !== "object" ||
|
|
@@ -1866,8 +1718,6 @@ export const getNormalizedSetElements = (value: Value) => {
|
|
|
1866
1718
|
return elements;
|
|
1867
1719
|
};
|
|
1868
1720
|
|
|
1869
|
-
// TLC streams the sets a lazy set combines until it caches it, so a shared element repeats. Like
|
|
1870
|
-
// its enumerators, the stream stops at the first element visit accepts.
|
|
1871
1721
|
export const someStreamedElement = (value: Value, visit: (element: Value) => boolean): boolean => {
|
|
1872
1722
|
if (typeof value !== "object" || isCachedSet(value)) {
|
|
1873
1723
|
return toFiniteSet(value).elements.some(visit);
|
|
@@ -1875,7 +1725,6 @@ export const someStreamedElement = (value: Value, visit: (element: Value) => boo
|
|
|
1875
1725
|
const sets = setTrace.sets;
|
|
1876
1726
|
sets?.push(value);
|
|
1877
1727
|
openStream(value);
|
|
1878
|
-
// The set is enumerated only while it computes an element, not while visit looks at one.
|
|
1879
1728
|
const isFound = someElementOfStream(value, (element) => {
|
|
1880
1729
|
sets?.pop();
|
|
1881
1730
|
const isAccepted = visit(element);
|
|
@@ -1904,9 +1753,6 @@ const getCombinedSets = (value: ObjectValue) =>
|
|
|
1904
1753
|
? [value.range]
|
|
1905
1754
|
: undefined;
|
|
1906
1755
|
|
|
1907
|
-
// Whether one evaluation can stand for the next: no UNION or \cup, which streams until TLC
|
|
1908
|
-
// caches it, no lambda, which fingerprinting turns into a record, and no record a
|
|
1909
|
-
// comparison reorders.
|
|
1910
1756
|
export const isSettledValue = (value: Value): boolean => {
|
|
1911
1757
|
if (typeof value !== "object") return true;
|
|
1912
1758
|
switch (value.kind) {
|
|
@@ -1935,7 +1781,6 @@ export const isSettledValue = (value: Value): boolean => {
|
|
|
1935
1781
|
}
|
|
1936
1782
|
};
|
|
1937
1783
|
|
|
1938
|
-
// A set of tuples, records, or functions with such a component has to stream too.
|
|
1939
1784
|
const isStreamedApart = (value: Value): boolean => {
|
|
1940
1785
|
if (typeof value !== "object" || isCachedSet(value)) return false;
|
|
1941
1786
|
if (value.kind === "Union") return true;
|
|
@@ -1949,7 +1794,6 @@ const isStreamedApart = (value: Value): boolean => {
|
|
|
1949
1794
|
};
|
|
1950
1795
|
|
|
1951
1796
|
const someElementOfStream = (value: ObjectValue, visit: (element: Value) => boolean): boolean => {
|
|
1952
|
-
// TLC streams the sets of a UNION it hasn't enumerated, so a repeated set yields them twice.
|
|
1953
1797
|
if (value.kind === "Union") {
|
|
1954
1798
|
return getUnionSets(value, getStreamedElements).some((set, index) =>
|
|
1955
1799
|
someStreamedElement(getUnionSet(set, index, value), visit),
|
|
@@ -2026,7 +1870,6 @@ const getProductCardinality = (
|
|
|
2026
1870
|
const describeOverflow = (value: Value) =>
|
|
2027
1871
|
`Overflow when computing the number of elements in:\n${formatValue(value)}`;
|
|
2028
1872
|
|
|
2029
|
-
// TLC 1.7.4 sizes every component without checking for an empty one, so an infinite one fails.
|
|
2030
1873
|
export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
2031
1874
|
if (typeof value !== "object") {
|
|
2032
1875
|
throw new TlaEvaluationError(
|
|
@@ -2070,12 +1913,12 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
2070
1913
|
const domainSize = getCardinality(value.domain, version);
|
|
2071
1914
|
const rangeSize = getCardinality(value.range, version);
|
|
2072
1915
|
if (rangeSize <= 1) return domainSize === 0 ? 1 : rangeSize;
|
|
2073
|
-
|
|
1916
|
+
let size = 1;
|
|
2074
1917
|
for (let index = 0; index < domainSize; index++) {
|
|
2075
|
-
size
|
|
2076
|
-
if (size
|
|
1918
|
+
size *= rangeSize;
|
|
1919
|
+
if (size > MAXIMUM_INTEGER) throw new TlaEvaluationError(describeOverflow(value));
|
|
2077
1920
|
}
|
|
2078
|
-
return size
|
|
1921
|
+
return size;
|
|
2079
1922
|
}
|
|
2080
1923
|
case "RecordSet":
|
|
2081
1924
|
if (version !== "1.7.4" && isEmptySet(value)) return 0;
|
|
@@ -2128,12 +1971,12 @@ export const isFiniteSet = (value: Value): boolean => {
|
|
|
2128
1971
|
case "RecordSet":
|
|
2129
1972
|
case "ProductSet": {
|
|
2130
1973
|
const parts = value.kind === "RecordSet" ? value.sets : value.factors;
|
|
2131
|
-
|
|
1974
|
+
let isAllFinite = true;
|
|
2132
1975
|
for (const part of parts) {
|
|
2133
|
-
if (!isFiniteSet(part))
|
|
1976
|
+
if (!isFiniteSet(part)) isAllFinite = false;
|
|
2134
1977
|
else if (isEmptySet(part)) return true;
|
|
2135
1978
|
}
|
|
2136
|
-
return
|
|
1979
|
+
return isAllFinite;
|
|
2137
1980
|
}
|
|
2138
1981
|
case "Union":
|
|
2139
1982
|
if (!isTlcEnumerable(value.base)) {
|
|
@@ -2164,18 +2007,18 @@ export const isFiniteSet = (value: Value): boolean => {
|
|
|
2164
2007
|
};
|
|
2165
2008
|
|
|
2166
2009
|
const findSortedIndex = (sortedValues: Value[], target: Value, compare = compareValues) => {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2010
|
+
let low = 0;
|
|
2011
|
+
let high = sortedValues.length - 1;
|
|
2012
|
+
while (low <= high) {
|
|
2013
|
+
const middle = (low + high) >> 1;
|
|
2170
2014
|
const comparison = compare(sortedValues[middle], target);
|
|
2171
2015
|
if (comparison === 0) return middle;
|
|
2172
|
-
if (comparison < 0)
|
|
2173
|
-
else
|
|
2016
|
+
if (comparison < 0) low = middle + 1;
|
|
2017
|
+
else high = middle - 1;
|
|
2174
2018
|
}
|
|
2175
2019
|
return -1;
|
|
2176
2020
|
};
|
|
2177
2021
|
|
|
2178
|
-
// A sorted set as TLC builds it unsorted, by adding each element it doesn't hold yet.
|
|
2179
2022
|
export const createUnsortedCopy = (set: SetValue, added: Value[]): SetValue => {
|
|
2180
2023
|
const elements = set.elements;
|
|
2181
2024
|
if (elements.length > getMaximumSetSize()) throw new TlaSetBoundError(getSetBoundMessage());
|
|
@@ -2227,14 +2070,10 @@ interface TracedCallStack {
|
|
|
2227
2070
|
fingerprint?: unknown;
|
|
2228
2071
|
}
|
|
2229
2072
|
|
|
2230
|
-
// The values being checked or enumerated, outermost first, as TLC's CallStackTool replays a
|
|
2231
|
-
// computation. TLC adds each one with a source to the FingerprintException.
|
|
2232
2073
|
export const setTrace: { sets: Value[] | undefined; callStack?: TracedCallStack } = {
|
|
2233
2074
|
sets: undefined,
|
|
2234
2075
|
};
|
|
2235
2076
|
|
|
2236
|
-
// TLC never takes the fast path, so the failure's leftovers in the replay's trace go first.
|
|
2237
|
-
// The operands are arguments so that a hot caller passes functions it doesn't allocate.
|
|
2238
2077
|
export const computeLikeTlcOnFailure = <Left, Right, Result>(
|
|
2239
2078
|
compute: (left: Left, right: Right) => Result,
|
|
2240
2079
|
computeLikeTlc: (left: Left, right: Right, error: TlaEvaluationError) => Result,
|
|
@@ -2273,17 +2112,17 @@ export const isElementOf = (element: Value, set: Value): boolean => {
|
|
|
2273
2112
|
return isElement;
|
|
2274
2113
|
};
|
|
2275
2114
|
|
|
2276
|
-
// Integers compare by subtraction, so a search that meets only integers needs no other comparison.
|
|
2277
2115
|
const isIntegerInSortedSet = (element: number, set: SetValue) => {
|
|
2278
2116
|
const elements = set.elements;
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2117
|
+
let low = 0;
|
|
2118
|
+
let high = elements.length - 1;
|
|
2119
|
+
while (low <= high) {
|
|
2120
|
+
const middle = (low + high) >> 1;
|
|
2282
2121
|
const probe = elements[middle];
|
|
2283
2122
|
if (typeof probe !== "number") return undefined;
|
|
2284
2123
|
if (probe === element) return true;
|
|
2285
|
-
if (probe < element)
|
|
2286
|
-
else
|
|
2124
|
+
if (probe < element) low = middle + 1;
|
|
2125
|
+
else high = middle - 1;
|
|
2287
2126
|
}
|
|
2288
2127
|
return false;
|
|
2289
2128
|
};
|
|
@@ -2319,7 +2158,6 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2319
2158
|
if (!isSetValue(set)) throw new TlaEvaluationError(describeNonSetMembership(element, set));
|
|
2320
2159
|
switch (set.kind) {
|
|
2321
2160
|
case "Set":
|
|
2322
|
-
// TLC compares the element with the set's.
|
|
2323
2161
|
cacheSet(element);
|
|
2324
2162
|
return computeLikeTlcOnFailure(isInSortedSet, isInSortedSetLikeTlc, element, set);
|
|
2325
2163
|
case "MixedSet":
|
|
@@ -2345,7 +2183,6 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2345
2183
|
return set.name !== "Nat" || (typeof element === "number" && element >= 0);
|
|
2346
2184
|
}
|
|
2347
2185
|
case "Subset":
|
|
2348
|
-
// TLC fails on a value that isn't Enumerable, model values and Java-overridden sets included.
|
|
2349
2186
|
if (!isSetValue(element) || isOverriddenSet(element)) {
|
|
2350
2187
|
throw new TlaEvaluationError(
|
|
2351
2188
|
`Attempted to check if the non-enumerable value\n${prettyPrint(formatValue(element))}\nis element of\n${prettyPrint(formatValue(set))}`,
|
|
@@ -2355,7 +2192,6 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2355
2192
|
case "FunctionSet": {
|
|
2356
2193
|
if (!isFunctionValue(element)) {
|
|
2357
2194
|
if (isModelValue(element)) return isModelValueMember(element, set);
|
|
2358
|
-
// TLC prints the element without Values.ppr.
|
|
2359
2195
|
throw new TlaEvaluationError(
|
|
2360
2196
|
`Attempted to check if \n${formatValue(element)}\nwhich is not a TLC function value, is in the set of functions:\n${prettyPrint(formatValue(set))}`,
|
|
2361
2197
|
);
|
|
@@ -2420,7 +2256,6 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2420
2256
|
);
|
|
2421
2257
|
}
|
|
2422
2258
|
const sets = toFiniteSet(set.base).elements;
|
|
2423
|
-
// TLC sorts the sets to enumerate them, and comparing two sets normalizes both.
|
|
2424
2259
|
if (sets.length > 1) {
|
|
2425
2260
|
sets.forEach((inner) => {
|
|
2426
2261
|
if (typeof inner === "object" && inner.kind === "Set") inner.isNormalized = true;
|
|
@@ -2439,7 +2274,6 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2439
2274
|
const elements = getSequenceElements(element);
|
|
2440
2275
|
if (elements === undefined) {
|
|
2441
2276
|
if (isModelValue(element)) return isModelValueMember(element, set);
|
|
2442
|
-
// TLC raises TLC_MODULE_CHECK_MEMBER_OF.
|
|
2443
2277
|
throw new TlaModuleError(
|
|
2444
2278
|
`Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of ${prettyPrint(formatValue(set))}.`,
|
|
2445
2279
|
);
|
|
@@ -2523,16 +2357,14 @@ export const describeMissingArgument = (
|
|
|
2523
2357
|
}
|
|
2524
2358
|
};
|
|
2525
2359
|
|
|
2526
|
-
// TLC 1.7.4 words a key of the wrong type in an EXCEPT, which selects rather than applies, apart.
|
|
2527
2360
|
const describeExceptKey = (functionValue: FunctionValue, argument: Value) => {
|
|
2528
|
-
if (!
|
|
2361
|
+
if (!isVersion174) return describeMissingArgument(functionValue, argument);
|
|
2529
2362
|
const shown = prettyPrint(formatValue(argument));
|
|
2530
2363
|
return getFunctionClass(functionValue) === "tuple"
|
|
2531
2364
|
? `Attempted to apply tuple to a non-integer argument ${shown}.`
|
|
2532
2365
|
: `Attempted to apply record to a non-string argument ${shown}.`;
|
|
2533
2366
|
};
|
|
2534
2367
|
|
|
2535
|
-
// A key the domain holds itself, which TLC finds without a comparison that can fail.
|
|
2536
2368
|
const findIdenticalKey = (domain: Value[], argument: Value) => {
|
|
2537
2369
|
const first = domain[0];
|
|
2538
2370
|
if (typeof argument === "number" && typeof first === "number") {
|
|
@@ -2547,20 +2379,18 @@ export const createNonIntegerKeyError = (argument: Value) =>
|
|
|
2547
2379
|
`Attempted to apply function with integer domain to the non-integer argument ${prettyPrint(formatValue(argument))}`,
|
|
2548
2380
|
);
|
|
2549
2381
|
|
|
2550
|
-
// TLC searches a domain this small linearly with equals, and a larger one with compareTo.
|
|
2551
2382
|
const LINEAR_SEARCH_LIMIT = 32;
|
|
2552
2383
|
|
|
2553
2384
|
const findDomainIndex = (functionValue: FunctionValue, argument: Value) =>
|
|
2554
2385
|
findSortedIndex(functionValue.domain, argument);
|
|
2555
2386
|
|
|
2556
|
-
// TLC searches a function it hasn't normalized linearly, in the order its keys were written.
|
|
2557
2387
|
const failKeyLikeTlc = (
|
|
2558
2388
|
functionValue: FunctionValue,
|
|
2559
2389
|
argument: Value,
|
|
2560
2390
|
error: TlaEvaluationError,
|
|
2561
2391
|
): never => {
|
|
2562
2392
|
const keys = getWrittenKeys(functionValue);
|
|
2563
|
-
if (
|
|
2393
|
+
if (isVersion174 || keys !== functionValue.domain || keys.length < LINEAR_SEARCH_LIMIT) {
|
|
2564
2394
|
keys.forEach((key) => equalsLikeTlc(key, argument));
|
|
2565
2395
|
} else {
|
|
2566
2396
|
findSortedIndex(keys, argument, compareLikeTlc);
|
|
@@ -2568,8 +2398,6 @@ const failKeyLikeTlc = (
|
|
|
2568
2398
|
throw error;
|
|
2569
2399
|
};
|
|
2570
2400
|
|
|
2571
|
-
// A tuple or a record rejects a key of the wrong type, and another function a non-integer for
|
|
2572
|
-
// an interval domain, which TLC 1.7.4 doesn't. Any other key type fails TLC's comparison.
|
|
2573
2401
|
const findKeyIndexLikeTlc = (
|
|
2574
2402
|
functionValue: FunctionValue,
|
|
2575
2403
|
argument: Value,
|
|
@@ -2585,7 +2413,7 @@ const findKeyIndexLikeTlc = (
|
|
|
2585
2413
|
}
|
|
2586
2414
|
if (
|
|
2587
2415
|
keyType === undefined &&
|
|
2588
|
-
!
|
|
2416
|
+
!isVersion174 &&
|
|
2589
2417
|
typeof argument !== "number" &&
|
|
2590
2418
|
isIntervalDomain(domain)
|
|
2591
2419
|
) {
|
|
@@ -2597,8 +2425,7 @@ const findKeyIndexLikeTlc = (
|
|
|
2597
2425
|
return computeLikeTlcOnFailure(findDomainIndex, failKeyLikeTlc, functionValue, argument);
|
|
2598
2426
|
};
|
|
2599
2427
|
|
|
2600
|
-
// TLC
|
|
2601
|
-
// argument tuple shorter than the bounds and ignores one longer, where this rejects the list.
|
|
2428
|
+
// Deviation from TLC: FcnLambdaValue#apply indexes past an argument tuple shorter than the bounds and ignores a longer one, where this rejects the list.
|
|
2602
2429
|
const checkBoundArguments = (
|
|
2603
2430
|
functionValue: LazyFunctionValue,
|
|
2604
2431
|
tupleLengths: (number | undefined)[],
|
|
@@ -2642,8 +2469,6 @@ const checkBoundArguments = (
|
|
|
2642
2469
|
if (elements.length > tupleLengths.length) throw createListError();
|
|
2643
2470
|
};
|
|
2644
2471
|
|
|
2645
|
-
// TLC checks that a FcnLambdaValue's domain holds the argument, and searches only the FcnRcdValue
|
|
2646
|
-
// it converts the lambda to when it fingerprints it.
|
|
2647
2472
|
const isOutsideLambdaDomain = (functionValue: FunctionValue, argument: Value) =>
|
|
2648
2473
|
functionValue.lambdaDomain !== undefined &&
|
|
2649
2474
|
functionValue.hash === 0 &&
|
|
@@ -2700,7 +2525,6 @@ export const getDomain = (functionValue: Value): Value => {
|
|
|
2700
2525
|
const interval = getDomainInterval(finite.domain);
|
|
2701
2526
|
if (interval) return interval;
|
|
2702
2527
|
const set = createSortedSet(finite.domain);
|
|
2703
|
-
// TLC keeps a record's domain in written order and sorts any other function's.
|
|
2704
2528
|
if (finite.functionClass === "record") {
|
|
2705
2529
|
if (finite.writtenKeys) set.writtenElements = finite.writtenKeys;
|
|
2706
2530
|
return set;
|
|
@@ -2804,8 +2628,6 @@ const getElementContribution = (elementHash: number) =>
|
|
|
2804
2628
|
const getEntryContribution = (keyHash: number, valueHash: number) =>
|
|
2805
2629
|
finalizeHash((Math.imul(keyHash, 0x27d4eb2d) + valueHash) | 0);
|
|
2806
2630
|
|
|
2807
|
-
// The hash of a value TLC fails to fingerprint, such as Nat. Calls with one as an argument still
|
|
2808
|
-
// share their result, and a state that holds one fails when TLC fingerprints it.
|
|
2809
2631
|
const UNFINGERPRINTABLE_HASH = 0x2f6b1c4d;
|
|
2810
2632
|
|
|
2811
2633
|
const computeValueHash = (value: SetValue | FunctionValue) => {
|
|
@@ -2831,7 +2653,6 @@ const computeValueHash = (value: SetValue | FunctionValue) => {
|
|
|
2831
2653
|
return hash;
|
|
2832
2654
|
};
|
|
2833
2655
|
|
|
2834
|
-
// TLC enumerates each set and function, and fails on Nat, Seq(S) and the like.
|
|
2835
2656
|
const fingerprintValue = (value: Value): void => {
|
|
2836
2657
|
if (typeof value !== "object" || value.kind === "ModelValue") return;
|
|
2837
2658
|
if (value.kind === "InfiniteSet" || value.kind === "SequenceSet") {
|
|
@@ -2848,7 +2669,6 @@ const fingerprintValue = (value: Value): void => {
|
|
|
2848
2669
|
functionValue.range.forEach(fingerprintValue);
|
|
2849
2670
|
};
|
|
2850
2671
|
|
|
2851
|
-
// Hashing can fail, as for a set too large to enumerate, and so can a value TLC fails on.
|
|
2852
2672
|
export const getFingerprintError = (value: Value) => {
|
|
2853
2673
|
if (typeof value !== "object" || value.kind === "ModelValue") return undefined;
|
|
2854
2674
|
try {
|
|
@@ -2992,14 +2812,7 @@ const PRINTED_ESCAPES: Record<string, string> = {
|
|
|
2992
2812
|
const formatString = (value: string) =>
|
|
2993
2813
|
`"${value.replace(/["\\\t\n\f\r]/g, (character) => PRINTED_ESCAPES[character])}"`;
|
|
2994
2814
|
|
|
2995
|
-
type LazySetValue =
|
|
2996
|
-
| SubsetValue
|
|
2997
|
-
| FunctionSetValue
|
|
2998
|
-
| RecordSetValue
|
|
2999
|
-
| ProductSetValue
|
|
3000
|
-
| SetOperationValue
|
|
3001
|
-
| FilteredSetValue
|
|
3002
|
-
| UnionValue;
|
|
2815
|
+
type LazySetValue = Exclude<ConvertibleSetValue, MixedSetValue | SequenceSetValue>;
|
|
3003
2816
|
|
|
3004
2817
|
const MAXIMUM_EXPANDED_SUBSET_BASE = 6;
|
|
3005
2818
|
const MAXIMUM_EXPANDED_PRODUCT = 1999;
|
|
@@ -3016,7 +2829,6 @@ const expandLazySet = (value: LazySetValue) => {
|
|
|
3016
2829
|
if (value.kind === "SetOperation" || value.kind === "FilteredSet" || value.kind === "Union") {
|
|
3017
2830
|
return toFiniteSet(value);
|
|
3018
2831
|
}
|
|
3019
|
-
// TLC asks whether the domain is empty before it sizes it.
|
|
3020
2832
|
if (value.kind === "FunctionSet") {
|
|
3021
2833
|
const domainSize = isEmptySet(value.domain) ? 0 : getCardinality(value.domain);
|
|
3022
2834
|
const size = domainSize === 0 ? 1 : getCardinality(value.range) ** domainSize;
|
|
@@ -3027,9 +2839,7 @@ const expandLazySet = (value: LazySetValue) => {
|
|
|
3027
2839
|
};
|
|
3028
2840
|
|
|
3029
2841
|
const getExpandedLazySet = (value: LazySetValue, isStrict: boolean) => {
|
|
3030
|
-
// UnionValue alone of TLC's lazy sets doesn't swallow the failure to enumerate itself.
|
|
3031
2842
|
if (isStrict || value.kind === "Union") return expandLazySet(value);
|
|
3032
|
-
// TLC sizes the base of SUBSET before it enumerates it, and only a failure to size it is quiet.
|
|
3033
2843
|
if (
|
|
3034
2844
|
value.kind === "Subset" &&
|
|
3035
2845
|
isFunctionValue(value.base) &&
|
|
@@ -3037,7 +2847,6 @@ const getExpandedLazySet = (value: LazySetValue, isStrict: boolean) => {
|
|
|
3037
2847
|
) {
|
|
3038
2848
|
return expandLazySet(value);
|
|
3039
2849
|
}
|
|
3040
|
-
// TLC prints a set it can't enumerate symbolically, except in Print, PrintT, and ToString.
|
|
3041
2850
|
if (!isEnumerable(value)) return undefined;
|
|
3042
2851
|
try {
|
|
3043
2852
|
return expandLazySet(value);
|
|
@@ -3071,7 +2880,6 @@ const formatLazySet = (value: LazySetValue, isStrict: boolean): string => {
|
|
|
3071
2880
|
}
|
|
3072
2881
|
};
|
|
3073
2882
|
|
|
3074
|
-
// TLC prints a record when every key is letters, digits, and underscores, with a letter.
|
|
3075
2883
|
const isFieldName = (name: string) =>
|
|
3076
2884
|
/^[\p{L}\p{Nd}_]*$/u.test(name) &&
|
|
3077
2885
|
/\p{L}/u.test(name) &&
|
|
@@ -3087,7 +2895,6 @@ const toPrintedFunction = (value: LazyFunctionValue) => {
|
|
|
3087
2895
|
}
|
|
3088
2896
|
};
|
|
3089
2897
|
|
|
3090
|
-
// TLC prints normalized copies, so the printed values themselves stay unnormalized.
|
|
3091
2898
|
export const formatNormalizedCopies = (values: Value[]) => {
|
|
3092
2899
|
const markedSets: SetValue[] = [];
|
|
3093
2900
|
const normalize = (value: Value): void => {
|
|
@@ -3190,12 +2997,11 @@ export const formatValue = (value: Value, isStrict = false, isNormalized = false
|
|
|
3190
2997
|
}
|
|
3191
2998
|
if (
|
|
3192
2999
|
functionValue.domain.length === 0 &&
|
|
3193
|
-
|
|
3000
|
+
isVersion174 &&
|
|
3194
3001
|
getFunctionClass(value) !== "tuple"
|
|
3195
3002
|
) {
|
|
3196
3003
|
return "<< >>";
|
|
3197
3004
|
}
|
|
3198
|
-
// TLC normalizes a lambda's domain to print it, but evaluates its body afterward.
|
|
3199
3005
|
const formatRange = (inner: Value) =>
|
|
3200
3006
|
formatValue(inner, isStrict, isNormalized && getFunctionClass(value) !== "lambda");
|
|
3201
3007
|
if (functionValue.domain.length === 0 && getFunctionClass(value) === "record") return "[]";
|
|
@@ -3205,7 +3011,6 @@ export const formatValue = (value: Value, isStrict = false, isNormalized = false
|
|
|
3205
3011
|
const pairs = isNormalized
|
|
3206
3012
|
? functionValue.domain.map((key, index) => [key, functionValue.range[index]])
|
|
3207
3013
|
: getPrintedPairs(functionValue);
|
|
3208
|
-
// A RecordValue always prints as a record, a FcnRcdValue only if its keys are names.
|
|
3209
3014
|
if (
|
|
3210
3015
|
getFunctionClass(value) === "record" ||
|
|
3211
3016
|
functionValue.domain.every((key) => typeof key === "string" && isFieldName(key))
|
|
@@ -3217,7 +3022,6 @@ export const formatValue = (value: Value, isStrict = false, isNormalized = false
|
|
|
3217
3022
|
}
|
|
3218
3023
|
};
|
|
3219
3024
|
|
|
3220
|
-
// TLC counts a value it can't compare with the previous one as changed.
|
|
3221
3025
|
const isUnchanged = (previous: Value | undefined, value: Value) => {
|
|
3222
3026
|
if (previous === undefined) return false;
|
|
3223
3027
|
try {
|
|
@@ -3230,15 +3034,10 @@ const isUnchanged = (previous: Value | undefined, value: Value) => {
|
|
|
3230
3034
|
|
|
3231
3035
|
const JAVA_FORMAT_SPECIFIER = /%(\d+\$)?([-#+ 0,(<]*)(\d+)?(\.\d+)?(.?)/gs;
|
|
3232
3036
|
|
|
3233
|
-
const getJavaHashCode = (text: string) =>
|
|
3234
|
-
Array.from({ length: text.length }, (_, index) => text.charCodeAt(index)).reduce(
|
|
3235
|
-
(hash, unit) => (Math.imul(hash, 31) + unit) | 0,
|
|
3236
|
-
0,
|
|
3237
|
-
);
|
|
3238
|
-
|
|
3239
3037
|
const formatJava = (format: string, args: string[]) => {
|
|
3240
|
-
|
|
3241
|
-
|
|
3038
|
+
let nextIndex = 0;
|
|
3039
|
+
let lastIndex = -1;
|
|
3040
|
+
let isFitting = true;
|
|
3242
3041
|
const text = format.replace(
|
|
3243
3042
|
JAVA_FORMAT_SPECIFIER,
|
|
3244
3043
|
(match, explicit?: string, flags = "", width?: string, precision?: string, conversion = "") => {
|
|
@@ -3248,15 +3047,15 @@ const formatJava = (format: string, args: string[]) => {
|
|
|
3248
3047
|
const otherFlags = flags.replace("<", "");
|
|
3249
3048
|
if (conversion === "n" && match === "%n") return "\n";
|
|
3250
3049
|
if (conversion === "%" && precision === undefined && /^-?$/.test(otherFlags)) {
|
|
3251
|
-
if (otherFlags === "-" && width === undefined) isFitting
|
|
3050
|
+
if (otherFlags === "-" && width === undefined) isFitting = false;
|
|
3252
3051
|
return pad("%");
|
|
3253
3052
|
}
|
|
3254
3053
|
const index = isRelative
|
|
3255
|
-
?
|
|
3054
|
+
? lastIndex
|
|
3256
3055
|
: explicit === undefined
|
|
3257
|
-
?
|
|
3056
|
+
? nextIndex++
|
|
3258
3057
|
: Number(explicit.slice(0, -1)) - 1;
|
|
3259
|
-
|
|
3058
|
+
lastIndex = index;
|
|
3260
3059
|
const arg = args[index];
|
|
3261
3060
|
if (
|
|
3262
3061
|
!"sSbBhH".includes(conversion) ||
|
|
@@ -3265,7 +3064,7 @@ const formatJava = (format: string, args: string[]) => {
|
|
|
3265
3064
|
(otherFlags === "-" && width === undefined) ||
|
|
3266
3065
|
arg === undefined
|
|
3267
3066
|
) {
|
|
3268
|
-
isFitting
|
|
3067
|
+
isFitting = false;
|
|
3269
3068
|
return match;
|
|
3270
3069
|
}
|
|
3271
3070
|
const lower = conversion.toLowerCase();
|
|
@@ -3277,10 +3076,9 @@ const formatJava = (format: string, args: string[]) => {
|
|
|
3277
3076
|
return conversion === lower ? shown : shown.toUpperCase();
|
|
3278
3077
|
},
|
|
3279
3078
|
);
|
|
3280
|
-
return isFitting
|
|
3079
|
+
return isFitting ? text : undefined;
|
|
3281
3080
|
};
|
|
3282
3081
|
|
|
3283
|
-
// TLC prints the VIEW of a state, but not of one it prints as a difference from the previous.
|
|
3284
3082
|
export const formatState = (state: Record<string, Value>, previous?: Record<string, Value>) => {
|
|
3285
3083
|
const getViewText = previous ? undefined : viewTexts.get(state);
|
|
3286
3084
|
if (getViewText) return getViewText();
|