tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.2813db5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +7 -7
- package/dist/prove.js +32 -32
- package/dist/run.cjs +7 -7
- package/dist/run.js +25 -25
- package/dist/transfer.cjs +18 -18
- package/dist/transfer.js +18 -18
- package/package.json +1 -1
- package/src/check.ts +33 -15
- package/src/cli/options.ts +1 -0
- package/src/cli/tlc.ts +9 -0
- package/src/evaluate.ts +2 -1
- package/src/parallel-worker.ts +6 -3
- package/src/parallel.ts +15 -7
- package/src/sany/generator.ts +9 -7
- package/src/sany/linter.ts +30 -21
- package/src/search.ts +43 -24
- package/src/values.ts +29 -2
package/package.json
CHANGED
package/src/check.ts
CHANGED
|
@@ -114,6 +114,9 @@ export interface CheckOptions {
|
|
|
114
114
|
dump?: StateDump;
|
|
115
115
|
// TLC's -tool, which changes the messages of TLC's errors.
|
|
116
116
|
isTool?: boolean;
|
|
117
|
+
// TLC's -continue: the search reports each violated invariant and action property through
|
|
118
|
+
// onProgress and goes on.
|
|
119
|
+
isContinued?: boolean;
|
|
117
120
|
// Whether TLC records a binary trace for its trace exploration spec, for which it loads Integers.
|
|
118
121
|
isTraceRecorded?: boolean;
|
|
119
122
|
// Whether the caller printed SANY's report, its warnings included, before the check.
|
|
@@ -163,8 +166,11 @@ export type CheckProgress =
|
|
|
163
166
|
statistics: SearchStatistics;
|
|
164
167
|
}
|
|
165
168
|
| { kind: "liveness-finished" }
|
|
169
|
+
| { kind: "sequential-fallback"; string: string }
|
|
166
170
|
// A warning TLC prints as it evaluates the spec, with its message code.
|
|
167
171
|
| { kind: "warning"; code: number; text: string }
|
|
172
|
+
// A violation that the search goes on past with -continue.
|
|
173
|
+
| { kind: "violation"; status: CheckStatus; violation: Violation }
|
|
168
174
|
// A method of the class named after a module, which TLC reports as it loads the class.
|
|
169
175
|
| ({ kind: "java-override" } & JavaOverride);
|
|
170
176
|
|
|
@@ -551,6 +557,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
551
557
|
...(checked.postcondition && { postcondition: checked.postcondition }),
|
|
552
558
|
});
|
|
553
559
|
};
|
|
560
|
+
// With -continue, TLC prints the trace of a violation without checking the postconditions.
|
|
561
|
+
const reportContinuedViolation = (status: CheckStatus, violation: Omit<Violation, "loopStart">) =>
|
|
562
|
+
options.onProgress?.({
|
|
563
|
+
kind: "violation",
|
|
564
|
+
status,
|
|
565
|
+
violation: { ...violation, loopStart: undefined },
|
|
566
|
+
});
|
|
554
567
|
const spec = search.spec;
|
|
555
568
|
const getFingerprintState = search.getFingerprintState;
|
|
556
569
|
const specNextActions = { value: undefined as SpecAction[] | undefined };
|
|
@@ -1164,7 +1177,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1164
1177
|
liveness?.addInitialState(states.length, state);
|
|
1165
1178
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
1166
1179
|
}
|
|
1167
|
-
|
|
1180
|
+
if (options.isContinued) {
|
|
1181
|
+
search.getViolatedInvariants(state).forEach((invariant) =>
|
|
1182
|
+
reportContinuedViolation("invariant-violation", {
|
|
1183
|
+
name: invariant.name,
|
|
1184
|
+
...toTrace([{ action: undefined, state }], []),
|
|
1185
|
+
}),
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
1168
1189
|
if (violated) {
|
|
1169
1190
|
return reportViolation("invariant-violation", {
|
|
1170
1191
|
name: violated.name,
|
|
@@ -1231,14 +1252,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1231
1252
|
if (existing === -1) {
|
|
1232
1253
|
try {
|
|
1233
1254
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
name: violated.name,
|
|
1238
|
-
...getTrace(index, successor),
|
|
1239
|
-
}),
|
|
1240
|
-
);
|
|
1255
|
+
const violation = violated && { name: violated.name, ...getTrace(index, successor) };
|
|
1256
|
+
if (violation && !options.isContinued) {
|
|
1257
|
+
return withOutDegrees(reportViolation("invariant-violation", violation));
|
|
1241
1258
|
}
|
|
1259
|
+
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1242
1260
|
} catch (error) {
|
|
1243
1261
|
if (isStackOverflow(error)) throw error;
|
|
1244
1262
|
// TLC replays the expansion and skips the invariants of a state it has seen, the failed one
|
|
@@ -1253,14 +1271,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1253
1271
|
}
|
|
1254
1272
|
}
|
|
1255
1273
|
const violatedProperty = search.findViolatedActionProperty(state, successor.state);
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
);
|
|
1274
|
+
const propertyViolation = violatedProperty && {
|
|
1275
|
+
name: violatedProperty.name,
|
|
1276
|
+
...getTrace(index, successor),
|
|
1277
|
+
};
|
|
1278
|
+
if (propertyViolation && !options.isContinued) {
|
|
1279
|
+
return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
|
|
1263
1280
|
}
|
|
1281
|
+
if (propertyViolation) reportContinuedViolation("liveness-violation", propertyViolation);
|
|
1264
1282
|
if (!isNew) return undefined;
|
|
1265
1283
|
if (!isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1266
1284
|
markSeen(hash, states.length);
|
package/src/cli/options.ts
CHANGED
|
@@ -65,6 +65,7 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
65
65
|
|
|
66
66
|
export const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options}", [
|
|
67
67
|
{ flag: "-config <Spec.cfg>" },
|
|
68
|
+
{ flag: "-continue" },
|
|
68
69
|
{ flag: "-deadlock" },
|
|
69
70
|
// Like TLC, -dump takes a format only when the next argument starts with dot and a file follows.
|
|
70
71
|
{
|
package/src/cli/tlc.ts
CHANGED
|
@@ -351,8 +351,16 @@ const printCheckProgress = (
|
|
|
351
351
|
case "liveness-finished":
|
|
352
352
|
printLivenessEnd(printer, timing);
|
|
353
353
|
return;
|
|
354
|
+
case "sequential-fallback":
|
|
355
|
+
process.stderr.write(
|
|
356
|
+
`Warning: the search created the string ${JSON.stringify(progress.string)}, so tla-ts checks the model again with one worker. Workers agree on the order of strings only when the strings exist before the search.\n`,
|
|
357
|
+
);
|
|
358
|
+
return;
|
|
354
359
|
case "warning":
|
|
355
360
|
print(progress.code, MESSAGE_LEVEL.warning, progress.text);
|
|
361
|
+
return;
|
|
362
|
+
case "violation":
|
|
363
|
+
printViolation(progress.status, progress.violation, printer);
|
|
356
364
|
}
|
|
357
365
|
};
|
|
358
366
|
|
|
@@ -823,6 +831,7 @@ const checkSpec = async (
|
|
|
823
831
|
seed: BigInt(seed),
|
|
824
832
|
dump: dumpValues && getStateDump(dumpValues),
|
|
825
833
|
isTool: printer.isTool,
|
|
834
|
+
isContinued: args.has("-continue"),
|
|
826
835
|
isTraceRecorded: isRecorded,
|
|
827
836
|
isSanyReported: true,
|
|
828
837
|
isWarningEnabled: !args.has("-nowarning"),
|
package/src/evaluate.ts
CHANGED
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
getLazySubsets,
|
|
49
49
|
getStreamedElements,
|
|
50
50
|
getFunctionClass,
|
|
51
|
+
getNormalizedSetElements,
|
|
51
52
|
getSequenceElements,
|
|
52
53
|
isElementOf,
|
|
53
54
|
isEnumerable,
|
|
@@ -476,7 +477,7 @@ const checkEnumerable = (set: Value, expression: Expression, version: TlcVersion
|
|
|
476
477
|
const getEnumeratedElements = (set: Value, expression: Expression, version: TlcVersion) => {
|
|
477
478
|
checkEnumerable(set, expression, version);
|
|
478
479
|
if (typeof set === "object" && set.kind === "Interval") return getIntervalElements(set);
|
|
479
|
-
return getLazySubsets(set) ??
|
|
480
|
+
return getLazySubsets(set) ?? getNormalizedSetElements(set);
|
|
480
481
|
};
|
|
481
482
|
|
|
482
483
|
// The elements Tool.contexts binds to the bound of a quantifier or a set map. TLC 1.7.4 streams a
|
package/src/parallel-worker.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
isSharedFingerprintsFull,
|
|
6
6
|
writeStateFingerprint,
|
|
7
7
|
} from "./fingerprints";
|
|
8
|
-
import type { CoordinatorMessage,
|
|
8
|
+
import type { CoordinatorMessage, StartMessage, WorkerMessage } from "./parallel";
|
|
9
9
|
import { createSearch } from "./search";
|
|
10
10
|
import { getSuccessors, type Successor } from "./successors";
|
|
11
11
|
import { createTlcOrder } from "./tlc/order";
|
|
@@ -13,6 +13,7 @@ import { OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
|
13
13
|
import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
|
|
14
14
|
import {
|
|
15
15
|
createCanonicalizer,
|
|
16
|
+
getRankedString,
|
|
16
17
|
getRankedStringCount,
|
|
17
18
|
setStringOrder,
|
|
18
19
|
setValueVersion,
|
|
@@ -188,7 +189,7 @@ const runWorker = (start: StartMessage, parent: Port) => {
|
|
|
188
189
|
const report = (message: WorkerMessage) =>
|
|
189
190
|
parent.postMessage(message, message.type === "level" ? [message.fingerprints.buffer] : []);
|
|
190
191
|
|
|
191
|
-
const runLevel = async (): Promise<
|
|
192
|
+
const runLevel = async (): Promise<WorkerMessage | undefined> => {
|
|
192
193
|
const expansion: Expansion = {
|
|
193
194
|
states: frontier.states,
|
|
194
195
|
origin: 0,
|
|
@@ -222,7 +223,9 @@ const runWorker = (start: StartMessage, parent: Port) => {
|
|
|
222
223
|
}
|
|
223
224
|
if (!(await steal(expansion))) break;
|
|
224
225
|
}
|
|
225
|
-
if (getRankedStringCount() !== startupStrings)
|
|
226
|
+
if (getRankedStringCount() !== startupStrings) {
|
|
227
|
+
return { type: "abort", string: getRankedString(startupStrings) };
|
|
228
|
+
}
|
|
226
229
|
frontier.states = expansion.next;
|
|
227
230
|
Atomics.store(remaining, workerIndex, frontier.states.length);
|
|
228
231
|
return {
|
package/src/parallel.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { createStateEncoder, type EncodedStates } from "./transfer";
|
|
|
31
31
|
import type { TlcVersion } from "./tlc/version";
|
|
32
32
|
import {
|
|
33
33
|
createCanonicalizer,
|
|
34
|
+
getRankedString,
|
|
34
35
|
getRankedStringCount,
|
|
35
36
|
setStringOrder,
|
|
36
37
|
setValueVersion,
|
|
@@ -56,7 +57,7 @@ export interface StartMessage {
|
|
|
56
57
|
remaining: Int32Array;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
interface LevelMessage {
|
|
60
61
|
type: "level";
|
|
61
62
|
generated: number;
|
|
62
63
|
added: number;
|
|
@@ -66,7 +67,7 @@ export interface LevelMessage {
|
|
|
66
67
|
|
|
67
68
|
export type WorkerMessage =
|
|
68
69
|
| { type: "ready" }
|
|
69
|
-
| { type: "abort" }
|
|
70
|
+
| { type: "abort"; string?: string }
|
|
70
71
|
| { type: "paused" }
|
|
71
72
|
| LevelMessage;
|
|
72
73
|
|
|
@@ -96,7 +97,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
96
97
|
};
|
|
97
98
|
// The search on the calling thread prints and reports what this one did while it started, so it
|
|
98
99
|
// skips that.
|
|
99
|
-
const fallBack = () => {
|
|
100
|
+
const fallBack = (createdString?: string) => {
|
|
101
|
+
if (createdString !== undefined) {
|
|
102
|
+
options.onProgress?.({ kind: "sequential-fallback", string: createdString });
|
|
103
|
+
}
|
|
100
104
|
const skipped = { count: printed.count };
|
|
101
105
|
return checkSequentially({
|
|
102
106
|
...options,
|
|
@@ -108,12 +112,13 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
108
112
|
});
|
|
109
113
|
};
|
|
110
114
|
const workerCount = options.workers ?? 1;
|
|
111
|
-
// TLC's workers write the -dump state graph
|
|
112
|
-
//
|
|
115
|
+
// TLC's workers write the -dump state graph, and print the violations -continue goes on past, in
|
|
116
|
+
// whichever order they find them, so one worker does what a single TLC worker does.
|
|
113
117
|
const isSequential =
|
|
114
118
|
workerCount < 2 ||
|
|
115
119
|
typeof SharedArrayBuffer !== "function" ||
|
|
116
120
|
options.dump !== undefined ||
|
|
121
|
+
options.isContinued === true ||
|
|
117
122
|
config.view !== undefined ||
|
|
118
123
|
config.postconditions.length > 0 ||
|
|
119
124
|
config.possible.length > 0;
|
|
@@ -232,7 +237,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
232
237
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
233
238
|
return fallBack();
|
|
234
239
|
}
|
|
235
|
-
if (getRankedStringCount() !== startupStrings) return fallBack();
|
|
240
|
+
if (getRankedStringCount() !== startupStrings) return fallBack(getRankedString(startupStrings));
|
|
236
241
|
statistics.depth = statistics.generatedStates === 0 ? 0 : 1;
|
|
237
242
|
statistics.initialStates = {
|
|
238
243
|
generated: statistics.generatedStates,
|
|
@@ -324,7 +329,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
324
329
|
const messages = await collectLevels(await reported);
|
|
325
330
|
if (isAborted(messages)) {
|
|
326
331
|
terminate();
|
|
327
|
-
|
|
332
|
+
const aborted = messages.find(
|
|
333
|
+
(message) => message.type === "abort" && message.string !== undefined,
|
|
334
|
+
);
|
|
335
|
+
return fallBack(aborted?.type === "abort" ? aborted.string : undefined);
|
|
328
336
|
}
|
|
329
337
|
const levels = messages.flatMap((message) => (message.type === "level" ? [message] : []));
|
|
330
338
|
const added = levels.reduce((sum, message) => sum + message.added, 0);
|
package/src/sany/generator.ts
CHANGED
|
@@ -1783,11 +1783,15 @@ export const generateSanySpecification = (
|
|
|
1783
1783
|
(params.length === 0 || params[params.length - 1].arity === 0);
|
|
1784
1784
|
if (existing.letInLevel !== state.curLevel) {
|
|
1785
1785
|
addError(location, `Recursive operator ${name} defined at wrong LET/IN level.`);
|
|
1786
|
-
} else
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1786
|
+
} else {
|
|
1787
|
+
if (!isMatching) {
|
|
1788
|
+
addError(
|
|
1789
|
+
location,
|
|
1790
|
+
`Definition of ${existing.name} has different arity than its RECURSIVE declaration.`,
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
// SANY sets the parameters before it analyzes the body.
|
|
1794
|
+
existing.params = params;
|
|
1791
1795
|
}
|
|
1792
1796
|
} else if (existing !== undefined) {
|
|
1793
1797
|
addError(location, `Operator ${name} already defined or declared.`);
|
|
@@ -1805,8 +1809,6 @@ export const generateSanySpecification = (
|
|
|
1805
1809
|
!existing.isDefined &&
|
|
1806
1810
|
existing.letInLevel === state.curLevel
|
|
1807
1811
|
) {
|
|
1808
|
-
// OpDefNode.setParams keeps the arity of the RECURSIVE declaration.
|
|
1809
|
-
existing.params = params;
|
|
1810
1812
|
existing.weights = params.map(() => 0);
|
|
1811
1813
|
existing.maxLevels = params.map(() => TEMPORAL_LEVEL);
|
|
1812
1814
|
existing.isLeibnizArg = params.map(() => true);
|
package/src/sany/linter.ts
CHANGED
|
@@ -74,13 +74,14 @@ const getFieldName = (pair: OpApplNode) => {
|
|
|
74
74
|
return name?.kind === "String" ? name : undefined;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
// Records.sameDomain.
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
// Records.sameDomain, given that SANY rejects a record with two fields of the same name.
|
|
78
|
+
const getDomain = (record: OpApplNode) =>
|
|
79
|
+
JSON.stringify([
|
|
80
|
+
record.operands.length,
|
|
81
|
+
...getFieldPairs(record)
|
|
82
|
+
.map((pair) => getFieldName(pair)?.value)
|
|
83
|
+
.sort(),
|
|
84
|
+
]);
|
|
84
85
|
|
|
85
86
|
// ModuleNode.getExtendedModuleSet(true).
|
|
86
87
|
const getExtendedModules = (module: ModuleNode, found = new Set<ModuleNode>()) => {
|
|
@@ -94,19 +95,9 @@ const getExtendedModules = (module: ModuleNode, found = new Set<ModuleNode>()) =
|
|
|
94
95
|
|
|
95
96
|
// Linter.lintRecords: the warnings for the records of a module.
|
|
96
97
|
export const lintSanyModule = (module: ModuleNode): SanyMessage[] => {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
];
|
|
101
|
-
return module.records.flatMap((record) => {
|
|
102
|
-
// Linter checks the field's value, the record's fields and the fields of every record with the
|
|
103
|
-
// same domain, which includes the record itself.
|
|
104
|
-
const isExempt = allRecords
|
|
105
|
-
.filter((other) => isSameDomain(other, record))
|
|
106
|
-
.flatMap(getFieldPairs)
|
|
107
|
-
.some(isBuiltFromDeclarations);
|
|
108
|
-
if (isExempt) return [];
|
|
109
|
-
return getFieldPairs(record).flatMap((pair) => {
|
|
98
|
+
const linted = module.records.map((record) => ({
|
|
99
|
+
domain: getDomain(record),
|
|
100
|
+
warnings: getFieldPairs(record).flatMap((pair): SanyMessage[] => {
|
|
110
101
|
const name = getFieldName(pair);
|
|
111
102
|
const symbol = name && getContextSymbol(module.context, name.value);
|
|
112
103
|
if (name === undefined || symbol === undefined) return [];
|
|
@@ -117,6 +108,24 @@ export const lintSanyModule = (module: ModuleNode): SanyMessage[] => {
|
|
|
117
108
|
isWarning: true,
|
|
118
109
|
},
|
|
119
110
|
];
|
|
120
|
-
})
|
|
111
|
+
}),
|
|
112
|
+
}));
|
|
113
|
+
const warnedDomains = new Set(
|
|
114
|
+
linted.flatMap((item) => (item.warnings.length > 0 ? [item.domain] : [])),
|
|
115
|
+
);
|
|
116
|
+
const exemptDomains = new Set<string>();
|
|
117
|
+
[
|
|
118
|
+
...[...getExtendedModules(module)].flatMap((extended) => extended.records),
|
|
119
|
+
...module.records,
|
|
120
|
+
].forEach((record) => {
|
|
121
|
+
const domain = getDomain(record);
|
|
122
|
+
if (
|
|
123
|
+
warnedDomains.has(domain) &&
|
|
124
|
+
!exemptDomains.has(domain) &&
|
|
125
|
+
getFieldPairs(record).some(isBuiltFromDeclarations)
|
|
126
|
+
) {
|
|
127
|
+
exemptDomains.add(domain);
|
|
128
|
+
}
|
|
121
129
|
});
|
|
130
|
+
return linted.flatMap((item) => (exemptDomains.has(item.domain) ? [] : item.warnings));
|
|
122
131
|
};
|
package/src/search.ts
CHANGED
|
@@ -563,6 +563,8 @@ interface Search {
|
|
|
563
563
|
// TLC drops a constraint that is a true constant formula.
|
|
564
564
|
isConstrained: boolean;
|
|
565
565
|
findViolatedInvariant: (state: Value[], parent?: Value[]) => StateCheck | undefined;
|
|
566
|
+
// Every invariant an initial state violates, which TLC reports with -continue.
|
|
567
|
+
getViolatedInvariants: (state: Value[]) => StateCheck[];
|
|
566
568
|
// The checks of a state that TLC evaluates when it replays the computation of the initial states
|
|
567
569
|
// or of the successors of a state, with an environment that records the call stack. The first
|
|
568
570
|
// returns the check that stops the replay, and the second false where TLC stops it.
|
|
@@ -760,6 +762,32 @@ export const createSearch = (
|
|
|
760
762
|
: [getViewValue(view.expression, representative)],
|
|
761
763
|
);
|
|
762
764
|
};
|
|
765
|
+
// With -continue, TLC goes on to the successors of a state that violates an invariant.
|
|
766
|
+
const violatingStates = new WeakSet<Value[]>();
|
|
767
|
+
const isViolated = (invariant: StateCheck, state: Value[], parent: Value[] | undefined) => {
|
|
768
|
+
// A parent that satisfies every invariant leaves only what the step changed to fail.
|
|
769
|
+
const checkedParent = parent && !violatingStates.has(parent) ? parent : undefined;
|
|
770
|
+
if (isUnchangedFor(invariant, state, checkedParent)) return false;
|
|
771
|
+
try {
|
|
772
|
+
const context = getContext(environment, state, undefined, invariant.scope);
|
|
773
|
+
const membership = invariant.membership;
|
|
774
|
+
return checkedParent && membership
|
|
775
|
+
? !isUpdatedElementOf(
|
|
776
|
+
state[membership.variable],
|
|
777
|
+
checkedParent[membership.variable],
|
|
778
|
+
evaluate(membership.set, context),
|
|
779
|
+
)
|
|
780
|
+
: !holdsAsConjunct(invariant, context);
|
|
781
|
+
} catch (error) {
|
|
782
|
+
// TLC reports a failure only on a state after the initial states as an invariant failure.
|
|
783
|
+
if (!parent) throw error;
|
|
784
|
+
throw withHeadline(
|
|
785
|
+
setExitCode(error, EXIT_STATUS.safetyEvaluationFailure),
|
|
786
|
+
MESSAGE_CODE.invariantEvaluationFailed,
|
|
787
|
+
`Evaluating invariant ${invariant.name} failed.`,
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
763
791
|
const isFingerprintedLikeTlc = hasWideString(config, environment);
|
|
764
792
|
runtime.getFingerprint = getTlcStateFingerprint;
|
|
765
793
|
const findUnwitnessedPossible = () => {
|
|
@@ -795,30 +823,21 @@ export const createSearch = (
|
|
|
795
823
|
: getRepresentative(state, symmetryGroup, getTlcOrder());
|
|
796
824
|
return view === undefined ? representative : [getViewValue(view.expression, representative)];
|
|
797
825
|
},
|
|
798
|
-
findViolatedInvariant: (state, parent) =>
|
|
799
|
-
invariants.find((invariant) =>
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
// TLC reports a failure only on a state after the initial states as an invariant failure.
|
|
814
|
-
if (!parent) throw error;
|
|
815
|
-
throw withHeadline(
|
|
816
|
-
setExitCode(error, EXIT_STATUS.safetyEvaluationFailure),
|
|
817
|
-
MESSAGE_CODE.invariantEvaluationFailed,
|
|
818
|
-
`Evaluating invariant ${invariant.name} failed.`,
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
}),
|
|
826
|
+
findViolatedInvariant: (state, parent) => {
|
|
827
|
+
const violated = invariants.find((invariant) => isViolated(invariant, state, parent));
|
|
828
|
+
if (violated) violatingStates.add(state);
|
|
829
|
+
return violated;
|
|
830
|
+
},
|
|
831
|
+
getViolatedInvariants: (state) => {
|
|
832
|
+
const violated = invariantPredicates.filter((predicate) =>
|
|
833
|
+
invariants.some(
|
|
834
|
+
(invariant) =>
|
|
835
|
+
invariant.predicate === predicate.predicate && isViolated(invariant, state, undefined),
|
|
836
|
+
),
|
|
837
|
+
);
|
|
838
|
+
if (violated.length > 0) violatingStates.add(state);
|
|
839
|
+
return violated;
|
|
840
|
+
},
|
|
822
841
|
checkReplayedInitialState: (state, tracing, addFingerprint) => {
|
|
823
842
|
const holdsIn = (expression: Expression, scope: Scope | undefined) =>
|
|
824
843
|
holdsLikeTlc(expression, getContext(tracing, state, undefined, scope));
|
package/src/values.ts
CHANGED
|
@@ -344,6 +344,9 @@ export const rankString = (text: string) => {
|
|
|
344
344
|
|
|
345
345
|
export const getRankedStringCount = () => stringOrder.size;
|
|
346
346
|
|
|
347
|
+
export const getRankedString = (rank: number) =>
|
|
348
|
+
Object.keys(stringOrder.ranks).find((text) => stringOrder.ranks[text] === rank);
|
|
349
|
+
|
|
347
350
|
export const getStringRank = (text: string) => stringOrder.ranks[rankString(text)];
|
|
348
351
|
|
|
349
352
|
const compareStrings = (left: string, right: string) => {
|
|
@@ -1578,8 +1581,14 @@ const enumerateSet = (
|
|
|
1578
1581
|
`Attempted to enumerate S \\ T when S:\n${formatValue(value.left)}\nis not enumerable.`,
|
|
1579
1582
|
);
|
|
1580
1583
|
}
|
|
1581
|
-
if (value.operator === "\\cup")
|
|
1582
|
-
return
|
|
1584
|
+
if (value.operator === "\\cup") {
|
|
1585
|
+
return computeLikeTlcOnFailure(
|
|
1586
|
+
(union) => getSortedUnion(toFiniteSet(union.left), toFiniteSet(union.right)).elements,
|
|
1587
|
+
(union) => sortLikeTlc(listUnionLikeTlc(union)),
|
|
1588
|
+
value,
|
|
1589
|
+
value,
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1583
1592
|
const isLeftEnumerated = value.operator === "\\" || isTlcEnumerable(value.left);
|
|
1584
1593
|
const enumerated = isLeftEnumerated ? value.left : value.right;
|
|
1585
1594
|
const other = isLeftEnumerated ? value.right : value.left;
|
|
@@ -1622,6 +1631,24 @@ export const toFiniteSet = (value: Value): SetValue => {
|
|
|
1622
1631
|
return set;
|
|
1623
1632
|
};
|
|
1624
1633
|
|
|
1634
|
+
// SetCupValue#toSetEnum.
|
|
1635
|
+
const listUnionLikeTlc = (union: SetOperationValue) => [
|
|
1636
|
+
...toFiniteSet(union.left).elements,
|
|
1637
|
+
...toFiniteSet(union.right).elements,
|
|
1638
|
+
];
|
|
1639
|
+
|
|
1640
|
+
// EnumerableValue#elements(NORMALIZED) sorts a union outside its methods, so a failed comparison
|
|
1641
|
+
// isn't a fingerprint failure.
|
|
1642
|
+
export const getNormalizedSetElements = (value: Value) =>
|
|
1643
|
+
typeof value === "object" && value.kind === "SetOperation" && value.operator === "\\cup"
|
|
1644
|
+
? computeLikeTlcOnFailure(
|
|
1645
|
+
(union) => toFiniteSet(union).elements,
|
|
1646
|
+
(union) => sortLikeTlc(callTracedMethod(union, () => listUnionLikeTlc(union))),
|
|
1647
|
+
value,
|
|
1648
|
+
value,
|
|
1649
|
+
)
|
|
1650
|
+
: toFiniteSet(value).elements;
|
|
1651
|
+
|
|
1625
1652
|
// TLC's Enumerator for a lazy set streams the sets it combines until the set caches its elements,
|
|
1626
1653
|
// so an element that two of them share comes up once for each.
|
|
1627
1654
|
export const getStreamedElements = (value: Value): Value[] => {
|