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/spec-description.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
isLocallyResolved,
|
|
3
|
+
type Definition,
|
|
4
|
+
type Expression,
|
|
5
|
+
type SourceLocation,
|
|
6
|
+
type SourceRange,
|
|
7
|
+
} from "./ast";
|
|
2
8
|
import type { ModelConfig } from "./config";
|
|
3
9
|
import type { InstanceAction } from "./environment";
|
|
4
|
-
import { TlaError } from "./errors";
|
|
10
|
+
import { formatRange, TlaError } from "./errors";
|
|
5
11
|
import {
|
|
6
12
|
bindDefinitions,
|
|
7
13
|
bindOperatorArguments,
|
|
8
14
|
evaluate,
|
|
9
15
|
forEachBinding,
|
|
10
|
-
formatRange,
|
|
11
16
|
getDefinition,
|
|
12
17
|
isConstantLevel,
|
|
13
|
-
isLocallyResolved,
|
|
14
18
|
lookupScope,
|
|
15
19
|
resolveGlobalOperator,
|
|
16
20
|
type Closure,
|
|
@@ -20,6 +24,7 @@ import {
|
|
|
20
24
|
import { TEMPORAL_LEVEL } from "./levels";
|
|
21
25
|
import { getLevel } from "./liveness";
|
|
22
26
|
import { createRecord, createSet, createTuple, formatValue, type Value } from "./values";
|
|
27
|
+
import type { TlcVersion } from "./tlc-version";
|
|
23
28
|
|
|
24
29
|
export interface SpecAction {
|
|
25
30
|
name: string;
|
|
@@ -58,7 +63,8 @@ const toLocationValue = (location: SourceLocation) => {
|
|
|
58
63
|
]);
|
|
59
64
|
};
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
// TLC's RecordValue(Action): the action's name and location, with the values of its parameters.
|
|
67
|
+
export const toActionValue = (action: SpecAction) => {
|
|
62
68
|
const fields: [string, Value][] = [
|
|
63
69
|
["name", action.name],
|
|
64
70
|
["location", toLocationValue(action.location)],
|
|
@@ -245,8 +251,12 @@ const getActions = (
|
|
|
245
251
|
return getInstanceActions(instanceAction, expression, scope, called, environment);
|
|
246
252
|
if (!called) return [createSplitAction()];
|
|
247
253
|
const args = getArguments(expression);
|
|
254
|
+
// TLC names an action after the operator it applies, as SANY names it in the spec.
|
|
255
|
+
const calledName = isLocallyResolved(expression)
|
|
256
|
+
? called.name
|
|
257
|
+
: (environment.instanceNames.get(getOperatorName(expression) ?? "") ?? called.name);
|
|
248
258
|
const callAction = (): SpecAction[] => [
|
|
249
|
-
{ name:
|
|
259
|
+
{ name: calledName, location: expression.location, parameters: [], expression, scope },
|
|
250
260
|
];
|
|
251
261
|
if (isConstantDefinition(called, environment)) return callAction();
|
|
252
262
|
if (args.some((arg) => getLevel(arg, scope, environment) !== 0)) return callAction();
|
|
@@ -262,7 +272,13 @@ const getActions = (
|
|
|
262
272
|
}),
|
|
263
273
|
called.scope,
|
|
264
274
|
);
|
|
265
|
-
return getActions(
|
|
275
|
+
return getActions(
|
|
276
|
+
called.body,
|
|
277
|
+
boundScope,
|
|
278
|
+
{ ...called, name: calledName },
|
|
279
|
+
environment,
|
|
280
|
+
instanceActions,
|
|
281
|
+
);
|
|
266
282
|
}, callAction);
|
|
267
283
|
};
|
|
268
284
|
|
|
@@ -457,6 +473,13 @@ const describe = (
|
|
|
457
473
|
return description;
|
|
458
474
|
};
|
|
459
475
|
|
|
476
|
+
// TLC's initial predicates, which it conjoins to compute the initial states.
|
|
477
|
+
export const getInitActions = (
|
|
478
|
+
config: ModelConfig,
|
|
479
|
+
environment: Environment,
|
|
480
|
+
instanceActions: Map<string, InstanceAction>,
|
|
481
|
+
) => describe(config, environment, instanceActions).inits;
|
|
482
|
+
|
|
460
483
|
// TLC's split of the next-state relation into the actions it names in a behavior.
|
|
461
484
|
export const getNextActions = (
|
|
462
485
|
config: ModelConfig,
|
|
@@ -464,10 +487,18 @@ export const getNextActions = (
|
|
|
464
487
|
instanceActions: Map<string, InstanceAction>,
|
|
465
488
|
) => describe(config, environment, instanceActions).actions;
|
|
466
489
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
490
|
+
const formatParameters = (action: SpecAction) =>
|
|
491
|
+
action.parameters.length === 0
|
|
492
|
+
? ""
|
|
493
|
+
: `(${action.parameters.map((parameter) => formatValue(parameter[1])).join(",")})`;
|
|
494
|
+
|
|
495
|
+
// TLC's Action.getLocation, which TLC 1.7.4 names the action in without its parameters.
|
|
496
|
+
export const getActionLabel = (action: SpecAction, version?: TlcVersion) =>
|
|
497
|
+
`${action.name === UNNAMED_ACTION ? "Action" : action.name}${version === "1.7.4" ? "" : formatParameters(action)} ${formatRange(action.location.range ?? BUILTIN_RANGE)}`;
|
|
498
|
+
|
|
499
|
+
// TLC's Action.getInvocationSignature, which names the action and the values of its parameters.
|
|
500
|
+
export const getActionSignature = (action: SpecAction) =>
|
|
501
|
+
`${action.name}${formatParameters(action)}`;
|
|
471
502
|
|
|
472
503
|
export const getSpecificationValue = (
|
|
473
504
|
config: ModelConfig,
|
package/src/standard-modules.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
getNumber,
|
|
12
12
|
getOperator,
|
|
13
13
|
getSet,
|
|
14
|
-
|
|
14
|
+
getJavaSignature,
|
|
15
15
|
getJavaInteger,
|
|
16
16
|
getValue,
|
|
17
17
|
isOutOfRange,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from "./builtins";
|
|
20
20
|
import type { Builtin, BuiltinArgument } from "./evaluate";
|
|
21
21
|
import type { CheckerRuntime } from "./runtime";
|
|
22
|
-
import {
|
|
22
|
+
import { createBagsOperators } from "./bags";
|
|
23
23
|
import { createJsonOperators, type FileSystem } from "./json";
|
|
24
24
|
import { createRandomizationOperators } from "./randomization";
|
|
25
25
|
import { createPossibleOperators, createTlcExtOperators } from "./tlc-ext";
|
|
@@ -40,6 +40,9 @@ import {
|
|
|
40
40
|
isEnumerable,
|
|
41
41
|
isFiniteSet,
|
|
42
42
|
isFunctionValue,
|
|
43
|
+
computeLikeTlcOnFailure,
|
|
44
|
+
isReducibleSet,
|
|
45
|
+
markStreamedSet,
|
|
43
46
|
isSetValue,
|
|
44
47
|
toFiniteSet,
|
|
45
48
|
unionSorted,
|
|
@@ -54,6 +57,7 @@ import {
|
|
|
54
57
|
type Value,
|
|
55
58
|
rankString,
|
|
56
59
|
} from "./values";
|
|
60
|
+
import type { TlcVersion } from "./tlc-version";
|
|
57
61
|
|
|
58
62
|
interface StandardModule {
|
|
59
63
|
extends: string[];
|
|
@@ -77,10 +81,6 @@ const SET_OPERATORS: SetOperationValue["operator"][] = ["\\cup", "\\cap", "\\"];
|
|
|
77
81
|
|
|
78
82
|
type ReducibleSet = SetValue | MixedSetValue | IntervalValue;
|
|
79
83
|
|
|
80
|
-
const isReducible = (value: Value): value is ReducibleSet =>
|
|
81
|
-
typeof value === "object" &&
|
|
82
|
-
(value.kind === "Set" || value.kind === "MixedSet" || value.kind === "Interval");
|
|
83
|
-
|
|
84
84
|
const isMixedSet = (value: Value) => typeof value === "object" && value.kind === "MixedSet";
|
|
85
85
|
|
|
86
86
|
const getReducibleElements = (set: ReducibleSet) =>
|
|
@@ -101,7 +101,9 @@ const combineReducible = (
|
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
if (elements.length === 0) return other;
|
|
104
|
-
if (!
|
|
104
|
+
if (!isReducibleSet(other)) {
|
|
105
|
+
return markStreamedSet({ kind: "SetOperation", operator, left: set, right: other });
|
|
106
|
+
}
|
|
105
107
|
const added = toFiniteSet(other).elements.filter((element) => !isElementOf(element, set));
|
|
106
108
|
return createEnumeratedSet([...elements, ...added]);
|
|
107
109
|
};
|
|
@@ -128,7 +130,8 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
128
130
|
),
|
|
129
131
|
defineOperator("\\subseteq", 2, (args) => {
|
|
130
132
|
const left = getSet(args, 0, "\\subseteq");
|
|
131
|
-
|
|
133
|
+
// TLC tests each element of the left set for membership in the right value.
|
|
134
|
+
const right = getValue(args, 1, "\\subseteq");
|
|
132
135
|
const isPowerSets =
|
|
133
136
|
typeof left === "object" &&
|
|
134
137
|
left.kind === "Subset" &&
|
|
@@ -138,11 +141,18 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
138
141
|
if (isPowerSets) return isSubsetOf(toFiniteSet(left.base).elements, right.base);
|
|
139
142
|
return isSubsetOf(toFiniteSet(left).elements, right);
|
|
140
143
|
}),
|
|
144
|
+
// TLC defers the set operations of values that aren't sets to the enumeration or the membership
|
|
145
|
+
// tests of the result.
|
|
141
146
|
...SET_OPERATORS.map((operator) =>
|
|
142
147
|
defineOperator(operator, 2, (args) => {
|
|
143
|
-
const left =
|
|
144
|
-
const right =
|
|
145
|
-
if (
|
|
148
|
+
const left = getValue(args, 0, operator);
|
|
149
|
+
const right = getValue(args, 1, operator);
|
|
150
|
+
if (
|
|
151
|
+
isReducibleSet(left) &&
|
|
152
|
+
isReducibleSet(right) &&
|
|
153
|
+
!isMixedSet(left) &&
|
|
154
|
+
!isMixedSet(right)
|
|
155
|
+
) {
|
|
146
156
|
if (operator === "\\cup" && isEmptySet(left)) return right;
|
|
147
157
|
const merge =
|
|
148
158
|
operator === "\\cup"
|
|
@@ -150,19 +160,27 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
150
160
|
: operator === "\\cap"
|
|
151
161
|
? intersectSorted
|
|
152
162
|
: differenceSorted;
|
|
153
|
-
|
|
163
|
+
// The merge compares the elements, which TLC tests for membership one by one instead.
|
|
164
|
+
return computeLikeTlcOnFailure(
|
|
165
|
+
(finiteLeft, finiteRight) => merge(toFiniteSet(finiteLeft), toFiniteSet(finiteRight)),
|
|
166
|
+
(reducibleLeft, reducibleRight) =>
|
|
167
|
+
combineReducible(operator, reducibleLeft, reducibleRight),
|
|
168
|
+
left,
|
|
169
|
+
right,
|
|
170
|
+
);
|
|
154
171
|
}
|
|
155
|
-
if (
|
|
156
|
-
if (operator !== "\\" &&
|
|
157
|
-
|
|
172
|
+
if (isReducibleSet(left)) return combineReducible(operator, left, right);
|
|
173
|
+
if (operator !== "\\" && isReducibleSet(right))
|
|
174
|
+
return combineReducible(operator, right, left);
|
|
175
|
+
return markStreamedSet({ kind: "SetOperation", operator, left, right });
|
|
158
176
|
}),
|
|
159
177
|
),
|
|
160
|
-
defineOperator("SUBSET", 1, (args) => ({ kind: "Subset", base:
|
|
178
|
+
defineOperator("SUBSET", 1, (args) => ({ kind: "Subset", base: getValue(args, 0, "SUBSET") })),
|
|
161
179
|
defineOperator("UNION", 1, (args) => {
|
|
162
180
|
const outer = getSet(args, 0, "UNION");
|
|
163
181
|
const sets = isEnumeratedSet(outer) ? outer.elements.filter(isEnumeratedSet) : [];
|
|
164
182
|
if (!isEnumeratedSet(outer) || sets.length !== outer.elements.length) {
|
|
165
|
-
return { kind: "Union", base: outer };
|
|
183
|
+
return markStreamedSet({ kind: "Union", base: outer });
|
|
166
184
|
}
|
|
167
185
|
if (isMixedSet(outer) || sets.some(isMixedSet)) {
|
|
168
186
|
const union: MixedSetValue = { kind: "MixedSet", elements: [] };
|
|
@@ -184,51 +202,79 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
184
202
|
}),
|
|
185
203
|
];
|
|
186
204
|
|
|
187
|
-
const
|
|
205
|
+
const NEG_SIGNATURE = getJavaSignature("Integers", "Neg", "IntValue", 1);
|
|
188
206
|
|
|
189
|
-
|
|
207
|
+
// TLC overrides the arithmetic of Naturals with the Java methods of tlc2.module.Naturals, or with
|
|
208
|
+
// those of tlc2.module.Integers when the spec loads Integers, and names the method in an error.
|
|
209
|
+
const createArithmeticOperators = (module: string) => {
|
|
210
|
+
const dotDotSignature = getJavaSignature(module, "DotDot", "IntervalValue", 2);
|
|
211
|
+
return [
|
|
212
|
+
defineArithmetic(module, "+", "Plus", (left, right) => left + right),
|
|
213
|
+
defineArithmetic(module, "-", "Minus", (left, right) => left - right),
|
|
214
|
+
defineArithmetic(module, "*", "Times", (left, right) => left * right),
|
|
215
|
+
defineArithmetic(module, "^", "Expt", (base, exponent) => {
|
|
216
|
+
if (exponent < 0) {
|
|
217
|
+
throw new TlaModuleError(
|
|
218
|
+
`The second argument of ^ should be a natural number, but instead it is:\n${exponent}`,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
if (base === 0 && exponent === 0) throw new TlaModuleError("0^0 is undefined.");
|
|
222
|
+
return base ** exponent;
|
|
223
|
+
}),
|
|
224
|
+
defineArithmetic(module, "\\div", "Divide", (left, right) => {
|
|
225
|
+
if (right === 0) throw new TlaModuleError("The second argument of \\div is 0.");
|
|
226
|
+
// tlc2.module.Naturals#Divide floors only a quotient Java truncates below 0, and lets
|
|
227
|
+
// -2147483648 \div -1 overflow.
|
|
228
|
+
if (module === "Naturals") {
|
|
229
|
+
const truncated = Math.trunc(left / right) | 0;
|
|
230
|
+
return truncated < 0 && Math.imul(truncated, right) !== left ? truncated - 1 : truncated;
|
|
231
|
+
}
|
|
232
|
+
const quotient = Math.floor(left / right);
|
|
233
|
+
if (isOutOfRange(quotient)) throw createOverflowError(`${left} \\div ${right}`);
|
|
234
|
+
return quotient;
|
|
235
|
+
}),
|
|
236
|
+
defineArithmetic(module, "%", "Mod", (left, right) => {
|
|
237
|
+
if (right <= 0) {
|
|
238
|
+
throw new TlaModuleError(
|
|
239
|
+
`The second argument of % should be a positive number, but instead it is:\n${right}`,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return ((left % right) + right) % right;
|
|
243
|
+
}),
|
|
244
|
+
defineOperator("..", 2, (args) => ({
|
|
245
|
+
kind: "Interval",
|
|
246
|
+
low: getJavaInteger(getValue(args, 0, ".."), dotDotSignature),
|
|
247
|
+
high: getJavaInteger(getValue(args, 1, ".."), dotDotSignature),
|
|
248
|
+
})),
|
|
249
|
+
];
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const NATURALS_ARITHMETIC = createArithmeticOperators("Naturals");
|
|
253
|
+
|
|
254
|
+
const INTEGERS_ARITHMETIC = createArithmeticOperators("Integers");
|
|
255
|
+
|
|
256
|
+
// The operators of Naturals that TLC overrides with the methods of tlc2.module.Integers when it
|
|
257
|
+
// loads Integers for its trace exploration spec, by the operator each replaces.
|
|
258
|
+
export const getTraceSpecArithmetic = (builtin: Builtin) => {
|
|
259
|
+
const index = NATURALS_ARITHMETIC.indexOf(builtin);
|
|
260
|
+
return index === -1 ? undefined : INTEGERS_ARITHMETIC[index];
|
|
261
|
+
};
|
|
190
262
|
|
|
191
263
|
const NATURALS_OPERATORS = [
|
|
192
264
|
defineConstant("Nat", { kind: "InfiniteSet", name: "Nat" }),
|
|
193
|
-
|
|
194
|
-
defineArithmetic("-", "Minus", (left, right) => left - right),
|
|
195
|
-
defineArithmetic("*", "Times", (left, right) => left * right),
|
|
196
|
-
defineArithmetic("^", "Expt", (base, exponent) => {
|
|
197
|
-
if (exponent < 0) {
|
|
198
|
-
throw new TlaModuleError(
|
|
199
|
-
`The second argument of ^ should be a natural number, but instead it is:\n${exponent}`,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
if (base === 0 && exponent === 0) throw new TlaModuleError("0^0 is undefined.");
|
|
203
|
-
return base ** exponent;
|
|
204
|
-
}),
|
|
205
|
-
defineArithmetic("\\div", "Divide", (left, right) => {
|
|
206
|
-
if (right === 0) throw new TlaModuleError("The second argument of \\div is 0.");
|
|
207
|
-
const quotient = Math.floor(left / right);
|
|
208
|
-
if (isOutOfRange(quotient)) throw createOverflowError(`${left} \\div ${right}`);
|
|
209
|
-
return quotient;
|
|
210
|
-
}),
|
|
211
|
-
defineArithmetic("%", "Mod", (left, right) => {
|
|
212
|
-
if (right <= 0) {
|
|
213
|
-
throw new TlaModuleError(
|
|
214
|
-
`The second argument of % should be a positive number, but instead it is:\n${right}`,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
return ((left % right) + right) % right;
|
|
218
|
-
}),
|
|
265
|
+
...NATURALS_ARITHMETIC,
|
|
219
266
|
defineComparison("<", (left, right) => left < right),
|
|
220
267
|
defineComparison(">", (left, right) => left > right),
|
|
221
268
|
defineComparison("<=", (left, right) => left <= right),
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
low: getJavaInteger(getValue(args, 0, ".."), DOT_DOT_SIGNATURE),
|
|
226
|
-
high: getJavaInteger(getValue(args, 1, ".."), DOT_DOT_SIGNATURE),
|
|
227
|
-
})),
|
|
269
|
+
// tlc2.module.Naturals#GEQ names itself > in its errors. Only a spec that extends Integers gets
|
|
270
|
+
// the GEQ of tlc2.module.Integers, not one that loads Integers for its trace exploration spec.
|
|
271
|
+
defineComparison(">=", (left, right) => left >= right, ">"),
|
|
228
272
|
];
|
|
229
273
|
|
|
230
274
|
const INTEGERS_OPERATORS = [
|
|
231
275
|
defineConstant("Int", { kind: "InfiniteSet", name: "Int" }),
|
|
276
|
+
...INTEGERS_ARITHMETIC,
|
|
277
|
+
defineComparison(">=", (left, right) => left >= right),
|
|
232
278
|
defineOperator("-.", 1, (args) => {
|
|
233
279
|
const value = getJavaInteger(getValue(args, 0, "-"), NEG_SIGNATURE);
|
|
234
280
|
if (isOutOfRange(-value)) throw createOverflowError(`-${value}`);
|
|
@@ -268,103 +314,111 @@ const withJavaMethods = (module: string, operators: Builtin[]) => {
|
|
|
268
314
|
});
|
|
269
315
|
};
|
|
270
316
|
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
317
|
+
const createSequencesOperators = (version: TlcVersion) =>
|
|
318
|
+
withJavaMethods("Sequences", [
|
|
319
|
+
defineOperator("Seq", 1, (args) => ({ kind: "SequenceSet", base: getValue(args, 0, "Seq") })),
|
|
320
|
+
defineOperator(
|
|
321
|
+
"Len",
|
|
322
|
+
1,
|
|
323
|
+
(args) => getSequenceOrString(args, 0, getSequenceMessage("", "Len")).length,
|
|
324
|
+
),
|
|
325
|
+
defineOperator("\\o", 2, (args) => {
|
|
326
|
+
const left = getSequenceOrString(args, 0, getEvaluatingMessage("s \\o t", "sequence"));
|
|
327
|
+
if (typeof left !== "string") {
|
|
328
|
+
const right = getSequenceArgument(args, 1, getEvaluatingMessage("t \\o s", "sequence"));
|
|
329
|
+
return createTuple([...left, ...right]);
|
|
330
|
+
}
|
|
331
|
+
const right = getValue(args, 1, "\\o");
|
|
332
|
+
if (typeof right !== "string") {
|
|
333
|
+
throw new TlaModuleError(
|
|
334
|
+
`${getEvaluatingMessage("t \\o s", "string")}\n${formatValue(right)}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
return rankString(left + right);
|
|
338
|
+
}),
|
|
339
|
+
defineOperator("Append", 2, (args) =>
|
|
340
|
+
createTuple([
|
|
341
|
+
...getSequenceArgument(
|
|
342
|
+
args,
|
|
343
|
+
0,
|
|
344
|
+
getEvaluatingMessage(version === "1.7.4" ? "Append(v, s)" : "Append(s, v)", "sequence"),
|
|
345
|
+
),
|
|
346
|
+
getValue(args, 1, "Append"),
|
|
347
|
+
]),
|
|
348
|
+
),
|
|
349
|
+
defineOperator("Head", 1, (args) => {
|
|
350
|
+
const elements = getSequenceArgument(args, 0, getSequenceMessage("", "Head"));
|
|
351
|
+
if (elements.length === 0)
|
|
352
|
+
throw new TlaModuleError("Attempted to apply Head to the empty sequence.");
|
|
353
|
+
return elements[0];
|
|
354
|
+
}),
|
|
355
|
+
defineOperator("Tail", 1, (args) => {
|
|
356
|
+
const sequence = getSequenceOrString(args, 0, getSequenceMessage("", "Tail"));
|
|
357
|
+
if (sequence.length === 0)
|
|
358
|
+
throw new TlaModuleError("Attempted to apply Tail to the empty sequence.");
|
|
359
|
+
return sliceSequence(sequence, 1);
|
|
360
|
+
}),
|
|
361
|
+
defineOperator("SubSeq", 3, (args) => {
|
|
362
|
+
const sequence = getSequenceOrString(args, 0, getSequenceMessage("first ", "SubSeq"));
|
|
363
|
+
const start = getNumber(args, 1, "SubSeq");
|
|
364
|
+
const end = getNumber(args, 2, "SubSeq");
|
|
365
|
+
if (start > end) return sliceSequence(sequence, 0, 0);
|
|
366
|
+
const outOfDomain =
|
|
367
|
+
start < 1 || start > sequence.length
|
|
368
|
+
? { position: "second", value: start }
|
|
369
|
+
: end > sequence.length
|
|
370
|
+
? { position: "third", value: end }
|
|
371
|
+
: undefined;
|
|
372
|
+
if (outOfDomain) {
|
|
373
|
+
throw new TlaModuleError(
|
|
374
|
+
`The ${outOfDomain.position} argument of SubSeq must be in the domain of its first argument:\n${formatValue(getValue(args, 0, "SubSeq"))}\n, but instead it is\n${outOfDomain.value}`,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
return sliceSequence(sequence, start - 1, end);
|
|
378
|
+
}),
|
|
379
|
+
defineHigherOrderOperator("SelectSeq", 2, (args) => {
|
|
380
|
+
const test = getOperator(args, 1, "SelectSeq");
|
|
381
|
+
return createTuple(
|
|
382
|
+
getSequenceArgument(args, 0, getSequenceMessage("first ", "SelectSeq")).filter(
|
|
383
|
+
(element) => {
|
|
384
|
+
const result = test.call([element]);
|
|
385
|
+
if (typeof result !== "boolean") {
|
|
386
|
+
throw new TlaModuleError(
|
|
387
|
+
`The second argument of SelectSeq should be a operator, but instead it is:\n${formatValue(result)}`,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
return result;
|
|
391
|
+
},
|
|
392
|
+
),
|
|
324
393
|
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
}),
|
|
328
|
-
defineHigherOrderOperator("SelectSeq", 2, (args) => {
|
|
329
|
-
const test = getOperator(args, 1, "SelectSeq");
|
|
330
|
-
return createTuple(
|
|
331
|
-
getSequenceArgument(args, 0, getSequenceMessage("first ", "SelectSeq")).filter((element) => {
|
|
332
|
-
const result = test.call([element]);
|
|
333
|
-
if (typeof result !== "boolean") {
|
|
334
|
-
throw new TlaModuleError(
|
|
335
|
-
`The second argument of SelectSeq should be a operator, but instead it is:\n${formatValue(result)}`,
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
return result;
|
|
339
|
-
}),
|
|
340
|
-
);
|
|
341
|
-
}),
|
|
342
|
-
]);
|
|
394
|
+
}),
|
|
395
|
+
]);
|
|
343
396
|
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}),
|
|
355
|
-
defineOperator("Cardinality", 1, (args) => {
|
|
356
|
-
const set = getValue(args, 0, "Cardinality");
|
|
357
|
-
if (
|
|
358
|
-
!isSetValue(set) ||
|
|
359
|
-
(typeof set === "object" && (set.kind === "InfiniteSet" || set.kind === "SequenceSet"))
|
|
360
|
-
) {
|
|
361
|
-
throw new TlaModuleError(
|
|
362
|
-
`Attempted to compute cardinality of the value\n${formatValue(set)}`,
|
|
397
|
+
const createFiniteSetsOperators = (version: TlcVersion) =>
|
|
398
|
+
withJavaMethods("FiniteSets", [
|
|
399
|
+
defineOperator("IsFiniteSet", 1, (args) => {
|
|
400
|
+
const value = getValue(args, 0, "IsFiniteSet");
|
|
401
|
+
if (isSetValue(value)) return isFiniteSet(value);
|
|
402
|
+
if (typeof value === "object" && value.kind === "Function") return true;
|
|
403
|
+
throw new TlaEvaluationError(
|
|
404
|
+
typeof value === "object" && value.kind === "LazyFunction"
|
|
405
|
+
? `Attempted to check if the function:\n${formatValue(value)}\nis a finite set.`
|
|
406
|
+
: `Attempted to check if the ${describeKind(value)} ${formatValue(value)} is a finite set.`,
|
|
363
407
|
);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
408
|
+
}),
|
|
409
|
+
defineOperator("Cardinality", 1, (args) => {
|
|
410
|
+
const set = getValue(args, 0, "Cardinality");
|
|
411
|
+
if (
|
|
412
|
+
!isSetValue(set) ||
|
|
413
|
+
(typeof set === "object" && (set.kind === "InfiniteSet" || set.kind === "SequenceSet"))
|
|
414
|
+
) {
|
|
415
|
+
throw new TlaModuleError(
|
|
416
|
+
`Attempted to compute cardinality of the value\n${formatValue(set)}`,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
return getCardinality(set, version);
|
|
420
|
+
}),
|
|
421
|
+
]);
|
|
368
422
|
|
|
369
423
|
// The modules that each standard module loads through EXTENDS and LOCAL INSTANCE in TLC.
|
|
370
424
|
export const STANDARD_DEPENDENCIES = new Map([
|
|
@@ -384,6 +438,7 @@ export const getStandardModule = (
|
|
|
384
438
|
print: (text: string) => void,
|
|
385
439
|
runtime: CheckerRuntime,
|
|
386
440
|
files: FileSystem,
|
|
441
|
+
builtins: ReadonlyMap<string, Builtin>,
|
|
387
442
|
): StandardModule | undefined => {
|
|
388
443
|
switch (name) {
|
|
389
444
|
case "Naturals":
|
|
@@ -391,9 +446,9 @@ export const getStandardModule = (
|
|
|
391
446
|
case "Integers":
|
|
392
447
|
return { extends: ["Naturals"], operators: INTEGERS_OPERATORS };
|
|
393
448
|
case "Sequences":
|
|
394
|
-
return { extends: [], operators:
|
|
449
|
+
return { extends: [], operators: createSequencesOperators(runtime.version) };
|
|
395
450
|
case "FiniteSets":
|
|
396
|
-
return { extends: [], operators:
|
|
451
|
+
return { extends: [], operators: createFiniteSetsOperators(runtime.version) };
|
|
397
452
|
case "TLC":
|
|
398
453
|
return { extends: [], operators: withJavaMethods("TLC", createTlcOperators(print, runtime)) };
|
|
399
454
|
case "Randomization":
|
|
@@ -403,7 +458,7 @@ export const getStandardModule = (
|
|
|
403
458
|
case "Json":
|
|
404
459
|
return { extends: [], operators: createJsonOperators(files) };
|
|
405
460
|
case "Bags":
|
|
406
|
-
return { extends: [], operators:
|
|
461
|
+
return { extends: [], operators: createBagsOperators(builtins) };
|
|
407
462
|
case "TLCExt":
|
|
408
463
|
return { extends: [], operators: createTlcExtOperators(print, runtime) };
|
|
409
464
|
default:
|