tla-ts 0.0.10-dev.a17d6d9fa → 0.0.10-dev.a5705bfbf
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 +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -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 +64 -64
- package/dist/prove.js +76 -76
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +37 -35
- package/dist/transfer.js +43 -41
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +10 -1
- package/src/check-failure.ts +12 -10
- package/src/check-trace.ts +36 -23
- package/src/check.ts +182 -135
- package/src/cli/tlc-output.ts +17 -2
- package/src/cli/tlc.ts +2 -2
- package/src/codegen.ts +15 -19
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +19 -6
- package/src/dfid.ts +80 -27
- package/src/environment.ts +30 -1
- package/src/evaluate.ts +254 -59
- package/src/exit-codes.ts +25 -13
- package/src/instances.ts +11 -1
- package/src/levels.ts +48 -7
- package/src/liveness-checker.ts +98 -27
- package/src/liveness.ts +4 -1
- package/src/obligations/source.ts +2 -0
- package/src/parser.ts +3 -0
- package/src/prover/smt/solver/card2bv.ts +7 -4
- package/src/prover/smt/solver/context.ts +20 -4
- package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- 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/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 +1 -0
- package/src/prover/smt/solver/opt-solver.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/qsat.ts +7 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
- 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 +9 -2
- package/src/prover/smt/solver/smtlib-parser.ts +6 -2
- package/src/prover/smt/solver/smtlib-script.ts +197 -73
- package/src/prover/smt/solver/tactic.ts +64 -37
- package/src/resolve.ts +143 -39
- package/src/sany/generator-expressions.ts +2 -0
- package/src/sany/generator-proofs.ts +1 -0
- package/src/search.ts +156 -37
- package/src/simulate.ts +143 -150
- package/src/spec-description.ts +3 -0
- package/src/standard-modules.ts +41 -16
- package/src/subexpressions.ts +168 -63
- package/src/successors.ts +33 -11
- package/src/symmetry.ts +1 -0
- package/src/tlc/replay.ts +64 -41
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +20 -6
- package/src/values.ts +15 -1
package/src/simulate.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CheckOptions, TraceStep, Violation } from "./check";
|
|
2
|
+
import type { CoverageOutput } from "./coverage";
|
|
2
3
|
import {
|
|
3
4
|
isStackOverflow,
|
|
4
5
|
TlaEvaluationError,
|
|
@@ -11,12 +12,19 @@ import {
|
|
|
11
12
|
UNEXPECTED_EXCEPTION,
|
|
12
13
|
} from "./errors";
|
|
13
14
|
import type { State } from "./evaluate";
|
|
14
|
-
import { EXIT_STATUS, getMessageExitStatus,
|
|
15
|
+
import { EXIT_STATUS, getMessageExitStatus, withLivenessChecksExitCode } from "./exit-codes";
|
|
15
16
|
import { getHashMapOrder } from "./java-hash";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
17
|
+
import { createLivenessChecks } from "./liveness-checker";
|
|
18
|
+
import {
|
|
19
|
+
addActionCoverage,
|
|
20
|
+
getIncompleteSuccessorMessage,
|
|
21
|
+
prepareSearch,
|
|
22
|
+
reportAssumptionViolation,
|
|
23
|
+
STOP_WALK,
|
|
24
|
+
walkCoveredSuccessors,
|
|
25
|
+
} from "./search";
|
|
18
26
|
import { getActionLabel, toActionValue, type SpecAction } from "./spec-description";
|
|
19
|
-
import { forEachInitialState, forEachSuccessor } from "./successors";
|
|
27
|
+
import { forEachInitialState, forEachSuccessor, type Successor } from "./successors";
|
|
20
28
|
import {
|
|
21
29
|
formatInnerMessage,
|
|
22
30
|
formatNestedMessage,
|
|
@@ -27,8 +35,10 @@ import {
|
|
|
27
35
|
isHeadedError,
|
|
28
36
|
MESSAGE_CODE,
|
|
29
37
|
withUnexpectedException,
|
|
38
|
+
type FailureMessage,
|
|
30
39
|
} from "./tlc/messages";
|
|
31
40
|
import { createJavaRandom, nextPrime, type JavaRandom } from "./tlc/random";
|
|
41
|
+
import { replayInitialStates } from "./tlc/replay";
|
|
32
42
|
import {
|
|
33
43
|
createActionRecord,
|
|
34
44
|
createCounterExample,
|
|
@@ -67,6 +77,7 @@ export interface SimulationStatistics {
|
|
|
67
77
|
export type SimulationOutput =
|
|
68
78
|
| { kind: "message"; code: number; isError: boolean; message: string; toolMessage: string }
|
|
69
79
|
| { kind: "behavior"; trace: TraceStep[]; isLastStateOnly: boolean }
|
|
80
|
+
| CoverageOutput
|
|
70
81
|
| { kind: "progress"; statistics: SimulationStatistics }
|
|
71
82
|
| { kind: "summary"; statistics: SimulationStatistics };
|
|
72
83
|
|
|
@@ -87,6 +98,7 @@ interface WorkerError {
|
|
|
87
98
|
isException: boolean;
|
|
88
99
|
isSummarized: boolean;
|
|
89
100
|
violation?: Violation;
|
|
101
|
+
failures?: FailureMessage[];
|
|
90
102
|
counterExample?: Value;
|
|
91
103
|
}
|
|
92
104
|
|
|
@@ -130,59 +142,6 @@ const getTrace = (last: TraceNode, order: number[]) => {
|
|
|
130
142
|
return trace;
|
|
131
143
|
};
|
|
132
144
|
|
|
133
|
-
// Deviation from TLC: LiveCheck1 gives the initial state no stuttering step into a tableau node that isn't initial, so it misses a behavior that stutters there.
|
|
134
|
-
const findTemporalViolation = (
|
|
135
|
-
trace: TraceNode[],
|
|
136
|
-
getFingerprint: (state: Value[]) => bigint,
|
|
137
|
-
createChecker: (successors: number[][], states: Value[][]) => LivenessChecker | undefined,
|
|
138
|
-
) => {
|
|
139
|
-
const fingerprints = trace.map((node) => getFingerprint(node.state));
|
|
140
|
-
const indices = new Map<bigint, number>();
|
|
141
|
-
const states: Value[][] = [];
|
|
142
|
-
const successors: number[][] = [];
|
|
143
|
-
fingerprints.forEach((fingerprint, position) => {
|
|
144
|
-
if (!indices.has(fingerprint)) {
|
|
145
|
-
indices.set(fingerprint, states.length);
|
|
146
|
-
states.push(trace[position].state);
|
|
147
|
-
successors.push([]);
|
|
148
|
-
}
|
|
149
|
-
if (position === 0) return;
|
|
150
|
-
const source = indices.get(fingerprints[position - 1]) ?? 0;
|
|
151
|
-
const target = indices.get(fingerprint) ?? 0;
|
|
152
|
-
if (source !== target && !successors[source].includes(target)) {
|
|
153
|
-
successors[source].push(target);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
const checker = createChecker(successors, states);
|
|
157
|
-
if (!checker) return undefined;
|
|
158
|
-
checker.addInitialState(0, states[0]);
|
|
159
|
-
states.forEach((state, index) =>
|
|
160
|
-
checker.addState(
|
|
161
|
-
index,
|
|
162
|
-
state,
|
|
163
|
-
successors[index].map((successor) => ({ index: successor, state: states[successor] })),
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
const lasso = checker.findViolation();
|
|
167
|
-
if (!lasso) return undefined;
|
|
168
|
-
const getLength = (path: number[]) =>
|
|
169
|
-
path.filter((index, position) => position === 0 || index !== path[position - 1]).length;
|
|
170
|
-
const path = [...lasso.prefix, ...lasso.cycle];
|
|
171
|
-
const length = getLength(path);
|
|
172
|
-
const cyclePosition = getLength(path.slice(0, lasso.prefix.length + 1));
|
|
173
|
-
const isStuttering =
|
|
174
|
-
fingerprints[length - 1] === getFingerprint(states[path[lasso.prefix.length]]);
|
|
175
|
-
return {
|
|
176
|
-
length,
|
|
177
|
-
isStuttering,
|
|
178
|
-
loopStart: isStuttering ? length - 1 : cyclePosition - 1,
|
|
179
|
-
properties: checker.getViolatedProperties(
|
|
180
|
-
trace.slice(0, length).map((node) => node.state),
|
|
181
|
-
cyclePosition - 1,
|
|
182
|
-
),
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
|
|
186
145
|
const createScheduler = (
|
|
187
146
|
scheduler: SimulationOptions["scheduler"],
|
|
188
147
|
nextActions: SpecAction[],
|
|
@@ -266,11 +225,20 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
266
225
|
};
|
|
267
226
|
const reportMessage = (code: number, text: string, toolText = text, isError = true) =>
|
|
268
227
|
output({ kind: "message", code, isError, message: text, toolMessage: toolText });
|
|
269
|
-
const
|
|
228
|
+
const reportCoverage = () => {
|
|
229
|
+
const report = prepared.getCoverage();
|
|
230
|
+
if (report) output({ kind: "coverage", coverage: report });
|
|
231
|
+
};
|
|
232
|
+
const printSummary = () => {
|
|
233
|
+
reportCoverage();
|
|
234
|
+
output({ kind: "summary", statistics: { ...statistics } });
|
|
235
|
+
};
|
|
270
236
|
const nodes = new WeakMap<(Value | undefined)[], TraceNode>();
|
|
271
237
|
const description = prepared.getDescription();
|
|
272
238
|
const initActions = description.inits;
|
|
273
239
|
const nextActions = description.actions;
|
|
240
|
+
const coverage = prepared.coverage;
|
|
241
|
+
const covered = coverage && addActionCoverage(coverage, environment, description);
|
|
274
242
|
let traceCount = 0;
|
|
275
243
|
let currentTrace = 0;
|
|
276
244
|
let evaluatedAction: SpecAction | undefined;
|
|
@@ -351,24 +319,12 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
351
319
|
);
|
|
352
320
|
return postcondition;
|
|
353
321
|
};
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Number(BigInt.asIntN(32, runtime.getFingerprint(successor.state))),
|
|
361
|
-
forEachActionSuccessors: (index, _state, onSuccessors) =>
|
|
362
|
-
onSuccessors(
|
|
363
|
-
successors[index].map((successor) => ({
|
|
364
|
-
index: successor,
|
|
365
|
-
state: states[successor],
|
|
366
|
-
})),
|
|
367
|
-
),
|
|
368
|
-
}),
|
|
369
|
-
),
|
|
370
|
-
);
|
|
371
|
-
const branches = createTemporalChecker([], [])?.branches;
|
|
322
|
+
const livenessChecks = withLivenessChecksExitCode(() =>
|
|
323
|
+
withUnexpectedException(() =>
|
|
324
|
+
createLivenessChecks(search.properties.liveness, search.spec.temporals, environment),
|
|
325
|
+
),
|
|
326
|
+
);
|
|
327
|
+
const branches = livenessChecks?.solutions.length;
|
|
372
328
|
if (branches) options.onProgress?.({ kind: "liveness-prepared", branches });
|
|
373
329
|
const assumptionStatus = reportAssumptionViolation(
|
|
374
330
|
specification.assumptions,
|
|
@@ -447,7 +403,13 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
447
403
|
return false;
|
|
448
404
|
};
|
|
449
405
|
try {
|
|
450
|
-
if (
|
|
406
|
+
if (covered) {
|
|
407
|
+
replayInitialStates(covered.inits, environment, addGenerated, (partial) =>
|
|
408
|
+
addGenerated([...partial]),
|
|
409
|
+
);
|
|
410
|
+
} else if (init) {
|
|
411
|
+
forEachInitialState(init, environment, addGenerated, search.spec.scope, addGenerated);
|
|
412
|
+
}
|
|
451
413
|
} catch (error) {
|
|
452
414
|
return reportInitialException(error, undefined);
|
|
453
415
|
}
|
|
@@ -458,6 +420,7 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
458
420
|
undefined,
|
|
459
421
|
false,
|
|
460
422
|
);
|
|
423
|
+
const generatedNodes: TraceNode[] = [];
|
|
461
424
|
for (const state of generated) {
|
|
462
425
|
if (!isComplete(state)) {
|
|
463
426
|
reportMessage(
|
|
@@ -479,18 +442,7 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
479
442
|
reportPostcondition(true);
|
|
480
443
|
return EXIT_STATUS.safetyViolation;
|
|
481
444
|
}
|
|
482
|
-
|
|
483
|
-
const predicate = search.findFailedInitialPredicate(state);
|
|
484
|
-
if (predicate) {
|
|
485
|
-
const alias = toTraceSteps([node])[0].state;
|
|
486
|
-
reportMessage(
|
|
487
|
-
MESSAGE_CODE.propertyViolatedInitial,
|
|
488
|
-
`Property ${predicate.name} is violated by the initial state:\n${formatState(alias)}`,
|
|
489
|
-
);
|
|
490
|
-
runtime.counterExample = getInitialCounterExample(node);
|
|
491
|
-
reportPostcondition(true);
|
|
492
|
-
return EXIT_STATUS.livenessViolation;
|
|
493
|
-
}
|
|
445
|
+
generatedNodes.push(node);
|
|
494
446
|
if (search.satisfiesConstraints(state)) {
|
|
495
447
|
search.trackStatePossible(state);
|
|
496
448
|
initialStates.push(node);
|
|
@@ -513,6 +465,24 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
513
465
|
);
|
|
514
466
|
return EXIT_STATUS.error;
|
|
515
467
|
}
|
|
468
|
+
// Deviation from TLC: its simulator checks no implied init, tla-ts checks them after TLC's own checks of the initial states.
|
|
469
|
+
for (const node of generatedNodes) {
|
|
470
|
+
try {
|
|
471
|
+
const predicate = search.findFailedInitialPredicate(node.state);
|
|
472
|
+
if (predicate) {
|
|
473
|
+
const alias = toTraceSteps([node])[0].state;
|
|
474
|
+
reportMessage(
|
|
475
|
+
MESSAGE_CODE.propertyViolatedInitial,
|
|
476
|
+
`Property ${predicate.name} is violated by the initial state:\n${formatState(alias)}`,
|
|
477
|
+
);
|
|
478
|
+
runtime.counterExample = getInitialCounterExample(node);
|
|
479
|
+
reportPostcondition(true);
|
|
480
|
+
return EXIT_STATUS.livenessViolation;
|
|
481
|
+
}
|
|
482
|
+
} catch (error) {
|
|
483
|
+
return reportInitialException(error, node.state);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
516
486
|
reportMessage(
|
|
517
487
|
MESSAGE_CODE.initGenerated1,
|
|
518
488
|
`Finished computing initial states: ${initialStates.length} distinct state generated at ${formatTlcDate(new Date())}.`,
|
|
@@ -530,61 +500,77 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
530
500
|
isException: false,
|
|
531
501
|
isSummarized: true,
|
|
532
502
|
});
|
|
533
|
-
const getSuccessors = (current: TraceNode,
|
|
503
|
+
const getSuccessors = (current: TraceNode, index: number) => {
|
|
504
|
+
const action = nextActions[index];
|
|
505
|
+
const coveredAction = covered?.actions[index];
|
|
534
506
|
const successors: TraceNode[] = [];
|
|
535
507
|
let failure: WorkerError | undefined;
|
|
536
508
|
runtime.deferred = undefined;
|
|
537
509
|
evaluatedAction = action;
|
|
510
|
+
const visit = (successor: Successor) => {
|
|
511
|
+
const node = toNode(successor.state, action, current);
|
|
512
|
+
node.deferred = runtime.deferred;
|
|
513
|
+
runtime.deferred = undefined;
|
|
514
|
+
statistics.generatedStates++;
|
|
515
|
+
try {
|
|
516
|
+
const violated = search.findViolatedInvariant(node.state, current.state);
|
|
517
|
+
if (violated) {
|
|
518
|
+
failure = toWorkerError(
|
|
519
|
+
MESSAGE_CODE.invariantViolatedBehavior,
|
|
520
|
+
`Invariant ${violated.name} is violated.`,
|
|
521
|
+
node,
|
|
522
|
+
);
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
const property = search.findViolatedActionProperty(current.state, node.state);
|
|
526
|
+
if (property) {
|
|
527
|
+
failure = toWorkerError(
|
|
528
|
+
MESSAGE_CODE.actionPropertyViolatedBehavior,
|
|
529
|
+
`Action property ${property.name} is violated.`,
|
|
530
|
+
node,
|
|
531
|
+
);
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
} catch (error) {
|
|
535
|
+
if (!(error instanceof TlaEvaluationError) || !isHeadedError(error)) throw error;
|
|
536
|
+
const text = getFailureMessage(error, true);
|
|
537
|
+
failure = {
|
|
538
|
+
...toWorkerError(text.code, text.message, node),
|
|
539
|
+
toolMessage: text.toolMessage,
|
|
540
|
+
};
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
if (!search.satisfiesConstraints(node.state, current.state)) return false;
|
|
544
|
+
search.trackStatePossible(node.state);
|
|
545
|
+
if (!search.satisfiesActionConstraints(current.state, node.state)) return false;
|
|
546
|
+
search.trackActionPossible(current.state, node.state);
|
|
547
|
+
if (successors.length === getSetBound()) throw new TlaTooManyStatesError();
|
|
548
|
+
if (coverage && coveredAction) coverage.secondary[coveredAction.node]++;
|
|
549
|
+
successors.push(node);
|
|
550
|
+
return false;
|
|
551
|
+
};
|
|
538
552
|
try {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const property = search.findViolatedActionProperty(current.state, node.state);
|
|
559
|
-
if (property) {
|
|
560
|
-
failure = toWorkerError(
|
|
561
|
-
MESSAGE_CODE.actionPropertyViolatedBehavior,
|
|
562
|
-
`Action property ${property.name} is violated.`,
|
|
563
|
-
node,
|
|
564
|
-
);
|
|
565
|
-
return true;
|
|
566
|
-
}
|
|
567
|
-
} catch (error) {
|
|
568
|
-
if (!(error instanceof TlaEvaluationError) || !isHeadedError(error)) throw error;
|
|
569
|
-
const text = getFailureMessage(error, true);
|
|
570
|
-
failure = {
|
|
571
|
-
...toWorkerError(text.code, text.message, node),
|
|
572
|
-
toolMessage: text.toolMessage,
|
|
573
|
-
};
|
|
574
|
-
return true;
|
|
575
|
-
}
|
|
576
|
-
if (!search.satisfiesConstraints(node.state, current.state)) return false;
|
|
577
|
-
search.trackStatePossible(node.state);
|
|
578
|
-
if (!search.satisfiesActionConstraints(current.state, node.state)) return false;
|
|
579
|
-
search.trackActionPossible(current.state, node.state);
|
|
580
|
-
if (successors.length === getSetBound()) throw new TlaTooManyStatesError();
|
|
581
|
-
successors.push(node);
|
|
582
|
-
return false;
|
|
583
|
-
},
|
|
584
|
-
action.scope,
|
|
585
|
-
options.isGenerating ? workerRandom : undefined,
|
|
586
|
-
);
|
|
553
|
+
if (coverage && coveredAction && !options.isGenerating) {
|
|
554
|
+
walkCoveredSuccessors(coverage, coveredAction, current.state, environment, (state) => {
|
|
555
|
+
if (visit({ state, action: action.name })) throw STOP_WALK;
|
|
556
|
+
});
|
|
557
|
+
} else {
|
|
558
|
+
forEachSuccessor(
|
|
559
|
+
action.expression,
|
|
560
|
+
current.state,
|
|
561
|
+
environment,
|
|
562
|
+
coverage && coveredAction
|
|
563
|
+
? (successor) => {
|
|
564
|
+
coverage.primary[coveredAction.node]++;
|
|
565
|
+
return visit(successor);
|
|
566
|
+
}
|
|
567
|
+
: visit,
|
|
568
|
+
action.scope,
|
|
569
|
+
options.isGenerating ? workerRandom : undefined,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
587
572
|
} catch (error) {
|
|
573
|
+
if (error === STOP_WALK) return { successors, error: failure };
|
|
588
574
|
if (!(error instanceof TlaIncompleteSuccessorError)) throw error;
|
|
589
575
|
const node = toNode(
|
|
590
576
|
error.state.map((value) => value ?? createModelValue("null")),
|
|
@@ -611,19 +597,22 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
611
597
|
search.getReward,
|
|
612
598
|
);
|
|
613
599
|
const getTemporalViolation = (last: TraceNode): WorkerError | undefined => {
|
|
614
|
-
if (
|
|
600
|
+
if (!livenessChecks) return undefined;
|
|
615
601
|
const trace = getTrace(last, search.getTlcOrder());
|
|
616
602
|
// TLC's LiveCheck#checkTrace fingerprints each state, which sorts its records.
|
|
617
603
|
for (let position = 0; position < trace.length; position++) {
|
|
618
604
|
trace[position].state.forEach(markNormalized);
|
|
619
605
|
}
|
|
620
|
-
const found =
|
|
606
|
+
const found = livenessChecks.findTraceViolation(
|
|
607
|
+
trace.map((node) => node.state),
|
|
608
|
+
trace.map((node) => runtime.getFingerprint(node.state)),
|
|
609
|
+
);
|
|
621
610
|
if (!found) return undefined;
|
|
622
|
-
const back = trace[found.
|
|
623
|
-
const lasso =
|
|
611
|
+
const back = found.backPosition === undefined ? undefined : trace[found.backPosition];
|
|
612
|
+
const lasso = found.positions.map((position) => trace[position]);
|
|
613
|
+
const loopStart = back ? found.cyclePosition - 1 : lasso.length - 1;
|
|
624
614
|
const steps = toTraceSteps(lasso);
|
|
625
|
-
const loopAction =
|
|
626
|
-
found.isStuttering || !back ? createActionRecord(undefined) : toActionValue(back.action);
|
|
615
|
+
const loopAction = back ? toActionValue(back.action) : createActionRecord(undefined);
|
|
627
616
|
return {
|
|
628
617
|
...toWorkerError(MESSAGE_CODE.temporalPropertyViolated, "", last),
|
|
629
618
|
isException: true,
|
|
@@ -631,13 +620,11 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
631
620
|
name: found.properties[0],
|
|
632
621
|
properties: found.properties,
|
|
633
622
|
trace: steps,
|
|
634
|
-
loopStart
|
|
623
|
+
loopStart,
|
|
635
624
|
loopLabel: back && getActionLabel(back.action, options.version, back.level === 1),
|
|
636
625
|
},
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
action: loopAction,
|
|
640
|
-
}),
|
|
626
|
+
failures: found.failures.map((failure) => toException(failure, last)),
|
|
627
|
+
counterExample: getCounterExample(lasso, steps, { start: loopStart, action: loopAction }),
|
|
641
628
|
};
|
|
642
629
|
};
|
|
643
630
|
const simulateTrace = (): WorkerError | "stopped" | undefined => {
|
|
@@ -648,7 +635,8 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
648
635
|
const prime = nextPrime(workerRandom);
|
|
649
636
|
let successors: TraceNode[] = [];
|
|
650
637
|
for (let attempt = 0; attempt < nextActions.length; attempt++) {
|
|
651
|
-
const result = getSuccessors(currentNode,
|
|
638
|
+
const result = getSuccessors(currentNode, actionIndex);
|
|
639
|
+
// Deviation from TLC: TLCSet("exit") interrupts TLC's SimulationWorker, whose BlockingQueue#put then drops a violation found in the same step.
|
|
652
640
|
if (result.error) return result.error;
|
|
653
641
|
successors = result.successors;
|
|
654
642
|
if (successors.length > 0) break;
|
|
@@ -730,6 +718,9 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
730
718
|
const reported = printed === -1 ? errors : errors.slice(0, printed + 1);
|
|
731
719
|
reported.forEach((error) => {
|
|
732
720
|
if (error.violation) {
|
|
721
|
+
error.failures?.forEach((failure) =>
|
|
722
|
+
reportMessage(failure.code, failure.message, failure.toolMessage),
|
|
723
|
+
);
|
|
733
724
|
options.onProgress?.({
|
|
734
725
|
kind: "violation",
|
|
735
726
|
status: "liveness-violation",
|
|
@@ -758,6 +749,8 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
758
749
|
: EXIT_STATUS.success;
|
|
759
750
|
const status = Math.max(errorStatus, postconditionStatus);
|
|
760
751
|
output({ kind: "progress", statistics: { ...statistics } });
|
|
752
|
+
// TLC's ProgressReport prints the coverage again with its last progress unless -coverage spans more progress reports.
|
|
753
|
+
if (options.coverage !== undefined && options.coverage <= 1) reportCoverage();
|
|
761
754
|
if (status === EXIT_STATUS.success) printSummary();
|
|
762
755
|
return status;
|
|
763
756
|
};
|
package/src/spec-description.ts
CHANGED
|
@@ -274,6 +274,8 @@ const getActions = (
|
|
|
274
274
|
);
|
|
275
275
|
case "Label":
|
|
276
276
|
return getActions(expression.body, scope, closure, environment, instanceActions);
|
|
277
|
+
case "Selection":
|
|
278
|
+
return getActions(expression.expression, scope, closure, environment, instanceActions);
|
|
277
279
|
case "Or":
|
|
278
280
|
return expression.operands.flatMap((operand) =>
|
|
279
281
|
getActions(operand, scope, closure, environment, instanceActions),
|
|
@@ -525,6 +527,7 @@ export const getSubscriptVariables = (
|
|
|
525
527
|
return expression.elements.every((element) => collect(element, innerScope));
|
|
526
528
|
}
|
|
527
529
|
if (expression.kind === "Label") return collect(expression.body, innerScope);
|
|
530
|
+
if (expression.kind === "Selection") return collect(expression.expression, innerScope);
|
|
528
531
|
const unwrapped = unwrapBinding(expression, innerScope, environment);
|
|
529
532
|
if (unwrapped) return collect(unwrapped.expression, unwrapped.scope);
|
|
530
533
|
const argument =
|
package/src/standard-modules.ts
CHANGED
|
@@ -125,6 +125,43 @@ const combineReducible = (
|
|
|
125
125
|
return createEnumeratedSet(union);
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
+
const isIntervalInSortedSet = (interval: IntervalValue, set: SetValue) => {
|
|
129
|
+
const elements = set.elements;
|
|
130
|
+
let low = 0;
|
|
131
|
+
let high = elements.length;
|
|
132
|
+
while (low < high) {
|
|
133
|
+
const middle = (low + high) >> 1;
|
|
134
|
+
const probe = elements[middle];
|
|
135
|
+
if (typeof probe !== "number") return undefined;
|
|
136
|
+
if (probe < interval.low) low = middle + 1;
|
|
137
|
+
else high = middle;
|
|
138
|
+
}
|
|
139
|
+
for (let element = interval.low; element <= interval.high; element++, low++) {
|
|
140
|
+
if (low === elements.length) return false;
|
|
141
|
+
const probe = elements[low];
|
|
142
|
+
if (probe !== element) return typeof probe === "number" ? false : undefined;
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const isIntervalSubset = (left: IntervalValue, right: Value) => {
|
|
148
|
+
const isWithin =
|
|
149
|
+
typeof right === "object" &&
|
|
150
|
+
right.kind === "Interval" &&
|
|
151
|
+
right.low <= left.low &&
|
|
152
|
+
right.high >= left.high;
|
|
153
|
+
if (isWithin) return true;
|
|
154
|
+
const isContained =
|
|
155
|
+
typeof right === "object" && right.kind === "Set"
|
|
156
|
+
? isIntervalInSortedSet(left, right)
|
|
157
|
+
: undefined;
|
|
158
|
+
if (isContained !== undefined) return isContained;
|
|
159
|
+
for (let element = left.low; element <= left.high; element++) {
|
|
160
|
+
if (!isElementOf(element, right)) return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
};
|
|
164
|
+
|
|
128
165
|
const defineShortCircuit = (
|
|
129
166
|
name: string,
|
|
130
167
|
compute: (left: boolean, right: () => boolean) => boolean,
|
|
@@ -159,6 +196,7 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
159
196
|
(args) => !isElementOf(getValue(args, 0, "\\notin"), getValue(args, 1, "\\notin")),
|
|
160
197
|
),
|
|
161
198
|
defineBinary("\\subseteq", (left, right) => {
|
|
199
|
+
if (typeof left === "object" && left.kind === "Interval") return isIntervalSubset(left, right);
|
|
162
200
|
if (!isSetValue(left)) {
|
|
163
201
|
throw new TlaEvaluationError(`\\subseteq expects a set but received ${formatValue(left)}`);
|
|
164
202
|
}
|
|
@@ -169,18 +207,6 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
169
207
|
right.kind === "Subset" &&
|
|
170
208
|
isEnumerable(left.base);
|
|
171
209
|
if (isPowerSets) return isSubsetOf(toFiniteSet(left.base).elements, right.base);
|
|
172
|
-
if (typeof left === "object" && left.kind === "Interval") {
|
|
173
|
-
const isWithin =
|
|
174
|
-
typeof right === "object" &&
|
|
175
|
-
right.kind === "Interval" &&
|
|
176
|
-
right.low <= left.low &&
|
|
177
|
-
right.high >= left.high;
|
|
178
|
-
if (isWithin) return true;
|
|
179
|
-
for (let element = left.low; element <= left.high; element++) {
|
|
180
|
-
if (!isElementOf(element, right)) return false;
|
|
181
|
-
}
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
210
|
return !someStreamedElement(left, (element) => !isElementOf(element, right));
|
|
185
211
|
}),
|
|
186
212
|
...SET_OPERATORS.map((operator) =>
|
|
@@ -315,11 +341,10 @@ const createArithmeticOperators = (module: string) => {
|
|
|
315
341
|
}
|
|
316
342
|
return ((left % right) + right) % right;
|
|
317
343
|
}),
|
|
318
|
-
|
|
319
|
-
const low = getValue(args, 0, "..");
|
|
344
|
+
defineBinary("..", (low, high) => {
|
|
320
345
|
// TLC's MethodHandle casts the last argument first.
|
|
321
|
-
const
|
|
322
|
-
return { kind: "Interval", low: getJavaInteger(low, dotDotSignature), high };
|
|
346
|
+
const highNumber = getJavaInteger(high, dotDotSignature);
|
|
347
|
+
return { kind: "Interval", low: getJavaInteger(low, dotDotSignature), high: highNumber };
|
|
323
348
|
}),
|
|
324
349
|
];
|
|
325
350
|
};
|