tla-ts 0.0.3 → 0.0.4-dev.2a873ee
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 +46 -115
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +194 -8
- package/dist/index.d.ts +194 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +996 -0
- package/dist/prove.js +996 -0
- package/dist/run-cli.cjs +37 -20
- package/dist/run-cli.js +37 -20
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +1387 -18
- package/dist/transfer.js +1387 -18
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +24 -11
- package/src/ast.ts +149 -8
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1540 -235
- package/src/cli-options.ts +12 -6
- package/src/cli.ts +8 -1
- package/src/codegen.ts +98 -39
- package/src/config.ts +254 -181
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +540 -140
- package/src/errors.ts +284 -4
- package/src/evaluate.ts +1043 -293
- package/src/exit-codes.ts +22 -43
- package/src/fingerprints.ts +46 -11
- package/src/index.ts +11 -0
- package/src/instances.ts +19 -16
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +191 -45
- package/src/lexer.ts +127 -30
- package/src/live-check.ts +867 -0
- package/src/liveness.ts +218 -572
- package/src/{obligation-action.ts → obligations/action.ts} +247 -69
- package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
- package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
- package/src/{obligations.ts → obligations/index.ts} +32 -16
- package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
- package/src/{obligation-module.ts → obligations/module.ts} +113 -121
- package/src/obligations/pickle.ts +98 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/{obligation-source.ts → obligations/source.ts} +156 -99
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/ocaml-marshal.ts +166 -0
- package/src/parallel-worker.ts +169 -224
- package/src/parallel.ts +140 -81
- package/src/parser.ts +456 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/prove/decide-pool.ts +95 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/first-order.ts +78 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +446 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +546 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +433 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +331 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +330 -0
- package/src/prove/isabelle/pure/name.ts +98 -0
- package/src/prove/isabelle/pure/net.ts +215 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +631 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +133 -0
- package/src/prove/isabelle/pure/simplifier.ts +106 -0
- package/src/prove/isabelle/pure/table.ts +201 -0
- package/src/prove/isabelle/pure/tactic.ts +168 -0
- package/src/prove/isabelle/pure/tactical.ts +264 -0
- package/src/prove/isabelle/pure/term-ord.ts +105 -0
- package/src/prove/isabelle/pure/term.ts +688 -0
- package/src/prove/isabelle/pure/thm.ts +783 -0
- package/src/prove/isabelle/pure/type.ts +121 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +508 -0
- package/src/prove/prep/defs.ts +33 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +529 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +22 -0
- package/src/prove/prove.ts +498 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +255 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +209 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +164 -0
- package/src/prove/smt/extensionality.ts +65 -0
- package/src/prove/smt/flatten.ts +112 -0
- package/src/prove/smt/format.ts +154 -0
- package/src/prove/smt/instances.ts +181 -0
- package/src/prove/smt/rewrite.ts +772 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +91 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +18 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +379 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +162 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1481 -426
- package/src/run-cli.ts +1483 -212
- package/src/runtime.ts +19 -1
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +42 -11
- package/src/standard-modules.ts +203 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +180 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +241 -110
- package/src/symmetry.ts +194 -54
- package/src/tableau.ts +54 -25
- package/src/tlapm-cache.ts +236 -0
- package/src/tlc-ext.ts +42 -29
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +52 -43
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +78 -10
- package/src/tlc-random.ts +84 -33
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +19 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +787 -190
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
package/src/tlc-module.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { TlaModuleError } from "./errors";
|
|
2
2
|
import { EXIT_STATUS } from "./exit-codes";
|
|
3
|
-
import type { Builtin } from "./evaluate";
|
|
3
|
+
import type { Builtin, Context } from "./evaluate";
|
|
4
4
|
import { prettyPrint } from "./pretty-print";
|
|
5
5
|
import {
|
|
6
6
|
defineConstant,
|
|
7
7
|
defineHigherOrderOperator,
|
|
8
|
+
defineLazyOperator,
|
|
8
9
|
defineOperator,
|
|
9
10
|
defineStateOperator,
|
|
10
11
|
getElements,
|
|
@@ -12,10 +13,12 @@ import {
|
|
|
12
13
|
getFunction,
|
|
13
14
|
getOperator,
|
|
14
15
|
getSequence,
|
|
16
|
+
getThunk,
|
|
15
17
|
getValue,
|
|
18
|
+
overrideWithJava,
|
|
16
19
|
} from "./builtins";
|
|
17
20
|
import { getNamedRegisters, NAMED_REGISTER_PREFIX, type CheckerRuntime } from "./runtime";
|
|
18
|
-
import { createActionRecord } from "./tlc-ext";
|
|
21
|
+
import { createActionRecord, setTlcValue } from "./tlc-ext";
|
|
19
22
|
import { getRandomElement } from "./tlc-random";
|
|
20
23
|
import {
|
|
21
24
|
ANY_SET,
|
|
@@ -39,11 +42,22 @@ const formatCalendarVersion = (date: Date) =>
|
|
|
39
42
|
const getRegisterFunction = <Key extends Value>(registers: Map<Key, Value>) =>
|
|
40
43
|
createFunction([...registers].map(([key, value]): [Value, Value] => [key, createTuple([value])]));
|
|
41
44
|
|
|
45
|
+
// TLC creates its model checker after it processes the spec, so these are undefined before then.
|
|
46
|
+
const CHECKER_KEYS = new Set(["diameter", "generated", "distinct", "queue", "stats", "config"]);
|
|
47
|
+
// The keys of TLC 1.7.4's TLCGet, and those it can't read before it creates its model checker.
|
|
48
|
+
const TLC_174_KEYS = new Set(["diameter", "distinct", "queue", "duration", "level"]);
|
|
49
|
+
const CHECKER_KEYS_174 = new Set(["diameter", "distinct", "queue", "level"]);
|
|
50
|
+
|
|
42
51
|
const getRuntimeValue = (
|
|
43
52
|
runtime: CheckerRuntime,
|
|
44
53
|
key: string,
|
|
45
54
|
state: (Value | undefined)[] | undefined,
|
|
46
55
|
) => {
|
|
56
|
+
const isUndefined =
|
|
57
|
+
runtime.version === "1.7.4"
|
|
58
|
+
? !TLC_174_KEYS.has(key) || (!runtime.isStarted && CHECKER_KEYS_174.has(key))
|
|
59
|
+
: !runtime.isStarted && CHECKER_KEYS.has(key);
|
|
60
|
+
if (isUndefined) throw new TlaModuleError(`TLCGet(${key}) was undefined.`);
|
|
47
61
|
const duration = Math.floor((Date.now() - runtime.startedAt) / 1000);
|
|
48
62
|
switch (key) {
|
|
49
63
|
case "level":
|
|
@@ -105,6 +119,20 @@ const getRuntimeValue = (
|
|
|
105
119
|
throw new TlaModuleError(`TLCGet(${key}) was undefined.`);
|
|
106
120
|
};
|
|
107
121
|
|
|
122
|
+
const getTlcValue = (runtime: CheckerRuntime, key: Value, context: Context | undefined) => {
|
|
123
|
+
if (typeof key === "number" && key >= 0) {
|
|
124
|
+
const value = runtime.registers.get(key);
|
|
125
|
+
if (value === undefined) throw new TlaModuleError(`TLCGet(${key}) was undefined.`);
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
if (typeof key !== "string") {
|
|
129
|
+
throw new TlaModuleError(
|
|
130
|
+
`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return getRuntimeValue(runtime, key, context?.state);
|
|
134
|
+
};
|
|
135
|
+
|
|
108
136
|
const getPermutations = (elements: Value[]): Value[][] =>
|
|
109
137
|
elements.length === 0
|
|
110
138
|
? [[]]
|
|
@@ -187,49 +215,30 @@ export const createTlcOperators = (
|
|
|
187
215
|
}, []),
|
|
188
216
|
);
|
|
189
217
|
}),
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
218
|
+
// TLC evaluates TLCGet with its argument in TLCGetSet.TLCGetEval, so it reports any failure,
|
|
219
|
+
// the argument's too, as a failure of that method. TLC 1.7.4 calls TLC.TLCGet with the value of
|
|
220
|
+
// its argument.
|
|
221
|
+
runtime.version === "1.7.4"
|
|
222
|
+
? overrideWithJava(
|
|
223
|
+
{
|
|
224
|
+
...defineStateOperator("TLCGet", 1, (args, context) =>
|
|
225
|
+
getTlcValue(runtime, getValue(args, 0, "TLCGet"), context),
|
|
226
|
+
),
|
|
227
|
+
// Unlike TLCGetSet.TLCGetEval, TLC.TLCGet declares no minimum level.
|
|
228
|
+
isLevelConstant: true,
|
|
229
|
+
},
|
|
230
|
+
"public static tlc2.value.impl.Value tlc2.module.TLC.TLCGet(tlc2.value.impl.Value)",
|
|
231
|
+
)
|
|
232
|
+
: overrideWithJava(
|
|
233
|
+
defineLazyOperator("TLCGet", 1, (args, context) =>
|
|
234
|
+
getTlcValue(runtime, getThunk(args, 0, "TLCGet")(), context),
|
|
235
|
+
),
|
|
236
|
+
"public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
|
|
237
|
+
),
|
|
204
238
|
defineStateOperator("TLCSet", 2, (args) => {
|
|
205
239
|
const key = getValue(args, 0, "TLCSet");
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
runtime.registers.set(key, value);
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
if (key === "exit") {
|
|
212
|
-
if (value === true) runtime.isStopped = true;
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
if (key === "pause") {
|
|
216
|
-
if (value === true) {
|
|
217
|
-
print("Press enter to resume model checking.");
|
|
218
|
-
runtime.pause();
|
|
219
|
-
}
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
if (typeof key === "string" && key.startsWith(NAMED_REGISTER_PREFIX)) {
|
|
223
|
-
runtime.namedRegisters.set(key, value);
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
if (typeof key === "string" && key.startsWith("-D")) {
|
|
227
|
-
runtime.properties.set(key.slice(2), formatValue(value));
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
throw new TlaModuleError(
|
|
231
|
-
`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
232
|
-
);
|
|
240
|
+
setTlcValue(runtime, print, key, getValue(args, 1, "TLCSet"));
|
|
241
|
+
return true;
|
|
233
242
|
}),
|
|
234
243
|
defineConstant("Any", ANY_SET),
|
|
235
244
|
defineOperator("RandomElement", 1, (args) =>
|
package/src/tlc-modules.ts
CHANGED
|
@@ -550,6 +550,10 @@ export const SANY_NODE_NAMES = [
|
|
|
550
550
|
"N_AssertStep",
|
|
551
551
|
];
|
|
552
552
|
|
|
553
|
+
// The standard modules that a spec may ship its own file of, such as CommunityModules' Json.tla,
|
|
554
|
+
// which SANY reads in place of its own.
|
|
555
|
+
export const USER_STANDARD_MODULES = new Set(["Bags", "Json", "Randomization", "TLCExt"]);
|
|
556
|
+
|
|
553
557
|
export const TLC_MODULE_SOURCES = new Map([
|
|
554
558
|
[
|
|
555
559
|
"Naturals",
|
package/src/tlc-order.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// state's variables in the order of SANY's symbol table. This reproduces both orders.
|
|
3
3
|
import type { Module, SourceLocation } from "./ast";
|
|
4
4
|
import type { ConfigValue, ModelConfig } from "./config";
|
|
5
|
+
import { createMissingModuleError } from "./errors";
|
|
5
6
|
import { tokenize, type Token } from "./lexer";
|
|
6
7
|
import { extractModule, parseModule } from "./parser";
|
|
7
8
|
import { isBefore } from "./resolve";
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
TLC_MODULE_SOURCES,
|
|
13
14
|
TLC_RUNTIME_STRINGS,
|
|
14
15
|
TLC_STARTUP_STRINGS,
|
|
16
|
+
USER_STANDARD_MODULES,
|
|
15
17
|
} from "./tlc-modules";
|
|
16
18
|
|
|
17
19
|
type SymbolKind = "builtin" | "constant" | "variable" | "definition" | "theorem" | "module";
|
|
@@ -166,6 +168,9 @@ const getModuleReferences = (
|
|
|
166
168
|
innerModules.set(name, inner.references);
|
|
167
169
|
references.inner.push(inner.references);
|
|
168
170
|
index = inner.end;
|
|
171
|
+
} else if (tokens[index - 1]?.text === ".") {
|
|
172
|
+
// A record field named EXTENDS or INSTANCE, as in r.EXTENDS or [r EXCEPT !.INSTANCE = 0].
|
|
173
|
+
continue;
|
|
169
174
|
} else if (token.text === "EXTENDS") {
|
|
170
175
|
const names = getDeclarations(tokens, index + 1);
|
|
171
176
|
references.extends.push(...names);
|
|
@@ -184,9 +189,18 @@ const isAdjacent = (left: Token, right: Token | undefined) =>
|
|
|
184
189
|
right.line === left.line &&
|
|
185
190
|
right.column === left.column + left.text.length;
|
|
186
191
|
|
|
192
|
+
const STRING_ESCAPES: Record<string, string> = {
|
|
193
|
+
"\\": "\\\\",
|
|
194
|
+
'"': '\\"',
|
|
195
|
+
"\n": "\\n",
|
|
196
|
+
"\t": "\\t",
|
|
197
|
+
"\r": "\\r",
|
|
198
|
+
"\f": "\\f",
|
|
199
|
+
};
|
|
200
|
+
|
|
187
201
|
// The texts SANY interns while parsing, in order. SANY reads a proof step label such as <1>2 and
|
|
188
|
-
// a module header such as ---- MODULE as one token
|
|
189
|
-
// during semantic analysis.
|
|
202
|
+
// a module header such as ---- MODULE as one token. It interns a string literal as written, quotes
|
|
203
|
+
// included, and interns the literal's contents only during semantic analysis.
|
|
190
204
|
const getParsedTexts = (tokens: Token[]) => {
|
|
191
205
|
const texts: string[] = [];
|
|
192
206
|
for (let index = 0; index < tokens.length; index++) {
|
|
@@ -202,11 +216,19 @@ const getParsedTexts = (tokens: Token[]) => {
|
|
|
202
216
|
continue;
|
|
203
217
|
}
|
|
204
218
|
const isHeader = token.text === "MODULE" && tokens[index - 1]?.kind === "Separator";
|
|
205
|
-
if (
|
|
219
|
+
if (isHeader) continue;
|
|
220
|
+
texts.push(
|
|
221
|
+
token.kind === "String"
|
|
222
|
+
? `"${token.text.replace(/[\\"\n\t\r\f]/g, (character) => STRING_ESCAPES[character])}"`
|
|
223
|
+
: token.text,
|
|
224
|
+
);
|
|
206
225
|
}
|
|
207
226
|
return texts;
|
|
208
227
|
};
|
|
209
228
|
|
|
229
|
+
// A module starts with ---- MODULE Name, so its third token is its name.
|
|
230
|
+
const getModuleName = (tokens: Token[]) => tokens[2]?.text;
|
|
231
|
+
|
|
210
232
|
const getRanges = (tokens: Token[]) => {
|
|
211
233
|
const ranges = new Map<string, { start: number; end: number }>();
|
|
212
234
|
const open: { name: string; start: number }[] = [];
|
|
@@ -238,10 +260,13 @@ const createModuleSet = (source: string, loadModule: ModuleLoader) => {
|
|
|
238
260
|
const text =
|
|
239
261
|
name === undefined
|
|
240
262
|
? source
|
|
241
|
-
: (
|
|
263
|
+
: ((USER_STANDARD_MODULES.has(name) ? loadModule?.(name) : undefined) ??
|
|
264
|
+
TLC_MODULE_SOURCES.get(name) ??
|
|
265
|
+
loadModule?.(name) ??
|
|
266
|
+
extractModule(source, name));
|
|
242
267
|
const tokens = text === undefined ? [] : tokenize(text);
|
|
243
268
|
const ranges = getRanges(tokens);
|
|
244
|
-
const range = ranges.get(tokens
|
|
269
|
+
const range = ranges.get(getModuleName(tokens) ?? "") ?? { start: 0, end: 0 };
|
|
245
270
|
const parsed = { module: undefined as Module | undefined };
|
|
246
271
|
const file = {
|
|
247
272
|
tokens,
|
|
@@ -264,9 +289,8 @@ const createModuleSet = (source: string, loadModule: ModuleLoader) => {
|
|
|
264
289
|
(name === undefined ? undefined : nestedModules.get(name)) ?? getFile(name);
|
|
265
290
|
};
|
|
266
291
|
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
export const getTlcVariableOrder = (source: string, loadModule: ModuleLoader): string[] => {
|
|
292
|
+
// SANY's Context of each module, which the root module has under undefined.
|
|
293
|
+
const createContexts = (source: string, loadModule: ModuleLoader) => {
|
|
270
294
|
const getParsed = createModuleSet(source, loadModule);
|
|
271
295
|
const getUnits = (unit: ParsedModule) => {
|
|
272
296
|
const tokens = unit.tokens;
|
|
@@ -367,6 +391,8 @@ export const getTlcVariableOrder = (source: string, loadModule: ModuleLoader): s
|
|
|
367
391
|
};
|
|
368
392
|
|
|
369
393
|
const contexts = new Map<string, SymbolTable>();
|
|
394
|
+
// Where the entries a module adds itself start, after those of the modules it extends.
|
|
395
|
+
const ownStarts = new Map<SymbolTable, number>();
|
|
370
396
|
const getContext = (name: string | undefined): SymbolTable => {
|
|
371
397
|
const cached = contexts.get(name ?? "");
|
|
372
398
|
if (cached) return cached;
|
|
@@ -381,16 +407,53 @@ export const getTlcVariableOrder = (source: string, loadModule: ModuleLoader): s
|
|
|
381
407
|
if (!entry.isLocal) table.put(entry);
|
|
382
408
|
}),
|
|
383
409
|
);
|
|
410
|
+
ownStarts.set(table, table.inserted.length);
|
|
384
411
|
getUnits(unit).forEach((item) => item.apply(table));
|
|
385
412
|
return table;
|
|
386
413
|
};
|
|
387
|
-
return
|
|
414
|
+
return {
|
|
415
|
+
getContext,
|
|
416
|
+
getOwnEntries: (name: string | undefined) => {
|
|
417
|
+
const table = getContext(name);
|
|
418
|
+
return table.inserted.slice(ownStarts.get(table));
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// The variables or constants of the root module in the reverse of its context enumeration, as
|
|
424
|
+
// ModuleNode.getVariableDecls and getConstantDecls return them. TLC compares variables in this
|
|
425
|
+
// order, and checks that the configuration assigns each constant in it.
|
|
426
|
+
export const getTlcDeclarationOrder = (
|
|
427
|
+
source: string,
|
|
428
|
+
loadModule: ModuleLoader,
|
|
429
|
+
kind: "variable" | "constant",
|
|
430
|
+
): string[] =>
|
|
431
|
+
createContexts(source, loadModule)
|
|
432
|
+
.getContext(undefined)
|
|
388
433
|
.enumerate()
|
|
389
|
-
.filter((entry) => entry.kind ===
|
|
434
|
+
.filter((entry) => entry.kind === kind)
|
|
390
435
|
.map((entry) => entry.name)
|
|
391
436
|
.reverse();
|
|
437
|
+
|
|
438
|
+
// The names of the definitions each module adds to its context, in the order of
|
|
439
|
+
// ModuleNode.getOpDefs, in which TLC computes the constant definitions as it starts. An INSTANCE
|
|
440
|
+
// adds the definitions of the module it instantiates in the order that module's Hashtable
|
|
441
|
+
// enumerates them.
|
|
442
|
+
export const createTlcDefinitionOrder = (source: string, loadModule: ModuleLoader) => {
|
|
443
|
+
const contexts = createContexts(source, loadModule);
|
|
444
|
+
// The root module's context reads every file of the spec, and so finds the modules nested in
|
|
445
|
+
// the files it extends or instantiates.
|
|
446
|
+
contexts.getContext(undefined);
|
|
447
|
+
return (name: string | undefined) =>
|
|
448
|
+
contexts
|
|
449
|
+
.getOwnEntries(name)
|
|
450
|
+
.filter((entry) => entry.kind === "definition")
|
|
451
|
+
.map((entry) => entry.name);
|
|
392
452
|
};
|
|
393
453
|
|
|
454
|
+
export const getTlcVariableOrder = (source: string, loadModule: ModuleLoader) =>
|
|
455
|
+
getTlcDeclarationOrder(source, loadModule, "variable");
|
|
456
|
+
|
|
394
457
|
// Every string TLC interns before model checking starts, in order: values in the config, TLC's
|
|
395
458
|
// startup strings, each module's tokens in the order SpecObj.loadSpec parses the modules, string
|
|
396
459
|
// literals in semantic analysis order, and the names TLC interns for TLCGet.
|
|
@@ -474,6 +537,11 @@ export const getTlcStringOrder = (
|
|
|
474
537
|
dependencies.set(module.unit, [...(dependencies.get(module.unit) ?? []), name]);
|
|
475
538
|
if (parsedUnits.has(name)) continue;
|
|
476
539
|
parsedUnits.add(name);
|
|
540
|
+
// SANY stops at the first module it can't find, in the order it reads them.
|
|
541
|
+
if (getParsed(name).tokens.length === 0) {
|
|
542
|
+
const importer = module.unit ?? getModuleName(getParsed(undefined).tokens);
|
|
543
|
+
throw createMissingModuleError(name, importer);
|
|
544
|
+
}
|
|
477
545
|
getParsedTexts(getUnitTokens(name)).forEach(intern);
|
|
478
546
|
}
|
|
479
547
|
SEMANTIC_PRELUDE.forEach(intern);
|
package/src/tlc-random.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TlaEvaluationError } from "./errors";
|
|
2
|
+
import type { TlcVersion } from "./tlc-version";
|
|
2
3
|
import {
|
|
3
4
|
createRecord,
|
|
4
5
|
createSortedFunction,
|
|
@@ -181,22 +182,14 @@ const createShiftTable = (length: number) => {
|
|
|
181
182
|
|
|
182
183
|
// Extending a fingerprint by a byte is linear over GF(2), so extending it by a value's bytes
|
|
183
184
|
// XORs the value's own fingerprint from zero into the fingerprint shifted by their length.
|
|
184
|
-
// The fingerprinter caches each distinct
|
|
185
|
-
|
|
185
|
+
// The fingerprinter caches each distinct function or set it meets, nested ones included, for one
|
|
186
|
+
// pass over the stored states, as states share most of their values. It reads a state's variables
|
|
187
|
+
// in `order` and writes each fingerprint's low and high words into `words`, an Int32Array over a
|
|
188
|
+
// little-endian BigInt64Array.
|
|
189
|
+
export const createTlcFingerprinter = (order: number[], words: Int32Array) => {
|
|
186
190
|
const shiftTables = new Map<number, Int32Array>();
|
|
187
191
|
const indices = new Map<Value, number>();
|
|
188
192
|
const contributions: number[] = [];
|
|
189
|
-
const getContribution = (value: Value) => {
|
|
190
|
-
const cached = indices.get(value);
|
|
191
|
-
if (cached !== undefined) return cached;
|
|
192
|
-
const length = getFingerprintLength(value);
|
|
193
|
-
high = 0;
|
|
194
|
-
low = 0;
|
|
195
|
-
extendValue(value);
|
|
196
|
-
indices.set(value, contributions.length);
|
|
197
|
-
contributions.push(length, high, low);
|
|
198
|
-
return contributions.length - 3;
|
|
199
|
-
};
|
|
200
193
|
const getShiftTable = (length: number) => {
|
|
201
194
|
const cached = shiftTables.get(length);
|
|
202
195
|
if (cached) return cached;
|
|
@@ -204,28 +197,62 @@ export const createTlcFingerprinter = () => {
|
|
|
204
197
|
shiftTables.set(length, table);
|
|
205
198
|
return table;
|
|
206
199
|
};
|
|
207
|
-
|
|
200
|
+
// Extends the fingerprint by a value's bytes and returns how many there are.
|
|
201
|
+
const extendElement = (value: Value): number => {
|
|
202
|
+
if (typeof value !== "object" || isModelValue(value)) {
|
|
203
|
+
extendValue(value);
|
|
204
|
+
return getFingerprintLength(value);
|
|
205
|
+
}
|
|
206
|
+
const contribution = getContribution(value);
|
|
207
|
+
const shifted = { high, low };
|
|
208
|
+
const table = getShiftTable(contributions[contribution]);
|
|
209
|
+
high = contributions[contribution + 1];
|
|
210
|
+
low = contributions[contribution + 2];
|
|
211
|
+
for (let position = 0; position < 8; position++) {
|
|
212
|
+
const word = position < 4 ? shifted.low : shifted.high;
|
|
213
|
+
const entry = (position * 256 + ((word >>> ((position & 3) * 8)) & 0xff)) * 2;
|
|
214
|
+
high ^= table[entry];
|
|
215
|
+
low ^= table[entry + 1];
|
|
216
|
+
}
|
|
217
|
+
return contributions[contribution];
|
|
218
|
+
};
|
|
219
|
+
const getContribution = (value: Value) => {
|
|
220
|
+
const cached = indices.get(value);
|
|
221
|
+
if (cached !== undefined) return cached;
|
|
208
222
|
const outer = { high, low };
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const entry = (position * 256 + ((word >>> ((position & 3) * 8)) & 0xff)) * 2;
|
|
220
|
-
extended.high ^= table[entry];
|
|
221
|
-
extended.low ^= table[entry + 1];
|
|
223
|
+
high = 0;
|
|
224
|
+
low = 0;
|
|
225
|
+
const length = { value: 5 };
|
|
226
|
+
if (isFunctionValue(value)) {
|
|
227
|
+
const functionValue = toFiniteFunction(value);
|
|
228
|
+
extendByte(FCN_RCD_VALUE);
|
|
229
|
+
extendInt(functionValue.domain.length);
|
|
230
|
+
for (let index = 0; index < functionValue.domain.length; index++) {
|
|
231
|
+
length.value += extendElement(functionValue.domain[index]);
|
|
232
|
+
length.value += extendElement(functionValue.range[index]);
|
|
222
233
|
}
|
|
223
|
-
|
|
224
|
-
|
|
234
|
+
} else {
|
|
235
|
+
const elements = toFiniteSet(value).elements;
|
|
236
|
+
extendByte(SET_ENUM_VALUE);
|
|
237
|
+
extendInt(elements.length);
|
|
238
|
+
for (const element of elements) length.value += extendElement(element);
|
|
225
239
|
}
|
|
240
|
+
const contribution = contributions.length;
|
|
241
|
+
indices.set(value, contribution);
|
|
242
|
+
contributions.push(length.value, high, low);
|
|
243
|
+
high = outer.high;
|
|
244
|
+
low = outer.low;
|
|
245
|
+
return contribution;
|
|
246
|
+
};
|
|
247
|
+
return (state: Value[], position: number) => {
|
|
248
|
+
const outer = { high, low };
|
|
249
|
+
high = INITIAL_HIGH;
|
|
250
|
+
low = INITIAL_LOW;
|
|
251
|
+
for (const index of order) extendElement(state[index]);
|
|
252
|
+
words[2 * position] = low;
|
|
253
|
+
words[2 * position + 1] = high;
|
|
226
254
|
high = outer.high;
|
|
227
255
|
low = outer.low;
|
|
228
|
-
return (BigInt(fingerprint.high >>> 0) << 32n) | BigInt(fingerprint.low >>> 0);
|
|
229
256
|
};
|
|
230
257
|
};
|
|
231
258
|
|
|
@@ -286,7 +313,7 @@ const getModulusAndMultiplier = (size: number) => {
|
|
|
286
313
|
|
|
287
314
|
// EnumerableValue.SubsetEnumerator: count indices below size from a full-period linear
|
|
288
315
|
// congruential generator that starts at random.nextInt(size).
|
|
289
|
-
const
|
|
316
|
+
const getSubsetIndicesMaster = (count: number, size: number, random: JavaRandom) => {
|
|
290
317
|
if (size <= 0) return [];
|
|
291
318
|
const generator = getModulusAndMultiplier(size);
|
|
292
319
|
const state = { index: BigInt(random.nextInt(size)) };
|
|
@@ -299,6 +326,18 @@ const getSubsetIndices = (count: number, size: number, random: JavaRandom) => {
|
|
|
299
326
|
});
|
|
300
327
|
};
|
|
301
328
|
|
|
329
|
+
// TLC 1.7.4's EnumerableValue.SubsetEnumerator: the i-th index is (x * i + a) mod size, for a
|
|
330
|
+
// prime x above size and a = random.nextInt(size), so the first size indices are distinct.
|
|
331
|
+
const getSubsetIndices174 = (count: number, size: number, random: JavaRandom) => {
|
|
332
|
+
if (size <= 0) return [];
|
|
333
|
+
const stride = BigInt(size < 191 ? 191 : MAXIMUM_INT);
|
|
334
|
+
const offset = BigInt(random.nextInt(size));
|
|
335
|
+
return Array.from(
|
|
336
|
+
{ length: Math.min(count, size) },
|
|
337
|
+
(_, index) => (stride * BigInt(index) + offset) % BigInt(size),
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
302
341
|
const LARGE_STRIDE = (1n << 63n) - 1n - 24n;
|
|
303
342
|
|
|
304
343
|
// SetOfFcnsOrRcdsValue.BigIntegerSubsetEnumerator, for products with more than 2^31 - 1
|
|
@@ -352,15 +391,27 @@ const getProduct = (set: Value): Product | undefined => {
|
|
|
352
391
|
return undefined;
|
|
353
392
|
};
|
|
354
393
|
|
|
394
|
+
// TLC 1.7.4 enumerates a set of tuples to draw from it.
|
|
395
|
+
export const getEnumeratedFactors = (set: Value, version: TlcVersion) =>
|
|
396
|
+
version === "1.7.4" && typeof set === "object" && set.kind === "ProductSet"
|
|
397
|
+
? set.factors
|
|
398
|
+
: undefined;
|
|
399
|
+
|
|
355
400
|
// Enumerable#getRandomSubset, which Randomization's RandomSubset calls.
|
|
356
|
-
export const getRandomSubset = (
|
|
401
|
+
export const getRandomSubset = (
|
|
402
|
+
count: number,
|
|
403
|
+
set: Value,
|
|
404
|
+
random: JavaRandom,
|
|
405
|
+
version: TlcVersion,
|
|
406
|
+
): Value[] => {
|
|
357
407
|
if (isEmptySet(set)) return [];
|
|
408
|
+
const getSubsetIndices = version === "1.7.4" ? getSubsetIndices174 : getSubsetIndicesMaster;
|
|
358
409
|
if (typeof set === "object" && set.kind === "Interval") {
|
|
359
410
|
return getSubsetIndices(count, Math.max(0, set.high - set.low + 1), random).map(
|
|
360
411
|
(index) => set.low + Number(index),
|
|
361
412
|
);
|
|
362
413
|
}
|
|
363
|
-
const product = getProduct(set);
|
|
414
|
+
const product = getEnumeratedFactors(set, version) ? undefined : getProduct(set);
|
|
364
415
|
if (product) {
|
|
365
416
|
const size = product.lists.reduce((total, list) => total * BigInt(list.length), 1n);
|
|
366
417
|
const indices =
|