tla-ts 0.0.10-dev.99796fe03 → 0.0.10-dev.a17d6d9fa
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 +54 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- 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 +60 -60
- package/dist/prove.js +78 -78
- package/dist/run.cjs +42 -44
- package/dist/run.js +44 -46
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +43 -43
- package/dist/transfer.js +39 -39
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +1 -0
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +1 -1
- package/src/check-trace.ts +90 -51
- package/src/check.ts +367 -178
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +1 -2
- package/src/cli/tlc.ts +16 -10
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +26 -9
- package/src/dependencies.ts +49 -9
- package/src/dfid.ts +22 -10
- package/src/environment.ts +58 -33
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +117 -41
- package/src/exit-codes.ts +4 -2
- package/src/instances.ts +5 -5
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +138 -90
- package/src/liveness-checker.ts +81 -33
- package/src/liveness.ts +49 -11
- package/src/obligations/index.ts +1 -1
- package/src/obligations/normalize.ts +1 -4
- package/src/obligations/printer.ts +5 -5
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/parser.ts +112 -145
- 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 +169 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +63 -14
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- 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 +32 -18
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
- package/src/prover/smt/solver/context.ts +47 -9
- 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 +9 -4
- package/src/prover/smt/solver/diff-neq.ts +1 -2
- 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 +2 -0
- 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 +9 -2
- package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
- package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
- package/src/prover/smt/solver/lp/pdd.ts +2 -3
- 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/model-based-opt.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 +10 -4
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
- package/src/prover/smt/solver/muz/dl-rule.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 +1 -1
- 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/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 +20 -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 +9 -5
- package/src/prover/smt/solver/optsmt.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 +16 -6
- 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.ts +31 -25
- package/src/prover/smt/solver/rlimit.ts +4 -0
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +39 -5
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -5
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +25 -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-kernel.ts +39 -5
- package/src/prover/smt/solver/smt-setup.ts +96 -10
- package/src/prover/smt/solver/smtlib-parser.ts +584 -223
- package/src/prover/smt/solver/smtlib-script.ts +509 -154
- 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 +284 -168
- 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.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/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 +959 -243
- package/src/runtime.ts +7 -1
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +2 -13
- package/src/sany/generator-definitions.ts +3 -1
- package/src/sany/generator-expressions.ts +36 -30
- package/src/sany/generator-proofs.ts +5 -3
- package/src/sany/generator.ts +2 -1
- package/src/sany/lexer.ts +3 -3
- 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 +166 -101
- package/src/simulate.ts +110 -50
- package/src/spec-description.ts +5 -6
- package/src/standard-modules.ts +15 -6
- package/src/subexpressions.ts +398 -108
- package/src/successors.ts +4 -2
- package/src/symmetry.ts +1 -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 +3 -2
- 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/typed-tier.ts +32 -25
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +135 -78
package/src/levels.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getChildren,
|
|
3
3
|
type AssumeProve,
|
|
4
|
+
type Bound,
|
|
4
5
|
type Definition,
|
|
5
6
|
type Expression,
|
|
6
7
|
type Module,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
} from "./errors";
|
|
19
20
|
import { forEachChild } from "./instances";
|
|
20
21
|
import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
|
|
22
|
+
import { resolveSynonym } from "./tlc/jar-data";
|
|
21
23
|
import { STANDARD_LEVELS } from "./standard-definitions";
|
|
22
24
|
|
|
23
25
|
interface LevelData {
|
|
@@ -154,27 +156,50 @@ const CORE_SIGNATURES = new Map(
|
|
|
154
156
|
["BOOLEAN", 0, [], []],
|
|
155
157
|
["STRING", 0, [], []],
|
|
156
158
|
] as const
|
|
157
|
-
).map((
|
|
158
|
-
|
|
159
|
+
).map((signature): [string, OperatorLevels] => [
|
|
160
|
+
signature[0],
|
|
159
161
|
{
|
|
160
|
-
...createSignature(
|
|
161
|
-
nonLeibniz: new Set(
|
|
162
|
+
...createSignature(signature[0], signature[1], [...signature[2]], [...signature[3]]),
|
|
163
|
+
nonLeibniz: new Set(signature[1] > 1 ? [0, 1] : []),
|
|
162
164
|
},
|
|
163
165
|
]),
|
|
164
166
|
);
|
|
165
167
|
|
|
166
|
-
const SET_LEVELS = createSignature("$Set", 0, [2], [1]);
|
|
167
|
-
const JUNCTION_LEVELS = createSignature("$Junction", 0, [3], [1]);
|
|
168
|
-
const CHOOSE_LEVELS = createSignature("$Choose", 0, [2], [1]);
|
|
169
|
-
const FUNCTION_LEVELS = createSignature("$Function", 0, [3], [1]);
|
|
170
|
-
const APPLY_LEVELS = createSignature("$FcnApply", 0, [2, 2], [1, 1]);
|
|
171
|
-
const SELECT_LEVELS = createSignature("$RcdSelect", 0, [2, 0], [1, 1]);
|
|
172
168
|
const PRIME_LEVELS = createSignature("'", 2, [1], [0]);
|
|
169
|
+
const UNCHANGED_LEVELS = createSignature("UNCHANGED", 2, [1], [0]);
|
|
173
170
|
const ENABLED_LEVELS = createSignature("ENABLED", 1, [2], [0]);
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
171
|
+
const ALWAYS_LEVELS = createSignature("[]", 3, [3], [0]);
|
|
172
|
+
const EVENTUALLY_LEVELS = createSignature("<>", 3, [3], [0]);
|
|
173
|
+
const AND_LEVELS = createSignature("$ConjList", 0, [3], [1]);
|
|
174
|
+
const OR_LEVELS = createSignature("$DisjList", 0, [3], [1]);
|
|
175
|
+
const IF_LEVELS = createSignature("$IfThenElse", 0, [3], [1]);
|
|
176
|
+
const CASE_LEVELS = createSignature("$Case", 0, [3], [1]);
|
|
177
|
+
const FORALL_LEVELS = createSignature("$BoundedForall", 0, [3], [1]);
|
|
178
|
+
const EXISTS_LEVELS = createSignature("$BoundedExists", 0, [3], [1]);
|
|
179
|
+
const UNBOUNDED_FORALL_LEVELS = createSignature("$UnboundedForall", 0, [3], [1]);
|
|
180
|
+
const UNBOUNDED_EXISTS_LEVELS = createSignature("$UnboundedExists", 0, [3], [1]);
|
|
181
|
+
const TEMPORAL_FORALL_LEVELS = createSignature("$TemporalForall", 3, [3], [0]);
|
|
182
|
+
const TEMPORAL_EXISTS_LEVELS = createSignature("$TemporalExists", 3, [3], [0]);
|
|
183
|
+
const BOUNDED_CHOOSE_LEVELS = createSignature("$BoundedChoose", 0, [2], [1]);
|
|
184
|
+
const UNBOUNDED_CHOOSE_LEVELS = createSignature("$UnboundedChoose", 0, [2], [1]);
|
|
185
|
+
const SET_ENUMERATE_LEVELS = createSignature("$SetEnumerate", 0, [2], [1]);
|
|
186
|
+
const TUPLE_LEVELS = createSignature("$Tuple", 0, [2], [1]);
|
|
187
|
+
const SET_OF_FCNS_LEVELS = createSignature("$SetOfFcns", 0, [2], [1]);
|
|
188
|
+
const CARTESIAN_PROD_LEVELS = createSignature("$CartesianProd", 0, [2], [1]);
|
|
189
|
+
const SUBSET_OF_LEVELS = createSignature("$SubsetOf", 0, [2], [1]);
|
|
190
|
+
const SET_OF_ALL_LEVELS = createSignature("$SetOfAll", 0, [2], [1]);
|
|
191
|
+
const FCN_CONSTRUCTOR_LEVELS = createSignature("$FcnConstructor", 0, [3], [1]);
|
|
192
|
+
const RCD_CONSTRUCTOR_LEVELS = createSignature("$RcdConstructor", 0, [3], [1]);
|
|
193
|
+
const SET_OF_RCDS_LEVELS = createSignature("$SetOfRcds", 0, [2], [1]);
|
|
194
|
+
const EXCEPT_LEVELS = createSignature("$Except", 0, [2], [1]);
|
|
195
|
+
const PAIR_LEVELS = createSignature("$Pair", 0, [3], [1]);
|
|
196
|
+
const SEQ_LEVELS = createSignature("$Seq", 0, [2], [1]);
|
|
197
|
+
const APPLY_LEVELS = createSignature("$FcnApply", 0, [2, 2], [1, 1]);
|
|
198
|
+
const SELECT_LEVELS = createSignature("$RcdSelect", 0, [2, 0], [1, 1]);
|
|
199
|
+
const SQUARE_ACT_LEVELS = createSignature("$SquareAct", 2, [2, 1], [0, 0]);
|
|
200
|
+
const ANGLE_ACT_LEVELS = createSignature("$AngleAct", 2, [2, 1], [0, 0]);
|
|
201
|
+
const WF_LEVELS = createSignature("$WF", 3, [1, 2], [0, 0]);
|
|
202
|
+
const SF_LEVELS = createSignature("$SF", 3, [1, 2], [0, 0]);
|
|
178
203
|
|
|
179
204
|
const bindFormals = (scope: Scope, formals: OperatorParam[]) =>
|
|
180
205
|
formals.length === 0
|
|
@@ -253,15 +278,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
253
278
|
if (operand.kind !== "Value") return;
|
|
254
279
|
if (operand.data.level > getMaxLevel(operator, index)) {
|
|
255
280
|
throw new TlaSyntaxError(
|
|
256
|
-
`Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
|
|
281
|
+
`Level error in applying operator ${resolveSynonym(operator.name)}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
|
|
257
282
|
);
|
|
258
283
|
}
|
|
259
284
|
});
|
|
260
|
-
if (ranges.some((range) => range.level > ACTION_LEVEL)) {
|
|
261
|
-
throw new TlaSyntaxError(
|
|
262
|
-
`Level error in applying operator ${operator.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`,
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
285
|
const getOperand = (formal: string) => {
|
|
266
286
|
const index = operator.formals.findIndex((param) => param.name === formal);
|
|
267
287
|
return index === -1 ? undefined : operands[index];
|
|
@@ -448,16 +468,20 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
448
468
|
operator: OperatorLevels,
|
|
449
469
|
expressions: Expression[],
|
|
450
470
|
scope: Scope,
|
|
451
|
-
|
|
452
|
-
bound
|
|
471
|
+
bounds: Bound[] = [],
|
|
472
|
+
bound = getBoundNames(bounds),
|
|
453
473
|
) => {
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
474
|
+
const operands = toOperands(expressions, bindFormals(scope, toFormals(bound)));
|
|
475
|
+
const ranges = bounds.map((range) => analyze(range.set, scope));
|
|
476
|
+
const data = applyDefined(operator, operands, ranges, bound);
|
|
477
|
+
const pattern = bounds[ranges.findIndex((range) => range.level > ACTION_LEVEL)]?.pattern;
|
|
478
|
+
if (pattern) {
|
|
479
|
+
const range = pattern.ranges?.[0];
|
|
480
|
+
throw new TlaSyntaxError(
|
|
481
|
+
`Level error in applying operator ${operator.name}:\nThe level of the range for the bounded variable ${range ? formatRange(range) : getPatternNames(pattern)[0]} \nexceeds the maximum level allowed by the operator`,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
return data;
|
|
461
485
|
};
|
|
462
486
|
|
|
463
487
|
const applyResolved = (resolved: Resolved, operands: Operand[]) =>
|
|
@@ -465,11 +489,11 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
465
489
|
? applyDeclared(resolved.name, resolved.level, operands)
|
|
466
490
|
: applyDefined(resolved.levels, operands);
|
|
467
491
|
|
|
468
|
-
const checkJunction = (operands: Operand[], expression: Expression) => {
|
|
492
|
+
const checkJunction = (operands: Operand[], expression: Expression, name: string) => {
|
|
469
493
|
const levels = operands.map((operand) => operand.data.level);
|
|
470
494
|
if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
|
|
471
495
|
throw createLevelError(
|
|
472
|
-
|
|
496
|
+
`${name} has both temporal formula and action as arguments`,
|
|
473
497
|
expression,
|
|
474
498
|
);
|
|
475
499
|
}
|
|
@@ -483,7 +507,9 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
483
507
|
expression,
|
|
484
508
|
);
|
|
485
509
|
}
|
|
486
|
-
if (LOGICAL_OPERATORS.has(expression.operator))
|
|
510
|
+
if (LOGICAL_OPERATORS.has(expression.operator)) {
|
|
511
|
+
checkJunction(operands, expression, resolveSynonym(expression.operator));
|
|
512
|
+
}
|
|
487
513
|
};
|
|
488
514
|
|
|
489
515
|
const checkTemporal = (
|
|
@@ -549,29 +575,41 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
549
575
|
case "And":
|
|
550
576
|
case "Or": {
|
|
551
577
|
const operands = toOperands(expression.operands, scope);
|
|
552
|
-
|
|
553
|
-
|
|
578
|
+
const isAnd = expression.kind === "And";
|
|
579
|
+
checkJunction(
|
|
580
|
+
operands,
|
|
581
|
+
expression,
|
|
582
|
+
expression.isBulleted
|
|
583
|
+
? `${isAnd ? "Conjunction" : "Disjunction"} list`
|
|
584
|
+
: isAnd
|
|
585
|
+
? "\\land"
|
|
586
|
+
: "\\lor",
|
|
587
|
+
);
|
|
588
|
+
return applyDefined(isAnd ? AND_LEVELS : OR_LEVELS, operands);
|
|
554
589
|
}
|
|
555
590
|
case "Prime":
|
|
556
|
-
case "Unchanged":
|
|
557
591
|
return applyBuiltin(PRIME_LEVELS, [expression.expression], scope);
|
|
592
|
+
case "Unchanged":
|
|
593
|
+
return applyBuiltin(UNCHANGED_LEVELS, [expression.expression], scope);
|
|
558
594
|
case "Enabled":
|
|
559
595
|
return applyBuiltin(ENABLED_LEVELS, [expression.expression], scope);
|
|
560
596
|
case "Always":
|
|
561
597
|
case "Eventually": {
|
|
562
598
|
const operand = toOperand(expression.expression, scope);
|
|
563
599
|
checkTemporal(expression, operand.data.level);
|
|
564
|
-
return applyDefined(
|
|
600
|
+
return applyDefined(expression.kind === "Always" ? ALWAYS_LEVELS : EVENTUALLY_LEVELS, [
|
|
601
|
+
operand,
|
|
602
|
+
]);
|
|
565
603
|
}
|
|
566
604
|
case "If":
|
|
567
605
|
return applyBuiltin(
|
|
568
|
-
|
|
606
|
+
IF_LEVELS,
|
|
569
607
|
[expression.condition, expression.consequent, expression.alternative],
|
|
570
608
|
scope,
|
|
571
609
|
);
|
|
572
610
|
case "Case":
|
|
573
611
|
return applyBuiltin(
|
|
574
|
-
|
|
612
|
+
CASE_LEVELS,
|
|
575
613
|
[
|
|
576
614
|
...expression.arms.flatMap((arm) => [arm.condition, arm.body]),
|
|
577
615
|
...(expression.other ? [expression.other] : []),
|
|
@@ -583,11 +621,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
583
621
|
case "Forall":
|
|
584
622
|
case "Exists": {
|
|
585
623
|
const data = applyBuiltin(
|
|
586
|
-
|
|
624
|
+
expression.kind === "Forall" ? FORALL_LEVELS : EXISTS_LEVELS,
|
|
587
625
|
[expression.body],
|
|
588
626
|
scope,
|
|
589
|
-
expression.bounds
|
|
590
|
-
getBoundNames(expression.bounds),
|
|
627
|
+
expression.bounds,
|
|
591
628
|
);
|
|
592
629
|
const actionBound =
|
|
593
630
|
data.level === TEMPORAL_LEVEL
|
|
@@ -603,7 +640,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
603
640
|
}
|
|
604
641
|
case "UnboundedQuantifier":
|
|
605
642
|
return applyBuiltin(
|
|
606
|
-
expression.isTemporal
|
|
643
|
+
expression.isTemporal
|
|
644
|
+
? expression.quantifier === "Forall"
|
|
645
|
+
? TEMPORAL_FORALL_LEVELS
|
|
646
|
+
: TEMPORAL_EXISTS_LEVELS
|
|
647
|
+
: expression.quantifier === "Forall"
|
|
648
|
+
? UNBOUNDED_FORALL_LEVELS
|
|
649
|
+
: UNBOUNDED_EXISTS_LEVELS,
|
|
607
650
|
[expression.body],
|
|
608
651
|
scope,
|
|
609
652
|
[],
|
|
@@ -611,79 +654,67 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
611
654
|
);
|
|
612
655
|
case "Choose":
|
|
613
656
|
return applyBuiltin(
|
|
614
|
-
|
|
657
|
+
expression.set ? BOUNDED_CHOOSE_LEVELS : UNBOUNDED_CHOOSE_LEVELS,
|
|
615
658
|
[expression.body],
|
|
616
659
|
scope,
|
|
617
|
-
expression.set ? [expression.set] : [],
|
|
660
|
+
expression.set ? [{ pattern: expression.pattern, set: expression.set }] : [],
|
|
618
661
|
getPatternNames(expression.pattern),
|
|
619
662
|
);
|
|
620
663
|
case "SetEnumeration":
|
|
664
|
+
return applyBuiltin(SET_ENUMERATE_LEVELS, expression.elements, scope);
|
|
621
665
|
case "Tuple":
|
|
666
|
+
return applyBuiltin(TUPLE_LEVELS, expression.elements, scope);
|
|
622
667
|
case "FunctionSet":
|
|
668
|
+
return applyBuiltin(SET_OF_FCNS_LEVELS, [expression.domain, expression.range], scope);
|
|
623
669
|
case "Product":
|
|
624
|
-
return applyBuiltin(
|
|
625
|
-
SET_LEVELS,
|
|
626
|
-
expression.kind === "FunctionSet"
|
|
627
|
-
? [expression.domain, expression.range]
|
|
628
|
-
: expression.kind === "Product"
|
|
629
|
-
? expression.factors
|
|
630
|
-
: expression.elements,
|
|
631
|
-
scope,
|
|
632
|
-
);
|
|
670
|
+
return applyBuiltin(CARTESIAN_PROD_LEVELS, expression.factors, scope);
|
|
633
671
|
case "SetFilter":
|
|
634
|
-
return applyBuiltin(
|
|
635
|
-
SET_LEVELS,
|
|
636
|
-
[expression.predicate],
|
|
637
|
-
scope,
|
|
638
|
-
[expression.bound.set],
|
|
639
|
-
getPatternNames(expression.bound.pattern),
|
|
640
|
-
);
|
|
672
|
+
return applyBuiltin(SUBSET_OF_LEVELS, [expression.predicate], scope, [expression.bound]);
|
|
641
673
|
case "SetMap":
|
|
642
|
-
return applyBuiltin(
|
|
643
|
-
SET_LEVELS,
|
|
644
|
-
[expression.expression],
|
|
645
|
-
scope,
|
|
646
|
-
expression.bounds.map((bound) => bound.set),
|
|
647
|
-
getBoundNames(expression.bounds),
|
|
648
|
-
);
|
|
674
|
+
return applyBuiltin(SET_OF_ALL_LEVELS, [expression.expression], scope, expression.bounds);
|
|
649
675
|
case "FunctionConstruction":
|
|
650
|
-
return applyBuiltin(
|
|
651
|
-
FUNCTION_LEVELS,
|
|
652
|
-
[expression.body],
|
|
653
|
-
scope,
|
|
654
|
-
expression.bounds.map((bound) => bound.set),
|
|
655
|
-
getBoundNames(expression.bounds),
|
|
656
|
-
);
|
|
676
|
+
return applyBuiltin(FCN_CONSTRUCTOR_LEVELS, [expression.body], scope, expression.bounds);
|
|
657
677
|
case "Record":
|
|
658
678
|
return applyBuiltin(
|
|
659
|
-
|
|
679
|
+
RCD_CONSTRUCTOR_LEVELS,
|
|
660
680
|
expression.fields.map((field) => field.value),
|
|
661
681
|
scope,
|
|
662
682
|
);
|
|
663
683
|
case "RecordSet":
|
|
664
684
|
return applyBuiltin(
|
|
665
|
-
|
|
685
|
+
SET_OF_RCDS_LEVELS,
|
|
666
686
|
expression.fields.map((field) => field.value),
|
|
667
687
|
scope,
|
|
668
688
|
);
|
|
669
689
|
case "Except":
|
|
670
|
-
return
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
690
|
+
return applyDefined(EXCEPT_LEVELS, [
|
|
691
|
+
toOperand(expression.function, scope),
|
|
692
|
+
...expression.updates.map((update): Operand => ({
|
|
693
|
+
kind: "Value",
|
|
694
|
+
data: applyDefined(PAIR_LEVELS, [
|
|
695
|
+
{
|
|
696
|
+
kind: "Value",
|
|
697
|
+
data: applyDefined(
|
|
698
|
+
SEQ_LEVELS,
|
|
699
|
+
update.path.map((step): Operand =>
|
|
700
|
+
step.kind === "Field"
|
|
701
|
+
? { kind: "Value", data: createData() }
|
|
702
|
+
: step.args.length === 1
|
|
703
|
+
? toOperand(step.args[0], scope)
|
|
704
|
+
: { kind: "Value", data: applyBuiltin(TUPLE_LEVELS, step.args, scope) },
|
|
705
|
+
),
|
|
706
|
+
),
|
|
707
|
+
},
|
|
708
|
+
toOperand(update.value, scope),
|
|
677
709
|
]),
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
);
|
|
710
|
+
})),
|
|
711
|
+
]);
|
|
681
712
|
case "FunctionApplication":
|
|
682
713
|
return applyDefined(APPLY_LEVELS, [
|
|
683
714
|
toOperand(expression.function, scope),
|
|
684
715
|
expression.args.length === 1
|
|
685
716
|
? toOperand(expression.args[0], scope)
|
|
686
|
-
: { kind: "Value", data: applyBuiltin(
|
|
717
|
+
: { kind: "Value", data: applyBuiltin(TUPLE_LEVELS, expression.args, scope) },
|
|
687
718
|
]);
|
|
688
719
|
case "Bracket":
|
|
689
720
|
return createData();
|
|
@@ -694,10 +725,18 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
694
725
|
]);
|
|
695
726
|
case "BoxAction":
|
|
696
727
|
case "AngleAction":
|
|
697
|
-
return applyBuiltin(
|
|
728
|
+
return applyBuiltin(
|
|
729
|
+
expression.kind === "BoxAction" ? SQUARE_ACT_LEVELS : ANGLE_ACT_LEVELS,
|
|
730
|
+
[expression.action, expression.subscript],
|
|
731
|
+
scope,
|
|
732
|
+
);
|
|
698
733
|
case "WeakFairness":
|
|
699
734
|
case "StrongFairness":
|
|
700
|
-
return applyBuiltin(
|
|
735
|
+
return applyBuiltin(
|
|
736
|
+
expression.kind === "WeakFairness" ? WF_LEVELS : SF_LEVELS,
|
|
737
|
+
[expression.subscript, expression.action],
|
|
738
|
+
scope,
|
|
739
|
+
);
|
|
701
740
|
case "Label":
|
|
702
741
|
return analyze(expression.body, scope);
|
|
703
742
|
case "Subexpression":
|
|
@@ -957,7 +996,16 @@ export const checkModuleLevels = (
|
|
|
957
996
|
})),
|
|
958
997
|
...module.assumptions.map((assumption) => ({
|
|
959
998
|
location: assumption.location,
|
|
960
|
-
check: () =>
|
|
999
|
+
check: () => {
|
|
1000
|
+
const level = analyzer.analyze(assumption.expression, new Map()).level;
|
|
1001
|
+
const range = assumption.location.range;
|
|
1002
|
+
if (level !== CONSTANT_LEVEL && range) {
|
|
1003
|
+
throw createSemanticError(
|
|
1004
|
+
`Level error: assumptions must be level 0 (Constant), \nbut this one has level ${level}.`,
|
|
1005
|
+
range,
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
961
1009
|
})),
|
|
962
1010
|
...module.theorems.map((theorem) => ({
|
|
963
1011
|
location: theorem.location,
|
package/src/liveness-checker.ts
CHANGED
|
@@ -46,6 +46,7 @@ export interface LivenessChecker {
|
|
|
46
46
|
tracing?: Environment,
|
|
47
47
|
) => number[] | undefined;
|
|
48
48
|
storeState: (pending: number, index: number) => void;
|
|
49
|
+
getStateCounts: () => number[];
|
|
49
50
|
findViolation: () => Lasso | undefined;
|
|
50
51
|
getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
|
|
51
52
|
}
|
|
@@ -58,14 +59,20 @@ export interface LiveGraph<State> {
|
|
|
58
59
|
index: number,
|
|
59
60
|
state: State,
|
|
60
61
|
successors: LiveSuccessor<State>[],
|
|
62
|
+
isRerun?: boolean,
|
|
61
63
|
) => number[] | undefined;
|
|
62
64
|
storeState: (pending: number, index: number) => void;
|
|
65
|
+
getStateCounts: () => number[];
|
|
63
66
|
findViolation: () => Lasso | undefined;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
export interface SearchGraph<State> {
|
|
67
70
|
getFingerprint: (successor: LiveSuccessor<State>) => number;
|
|
68
|
-
|
|
71
|
+
forEachActionSuccessors: (
|
|
72
|
+
index: number,
|
|
73
|
+
state: State,
|
|
74
|
+
onSuccessors: (successors: LiveSuccessor<State>[]) => void,
|
|
75
|
+
) => void;
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
export interface LiveEvaluation<State> {
|
|
@@ -116,6 +123,7 @@ interface BehaviorGraph<State> {
|
|
|
116
123
|
nextSiblings: number[];
|
|
117
124
|
nodeIds: NodeTable;
|
|
118
125
|
isDone: boolean[];
|
|
126
|
+
stateCount: number;
|
|
119
127
|
errorNode: number | undefined;
|
|
120
128
|
}
|
|
121
129
|
|
|
@@ -367,8 +375,9 @@ export const createLivenessChecker = (
|
|
|
367
375
|
addInitialState: (index, state, replay) =>
|
|
368
376
|
traceWith(replay, () => graph.addInitialState(index, state)),
|
|
369
377
|
addState: (index, state, successors, replay) =>
|
|
370
|
-
traceWith(replay, () => graph.addState(index, state, successors)),
|
|
378
|
+
traceWith(replay, () => graph.addState(index, state, successors, replay !== undefined)),
|
|
371
379
|
storeState: graph.storeState,
|
|
380
|
+
getStateCounts: graph.getStateCounts,
|
|
372
381
|
findViolation: graph.findViolation,
|
|
373
382
|
getViolatedProperties: (path, cycleStart) => [
|
|
374
383
|
...new Set(
|
|
@@ -508,6 +517,7 @@ export const createLiveGraph = <State>(
|
|
|
508
517
|
nextSiblings: [],
|
|
509
518
|
nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
|
|
510
519
|
isDone: [],
|
|
520
|
+
stateCount: 0,
|
|
511
521
|
errorNode: undefined,
|
|
512
522
|
}));
|
|
513
523
|
const checkState = (
|
|
@@ -631,8 +641,16 @@ export const createLiveGraph = <State>(
|
|
|
631
641
|
writeToPool(behavior.lastNodes, state, [node]);
|
|
632
642
|
return node;
|
|
633
643
|
};
|
|
634
|
-
const
|
|
635
|
-
|
|
644
|
+
const hasState = (behavior: BehaviorGraph<State>, state: number) =>
|
|
645
|
+
state < 0
|
|
646
|
+
? behavior.checks.nodes.some(
|
|
647
|
+
(_checks, tableauNode) => getNodeId(behavior, state, tableauNode) !== undefined,
|
|
648
|
+
)
|
|
649
|
+
: behavior.isDone[state] === true || (behavior.firstNodes.data[state] ?? NO_NODE) !== NO_NODE;
|
|
650
|
+
const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
|
|
651
|
+
if (!hasState(behavior, state)) behavior.stateCount++;
|
|
652
|
+
return linkNode(behavior, state, tableauNode, pushNode(behavior, state, tableauNode));
|
|
653
|
+
};
|
|
636
654
|
// The action results of the edge to each target are at its position in actions.
|
|
637
655
|
const writeNode = (
|
|
638
656
|
behavior: BehaviorGraph<State>,
|
|
@@ -741,39 +759,57 @@ export const createLiveGraph = <State>(
|
|
|
741
759
|
actions.push(0);
|
|
742
760
|
if (existing === undefined) expandLate(behavior, tableau, state, index, target, row, offset);
|
|
743
761
|
}
|
|
744
|
-
const nextStates = search.getSuccessors(index, state);
|
|
745
762
|
// The results of the step to the state itself come first, then those of each successor.
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
763
|
+
const actionBatches = [selfResults];
|
|
764
|
+
let stepCount = 1;
|
|
765
|
+
search.forEachActionSuccessors(index, state, (nextStates) => {
|
|
766
|
+
const edges = createEdgeRows(nextStates.length);
|
|
767
|
+
const results = new Uint8Array(nextStates.length * actionCount);
|
|
768
|
+
actionBatches.push(results);
|
|
769
|
+
for (let position = 0; position < nextStates.length; position++) {
|
|
770
|
+
const successor = nextStates[position];
|
|
771
|
+
const successorRow = createRows(1);
|
|
772
|
+
checkAction(
|
|
773
|
+
behavior,
|
|
774
|
+
index,
|
|
775
|
+
state,
|
|
776
|
+
row,
|
|
777
|
+
offset,
|
|
778
|
+
successor.state,
|
|
779
|
+
edges,
|
|
780
|
+
position * actionIds.size,
|
|
781
|
+
results,
|
|
782
|
+
position * actionCount,
|
|
783
|
+
);
|
|
784
|
+
const isDone = behavior.isDone[successor.index] === true;
|
|
785
|
+
for (const next of tableauNode.successors) {
|
|
786
|
+
if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
|
|
787
|
+
const existing = getNodeId(behavior, successor.index, next);
|
|
788
|
+
if (existing !== undefined && successors.includes(existing)) continue;
|
|
789
|
+
const target = existing ?? recordNode(behavior, successor.index, next);
|
|
790
|
+
successors.push(target);
|
|
791
|
+
actions.push(stepCount + position);
|
|
792
|
+
if (existing === undefined && isDone) {
|
|
793
|
+
expandLate(
|
|
794
|
+
behavior,
|
|
795
|
+
tableau,
|
|
796
|
+
successor.state,
|
|
797
|
+
successor.index,
|
|
798
|
+
target,
|
|
799
|
+
successorRow,
|
|
800
|
+
0,
|
|
801
|
+
);
|
|
802
|
+
}
|
|
773
803
|
}
|
|
774
804
|
}
|
|
805
|
+
stepCount += nextStates.length;
|
|
775
806
|
});
|
|
776
807
|
if (successors.length > 0) {
|
|
808
|
+
const actionResults = new Uint8Array(stepCount * actionCount);
|
|
809
|
+
for (let batch = 0, resultOffset = 0; batch < actionBatches.length; batch++) {
|
|
810
|
+
actionResults.set(actionBatches[batch], resultOffset);
|
|
811
|
+
resultOffset += actionBatches[batch].length;
|
|
812
|
+
}
|
|
777
813
|
writeNode(behavior, node, successors, actionResults, actions, stateResults);
|
|
778
814
|
}
|
|
779
815
|
};
|
|
@@ -799,6 +835,7 @@ export const createLiveGraph = <State>(
|
|
|
799
835
|
}
|
|
800
836
|
}
|
|
801
837
|
});
|
|
838
|
+
if (!hasState(behavior, index)) behavior.stateCount++;
|
|
802
839
|
behavior.isDone[index] = true;
|
|
803
840
|
// TLC expands the nodes recorded before the loop, not the ones the loop records.
|
|
804
841
|
for (const node of getStateNodes(behavior, index)) {
|
|
@@ -848,6 +885,7 @@ export const createLiveGraph = <State>(
|
|
|
848
885
|
successors.push(successor.index);
|
|
849
886
|
actions.push(position);
|
|
850
887
|
});
|
|
888
|
+
if (!isWritten(behavior, index)) behavior.stateCount++;
|
|
851
889
|
writeNode(behavior, index, successors, actionResults, actions, stateResults);
|
|
852
890
|
};
|
|
853
891
|
|
|
@@ -1126,7 +1164,7 @@ export const createLiveGraph = <State>(
|
|
|
1126
1164
|
}
|
|
1127
1165
|
}
|
|
1128
1166
|
},
|
|
1129
|
-
addState: (index, state, successors) => {
|
|
1167
|
+
addState: (index, state, successors, isRerun) => {
|
|
1130
1168
|
const set = getSuccessorSet(index, state, successors);
|
|
1131
1169
|
const rows = createRows(set.length);
|
|
1132
1170
|
// The set holds the state itself, as a successor of the same index.
|
|
@@ -1151,6 +1189,15 @@ export const createLiveGraph = <State>(
|
|
|
1151
1189
|
);
|
|
1152
1190
|
const stateResults = checkState(behavior, index, state, rows, offset);
|
|
1153
1191
|
const tableau = behavior.solution.tableau;
|
|
1192
|
+
// TLC's rerun for a call stack fails an assertion, without a call stack, on a branch that has every edge of the state.
|
|
1193
|
+
if (
|
|
1194
|
+
isRerun &&
|
|
1195
|
+
(tableau
|
|
1196
|
+
? getStateNodes(behavior, index).some((node) => behavior.edgeCounts[node] > 0)
|
|
1197
|
+
: set.every((successor) => isWritten(behavior, successor.index)))
|
|
1198
|
+
) {
|
|
1199
|
+
throw new TlaEvaluationError("The behavior graph holds every edge of the state already.");
|
|
1200
|
+
}
|
|
1154
1201
|
if (!tableau) {
|
|
1155
1202
|
addPlainState(behavior, set, actionResults, stateResults, index);
|
|
1156
1203
|
continue;
|
|
@@ -1183,6 +1230,7 @@ export const createLiveGraph = <State>(
|
|
|
1183
1230
|
}
|
|
1184
1231
|
}
|
|
1185
1232
|
},
|
|
1233
|
+
getStateCounts: () => behaviors.map((behavior) => behavior.stateCount),
|
|
1186
1234
|
findViolation: () => {
|
|
1187
1235
|
for (const behavior of behaviors) {
|
|
1188
1236
|
for (const model of behavior.solution.models) {
|