tla-ts 0.0.10-dev.1ebc153bd → 0.0.10-dev.22f7435d3
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/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -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 +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- 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/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- 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-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +132 -78
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- 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 +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +446 -167
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +168 -49
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +9 -4
- package/src/values.ts +95 -57
package/src/liveness-checker.ts
CHANGED
|
@@ -51,6 +51,11 @@ export interface LivenessChecker {
|
|
|
51
51
|
getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export interface LivenessChecks {
|
|
55
|
+
solutions: Solution[];
|
|
56
|
+
createChecker: (search: SearchGraph<Value[]>, solutions: Solution[]) => LivenessChecker;
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
export interface LiveGraph<State> {
|
|
55
60
|
branches: number;
|
|
56
61
|
addInitialState: (index: number, state: State) => void;
|
|
@@ -59,6 +64,7 @@ export interface LiveGraph<State> {
|
|
|
59
64
|
index: number,
|
|
60
65
|
state: State,
|
|
61
66
|
successors: LiveSuccessor<State>[],
|
|
67
|
+
isRerun?: boolean,
|
|
62
68
|
) => number[] | undefined;
|
|
63
69
|
storeState: (pending: number, index: number) => void;
|
|
64
70
|
getStateCounts: () => number[];
|
|
@@ -67,7 +73,11 @@ export interface LiveGraph<State> {
|
|
|
67
73
|
|
|
68
74
|
export interface SearchGraph<State> {
|
|
69
75
|
getFingerprint: (successor: LiveSuccessor<State>) => number;
|
|
70
|
-
|
|
76
|
+
forEachActionSuccessors: (
|
|
77
|
+
index: number,
|
|
78
|
+
state: State,
|
|
79
|
+
onSuccessors: (successors: LiveSuccessor<State>[]) => void,
|
|
80
|
+
) => void;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
export interface LiveEvaluation<State> {
|
|
@@ -312,12 +322,11 @@ export const getLiveExpressions = (solutions: Solution[]) =>
|
|
|
312
322
|
getAtomExpressions(atom).map((item) => item.expression),
|
|
313
323
|
);
|
|
314
324
|
|
|
315
|
-
export const
|
|
325
|
+
export const createLivenessChecks = (
|
|
316
326
|
properties: TemporalProperty[],
|
|
317
327
|
temporals: ScopedExpression[],
|
|
318
328
|
environment: Environment,
|
|
319
|
-
|
|
320
|
-
): LivenessChecker | undefined => {
|
|
329
|
+
): LivenessChecks | undefined => {
|
|
321
330
|
if (properties.length === 0) return undefined;
|
|
322
331
|
const live = getLiveFormula(properties, temporals, environment);
|
|
323
332
|
// A check evaluated once for a state shows what TLC shows when no check repeats an effect. A
|
|
@@ -332,61 +341,75 @@ export const createLivenessChecker = (
|
|
|
332
341
|
"repeated",
|
|
333
342
|
)
|
|
334
343
|
: !hasRepeatedEffects(environment);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
344
|
+
return {
|
|
345
|
+
solutions: getSolutions(live.formula),
|
|
346
|
+
createChecker: (search, solutions) => {
|
|
347
|
+
const tracing = { environment, atoms: getInterpretedAtoms(environment) };
|
|
348
|
+
const graph = createLiveGraph(
|
|
349
|
+
solutions,
|
|
350
|
+
{
|
|
351
|
+
atoms: {
|
|
352
|
+
holdsState: (atom, state) => tracing.atoms.holdsState(atom, state),
|
|
353
|
+
holdsAction: (atom, state, next) => tracing.atoms.holdsAction(atom, state, next),
|
|
354
|
+
},
|
|
355
|
+
isShared,
|
|
356
|
+
isSame: isSameState,
|
|
357
|
+
evaluateFrom: (source, evaluate) => {
|
|
358
|
+
environment.runtime.setLivenessSource(source);
|
|
359
|
+
try {
|
|
360
|
+
return evaluate();
|
|
361
|
+
} finally {
|
|
362
|
+
environment.runtime.setLivenessSource(undefined);
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
search,
|
|
367
|
+
environment.runtime.version !== "1.7.4",
|
|
368
|
+
);
|
|
369
|
+
const traceWith = <Result>(replay: Environment | undefined, run: () => Result) => {
|
|
370
|
+
if (replay === undefined) return run();
|
|
371
|
+
tracing.atoms = getInterpretedAtoms(replay);
|
|
348
372
|
try {
|
|
349
|
-
return
|
|
373
|
+
return run();
|
|
350
374
|
} finally {
|
|
351
|
-
|
|
375
|
+
tracing.atoms = getInterpretedAtoms(environment);
|
|
352
376
|
}
|
|
353
|
-
}
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
branches: graph.branches,
|
|
380
|
+
solutions,
|
|
381
|
+
addInitialState: (index, state, replay) =>
|
|
382
|
+
traceWith(replay, () => graph.addInitialState(index, state)),
|
|
383
|
+
addState: (index, state, successors, replay) =>
|
|
384
|
+
traceWith(replay, () => graph.addState(index, state, successors, replay !== undefined)),
|
|
385
|
+
storeState: graph.storeState,
|
|
386
|
+
getStateCounts: graph.getStateCounts,
|
|
387
|
+
findViolation: graph.findViolation,
|
|
388
|
+
getViolatedProperties: (path, cycleStart) => [
|
|
389
|
+
...new Set(
|
|
390
|
+
properties
|
|
391
|
+
.filter(
|
|
392
|
+
(_property, position) =>
|
|
393
|
+
!evaluateOnLasso(live.negations[position].body, path, cycleStart, 0, environment),
|
|
394
|
+
)
|
|
395
|
+
.map((property) => property.name),
|
|
396
|
+
),
|
|
397
|
+
],
|
|
398
|
+
};
|
|
354
399
|
},
|
|
355
|
-
search,
|
|
356
|
-
environment.runtime.version !== "1.7.4",
|
|
357
|
-
);
|
|
358
|
-
const traceWith = <Result>(replay: Environment | undefined, run: () => Result) => {
|
|
359
|
-
if (replay === undefined) return run();
|
|
360
|
-
tracing.atoms = getInterpretedAtoms(replay);
|
|
361
|
-
try {
|
|
362
|
-
return run();
|
|
363
|
-
} finally {
|
|
364
|
-
tracing.atoms = getInterpretedAtoms(environment);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
return {
|
|
368
|
-
branches: graph.branches,
|
|
369
|
-
solutions,
|
|
370
|
-
addInitialState: (index, state, replay) =>
|
|
371
|
-
traceWith(replay, () => graph.addInitialState(index, state)),
|
|
372
|
-
addState: (index, state, successors, replay) =>
|
|
373
|
-
traceWith(replay, () => graph.addState(index, state, successors)),
|
|
374
|
-
storeState: graph.storeState,
|
|
375
|
-
getStateCounts: graph.getStateCounts,
|
|
376
|
-
findViolation: graph.findViolation,
|
|
377
|
-
getViolatedProperties: (path, cycleStart) => [
|
|
378
|
-
...new Set(
|
|
379
|
-
properties
|
|
380
|
-
.filter(
|
|
381
|
-
(_property, position) =>
|
|
382
|
-
!evaluateOnLasso(live.negations[position].body, path, cycleStart, 0, environment),
|
|
383
|
-
)
|
|
384
|
-
.map((property) => property.name),
|
|
385
|
-
),
|
|
386
|
-
],
|
|
387
400
|
};
|
|
388
401
|
};
|
|
389
402
|
|
|
403
|
+
export const createLivenessChecker = (
|
|
404
|
+
properties: TemporalProperty[],
|
|
405
|
+
temporals: ScopedExpression[],
|
|
406
|
+
environment: Environment,
|
|
407
|
+
search: SearchGraph<Value[]>,
|
|
408
|
+
): LivenessChecker | undefined => {
|
|
409
|
+
const checks = createLivenessChecks(properties, temporals, environment);
|
|
410
|
+
return checks?.createChecker(search, checks.solutions);
|
|
411
|
+
};
|
|
412
|
+
|
|
390
413
|
export const createLiveGraph = <State>(
|
|
391
414
|
solutions: Solution[],
|
|
392
415
|
evaluation: LiveEvaluation<State>,
|
|
@@ -754,39 +777,57 @@ export const createLiveGraph = <State>(
|
|
|
754
777
|
actions.push(0);
|
|
755
778
|
if (existing === undefined) expandLate(behavior, tableau, state, index, target, row, offset);
|
|
756
779
|
}
|
|
757
|
-
const nextStates = search.getSuccessors(index, state);
|
|
758
780
|
// The results of the step to the state itself come first, then those of each successor.
|
|
759
|
-
const
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
781
|
+
const actionBatches = [selfResults];
|
|
782
|
+
let stepCount = 1;
|
|
783
|
+
search.forEachActionSuccessors(index, state, (nextStates) => {
|
|
784
|
+
const edges = createEdgeRows(nextStates.length);
|
|
785
|
+
const results = new Uint8Array(nextStates.length * actionCount);
|
|
786
|
+
actionBatches.push(results);
|
|
787
|
+
for (let position = 0; position < nextStates.length; position++) {
|
|
788
|
+
const successor = nextStates[position];
|
|
789
|
+
const successorRow = createRows(1);
|
|
790
|
+
checkAction(
|
|
791
|
+
behavior,
|
|
792
|
+
index,
|
|
793
|
+
state,
|
|
794
|
+
row,
|
|
795
|
+
offset,
|
|
796
|
+
successor.state,
|
|
797
|
+
edges,
|
|
798
|
+
position * actionIds.size,
|
|
799
|
+
results,
|
|
800
|
+
position * actionCount,
|
|
801
|
+
);
|
|
802
|
+
const isDone = behavior.isDone[successor.index] === true;
|
|
803
|
+
for (const next of tableauNode.successors) {
|
|
804
|
+
if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
|
|
805
|
+
const existing = getNodeId(behavior, successor.index, next);
|
|
806
|
+
if (existing !== undefined && successors.includes(existing)) continue;
|
|
807
|
+
const target = existing ?? recordNode(behavior, successor.index, next);
|
|
808
|
+
successors.push(target);
|
|
809
|
+
actions.push(stepCount + position);
|
|
810
|
+
if (existing === undefined && isDone) {
|
|
811
|
+
expandLate(
|
|
812
|
+
behavior,
|
|
813
|
+
tableau,
|
|
814
|
+
successor.state,
|
|
815
|
+
successor.index,
|
|
816
|
+
target,
|
|
817
|
+
successorRow,
|
|
818
|
+
0,
|
|
819
|
+
);
|
|
820
|
+
}
|
|
786
821
|
}
|
|
787
822
|
}
|
|
823
|
+
stepCount += nextStates.length;
|
|
788
824
|
});
|
|
789
825
|
if (successors.length > 0) {
|
|
826
|
+
const actionResults = new Uint8Array(stepCount * actionCount);
|
|
827
|
+
for (let batch = 0, resultOffset = 0; batch < actionBatches.length; batch++) {
|
|
828
|
+
actionResults.set(actionBatches[batch], resultOffset);
|
|
829
|
+
resultOffset += actionBatches[batch].length;
|
|
830
|
+
}
|
|
790
831
|
writeNode(behavior, node, successors, actionResults, actions, stateResults);
|
|
791
832
|
}
|
|
792
833
|
};
|
|
@@ -1141,7 +1182,7 @@ export const createLiveGraph = <State>(
|
|
|
1141
1182
|
}
|
|
1142
1183
|
}
|
|
1143
1184
|
},
|
|
1144
|
-
addState: (index, state, successors) => {
|
|
1185
|
+
addState: (index, state, successors, isRerun) => {
|
|
1145
1186
|
const set = getSuccessorSet(index, state, successors);
|
|
1146
1187
|
const rows = createRows(set.length);
|
|
1147
1188
|
// The set holds the state itself, as a successor of the same index.
|
|
@@ -1166,6 +1207,15 @@ export const createLiveGraph = <State>(
|
|
|
1166
1207
|
);
|
|
1167
1208
|
const stateResults = checkState(behavior, index, state, rows, offset);
|
|
1168
1209
|
const tableau = behavior.solution.tableau;
|
|
1210
|
+
// TLC's rerun for a call stack fails an assertion, without a call stack, on a branch that has every edge of the state.
|
|
1211
|
+
if (
|
|
1212
|
+
isRerun &&
|
|
1213
|
+
(tableau
|
|
1214
|
+
? getStateNodes(behavior, index).some((node) => behavior.edgeCounts[node] > 0)
|
|
1215
|
+
: set.every((successor) => isWritten(behavior, successor.index)))
|
|
1216
|
+
) {
|
|
1217
|
+
throw new TlaEvaluationError("The behavior graph holds every edge of the state already.");
|
|
1218
|
+
}
|
|
1169
1219
|
if (!tableau) {
|
|
1170
1220
|
addPlainState(behavior, set, actionResults, stateResults, index);
|
|
1171
1221
|
continue;
|
package/src/liveness.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
forEachBoundElement,
|
|
17
17
|
getBoundElements,
|
|
18
18
|
getDefinition,
|
|
19
|
+
getReevaluatedDefinitions,
|
|
19
20
|
getStartupValue,
|
|
20
21
|
lookupScope,
|
|
21
22
|
resolveApplyOperator,
|
|
@@ -323,12 +324,17 @@ export const expandTemporal = (
|
|
|
323
324
|
return [{ expression, scope, name: expansion.name, path: expansion.path }];
|
|
324
325
|
};
|
|
325
326
|
|
|
326
|
-
|
|
327
|
+
// TLC takes a formula apart through a LET without binding its definitions, so it evaluates an impure one again at each reference.
|
|
328
|
+
export const bindLetDefinitions = (
|
|
327
329
|
expression: Expression & { kind: "Let" },
|
|
328
330
|
scope: Scope | undefined,
|
|
329
331
|
environment: Environment,
|
|
330
332
|
) => {
|
|
331
|
-
const bound = bindDefinitions(
|
|
333
|
+
const bound = bindDefinitions(
|
|
334
|
+
expression.definitions,
|
|
335
|
+
getConstantContext(environment, scope),
|
|
336
|
+
getReevaluatedDefinitions(expression.definitions, environment),
|
|
337
|
+
);
|
|
332
338
|
for (let current = bound; current && current !== scope; current = current.parent) {
|
|
333
339
|
if (current.binding.kind === "Thunk") definitionThunks.add(current.binding);
|
|
334
340
|
}
|
|
@@ -488,6 +494,45 @@ export const toLiveExpression = (
|
|
|
488
494
|
return level > ACTION_LEVEL ? parts : toAtom(expression, scope, level);
|
|
489
495
|
};
|
|
490
496
|
|
|
497
|
+
// SANY parses `a /\ b /\ c` as `(a /\ b) /\ c`, so TLC takes a prefix below the temporal level as one formula.
|
|
498
|
+
const convertJunction = (
|
|
499
|
+
expression: Expression & { kind: "And" | "Or" },
|
|
500
|
+
scope: Scope | undefined,
|
|
501
|
+
) => {
|
|
502
|
+
const operands = expression.operands;
|
|
503
|
+
const range = expression.location.range;
|
|
504
|
+
const prefixEnds = expression.prefixEnds;
|
|
505
|
+
if (expression.isBulleted || !range || !prefixEnds) {
|
|
506
|
+
return toWhole(
|
|
507
|
+
expression,
|
|
508
|
+
scope,
|
|
509
|
+
createJunction(
|
|
510
|
+
expression.kind,
|
|
511
|
+
operands.map((operand) => convert(operand, scope)),
|
|
512
|
+
),
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
return operands.slice(1).reduce(
|
|
516
|
+
(prefix, operand, index) => {
|
|
517
|
+
const node =
|
|
518
|
+
index === operands.length - 2
|
|
519
|
+
? expression
|
|
520
|
+
: {
|
|
521
|
+
...expression,
|
|
522
|
+
operands: operands.slice(0, index + 2),
|
|
523
|
+
prefixEnds: prefixEnds.slice(0, index + 1),
|
|
524
|
+
location: { ...expression.location, range: { ...range, end: prefixEnds[index] } },
|
|
525
|
+
};
|
|
526
|
+
return toWhole(
|
|
527
|
+
node,
|
|
528
|
+
scope,
|
|
529
|
+
createJunction(expression.kind, [prefix, convert(operand, scope)]),
|
|
530
|
+
);
|
|
531
|
+
},
|
|
532
|
+
convert(operands[0], scope),
|
|
533
|
+
);
|
|
534
|
+
};
|
|
535
|
+
|
|
491
536
|
// These forms are translated part by part at every level; any other form below the temporal level is an atom.
|
|
492
537
|
const convert = (expression: Expression, scope: Scope | undefined): LiveExpression => {
|
|
493
538
|
const level = getLevel(expression, scope, environment);
|
|
@@ -512,14 +557,7 @@ export const toLiveExpression = (
|
|
|
512
557
|
}
|
|
513
558
|
case "And":
|
|
514
559
|
case "Or":
|
|
515
|
-
return
|
|
516
|
-
expression,
|
|
517
|
-
scope,
|
|
518
|
-
createJunction(
|
|
519
|
-
expression.kind,
|
|
520
|
-
expression.operands.map((operand) => convert(operand, scope)),
|
|
521
|
-
),
|
|
522
|
-
);
|
|
560
|
+
return convertJunction(expression, scope);
|
|
523
561
|
case "Forall":
|
|
524
562
|
case "Exists":
|
|
525
563
|
return convertQuantifier(expression, scope);
|
package/src/parser.ts
CHANGED
|
@@ -251,6 +251,7 @@ const OPERATOR_ARGUMENTS = new Set([
|
|
|
251
251
|
|
|
252
252
|
const SELECTOR_SYMBOLS = new Set(["<<", ">>", ":", "@", "("]);
|
|
253
253
|
|
|
254
|
+
// Deviation from SANY: TLAplusParser#OpOrExpr's lookahead omits PROPOSITION, LEMMA and COROLLARY, so SANY parses an operator argument before them as an expression.
|
|
254
255
|
const UNIT_KEYWORDS = new Set([
|
|
255
256
|
"ASSUME",
|
|
256
257
|
"ASSUMPTION",
|
|
@@ -1956,7 +1957,11 @@ const parse = (
|
|
|
1956
1957
|
|
|
1957
1958
|
const parseDeclarationUnit = (): Declaration => {
|
|
1958
1959
|
const location = getLocation(peek());
|
|
1959
|
-
|
|
1960
|
+
const isOperatorDeclaration =
|
|
1961
|
+
isAt("_") &&
|
|
1962
|
+
peek(1).kind === "Operator" &&
|
|
1963
|
+
(INFIX_OPERATORS.has(peek(1).text) || DEFINABLE_POSTFIX_OPERATORS.has(peek(1).text));
|
|
1964
|
+
if (isOperatorDeclaration) {
|
|
1960
1965
|
advance();
|
|
1961
1966
|
const name = advance().text;
|
|
1962
1967
|
return { name, arity: accept("_") ? 2 : 1, location };
|
|
@@ -41,6 +41,7 @@ import { Anum } from "./nlsat/algebraic";
|
|
|
41
41
|
export const KERNEL_ARITH_OPTIONS: ArithRewriterOptions = {
|
|
42
42
|
isSom: true,
|
|
43
43
|
isSortSums: true,
|
|
44
|
+
isArithLhs: false,
|
|
44
45
|
isArithIneqLhs: true,
|
|
45
46
|
isGcdRounding: true,
|
|
46
47
|
isAnumSimp: true,
|
|
@@ -52,6 +53,7 @@ export const KERNEL_ARITH_OPTIONS: ArithRewriterOptions = {
|
|
|
52
53
|
export const TACTIC_ARITH_OPTIONS: ArithRewriterOptions = {
|
|
53
54
|
isSom: false,
|
|
54
55
|
isSortSums: false,
|
|
56
|
+
isArithLhs: false,
|
|
55
57
|
isArithIneqLhs: false,
|
|
56
58
|
isGcdRounding: false,
|
|
57
59
|
isAnumSimp: true,
|
|
@@ -118,7 +120,8 @@ export class ArithRewriter extends PolyRewriter {
|
|
|
118
120
|
]),
|
|
119
121
|
2,
|
|
120
122
|
);
|
|
121
|
-
if (!this.isArithTerm(left) && !this.isArithTerm(right))
|
|
123
|
+
if (!this.options.isArithLhs && !this.isArithTerm(left) && !this.isArithTerm(right))
|
|
124
|
+
return undefined;
|
|
122
125
|
return this.mkLeGeEq(left, right, KIND_EQ);
|
|
123
126
|
}
|
|
124
127
|
|
|
@@ -1259,7 +1262,12 @@ export class ArithRewriter extends PolyRewriter {
|
|
|
1259
1262
|
sides[index] = expr;
|
|
1260
1263
|
};
|
|
1261
1264
|
const cancelled = manager.withTemporaries(
|
|
1262
|
-
() =>
|
|
1265
|
+
() =>
|
|
1266
|
+
this.cancelMonomials(
|
|
1267
|
+
originalLeft,
|
|
1268
|
+
originalRight,
|
|
1269
|
+
this.options.isArithIneqLhs || this.options.isArithLhs,
|
|
1270
|
+
),
|
|
1263
1271
|
(result) => (result === undefined ? [] : [result.lhs, result.rhs]),
|
|
1264
1272
|
);
|
|
1265
1273
|
if (cancelled !== undefined) sides.push(cancelled.lhs, cancelled.rhs);
|
|
@@ -1366,7 +1374,7 @@ export class ArithRewriter extends PolyRewriter {
|
|
|
1366
1374
|
return this.reduce(manager.mkAnd([mkUpper(), lower]), 3);
|
|
1367
1375
|
}
|
|
1368
1376
|
const negated =
|
|
1369
|
-
this.options.isArithIneqLhs && this.manager.isNumeral(right)
|
|
1377
|
+
(this.options.isArithLhs || this.options.isArithIneqLhs) && this.manager.isNumeral(right)
|
|
1370
1378
|
? this.getNegatedPolynomial(left)
|
|
1371
1379
|
: undefined;
|
|
1372
1380
|
if (negated !== undefined) {
|
|
@@ -24,6 +24,7 @@ export class ArrayRewriter {
|
|
|
24
24
|
constructor(
|
|
25
25
|
private manager: AstManager,
|
|
26
26
|
private isSortingStore = false,
|
|
27
|
+
private isExpandingSelects = false,
|
|
27
28
|
) {}
|
|
28
29
|
|
|
29
30
|
private isOp(expr: number, op: number) {
|
|
@@ -193,7 +194,12 @@ export class ArrayRewriter {
|
|
|
193
194
|
(index, position) =>
|
|
194
195
|
manager.isValue(index) && manager.isValue(manager.getArg(array, position + 1)),
|
|
195
196
|
);
|
|
196
|
-
if (
|
|
197
|
+
if (
|
|
198
|
+
!this.isOp(base, OP_CONST_ARRAY) &&
|
|
199
|
+
!areValues &&
|
|
200
|
+
!(this.isExpandingSelects && manager.getRefCount(base) === 1)
|
|
201
|
+
)
|
|
202
|
+
return undefined;
|
|
197
203
|
const selectBase = this.mkApp(OP_SELECT, [base, ...indices]);
|
|
198
204
|
const value = manager.getArg(array, indices.length + 1);
|
|
199
205
|
const eqs = indices.map((index, position) =>
|
|
@@ -208,7 +214,11 @@ export class ArrayRewriter {
|
|
|
208
214
|
if (this.isOp(array, OP_ITE)) {
|
|
209
215
|
const thenArray = manager.getArg(array, 1);
|
|
210
216
|
const elseArray = manager.getArg(array, 2);
|
|
211
|
-
if (
|
|
217
|
+
if (
|
|
218
|
+
!this.isExpandingSelects &&
|
|
219
|
+
manager.getRefCount(thenArray) !== 1 &&
|
|
220
|
+
manager.getRefCount(elseArray) !== 1
|
|
221
|
+
)
|
|
212
222
|
return undefined;
|
|
213
223
|
const thenSelect = this.mkApp(OP_SELECT, [thenArray, ...indices]);
|
|
214
224
|
const elseSelect = this.mkApp(OP_SELECT, [elseArray, ...indices]);
|