tla-ts 0.0.10-dev.d618a2d79 → 0.0.10-dev.e3e5dd576
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/dist/compile.cjs +3 -3
- package/dist/compile.js +1 -1
- package/dist/deciders.cjs +36 -36
- package/dist/deciders.js +53 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +56 -56
- package/dist/prove.js +78 -78
- package/dist/run.cjs +40 -44
- package/dist/run.js +42 -46
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +49 -44
- package/dist/transfer.js +48 -43
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +14 -2
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +116 -64
- package/src/check.ts +516 -280
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +18 -4
- package/src/cli/tlc.ts +18 -12
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +23 -10
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +68 -15
- package/src/dfid.ts +101 -36
- package/src/environment.ts +123 -38
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +370 -99
- package/src/exit-codes.ts +28 -14
- package/src/instances.ts +135 -11
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +675 -236
- package/src/lexer.ts +12 -2
- package/src/liveness-checker.ts +179 -60
- package/src/liveness.ts +51 -10
- package/src/obligations/index.ts +1 -1
- package/src/obligations/normalize.ts +1 -4
- package/src/obligations/printer.ts +5 -5
- package/src/obligations/source.ts +2 -0
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/parser.ts +180 -149
- package/src/prover/isabelle/isar/attrib.ts +4 -4
- package/src/prover/isabelle/isar/rule-cases.ts +8 -6
- package/src/prover/isabelle/provers/clasimp.ts +1 -1
- package/src/prover/isabelle/provers/hypsubst.ts +2 -2
- package/src/prover/isabelle/pure/rewriter.ts +3 -3
- package/src/prover/isabelle/pure/term.ts +3 -3
- package/src/prover/prep/md5.ts +26 -29
- package/src/prover/smt/rewrite.ts +2 -7
- package/src/prover/smt/simplify.ts +1 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +171 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +66 -14
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +27 -1
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-simplifier.ts +11 -13
- package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
- package/src/prover/smt/solver/bv-rewriter.ts +1 -1
- package/src/prover/smt/solver/card2bv.ts +35 -18
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
- package/src/prover/smt/solver/context.ts +84 -15
- package/src/prover/smt/solver/ctx-simplify.ts +1 -2
- package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +28 -16
- package/src/prover/smt/solver/diff-neq.ts +1 -2
- package/src/prover/smt/solver/dt2bv-tactic.ts +57 -21
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
- package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/egraph.ts +4 -11
- package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
- package/src/prover/smt/solver/euf/mam.ts +1 -5
- package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
- package/src/prover/smt/solver/euf/th-solver.ts +0 -7
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fd-solver.ts +608 -139
- package/src/prover/smt/solver/fix-dl-var.ts +1 -2
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
- package/src/prover/smt/solver/goal.ts +6 -3
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/hashtable.ts +4 -0
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/logic-tactics.ts +15 -5
- package/src/prover/smt/solver/lp/core-solver.ts +12 -8
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +6 -2
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +158 -80
- package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -290
- package/src/prover/smt/solver/lp/union-find.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +1 -1
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-based-opt.ts +1 -1
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +85 -43
- package/src/prover/smt/solver/mpf.ts +2 -4
- package/src/prover/smt/solver/mus.ts +2 -3
- package/src/prover/smt/solver/muz/dl-context.ts +22 -44
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
- package/src/prover/smt/solver/muz/dl-rule.ts +8 -9
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
- package/src/prover/smt/solver/muz/horn-tactic.ts +15 -2
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/nlqsat.ts +1 -1
- package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
- package/src/prover/smt/solver/nlsat/solver.ts +74 -64
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
- package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
- package/src/prover/smt/solver/nnf.ts +6 -2
- package/src/prover/smt/solver/opt-context.ts +21 -7
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-preprocess.ts +1 -1
- package/src/prover/smt/solver/opt-solver.ts +10 -6
- package/src/prover/smt/solver/optsmt.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/pb-rewriter.ts +1 -4
- package/src/prover/smt/solver/poly-rewriter.ts +75 -18
- package/src/prover/smt/solver/probes.ts +88 -23
- package/src/prover/smt/solver/proto-model.ts +8 -8
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
- package/src/prover/smt/solver/qe-lite.ts +2 -2
- package/src/prover/smt/solver/qe.ts +3 -2
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/quantifier-manager.ts +14 -9
- package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/rlimit.ts +7 -3
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +65 -12
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +129 -43
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-constraint.ts +7 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +26 -7
- package/src/prover/smt/solver/sat/sat-tactic.ts +17 -7
- package/src/prover/smt/solver/sat/sat2goal.ts +72 -48
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +27 -47
- package/src/prover/smt/solver/seq-axioms.ts +20 -35
- package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
- package/src/prover/smt/solver/seq-derive.ts +2 -2
- package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
- package/src/prover/smt/solver/seq-monadic.ts +7 -5
- package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
- package/src/prover/smt/solver/seq-re-util.ts +1 -1
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +2 -2
- package/src/prover/smt/solver/seq-rewriter.ts +31 -29
- package/src/prover/smt/solver/seq-skolem.ts +0 -23
- package/src/prover/smt/solver/seq-view-witness.ts +4 -4
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +48 -7
- package/src/prover/smt/solver/smt-setup.ts +106 -13
- package/src/prover/smt/solver/smtlib-parser.ts +589 -224
- package/src/prover/smt/solver/smtlib-script.ts +713 -210
- package/src/prover/smt/solver/solve-eqs.ts +36 -37
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +350 -195
- package/src/prover/smt/solver/theory-bv.ts +13 -3
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
- package/src/prover/smt/solver/theory-lra-state.ts +1 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -1
- package/src/prover/smt/solver/theory-pb.ts +24 -7
- package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
- package/src/prover/smt/solver/theory-seq-state.ts +2 -21
- package/src/prover/smt/solver/theory-without-terms.ts +24 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/index-table.ts +5 -2
- package/src/prover/zenon/isar-case.ts +1 -1
- package/src/prover/zenon/isar.ts +2 -2
- package/src/prover/zenon/phrase.ts +1 -1
- package/src/resolve.ts +1274 -257
- package/src/runtime.ts +7 -1
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +5 -15
- package/src/sany/generator-def-entries.ts +123 -36
- package/src/sany/generator-definitions.ts +5 -3
- package/src/sany/generator-expressions.ts +60 -37
- package/src/sany/generator-proofs.ts +18 -12
- package/src/sany/generator.ts +12 -6
- package/src/sany/lexer.ts +15 -7
- package/src/sany/modules.ts +4 -2
- package/src/sany/nodes.ts +1 -1
- package/src/sany/selectors.ts +11 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +319 -135
- package/src/simulate.ts +235 -182
- package/src/spec-description.ts +8 -6
- package/src/standard-definitions.ts +1 -0
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +564 -138
- package/src/successors.ts +37 -13
- package/src/symmetry.ts +2 -1
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/order.ts +14 -3
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +67 -43
- package/src/tlc/tlc-operators.ts +10 -8
- package/src/tlc/tlcext-operators.ts +44 -15
- package/src/tlc/trace-spec.ts +9 -22
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +52 -31
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +150 -79
package/src/values.ts
CHANGED
|
@@ -107,6 +107,7 @@ export interface FilteredSetValue extends LazySet {
|
|
|
107
107
|
kind: "FilteredSet";
|
|
108
108
|
base: Value;
|
|
109
109
|
test: (element: Value, isMember: boolean) => boolean;
|
|
110
|
+
startPass?: (isMaterialized: boolean) => (element: Value) => boolean;
|
|
110
111
|
source?: FilteredSetSource;
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -231,7 +232,7 @@ export const isModelValue = (value: Value): value is ModelValue =>
|
|
|
231
232
|
export const isEnumeratedSet = (value: Value): value is SetValue | MixedSetValue =>
|
|
232
233
|
typeof value === "object" && (value.kind === "Set" || value.kind === "MixedSet");
|
|
233
234
|
|
|
234
|
-
|
|
235
|
+
const describeKind = (value: Value) => {
|
|
235
236
|
if (typeof value === "boolean") return "boolean";
|
|
236
237
|
if (typeof value === "number") return "integer";
|
|
237
238
|
if (typeof value === "string") return "string";
|
|
@@ -266,8 +267,19 @@ export const getPrintedPairs = (functionValue: FunctionValue): [Value, Value][]
|
|
|
266
267
|
? functionValue.domain.map((key, index) => [key, functionValue.range[index]])
|
|
267
268
|
: getWrittenPairs(functionValue);
|
|
268
269
|
|
|
269
|
-
export const createWrittenRecord = (
|
|
270
|
-
|
|
270
|
+
export const createWrittenRecord = (
|
|
271
|
+
names: Value[],
|
|
272
|
+
writtenIndexes: number[],
|
|
273
|
+
writtenRange: Value[],
|
|
274
|
+
writtenNames: Value[],
|
|
275
|
+
) =>
|
|
276
|
+
setWrittenOrder(
|
|
277
|
+
createSortedRecord(
|
|
278
|
+
names,
|
|
279
|
+
writtenIndexes.map((index) => writtenRange[index]),
|
|
280
|
+
),
|
|
281
|
+
writtenNames,
|
|
282
|
+
);
|
|
271
283
|
|
|
272
284
|
const forgetWrittenOrder = (value: Value): void => {
|
|
273
285
|
if (typeof value !== "object" || (value.kind !== "Function" && value.kind !== "Set")) return;
|
|
@@ -277,6 +289,13 @@ const forgetWrittenOrder = (value: Value): void => {
|
|
|
277
289
|
value.range.forEach(forgetWrittenOrder);
|
|
278
290
|
};
|
|
279
291
|
|
|
292
|
+
// TLC's SetOfRcdsValue#member and SetOfFcnsValue#member normalize the record or function they check in place.
|
|
293
|
+
const forgetOwnWrittenOrder = (value: Value) => {
|
|
294
|
+
if (isWrittenOrderUsed && typeof value === "object" && value.kind === "Function") {
|
|
295
|
+
value.writtenKeys = undefined;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
280
299
|
const isRecordDomain = (domain: Value[]) => domain.every((key) => typeof key === "string");
|
|
281
300
|
|
|
282
301
|
const isRecordMismatch = (left: Value[], right: Value[]) =>
|
|
@@ -339,16 +358,16 @@ const checkModelValueTypes = (left: Value, right: Value, isEquality: boolean) =>
|
|
|
339
358
|
if (isModelValue(left) && isModelValue(right)) {
|
|
340
359
|
if (leftType === undefined || rightType === undefined || leftType === rightType) return;
|
|
341
360
|
throw new TlaEvaluationError(
|
|
342
|
-
`Attempted to ${action} the differently-typed model values ${formatValue(left)} and ${formatValue(right)}`,
|
|
361
|
+
`Attempted to ${action} the differently-typed model values ${prettyPrint(formatValue(left))} and ${prettyPrint(formatValue(right))}`,
|
|
343
362
|
);
|
|
344
363
|
}
|
|
345
364
|
if (leftType !== undefined) {
|
|
346
365
|
throw new TlaEvaluationError(
|
|
347
|
-
`Attempted to ${action}${isEquality ? "" : " the"} typed model value ${formatValue(left)} and non-model value\n${formatValue(right)}`,
|
|
366
|
+
`Attempted to ${action}${isEquality ? "" : " the"} typed model value ${prettyPrint(formatValue(left))} and non-model value\n${prettyPrint(formatValue(right))}`,
|
|
348
367
|
);
|
|
349
368
|
}
|
|
350
369
|
throw new TlaEvaluationError(
|
|
351
|
-
`Attempted to ${action} the typed model value ${formatValue(right)} and the non-model value\n${formatValue(left)}`,
|
|
370
|
+
`Attempted to ${action} the typed model value ${prettyPrint(formatValue(right))} and the non-model value\n${prettyPrint(formatValue(left))}`,
|
|
352
371
|
);
|
|
353
372
|
};
|
|
354
373
|
|
|
@@ -453,7 +472,7 @@ const isOverriddenComparison = (left: Value, right: Value) =>
|
|
|
453
472
|
const createComparisonError = (left: Value, right: Value) =>
|
|
454
473
|
new TlaEvaluationError(
|
|
455
474
|
isOverriddenSet(left)
|
|
456
|
-
? `Attempted to compare overridden value ${formatValue(left, true)} with non-overridden value:\n${formatValue(right)}`
|
|
475
|
+
? `Attempted to compare overridden value ${prettyPrint(formatValue(left, true))} with non-overridden value:\n${prettyPrint(formatValue(right))}`
|
|
457
476
|
: `Attempted to compare ${describeKind(left)} ${formatValue(left)} with ${describeKind(right)} ${formatValue(right)}`,
|
|
458
477
|
);
|
|
459
478
|
|
|
@@ -464,7 +483,7 @@ const compareOverriddenSets = (
|
|
|
464
483
|
) => {
|
|
465
484
|
if (!isOverriddenSet(left)) {
|
|
466
485
|
throw new TlaEvaluationError(
|
|
467
|
-
`Attempted to ${verb} the set ${formatValue(isEnumerable(left) ? toFiniteSet(left) : left, true)} with the value:\n${formatValue(right, true)}`,
|
|
486
|
+
`Attempted to ${verb} the set ${prettyPrint(formatValue(isEnumerable(left) ? toFiniteSet(left) : left, true))} with the value:\n${prettyPrint(formatValue(right, true))}`,
|
|
468
487
|
);
|
|
469
488
|
}
|
|
470
489
|
if (!isOverriddenSet(right)) throw createComparisonError(left, right);
|
|
@@ -475,14 +494,16 @@ const compareOverriddenSets = (
|
|
|
475
494
|
return leftName === "Nat" ? -1 : 1;
|
|
476
495
|
}
|
|
477
496
|
throw new TlaModuleError(
|
|
478
|
-
`Attempted to compare ${formatValue(left, true)} with the value\n${formatValue(right, true)}`,
|
|
497
|
+
`Attempted to compare ${prettyPrint(formatValue(left, true))} with the value\n${prettyPrint(formatValue(right, true))}`,
|
|
479
498
|
);
|
|
480
499
|
};
|
|
481
500
|
|
|
482
501
|
export const ANY_SET: InfiniteSetValue = { kind: "InfiniteSet", name: "Any" };
|
|
483
502
|
|
|
484
503
|
const compareAny = (other: Value): never => {
|
|
485
|
-
throw new TlaModuleError(
|
|
504
|
+
throw new TlaModuleError(
|
|
505
|
+
`Attempted to compare ANY with the value\n${prettyPrint(formatValue(other))}`,
|
|
506
|
+
);
|
|
486
507
|
};
|
|
487
508
|
|
|
488
509
|
const compareWithItself = (value: Value) => {
|
|
@@ -863,7 +884,7 @@ const describeScalarMismatch = (
|
|
|
863
884
|
SCALAR_KINDS[
|
|
864
885
|
typeof left === "number" ? "number" : typeof left === "string" ? "string" : "boolean"
|
|
865
886
|
];
|
|
866
|
-
return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${formatValue(left)} with ${kind.other}:\n${formatValue(right)}`;
|
|
887
|
+
return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${prettyPrint(formatValue(left))} with ${kind.other}:\n${prettyPrint(formatValue(right))}`;
|
|
867
888
|
};
|
|
868
889
|
|
|
869
890
|
const getComparisonVerb = (isEquality: boolean) => (isEquality ? "check equality of" : "compare");
|
|
@@ -878,7 +899,7 @@ const compareTlcFunctions = (
|
|
|
878
899
|
if (!other) {
|
|
879
900
|
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
880
901
|
throw new TlaEvaluationError(
|
|
881
|
-
`Attempted to ${getComparisonVerb(isEquality)} the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
902
|
+
`Attempted to ${getComparisonVerb(isEquality)} the function ${prettyPrint(formatValue(left))} with the value:\n${prettyPrint(formatValue(right))}`,
|
|
882
903
|
);
|
|
883
904
|
}
|
|
884
905
|
if (functionValue.range.length !== other.range.length)
|
|
@@ -899,7 +920,7 @@ const compareTlcFunctions = (
|
|
|
899
920
|
const key = keys[index];
|
|
900
921
|
if (typeof key !== "number") {
|
|
901
922
|
throw new TlaEvaluationError(
|
|
902
|
-
`Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${formatValue(key)}.`,
|
|
923
|
+
`Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${prettyPrint(formatValue(key))}.`,
|
|
903
924
|
);
|
|
904
925
|
}
|
|
905
926
|
const difference =
|
|
@@ -936,7 +957,7 @@ const compareFunctionLikeTlc = (
|
|
|
936
957
|
if (!record) {
|
|
937
958
|
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
938
959
|
throw new TlaEvaluationError(
|
|
939
|
-
`Attempted to ${getComparisonVerb(isEquality)} record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
|
|
960
|
+
`Attempted to ${getComparisonVerb(isEquality)} record:\n${prettyPrint(formatValue(left))}\nwith non-record\n${prettyPrint(formatValue(right))}`,
|
|
940
961
|
);
|
|
941
962
|
}
|
|
942
963
|
return (
|
|
@@ -978,7 +999,7 @@ const compareSetLikeTlc = (left: ObjectValue, right: Value, isEquality: boolean)
|
|
|
978
999
|
if (!isSetValue(right)) {
|
|
979
1000
|
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
980
1001
|
throw new TlaEvaluationError(
|
|
981
|
-
`Attempted to ${getComparisonVerb(isEquality)} the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
1002
|
+
`Attempted to ${getComparisonVerb(isEquality)} the set ${prettyPrint(formatValue(left))} with the value:\n${prettyPrint(formatValue(right))}`,
|
|
982
1003
|
);
|
|
983
1004
|
}
|
|
984
1005
|
const sets = getSetElementsLikeTlc(left, right);
|
|
@@ -1057,6 +1078,7 @@ export const markNormalized = (value: Value): void => {
|
|
|
1057
1078
|
value.elements.forEach(markNormalized);
|
|
1058
1079
|
}
|
|
1059
1080
|
if (value.kind === "Function") {
|
|
1081
|
+
value.writtenKeys = undefined;
|
|
1060
1082
|
value.domain.forEach(markNormalized);
|
|
1061
1083
|
value.range.forEach(markNormalized);
|
|
1062
1084
|
}
|
|
@@ -1330,7 +1352,7 @@ const getUnionSet = (set: Value, index: number, union: UnionValue) => {
|
|
|
1330
1352
|
throw new TlaEvaluationError(
|
|
1331
1353
|
index === 0
|
|
1332
1354
|
? "Attempted to enumerate UNION(s), but some element of s is nonenumerable."
|
|
1333
|
-
: `Attempted to enumerate the nonenumerable set:\n${formatValue(set)}\nwhen enumerating:\n${formatUnion(union)}`,
|
|
1355
|
+
: `Attempted to enumerate the nonenumerable set:\n${prettyPrint(formatValue(set))}\nwhen enumerating:\n${prettyPrint(formatUnion(union))}`,
|
|
1334
1356
|
);
|
|
1335
1357
|
};
|
|
1336
1358
|
|
|
@@ -1530,13 +1552,13 @@ const enumerateSet = (
|
|
|
1530
1552
|
if (!isVersion174 && isEmptySet(value)) return [];
|
|
1531
1553
|
if (isOverriddenSet(value.domain)) {
|
|
1532
1554
|
throw new TlaEvaluationError(
|
|
1533
|
-
`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${formatValue(value.domain)}\ncannot be enumerated.`,
|
|
1555
|
+
`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${prettyPrint(formatValue(value.domain))}\ncannot be enumerated.`,
|
|
1534
1556
|
);
|
|
1535
1557
|
}
|
|
1536
1558
|
const domain = getFunctionDomain(value.domain);
|
|
1537
1559
|
if ((domain.length > 0 || isVersion174) && isOverriddenSet(value.range)) {
|
|
1538
1560
|
throw new TlaEvaluationError(
|
|
1539
|
-
`Attempted to enumerate a set of the form [D -> R],but the range R:\n${formatValue(value.range)}\ncannot be enumerated.`,
|
|
1561
|
+
`Attempted to enumerate a set of the form [D -> R],but the range R:\n${prettyPrint(formatValue(value.range))}\ncannot be enumerated.`,
|
|
1540
1562
|
);
|
|
1541
1563
|
}
|
|
1542
1564
|
const range = domain.length === 0 ? [] : getElements(value.range);
|
|
@@ -1550,7 +1572,7 @@ const enumerateSet = (
|
|
|
1550
1572
|
value.sets,
|
|
1551
1573
|
getElements,
|
|
1552
1574
|
(set, index) =>
|
|
1553
|
-
`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${value.names[index]}' field:\n${formatValue(set)}`,
|
|
1575
|
+
`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${value.names[index]}' field:\n${prettyPrint(formatValue(set))}`,
|
|
1554
1576
|
);
|
|
1555
1577
|
return getCartesianProduct(fields).map((combination) =>
|
|
1556
1578
|
createRecord(value.names.map((name, index): [string, Value] => [name, combination[index]])),
|
|
@@ -1562,19 +1584,21 @@ const enumerateSet = (
|
|
|
1562
1584
|
value.factors,
|
|
1563
1585
|
getElements,
|
|
1564
1586
|
(factor, index) =>
|
|
1565
|
-
`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${index}:\n${formatValue(factor)}`,
|
|
1587
|
+
`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${index}:\n${prettyPrint(formatValue(factor))}`,
|
|
1566
1588
|
);
|
|
1567
1589
|
return getCartesianProduct(factors).map(createTuple);
|
|
1568
1590
|
}
|
|
1569
1591
|
case "FilteredSet":
|
|
1570
1592
|
if (!isSetValue(value.base) || isOverriddenSet(value.base)) {
|
|
1571
1593
|
throw new TlaEvaluationError(
|
|
1572
|
-
`Attempted to enumerate { x \\in S : p(x) } when S:\n${formatValue(value.base)}\nis not enumerable`,
|
|
1594
|
+
`Attempted to enumerate { x \\in S : p(x) } when S:\n${prettyPrint(formatValue(value.base))}\nis not enumerable`,
|
|
1573
1595
|
);
|
|
1574
1596
|
}
|
|
1575
1597
|
return toFiniteSet(
|
|
1576
1598
|
createEnumeratedSet(
|
|
1577
|
-
getStreamedElements(value.base).filter(
|
|
1599
|
+
getStreamedElements(value.base).filter(
|
|
1600
|
+
value.startPass?.(true) ?? ((element) => value.test(element, false)),
|
|
1601
|
+
),
|
|
1578
1602
|
),
|
|
1579
1603
|
).elements;
|
|
1580
1604
|
case "Union": {
|
|
@@ -1593,12 +1617,12 @@ const enumerateSet = (
|
|
|
1593
1617
|
!isTlcEnumerable(value.right)
|
|
1594
1618
|
) {
|
|
1595
1619
|
throw new TlaEvaluationError(
|
|
1596
|
-
`Attempted to enumerate S \\cap T when neither S:\n${formatValue(value.left)}\nnor T:\n${formatValue(value.right)}\nis enumerable`,
|
|
1620
|
+
`Attempted to enumerate S \\cap T when neither S:\n${prettyPrint(formatValue(value.left))}\nnor T:\n${prettyPrint(formatValue(value.right))}\nis enumerable`,
|
|
1597
1621
|
);
|
|
1598
1622
|
}
|
|
1599
1623
|
if (value.operator === "\\" && !isTlcEnumerable(value.left)) {
|
|
1600
1624
|
throw new TlaEvaluationError(
|
|
1601
|
-
`Attempted to enumerate S \\ T when S:\n${formatValue(value.left)}\nis not enumerable.`,
|
|
1625
|
+
`Attempted to enumerate S \\ T when S:\n${prettyPrint(formatValue(value.left))}\nis not enumerable.`,
|
|
1602
1626
|
);
|
|
1603
1627
|
}
|
|
1604
1628
|
if (value.operator === "\\cup") {
|
|
@@ -1689,7 +1713,7 @@ const openStream = (value: Value): void => {
|
|
|
1689
1713
|
const listUnionLikeTlc = (union: SetOperationValue) => {
|
|
1690
1714
|
if (!isTlcEnumerable(union.left) || !isTlcEnumerable(union.right)) {
|
|
1691
1715
|
throw new TlaEvaluationError(
|
|
1692
|
-
`Attempted to enumerate S \\cup T when S:\n${formatValue(union.left)}\nand T:\n${formatValue(union.right)}\nare not both enumerable`,
|
|
1716
|
+
`Attempted to enumerate S \\cup T when S:\n${prettyPrint(formatValue(union.left))}\nand T:\n${prettyPrint(formatValue(union.right))}\nare not both enumerable`,
|
|
1693
1717
|
);
|
|
1694
1718
|
}
|
|
1695
1719
|
openStream(union.left);
|
|
@@ -1800,6 +1824,8 @@ const someElementOfStream = (value: ObjectValue, visit: (element: Value) => bool
|
|
|
1800
1824
|
);
|
|
1801
1825
|
}
|
|
1802
1826
|
if (value.kind === "FilteredSet" && isTlcEnumerable(value.base)) {
|
|
1827
|
+
const test = value.startPass?.(false);
|
|
1828
|
+
if (test) return someStreamedElement(value.base, (element) => test(element) && visit(element));
|
|
1803
1829
|
return someStreamedElement(
|
|
1804
1830
|
value.base,
|
|
1805
1831
|
(element) => value.test(element, false) && visit(element),
|
|
@@ -1827,6 +1853,7 @@ const someElementOfStream = (value: ObjectValue, visit: (element: Value) => bool
|
|
|
1827
1853
|
|
|
1828
1854
|
export const isEmptySet = (value: Value): boolean => {
|
|
1829
1855
|
if (typeof value !== "object" || !isSetValue(value)) {
|
|
1856
|
+
setTrace.sets?.push(value);
|
|
1830
1857
|
throw new TlaEvaluationError(`Shouldn't call isEmpty() on value ${formatValue(value)}`);
|
|
1831
1858
|
}
|
|
1832
1859
|
switch (value.kind) {
|
|
@@ -1868,18 +1895,18 @@ const getProductCardinality = (
|
|
|
1868
1895
|
}, 1);
|
|
1869
1896
|
|
|
1870
1897
|
const describeOverflow = (value: Value) =>
|
|
1871
|
-
`Overflow when computing the number of elements in:\n${formatValue(value)}`;
|
|
1898
|
+
`Overflow when computing the number of elements in:\n${prettyPrint(formatValue(value))}`;
|
|
1872
1899
|
|
|
1873
1900
|
export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
1874
1901
|
if (typeof value !== "object") {
|
|
1875
1902
|
throw new TlaEvaluationError(
|
|
1876
|
-
`Attempted to compute the number of elements in the ${describeKind(value)} ${formatValue(value)}.`,
|
|
1903
|
+
`Attempted to compute the number of elements in the ${describeKind(value)} ${prettyPrint(formatValue(value))}.`,
|
|
1877
1904
|
);
|
|
1878
1905
|
}
|
|
1879
1906
|
switch (value.kind) {
|
|
1880
1907
|
case "ModelValue":
|
|
1881
1908
|
throw new TlaEvaluationError(
|
|
1882
|
-
`Attempted to compute the number of elements in the model value ${formatValue(value)}.`,
|
|
1909
|
+
`Attempted to compute the number of elements in the model value ${prettyPrint(formatValue(value))}.`,
|
|
1883
1910
|
);
|
|
1884
1911
|
case "Function":
|
|
1885
1912
|
return value.domain.length;
|
|
@@ -1897,7 +1924,7 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
1897
1924
|
case "InfiniteSet":
|
|
1898
1925
|
case "SequenceSet":
|
|
1899
1926
|
throw new TlaEvaluationError(
|
|
1900
|
-
`Attempted to compute the number of elements in the overridden value ${formatValue(value)}.`,
|
|
1927
|
+
`Attempted to compute the number of elements in the overridden value ${prettyPrint(formatValue(value))}.`,
|
|
1901
1928
|
);
|
|
1902
1929
|
case "Subset": {
|
|
1903
1930
|
const size = getCardinality(value.base, version);
|
|
@@ -1928,7 +1955,8 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
1928
1955
|
return getProductCardinality(
|
|
1929
1956
|
value.factors,
|
|
1930
1957
|
version,
|
|
1931
|
-
() =>
|
|
1958
|
+
() =>
|
|
1959
|
+
`Overflow when computing the number of elements in ${prettyPrint(formatValue(value))}`,
|
|
1932
1960
|
);
|
|
1933
1961
|
default:
|
|
1934
1962
|
cacheSet(value);
|
|
@@ -1937,12 +1965,12 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
1937
1965
|
};
|
|
1938
1966
|
|
|
1939
1967
|
const describeInfiniteCheck = (value: Value) =>
|
|
1940
|
-
`Attempted to check if the set ${formatValue(value)}is finite.`;
|
|
1968
|
+
`Attempted to check if the set ${prettyPrint(formatValue(value))}is finite.`;
|
|
1941
1969
|
|
|
1942
1970
|
export const isFiniteSet = (value: Value): boolean => {
|
|
1943
1971
|
if (typeof value !== "object" || value.kind === "ModelValue") {
|
|
1944
1972
|
throw new TlaEvaluationError(
|
|
1945
|
-
`Attempted to check if the ${describeKind(value)} ${formatValue(value)} is a finite set.`,
|
|
1973
|
+
`Attempted to check if the ${describeKind(value)} ${prettyPrint(formatValue(value))} is a finite set.`,
|
|
1946
1974
|
);
|
|
1947
1975
|
}
|
|
1948
1976
|
switch (value.kind) {
|
|
@@ -1953,7 +1981,7 @@ export const isFiniteSet = (value: Value): boolean => {
|
|
|
1953
1981
|
return true;
|
|
1954
1982
|
case "LazyFunction":
|
|
1955
1983
|
throw new TlaEvaluationError(
|
|
1956
|
-
`Attempted to check if the function:\n${formatValue(value)}\nis a finite set.`,
|
|
1984
|
+
`Attempted to check if the function:\n${prettyPrint(formatValue(value))}\nis a finite set.`,
|
|
1957
1985
|
);
|
|
1958
1986
|
case "InfiniteSet":
|
|
1959
1987
|
return false;
|
|
@@ -1999,7 +2027,7 @@ export const isFiniteSet = (value: Value): boolean => {
|
|
|
1999
2027
|
case "FilteredSet":
|
|
2000
2028
|
if (!isFiniteSet(value.base)) {
|
|
2001
2029
|
throw new TlaEvaluationError(
|
|
2002
|
-
`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${formatValue(value.base)}\nis finite.`,
|
|
2030
|
+
`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${prettyPrint(formatValue(value.base))}\nis finite.`,
|
|
2003
2031
|
);
|
|
2004
2032
|
}
|
|
2005
2033
|
return true;
|
|
@@ -2053,14 +2081,15 @@ export const getSequenceElements = (value: Value): Value[] | undefined => {
|
|
|
2053
2081
|
};
|
|
2054
2082
|
|
|
2055
2083
|
const describeNonSetMembership = (element: Value, value: Value) => {
|
|
2056
|
-
const prefix = `Attempted to check if the value:\n${formatValue(element)}\nis an element of the`;
|
|
2057
|
-
if (!isFunctionValue(value))
|
|
2084
|
+
const prefix = `Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of the`;
|
|
2085
|
+
if (!isFunctionValue(value))
|
|
2086
|
+
return `${prefix} ${describeKind(value)} ${prettyPrint(formatValue(value))}`;
|
|
2058
2087
|
const functionClass = getFunctionClass(value);
|
|
2059
2088
|
if (functionClass === "record") {
|
|
2060
|
-
return `Attempted to check if element:\n${formatValue(element)}\nis in the record:\n${formatValue(value)}`;
|
|
2089
|
+
return `Attempted to check if element:\n${prettyPrint(formatValue(element))}\nis in the record:\n${prettyPrint(formatValue(value))}`;
|
|
2061
2090
|
}
|
|
2062
2091
|
if (functionClass === "tuple") return "Attempted to check set membership in a tuple value.";
|
|
2063
|
-
return `${prefix} function ${formatValue(value)}`;
|
|
2092
|
+
return `${prefix} function ${prettyPrint(formatValue(value))}`;
|
|
2064
2093
|
};
|
|
2065
2094
|
|
|
2066
2095
|
interface TracedCallStack {
|
|
@@ -2166,7 +2195,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2166
2195
|
if (typeof element === "number") return element >= set.low && element <= set.high;
|
|
2167
2196
|
if (set.low <= set.high && (!isModelValue(element) || element.type !== undefined)) {
|
|
2168
2197
|
throw new TlaEvaluationError(
|
|
2169
|
-
`Attempted to check if the value:\n${formatValue(element)}\nis in the integer interval ${formatValue(set)}`,
|
|
2198
|
+
`Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis in the integer interval ${prettyPrint(formatValue(set))}`,
|
|
2170
2199
|
);
|
|
2171
2200
|
}
|
|
2172
2201
|
return false;
|
|
@@ -2177,7 +2206,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2177
2206
|
set.name === "STRING" ? typeof element === "string" : typeof element === "number";
|
|
2178
2207
|
if (!isMemberType) {
|
|
2179
2208
|
throw new TlaModuleError(
|
|
2180
|
-
`Attempted to check if the value:\n${formatValue(element)}\nis an element of ${set.name}.`,
|
|
2209
|
+
`Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of ${set.name}.`,
|
|
2181
2210
|
);
|
|
2182
2211
|
}
|
|
2183
2212
|
return set.name !== "Nat" || (typeof element === "number" && element >= 0);
|
|
@@ -2196,6 +2225,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2196
2225
|
`Attempted to check if \n${formatValue(element)}\nwhich is not a TLC function value, is in the set of functions:\n${prettyPrint(formatValue(set))}`,
|
|
2197
2226
|
);
|
|
2198
2227
|
}
|
|
2228
|
+
forgetOwnWrittenOrder(element);
|
|
2199
2229
|
const functionValue = toFiniteFunction(element);
|
|
2200
2230
|
const low = getIntervalLow(element, functionValue.domain);
|
|
2201
2231
|
const isDomain =
|
|
@@ -2208,11 +2238,12 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2208
2238
|
return isDomain && functionValue.range.every((item) => isElementOf(item, set.range));
|
|
2209
2239
|
}
|
|
2210
2240
|
case "RecordSet": {
|
|
2241
|
+
forgetOwnWrittenOrder(element);
|
|
2211
2242
|
const functionValue = isFunctionValue(element) ? toFiniteFunction(element) : undefined;
|
|
2212
2243
|
if (!functionValue || !isRecordDomain(functionValue.domain)) {
|
|
2213
2244
|
if (isModelValue(element)) return isModelValueMember(element, set);
|
|
2214
2245
|
throw new TlaEvaluationError(
|
|
2215
|
-
`Attempted to check if non-record\n${formatValue(element)}\nis in the set of records:\n${formatValue(set)}`,
|
|
2246
|
+
`Attempted to check if non-record\n${formatValue(element)}\nis in the set of records:\n${prettyPrint(formatValue(set))}`,
|
|
2216
2247
|
);
|
|
2217
2248
|
}
|
|
2218
2249
|
return (
|
|
@@ -2232,7 +2263,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2232
2263
|
if (isModelValue(element)) return isModelValueMember(element, set);
|
|
2233
2264
|
if (isFunction) return false;
|
|
2234
2265
|
throw new TlaEvaluationError(
|
|
2235
|
-
`Attempted to check if non-tuple\n${formatValue(element)}\nis in the set of tuples:\n${formatValue(set)}`,
|
|
2266
|
+
`Attempted to check if non-tuple\n${prettyPrint(formatValue(element))}\nis in the set of tuples:\n${prettyPrint(formatValue(set))}`,
|
|
2236
2267
|
);
|
|
2237
2268
|
}
|
|
2238
2269
|
return (
|
|
@@ -2252,7 +2283,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2252
2283
|
case "Union": {
|
|
2253
2284
|
if (!isTlcEnumerable(set.base)) {
|
|
2254
2285
|
throw new TlaEvaluationError(
|
|
2255
|
-
`Attempted to check if:\n ${formatValue(element)}\nis an element of the non-enumerable set:\n ${formatUnion(set)}`,
|
|
2286
|
+
`Attempted to check if:\n ${prettyPrint(formatValue(element))}\nis an element of the non-enumerable set:\n ${prettyPrint(formatUnion(set))}`,
|
|
2256
2287
|
);
|
|
2257
2288
|
}
|
|
2258
2289
|
const sets = toFiniteSet(set.base).elements;
|
|
@@ -2311,12 +2342,9 @@ export const toFiniteFunction = (value: Value): FunctionValue => {
|
|
|
2311
2342
|
throw new TlaEvaluationError("The domains of formal parameters must be enumerable.");
|
|
2312
2343
|
}
|
|
2313
2344
|
const domain = getFunctionDomain(value.domain);
|
|
2314
|
-
value.enumerated =
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
domain.map((key) => value.apply(key)),
|
|
2318
|
-
),
|
|
2319
|
-
getFunctionClass(value),
|
|
2345
|
+
value.enumerated = createSortedFunction(
|
|
2346
|
+
domain,
|
|
2347
|
+
domain.map((key) => value.apply(key)),
|
|
2320
2348
|
);
|
|
2321
2349
|
return value.enumerated;
|
|
2322
2350
|
}
|
|
@@ -2425,6 +2453,24 @@ const findKeyIndexLikeTlc = (
|
|
|
2425
2453
|
return computeLikeTlcOnFailure(findDomainIndex, failKeyLikeTlc, functionValue, argument);
|
|
2426
2454
|
};
|
|
2427
2455
|
|
|
2456
|
+
const describeBoundArgument = (
|
|
2457
|
+
functionValue: LazyFunctionValue,
|
|
2458
|
+
position: string,
|
|
2459
|
+
shown: Value,
|
|
2460
|
+
problem: string,
|
|
2461
|
+
) =>
|
|
2462
|
+
`In applying the function\n${prettyPrint(formatValue(functionValue))},\nthe ${position} is:\n${prettyPrint(formatValue(shown))}\nwhich ${problem}.\n`;
|
|
2463
|
+
|
|
2464
|
+
const createArgumentListError = (functionValue: LazyFunctionValue, argument: Value) =>
|
|
2465
|
+
new TlaEvaluationError(
|
|
2466
|
+
describeBoundArgument(
|
|
2467
|
+
functionValue,
|
|
2468
|
+
"argument list",
|
|
2469
|
+
argument,
|
|
2470
|
+
"does not match its formal parameter",
|
|
2471
|
+
),
|
|
2472
|
+
);
|
|
2473
|
+
|
|
2428
2474
|
// Deviation from TLC: FcnLambdaValue#apply indexes past an argument tuple shorter than the bounds and ignores a longer one, where this rejects the list.
|
|
2429
2475
|
const checkBoundArguments = (
|
|
2430
2476
|
functionValue: LazyFunctionValue,
|
|
@@ -2433,25 +2479,20 @@ const checkBoundArguments = (
|
|
|
2433
2479
|
) => {
|
|
2434
2480
|
const domain = functionValue.domain;
|
|
2435
2481
|
const elements = getSequenceElements(argument);
|
|
2436
|
-
|
|
2437
|
-
`In applying the function\n${prettyPrint(formatValue(functionValue))},\nthe ${position} is:\n${prettyPrint(formatValue(shown))}\nwhich ${problem}.\n`;
|
|
2438
|
-
const createListError = () =>
|
|
2439
|
-
new TlaEvaluationError(
|
|
2440
|
-
describe("argument list", argument, "does not match its formal parameter"),
|
|
2441
|
-
);
|
|
2442
|
-
if (elements === undefined) throw createListError();
|
|
2482
|
+
if (elements === undefined) throw createArgumentListError(functionValue, argument);
|
|
2443
2483
|
if (typeof domain !== "object" || domain.kind !== "ProductSet") {
|
|
2444
2484
|
throw new TlaEvaluationError(
|
|
2445
2485
|
`Attempted to apply a function to ${formatValue(argument)}, which is not in its domain`,
|
|
2446
2486
|
);
|
|
2447
2487
|
}
|
|
2448
2488
|
tupleLengths.forEach((tupleLength, index) => {
|
|
2449
|
-
if (index >= elements.length) throw
|
|
2489
|
+
if (index >= elements.length) throw createArgumentListError(functionValue, argument);
|
|
2450
2490
|
const element = elements[index];
|
|
2451
2491
|
const position = `argument number ${index + 1}`;
|
|
2452
2492
|
if (!isElementOf(element, domain.factors[index])) {
|
|
2453
2493
|
throw new TlaEvaluationError(
|
|
2454
|
-
|
|
2494
|
+
describeBoundArgument(
|
|
2495
|
+
functionValue,
|
|
2455
2496
|
position,
|
|
2456
2497
|
element,
|
|
2457
2498
|
tupleLength === undefined
|
|
@@ -2462,11 +2503,18 @@ const checkBoundArguments = (
|
|
|
2462
2503
|
}
|
|
2463
2504
|
if (tupleLength !== undefined && getSequenceElements(element)?.length !== tupleLength) {
|
|
2464
2505
|
throw new TlaEvaluationError(
|
|
2465
|
-
|
|
2506
|
+
describeBoundArgument(
|
|
2507
|
+
functionValue,
|
|
2508
|
+
position,
|
|
2509
|
+
element,
|
|
2510
|
+
"does not match its formal parameter",
|
|
2511
|
+
),
|
|
2466
2512
|
);
|
|
2467
2513
|
}
|
|
2468
2514
|
});
|
|
2469
|
-
if (elements.length > tupleLengths.length)
|
|
2515
|
+
if (elements.length > tupleLengths.length) {
|
|
2516
|
+
throw createArgumentListError(functionValue, argument);
|
|
2517
|
+
}
|
|
2470
2518
|
};
|
|
2471
2519
|
|
|
2472
2520
|
const isOutsideLambdaDomain = (functionValue: FunctionValue, argument: Value) =>
|
|
@@ -2544,6 +2592,12 @@ export const updateFunction = (
|
|
|
2544
2592
|
functionValue.kind === "LazyFunction" &&
|
|
2545
2593
|
(isKeptLazy || functionValue.enumerated === undefined);
|
|
2546
2594
|
if (isLazy) {
|
|
2595
|
+
if (
|
|
2596
|
+
functionValue.boundTupleLengths !== undefined &&
|
|
2597
|
+
getSequenceElements(argument) === undefined
|
|
2598
|
+
) {
|
|
2599
|
+
throw createArgumentListError(functionValue, argument);
|
|
2600
|
+
}
|
|
2547
2601
|
if (!isElementOf(argument, functionValue.domain)) return functionValue;
|
|
2548
2602
|
const updated = update(functionValue.apply(argument));
|
|
2549
2603
|
return setFunctionClass<LazyFunctionValue>(
|
|
@@ -2657,7 +2711,7 @@ const fingerprintValue = (value: Value): void => {
|
|
|
2657
2711
|
if (typeof value !== "object" || value.kind === "ModelValue") return;
|
|
2658
2712
|
if (value.kind === "InfiniteSet" || value.kind === "SequenceSet") {
|
|
2659
2713
|
throw new TlaEvaluationError(
|
|
2660
|
-
`TLC has found a state in which the value of a variable contains ${formatValue(value)}`,
|
|
2714
|
+
`TLC has found a state in which the value of a variable contains ${prettyPrint(formatValue(value))}`,
|
|
2661
2715
|
);
|
|
2662
2716
|
}
|
|
2663
2717
|
if (isSetValue(value)) {
|
|
@@ -2897,56 +2951,73 @@ const toPrintedFunction = (value: LazyFunctionValue) => {
|
|
|
2897
2951
|
|
|
2898
2952
|
export const formatNormalizedCopies = (values: Value[]) => {
|
|
2899
2953
|
const markedSets: SetValue[] = [];
|
|
2900
|
-
const
|
|
2954
|
+
const writtenFunctions: [FunctionValue, Value[]][] = [];
|
|
2955
|
+
const copiedFunctions: LazyFunctionValue[] = [];
|
|
2956
|
+
// TLC prints a deep copy, which copies functions but shares sets, so it caches only the functions inside a set.
|
|
2957
|
+
const normalize = (value: Value, isWrittenOrderKept: boolean, isCopied: boolean): void => {
|
|
2901
2958
|
if (typeof value !== "object") return;
|
|
2959
|
+
const normalizeInner = (inner: Value) => normalize(inner, isWrittenOrderKept, false);
|
|
2902
2960
|
switch (value.kind) {
|
|
2903
2961
|
case "Set":
|
|
2904
|
-
value.elements.forEach(
|
|
2962
|
+
value.elements.forEach(normalizeInner);
|
|
2905
2963
|
if (value.isNormalized) return;
|
|
2906
2964
|
value.isNormalized = true;
|
|
2907
2965
|
markedSets.push(value);
|
|
2908
2966
|
return;
|
|
2909
2967
|
case "MixedSet":
|
|
2910
|
-
value.elements.forEach(
|
|
2968
|
+
value.elements.forEach(normalizeInner);
|
|
2911
2969
|
toFiniteSet(value);
|
|
2912
2970
|
return;
|
|
2913
|
-
case "Function":
|
|
2914
|
-
value
|
|
2971
|
+
case "Function": {
|
|
2972
|
+
const isRangeWrittenOrderKept = isWrittenOrderKept || getFunctionClass(value) === "lambda";
|
|
2973
|
+
value.range.forEach((inner) => normalize(inner, isRangeWrittenOrderKept, isCopied));
|
|
2974
|
+
if (isWrittenOrderKept || value.writtenKeys === undefined) return;
|
|
2975
|
+
writtenFunctions.push([value, value.writtenKeys]);
|
|
2976
|
+
value.writtenKeys = undefined;
|
|
2915
2977
|
return;
|
|
2978
|
+
}
|
|
2916
2979
|
case "LazyFunction":
|
|
2917
|
-
|
|
2980
|
+
if (value.enumerated) return normalize(value.enumerated, true, isCopied);
|
|
2981
|
+
if (isCopied) copiedFunctions.push(value);
|
|
2982
|
+
normalizeInner(value.domain);
|
|
2918
2983
|
return;
|
|
2919
2984
|
case "SetOperation":
|
|
2920
|
-
|
|
2921
|
-
|
|
2985
|
+
normalizeInner(value.left);
|
|
2986
|
+
normalizeInner(value.right);
|
|
2922
2987
|
return;
|
|
2923
2988
|
case "FunctionSet":
|
|
2924
|
-
|
|
2925
|
-
|
|
2989
|
+
normalizeInner(value.domain);
|
|
2990
|
+
normalizeInner(value.range);
|
|
2926
2991
|
return;
|
|
2927
2992
|
case "RecordSet":
|
|
2928
|
-
value.sets.forEach(
|
|
2993
|
+
value.sets.forEach(normalizeInner);
|
|
2929
2994
|
return;
|
|
2930
2995
|
case "ProductSet":
|
|
2931
|
-
value.factors.forEach(
|
|
2996
|
+
value.factors.forEach(normalizeInner);
|
|
2932
2997
|
return;
|
|
2933
2998
|
case "Subset":
|
|
2934
2999
|
case "Union":
|
|
2935
3000
|
case "FilteredSet":
|
|
2936
3001
|
case "SequenceSet":
|
|
2937
|
-
|
|
3002
|
+
normalizeInner(value.base);
|
|
2938
3003
|
return;
|
|
2939
3004
|
default:
|
|
2940
3005
|
return;
|
|
2941
3006
|
}
|
|
2942
3007
|
};
|
|
2943
3008
|
try {
|
|
2944
|
-
values.forEach(normalize);
|
|
3009
|
+
values.forEach((value) => normalize(value, false, true));
|
|
2945
3010
|
return values.map((value) => formatValue(value, true, true));
|
|
2946
3011
|
} finally {
|
|
2947
3012
|
markedSets.forEach((set) => {
|
|
2948
3013
|
set.isNormalized = false;
|
|
2949
3014
|
});
|
|
3015
|
+
copiedFunctions.forEach((copied) => {
|
|
3016
|
+
copied.enumerated = undefined;
|
|
3017
|
+
});
|
|
3018
|
+
writtenFunctions.forEach((entry) => {
|
|
3019
|
+
entry[0].writtenKeys = entry[1];
|
|
3020
|
+
});
|
|
2950
3021
|
}
|
|
2951
3022
|
};
|
|
2952
3023
|
|
|
@@ -3092,10 +3163,10 @@ export const formatState = (state: Record<string, Value>, previous?: Record<stri
|
|
|
3092
3163
|
);
|
|
3093
3164
|
}
|
|
3094
3165
|
return entries
|
|
3095
|
-
.filter((
|
|
3096
|
-
.filter((
|
|
3097
|
-
.map((
|
|
3098
|
-
const text = formatJava(format, [
|
|
3166
|
+
.filter((entry) => !(isFormatted && entry[0] === "_format"))
|
|
3167
|
+
.filter((entry) => !previous || !isUnchanged(previous[entry[0]], entry[1]))
|
|
3168
|
+
.map((entry) => {
|
|
3169
|
+
const text = formatJava(format, [entry[0], prettyPrint(formatValue(entry[1]))]);
|
|
3099
3170
|
if (text === undefined) {
|
|
3100
3171
|
throw new TlaAliasFormatError(
|
|
3101
3172
|
`The _format field of the ALIAS ${alias} is ${formatValue(format)}, but it must format two strings, the name and the value of a field.`,
|