tla-ts 0.0.10-dev.99796fe03 → 0.0.10-dev.c92e6a4ea
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/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +20 -20
- package/dist/prove.js +15 -15
- package/dist/run.cjs +4 -6
- package/dist/run.js +4 -6
- package/dist/transfer.cjs +35 -35
- package/dist/transfer.js +28 -28
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/check.ts +126 -61
- 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 +12 -7
- package/src/environment.ts +18 -0
- package/src/evaluate.ts +3 -1
- package/src/exit-codes.ts +1 -0
- package/src/liveness-checker.ts +20 -2
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/runtime.ts +2 -0
- package/src/search.ts +40 -11
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlcext-operators.ts +18 -5
package/dist/worker.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
9
|
+
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,getStateCounts:t.getStateCounts,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
10
10
|
|
|
11
11
|
`),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),h=(e,t)=>m([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),g=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
|
|
12
12
|
`)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,ne=(e,t)=>m([{location:_(t),message:e}]);var v=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
|
package/dist/worker.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
9
|
+
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,getStateCounts:t.getStateCounts,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
10
10
|
|
|
11
11
|
`),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),h=(e,t)=>m([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),g=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
|
|
12
12
|
`)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,ne=(e,t)=>m([{location:_(t),message:e}]);var v=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
|
package/package.json
CHANGED
package/src/check.ts
CHANGED
|
@@ -206,7 +206,7 @@ export type CheckProgress =
|
|
|
206
206
|
branches: number;
|
|
207
207
|
/** Whether TLC checks the complete state graph. */
|
|
208
208
|
isComplete: boolean;
|
|
209
|
-
/** How many states of
|
|
209
|
+
/** How many states the graphs of all branches have together. */
|
|
210
210
|
states: number;
|
|
211
211
|
statistics: SearchStatistics;
|
|
212
212
|
}
|
|
@@ -415,6 +415,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
415
415
|
key.startsWith(`${name}${KEY_SEPARATOR}`),
|
|
416
416
|
),
|
|
417
417
|
});
|
|
418
|
+
const getCoverage = () =>
|
|
419
|
+
coverage?.relations.some((relation) => relation.kind === "next")
|
|
420
|
+
? getCoverageReport(
|
|
421
|
+
coverage,
|
|
422
|
+
environment,
|
|
423
|
+
specification.variableLocations,
|
|
424
|
+
search?.getTlcOrder() ?? [],
|
|
425
|
+
)
|
|
426
|
+
: undefined;
|
|
418
427
|
const createResult = (
|
|
419
428
|
status: CheckStatus,
|
|
420
429
|
violation?: ReportedViolation,
|
|
@@ -435,14 +444,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
435
444
|
initialStates: computedInitialStates,
|
|
436
445
|
outDegrees: undefined,
|
|
437
446
|
fingerprintDistance: undefined,
|
|
438
|
-
coverage:
|
|
439
|
-
? getCoverageReport(
|
|
440
|
-
coverage,
|
|
441
|
-
environment,
|
|
442
|
-
specification.variableLocations,
|
|
443
|
-
search?.getTlcOrder() ?? [],
|
|
444
|
-
)
|
|
445
|
-
: undefined,
|
|
447
|
+
coverage: getCoverage(),
|
|
446
448
|
...(traceSpec !== undefined && { traceSpec }),
|
|
447
449
|
};
|
|
448
450
|
};
|
|
@@ -466,7 +468,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
466
468
|
: getFingerprintDistance(runtime.distinctStates, runtime.generatedStates, (visit) =>
|
|
467
469
|
visit(
|
|
468
470
|
search
|
|
469
|
-
? search.getStoredFingerprints(
|
|
471
|
+
? search.getStoredFingerprints(
|
|
472
|
+
exploredStates.length === 0 ? states : states.concat(exploredStates),
|
|
473
|
+
exploredStates.length === 0
|
|
474
|
+
? fingerprintStates
|
|
475
|
+
: fingerprintStates.concat(exploredFingerprintStates),
|
|
476
|
+
)
|
|
470
477
|
: BigInt64Array.from(states, runtime.getFingerprint),
|
|
471
478
|
),
|
|
472
479
|
),
|
|
@@ -479,6 +486,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
479
486
|
() => created.order.getDeclarationOrder("variable"),
|
|
480
487
|
options.onProgress,
|
|
481
488
|
specification.moduleOperators,
|
|
489
|
+
specification.runtimeInvariants,
|
|
482
490
|
);
|
|
483
491
|
const findViolatedAssumption = () =>
|
|
484
492
|
findAssumptionViolation(specification.assumptions, environment);
|
|
@@ -555,12 +563,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
555
563
|
const getFingerprintState = search.getFingerprintState;
|
|
556
564
|
// Tool's constructor splits the next-state relation into actions before TLC checks anything.
|
|
557
565
|
const nextActions = getDescription().actions;
|
|
558
|
-
runtime.getSuccessorAction = (state, next) =>
|
|
559
|
-
nextActions.find((action) =>
|
|
560
|
-
getSuccessors(action.expression, state, environment, action.scope).some((successor) =>
|
|
561
|
-
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
562
|
-
),
|
|
563
|
-
);
|
|
564
566
|
const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
|
|
565
567
|
actions.map((action): CoveredAction => ({
|
|
566
568
|
...action,
|
|
@@ -610,6 +612,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
610
612
|
);
|
|
611
613
|
return successors;
|
|
612
614
|
};
|
|
615
|
+
// TLC generates the successors of each action again, which its coverage counts.
|
|
616
|
+
const findSuccessorAction = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
617
|
+
coverage
|
|
618
|
+
? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
|
|
619
|
+
: nextActions.find((item) =>
|
|
620
|
+
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
621
|
+
);
|
|
622
|
+
runtime.getSuccessorAction = (state, next) =>
|
|
623
|
+
findSuccessorAction(state, (successor) =>
|
|
624
|
+
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
625
|
+
);
|
|
613
626
|
const rejectIncompleteInitialState = (partial: (Value | undefined)[]) => {
|
|
614
627
|
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
615
628
|
};
|
|
@@ -628,8 +641,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
628
641
|
return (state: Value[], callStack: CallStack | undefined) => {
|
|
629
642
|
fingerprintReplayed(state, getFingerprintState(state), callStack);
|
|
630
643
|
const fingerprintState = getFingerprintState(state);
|
|
644
|
+
const hash = getStateHash(fingerprintState);
|
|
631
645
|
const isSeen =
|
|
632
|
-
findStateIndex(seenStates,
|
|
646
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
647
|
+
isExplored(hash, fingerprintState) ||
|
|
633
648
|
replayed.some((seen) => isSameState(seen, fingerprintState));
|
|
634
649
|
if (isSeen) return false;
|
|
635
650
|
replayed.push(fingerprintState);
|
|
@@ -716,28 +731,38 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
716
731
|
if (spec.next === undefined) return successors;
|
|
717
732
|
const livenessSource = current.livenessSource;
|
|
718
733
|
current.livenessSource = source;
|
|
734
|
+
const addSuccessor = (successor: Value[]) => {
|
|
735
|
+
canonicalizeState(successor);
|
|
736
|
+
const isInModel =
|
|
737
|
+
search.satisfiesConstraints(successor, state) &&
|
|
738
|
+
search.satisfiesActionConstraints(state, successor);
|
|
739
|
+
if (!isInModel) return;
|
|
740
|
+
const fingerprintState = getFingerprintState(successor);
|
|
741
|
+
const hash = getStateHash(fingerprintState);
|
|
742
|
+
const index = findStateIndex(seenStates, hash, fingerprintState);
|
|
743
|
+
successors.push({
|
|
744
|
+
index: index === -1 ? getPendingIndex(hash, fingerprintState) : index,
|
|
745
|
+
state: successor,
|
|
746
|
+
});
|
|
747
|
+
};
|
|
719
748
|
try {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
return false;
|
|
738
|
-
},
|
|
739
|
-
spec.scope,
|
|
740
|
-
);
|
|
749
|
+
// TLC's coverage counts the successors of each action the graph generates again.
|
|
750
|
+
if (coverage) {
|
|
751
|
+
coverageActions.forEach((action) =>
|
|
752
|
+
walkCoveredSuccessors(action, state, addSuccessor),
|
|
753
|
+
);
|
|
754
|
+
} else {
|
|
755
|
+
forEachSuccessor(
|
|
756
|
+
spec.next,
|
|
757
|
+
state,
|
|
758
|
+
environment,
|
|
759
|
+
(successor) => {
|
|
760
|
+
addSuccessor(successor.state);
|
|
761
|
+
return false;
|
|
762
|
+
},
|
|
763
|
+
spec.scope,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
741
766
|
} finally {
|
|
742
767
|
current.livenessSource = livenessSource;
|
|
743
768
|
}
|
|
@@ -756,6 +781,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
756
781
|
const actions: (string | undefined)[] = [];
|
|
757
782
|
const depths: number[] = [];
|
|
758
783
|
const seenStates = createStateTable(fingerprintStates);
|
|
784
|
+
const exploredStates: Value[][] = [];
|
|
785
|
+
const exploredFingerprintStates: Value[][] = [];
|
|
786
|
+
let exploredTable: StateTable | undefined;
|
|
787
|
+
const isExplored = (hash: number, fingerprintState: Value[]) =>
|
|
788
|
+
exploredTable !== undefined && findStateIndex(exploredTable, hash, fingerprintState) !== -1;
|
|
759
789
|
const pendingFingerprintStates: Value[][] = [];
|
|
760
790
|
let pendingStates: StateTable | undefined;
|
|
761
791
|
const getPendingIndex = (hash: number, fingerprintState: Value[]) => {
|
|
@@ -868,7 +898,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
868
898
|
};
|
|
869
899
|
let unstoredFingerprint: Value[] | undefined;
|
|
870
900
|
const countDistinctState = (depth: number) => {
|
|
871
|
-
runtime.distinctStates = states.length + 1;
|
|
901
|
+
runtime.distinctStates = states.length + exploredStates.length + 1;
|
|
872
902
|
searchDepth = Math.max(searchDepth, depth);
|
|
873
903
|
runtime.diameter = Math.max(runtime.diameter, depth);
|
|
874
904
|
};
|
|
@@ -909,18 +939,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
909
939
|
tracedSteps,
|
|
910
940
|
captureOutput,
|
|
911
941
|
getInitialStates: getSpecInitialStates,
|
|
912
|
-
findSuccessorAction
|
|
913
|
-
coverage
|
|
914
|
-
? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
|
|
915
|
-
: nextActions.find((item) =>
|
|
916
|
-
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
917
|
-
),
|
|
942
|
+
findSuccessorAction,
|
|
918
943
|
});
|
|
919
944
|
const getPath = (index: number): Value[][] =>
|
|
920
945
|
index === -1 ? [] : [...getPath(parents[index]), states[index]];
|
|
946
|
+
// TLC adds a successor's fingerprint to its set before it checks the invariants of the successor.
|
|
921
947
|
runtime.isSeen = (state) => {
|
|
922
948
|
const fingerprintState = getFingerprintState(state);
|
|
923
|
-
|
|
949
|
+
const hash = getStateHash(fingerprintState);
|
|
950
|
+
return (
|
|
951
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
952
|
+
isExplored(hash, fingerprintState) ||
|
|
953
|
+
(unstoredFingerprint !== undefined && isSameState(unstoredFingerprint, fingerprintState))
|
|
954
|
+
);
|
|
955
|
+
};
|
|
956
|
+
runtime.markExplored = (state) => {
|
|
957
|
+
const fingerprintState = getFingerprintState(state);
|
|
958
|
+
exploredTable ??= createStateTable(exploredFingerprintStates);
|
|
959
|
+
markSeenState(exploredTable, getStateHash(fingerprintState), exploredStates.length);
|
|
960
|
+
exploredStates.push(state);
|
|
961
|
+
exploredFingerprintStates.push(fingerprintState);
|
|
962
|
+
runtime.distinctStates++;
|
|
924
963
|
};
|
|
925
964
|
runtime.getBehavior = (state) => {
|
|
926
965
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
@@ -1025,7 +1064,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1025
1064
|
fingerprintModelState(fingerprintState);
|
|
1026
1065
|
successor.state.forEach(markFingerprinted);
|
|
1027
1066
|
}
|
|
1028
|
-
|
|
1067
|
+
const existing = isInModel ? foundIndex : -1;
|
|
1068
|
+
return {
|
|
1069
|
+
fingerprintState,
|
|
1070
|
+
hash,
|
|
1071
|
+
isInModel,
|
|
1072
|
+
existing,
|
|
1073
|
+
isSeen: existing !== -1 || (isInModel && isExplored(hash, fingerprintState)),
|
|
1074
|
+
};
|
|
1029
1075
|
};
|
|
1030
1076
|
const visitSuccessor = (
|
|
1031
1077
|
index: number,
|
|
@@ -1044,7 +1090,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1044
1090
|
stateWriter?.writeSuccessor(
|
|
1045
1091
|
source,
|
|
1046
1092
|
getGraphState(successor.state, depths[index] + 1),
|
|
1047
|
-
found.
|
|
1093
|
+
found.isSeen,
|
|
1048
1094
|
action && getGraphAction(action),
|
|
1049
1095
|
);
|
|
1050
1096
|
}
|
|
@@ -1066,7 +1112,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1066
1112
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
1067
1113
|
liveSuccessors.push({ index: found.existing, state: isStored ? stored : successor.state });
|
|
1068
1114
|
}
|
|
1069
|
-
|
|
1115
|
+
if (found.isSeen && found.existing === -1 && liveness) {
|
|
1116
|
+
liveSuccessors.push({
|
|
1117
|
+
index: getPendingIndex(found.hash, found.fingerprintState),
|
|
1118
|
+
state: successor.state,
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
const isNew = found.isInModel && !found.isSeen;
|
|
1070
1122
|
if (isNew && liveness) liveSuccessors.push({ index: states.length, state: successor.state });
|
|
1071
1123
|
unstoredFingerprint = isNew ? found.fingerprintState : undefined;
|
|
1072
1124
|
if (isNew) {
|
|
@@ -1074,7 +1126,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1074
1126
|
newStateCount++;
|
|
1075
1127
|
if (coverage) coverage.secondary[coveredNode]++;
|
|
1076
1128
|
}
|
|
1077
|
-
if (found.
|
|
1129
|
+
if (!found.isSeen) {
|
|
1078
1130
|
try {
|
|
1079
1131
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1080
1132
|
const violation = violated && { name: violated.name, ...traces.getTrace(index, successor) };
|
|
@@ -1156,7 +1208,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1156
1208
|
kind: "liveness-started",
|
|
1157
1209
|
branches: liveness.branches,
|
|
1158
1210
|
isComplete: true,
|
|
1159
|
-
|
|
1211
|
+
// The tier stores and expands every successor, so the graph of each branch has every state.
|
|
1212
|
+
states: liveness.branches * typed.distinctStates,
|
|
1160
1213
|
statistics,
|
|
1161
1214
|
});
|
|
1162
1215
|
options.onProgress?.({ kind: "liveness-finished" });
|
|
@@ -1413,6 +1466,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1413
1466
|
return {
|
|
1414
1467
|
...result,
|
|
1415
1468
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1469
|
+
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1470
|
+
coverage: getCoverage(),
|
|
1416
1471
|
...(live.result && { liveCallStack: live.result }),
|
|
1417
1472
|
};
|
|
1418
1473
|
}
|
|
@@ -1544,24 +1599,31 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1544
1599
|
const startedAt = performance.now();
|
|
1545
1600
|
const periodic = {
|
|
1546
1601
|
at: startedAt + PERIODIC_START,
|
|
1547
|
-
size
|
|
1602
|
+
// The size of each branch's graph when TLC last checked it, which starts at 1.
|
|
1603
|
+
sizes: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1548
1604
|
time: 0,
|
|
1549
1605
|
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1550
1606
|
};
|
|
1551
|
-
|
|
1607
|
+
// TLC counts the states of the graphs of all branches, which can differ.
|
|
1608
|
+
const getGraphStates = (checker: LivenessChecker) =>
|
|
1609
|
+
checker.getStateCounts().reduce((sum, count) => sum + count, 0);
|
|
1610
|
+
const findPeriodicViolation = (checker: LivenessChecker) => {
|
|
1552
1611
|
const now = performance.now();
|
|
1553
|
-
const
|
|
1612
|
+
const counts = checker.getStateCounts();
|
|
1613
|
+
const isGrown = counts.some(
|
|
1614
|
+
(count, branch) =>
|
|
1615
|
+
(count - periodic.sizes[branch]) / periodic.sizes[branch] > LIVENESS_GROWTH,
|
|
1616
|
+
);
|
|
1554
1617
|
if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
|
|
1555
|
-
periodic.
|
|
1556
|
-
if (!liveness) return undefined;
|
|
1618
|
+
periodic.sizes = counts;
|
|
1557
1619
|
options.onProgress?.({
|
|
1558
1620
|
kind: "liveness-started",
|
|
1559
|
-
branches:
|
|
1621
|
+
branches: checker.branches,
|
|
1560
1622
|
isComplete: false,
|
|
1561
|
-
states:
|
|
1623
|
+
states: getGraphStates(checker),
|
|
1562
1624
|
statistics: createResult("success"),
|
|
1563
1625
|
});
|
|
1564
|
-
const lasso =
|
|
1626
|
+
const lasso = checker.findViolation();
|
|
1565
1627
|
if (!lasso) options.onProgress?.({ kind: "liveness-finished" });
|
|
1566
1628
|
periodic.time += performance.now() - now;
|
|
1567
1629
|
return lasso;
|
|
@@ -1687,7 +1749,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1687
1749
|
newStateCount = 0;
|
|
1688
1750
|
if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
|
|
1689
1751
|
periodic.at = performance.now() + PROGRESS_INTERVAL;
|
|
1690
|
-
const lasso = isPeriodic ? findPeriodicViolation(
|
|
1752
|
+
const lasso = isPeriodic && liveness ? findPeriodicViolation(liveness) : undefined;
|
|
1691
1753
|
if (liveness && lasso) return reportLasso(liveness, lasso);
|
|
1692
1754
|
const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
|
|
1693
1755
|
periodic.coverageCount = isCoverageDue
|
|
@@ -1709,7 +1771,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1709
1771
|
kind: "liveness-started",
|
|
1710
1772
|
branches: finalLiveness.branches,
|
|
1711
1773
|
isComplete: true,
|
|
1712
|
-
|
|
1774
|
+
// The tier that found the lasso stored and expanded every successor, so each graph has every state.
|
|
1775
|
+
states: typedLasso
|
|
1776
|
+
? finalLiveness.branches * runtime.distinctStates
|
|
1777
|
+
: getGraphStates(finalLiveness),
|
|
1713
1778
|
statistics: createResult("success"),
|
|
1714
1779
|
});
|
|
1715
1780
|
}
|
|
@@ -3,14 +3,9 @@ import { EXIT_STATUS, setExitCode } from "../exit-codes";
|
|
|
3
3
|
import { parseModule } from "../parser";
|
|
4
4
|
import { generateSanySpecification } from "../sany/generator";
|
|
5
5
|
import { checkModuleLevels } from "../sany/levels";
|
|
6
|
-
import {
|
|
7
|
-
VARIABLE_DECL_KIND,
|
|
8
|
-
type ModuleNode,
|
|
9
|
-
type OpDefNode,
|
|
10
|
-
type SymbolNode,
|
|
11
|
-
} from "../sany/nodes";
|
|
6
|
+
import type { ModuleNode, OpDefNode, SymbolNode } from "../sany/nodes";
|
|
12
7
|
import type { TlcVersion } from "../tlc/version";
|
|
13
|
-
import type {
|
|
8
|
+
import type { RuntimeInvariantTemplate } from "./tlc-arguments";
|
|
14
9
|
|
|
15
10
|
const CONSTANT_LEVEL = 0;
|
|
16
11
|
const TEMPORAL_LEVEL = 3;
|
|
@@ -31,21 +26,20 @@ const createParsingFailure = (detail: string) =>
|
|
|
31
26
|
EXIT_STATUS.specParseError,
|
|
32
27
|
);
|
|
33
28
|
|
|
34
|
-
const
|
|
35
|
-
|
|
29
|
+
const checkDebuggerExpression = (
|
|
30
|
+
source: string,
|
|
31
|
+
moduleName: string,
|
|
36
32
|
name: string,
|
|
37
33
|
expression: string,
|
|
38
34
|
loadModule: (name: string) => string | undefined,
|
|
39
35
|
version: TlcVersion,
|
|
40
36
|
) => {
|
|
41
|
-
const moduleName = name.replace("__DebuggerExpr__", "__DebuggerModule__");
|
|
42
|
-
const text = `---- MODULE ${moduleName} ----\nEXTENDS ${root}\n\n${name} == ${expression}\n====`;
|
|
43
37
|
const createFailure = (message: string) =>
|
|
44
38
|
createParsingFailure(
|
|
45
39
|
`Unknown location\n\n${message} while parsing breakpoint expression "${expression}"`,
|
|
46
40
|
);
|
|
47
41
|
try {
|
|
48
|
-
parseModule(
|
|
42
|
+
parseModule(source);
|
|
49
43
|
} catch (error) {
|
|
50
44
|
if (!(error instanceof TlaSyntaxError)) throw error;
|
|
51
45
|
throw createParsingFailure(`Syntax error while parsing breakpoint expression "${expression}"`);
|
|
@@ -54,7 +48,7 @@ const getDebuggerExpressionLevel = (
|
|
|
54
48
|
let isLevelCorrect = false;
|
|
55
49
|
const specification = (() => {
|
|
56
50
|
try {
|
|
57
|
-
return generateSanySpecification(
|
|
51
|
+
return generateSanySpecification(source, loadModule, {
|
|
58
52
|
version,
|
|
59
53
|
onModule: (module, messages) => {
|
|
60
54
|
const isCorrect = () => messages.every((message) => message.isWarning);
|
|
@@ -81,56 +75,26 @@ const getDebuggerExpressionLevel = (
|
|
|
81
75
|
`Unknown location\n\nDebug expressions must be action-level or below; actual level: ${level} (Temporal)`,
|
|
82
76
|
);
|
|
83
77
|
}
|
|
84
|
-
return level;
|
|
85
78
|
};
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
export const addRuntimeInvariants = (
|
|
80
|
+
export const getRuntimeInvariants = (
|
|
89
81
|
source: string,
|
|
90
82
|
root: ModuleNode,
|
|
91
|
-
invariants:
|
|
83
|
+
invariants: RuntimeInvariantTemplate[],
|
|
92
84
|
loadModule: (name: string) => string | undefined,
|
|
93
85
|
version: TlcVersion,
|
|
94
86
|
) => {
|
|
95
|
-
const stamp = Date.now();
|
|
96
|
-
const named = invariants.map((invariant, index) => ({
|
|
97
|
-
expression: invariant.expression,
|
|
98
|
-
name: findDefinition(root, invariant.expression)
|
|
99
|
-
? invariant.expression
|
|
100
|
-
: `__DebuggerExpr__${stamp + index}`,
|
|
101
|
-
}));
|
|
102
|
-
const names = named.map((invariant) => invariant.name);
|
|
103
|
-
const generated = named.filter((invariant) => invariant.name !== invariant.expression);
|
|
104
|
-
if (generated.length === 0) return { names, source };
|
|
105
87
|
const loadDependency = (name: string) => (name === root.name ? source : loadModule(name));
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
// HACK: TLC checks a constant-level -inv in every state, so an unused LET makes it depend on one.
|
|
119
|
-
return level === CONSTANT_LEVEL && variable
|
|
120
|
-
? `${invariant.name} ==\nLET ${invariant.name}State == ${variable.name} IN\n${" ".repeat(head.length)}${invariant.expression}`
|
|
121
|
-
: `${head}${invariant.expression}`;
|
|
88
|
+
// Deviation from TLC: TLC reads the clock for each name, which no fixed output can match; one reading plus an index keeps the names apart.
|
|
89
|
+
const stamp = Date.now();
|
|
90
|
+
return invariants.map((invariant, index) => {
|
|
91
|
+
if (findDefinition(root, invariant.expression)) {
|
|
92
|
+
return { name: invariant.expression, module: undefined, source: undefined };
|
|
93
|
+
}
|
|
94
|
+
const module = `__DebuggerModule__${stamp + index}`;
|
|
95
|
+
const name = `__DebuggerExpr__${stamp + index}`;
|
|
96
|
+
const text = `---- MODULE ${module} ----\nEXTENDS ${root.name}\n\n${name} == ${invariant.expression}\n====`;
|
|
97
|
+
checkDebuggerExpression(text, module, name, invariant.expression, loadDependency, version);
|
|
98
|
+
return { name, module, source: text };
|
|
122
99
|
});
|
|
123
|
-
const lines = source.split("\n");
|
|
124
|
-
const end = (parseModule(source).location.range?.end.line ?? lines.length) - 1;
|
|
125
|
-
const terminator = lines[end].search(/={4,}/);
|
|
126
|
-
return {
|
|
127
|
-
names,
|
|
128
|
-
source: [
|
|
129
|
-
...lines.slice(0, end),
|
|
130
|
-
lines[end].slice(0, terminator),
|
|
131
|
-
...definitions,
|
|
132
|
-
lines[end].slice(terminator),
|
|
133
|
-
...lines.slice(end + 1),
|
|
134
|
-
].join("\n"),
|
|
135
|
-
};
|
|
136
100
|
};
|
package/src/cli/tlc-arguments.ts
CHANGED
|
@@ -35,11 +35,11 @@ export interface TlcArguments {
|
|
|
35
35
|
suppressedCodes: number[];
|
|
36
36
|
errorCodes: number[];
|
|
37
37
|
userFile: string | undefined;
|
|
38
|
-
invariants:
|
|
38
|
+
invariants: RuntimeInvariantTemplate[];
|
|
39
39
|
moduleOperators: ModuleOperator[];
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export interface
|
|
42
|
+
export interface RuntimeInvariantTemplate {
|
|
43
43
|
modules: string[];
|
|
44
44
|
expression: string;
|
|
45
45
|
}
|
package/src/cli/tlc-output.ts
CHANGED
|
@@ -320,11 +320,10 @@ export const printCheckProgress = (
|
|
|
320
320
|
timing.livenessStartTime = Date.now();
|
|
321
321
|
if (progress.isComplete) printProgress(printer, progress.statistics);
|
|
322
322
|
const branches = progress.branches > 1 ? `${progress.branches} branches of ` : "";
|
|
323
|
-
const states = progress.branches * progress.states;
|
|
324
323
|
print(
|
|
325
324
|
MESSAGE_CODE.checkingTemporal,
|
|
326
325
|
MESSAGE_LEVEL.none,
|
|
327
|
-
`Checking ${branches}temporal properties for the ${progress.isComplete ? "complete" : "current"} state space with ${states} total distinct states at (${formatTlcDate(new Date())})`,
|
|
326
|
+
`Checking ${branches}temporal properties for the ${progress.isComplete ? "complete" : "current"} state space with ${progress.states} total distinct states at (${formatTlcDate(new Date())})`,
|
|
328
327
|
);
|
|
329
328
|
return;
|
|
330
329
|
}
|
package/src/cli/tlc.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { EXIT_STATUS } from "../exit-codes";
|
|
|
29
29
|
import { check } from "../parallel";
|
|
30
30
|
import { extractModule, parseModule } from "../parser";
|
|
31
31
|
import { simulate } from "../simulate";
|
|
32
|
-
import type {
|
|
32
|
+
import type { CliSettings } from "../search";
|
|
33
33
|
import type { StateDump } from "../state-graph";
|
|
34
34
|
import {
|
|
35
35
|
getSanyStandardModules,
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
type MessagePrinter,
|
|
50
50
|
zeroPad,
|
|
51
51
|
} from "../tlc/messages";
|
|
52
|
-
import {
|
|
52
|
+
import { getRuntimeInvariants } from "./runtime-invariants";
|
|
53
53
|
import { parseTlcArguments, type TlcArguments } from "./tlc-arguments";
|
|
54
54
|
import {
|
|
55
55
|
getClassPath,
|
|
@@ -378,15 +378,14 @@ const checkSpec = async (
|
|
|
378
378
|
}
|
|
379
379
|
const userFile = args.userFile;
|
|
380
380
|
const standardModules = getSanyStandardModules(version);
|
|
381
|
-
const
|
|
381
|
+
const runtimeInvariants = getRuntimeInvariants(
|
|
382
382
|
source,
|
|
383
383
|
specification.root,
|
|
384
384
|
args.invariants,
|
|
385
385
|
(name) => loadModule(name) ?? standardModules.get(name) ?? extractModule(source, name),
|
|
386
386
|
version,
|
|
387
387
|
);
|
|
388
|
-
|
|
389
|
-
const options: CheckOptions & StandardInput = {
|
|
388
|
+
const options: CheckOptions & CliSettings = {
|
|
390
389
|
workers: args.workers,
|
|
391
390
|
livenessCheck:
|
|
392
391
|
livenessCheck === "off"
|
|
@@ -410,11 +409,17 @@ const checkSpec = async (
|
|
|
410
409
|
version,
|
|
411
410
|
onProgress: (progress) => printCheckProgress(printer, progress, timing, directory),
|
|
412
411
|
onPrint: userFile === undefined ? undefined : (text) => appendFileSync(userFile, `${text}\n`),
|
|
413
|
-
source
|
|
412
|
+
source,
|
|
414
413
|
config,
|
|
415
414
|
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
416
415
|
readLine: readStandardInputLine,
|
|
417
|
-
|
|
416
|
+
runtimeInvariants: runtimeInvariants.map((invariant) => ({
|
|
417
|
+
name: invariant.name,
|
|
418
|
+
module: invariant.module,
|
|
419
|
+
})),
|
|
420
|
+
loadModule: (name) =>
|
|
421
|
+
runtimeInvariants.find((invariant) => invariant.module === name)?.source ??
|
|
422
|
+
loadModule(name),
|
|
418
423
|
loadClass: (name) => {
|
|
419
424
|
const classPath = getClassPath(directory, name);
|
|
420
425
|
return existsSync(classPath) ? readFileSync(classPath) : undefined;
|
package/src/environment.ts
CHANGED
|
@@ -100,6 +100,13 @@ interface EnvironmentOptions {
|
|
|
100
100
|
version?: TlcVersion;
|
|
101
101
|
moduleOperators?: ModuleOperator[];
|
|
102
102
|
readLine?: () => string | undefined;
|
|
103
|
+
runtimeInvariants?: RuntimeInvariant[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface RuntimeInvariant {
|
|
107
|
+
name: string;
|
|
108
|
+
/** Undefined when the invariant names a definition of the root module. */
|
|
109
|
+
module: string | undefined;
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
export interface ResolvedModuleOperator extends ModuleOperator {
|
|
@@ -114,6 +121,7 @@ export interface Specification {
|
|
|
114
121
|
startupDefinitions: Definition[];
|
|
115
122
|
javaOverrides: JavaOverride[];
|
|
116
123
|
moduleOperators: ResolvedModuleOperator[];
|
|
124
|
+
runtimeInvariants: RuntimeInvariant[];
|
|
117
125
|
rootName: string;
|
|
118
126
|
}
|
|
119
127
|
|
|
@@ -1031,6 +1039,15 @@ export const createEnvironment = (
|
|
|
1031
1039
|
);
|
|
1032
1040
|
linkOrder.push(...linkOrder.splice(linkOrder.indexOf(linkedRoot), 1));
|
|
1033
1041
|
if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
|
|
1042
|
+
const runtimeInvariants = options.runtimeInvariants ?? [];
|
|
1043
|
+
runtimeInvariants.forEach((invariant) => {
|
|
1044
|
+
if (invariant.module === undefined) return;
|
|
1045
|
+
linkedModules.set(root.name, linkedRoot);
|
|
1046
|
+
const linked = getLinkedModule(invariant.module, root.name);
|
|
1047
|
+
linkOrder.splice(linkOrder.indexOf(linked), 1);
|
|
1048
|
+
const definition = definitions.get(linked.visible.get(invariant.name)?.key ?? invariant.name);
|
|
1049
|
+
if (definition) definitions.set(invariant.name, definition);
|
|
1050
|
+
});
|
|
1034
1051
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
1035
1052
|
const definition = definitions.get(symbol.key);
|
|
1036
1053
|
if (definition && symbol.key !== name) definitions.set(name, definition);
|
|
@@ -1171,6 +1188,7 @@ export const createEnvironment = (
|
|
|
1171
1188
|
),
|
|
1172
1189
|
javaOverrides: linkOrder.flatMap((linked) => javaOverrides.get(linked.module.name) ?? []),
|
|
1173
1190
|
moduleOperators,
|
|
1191
|
+
runtimeInvariants,
|
|
1174
1192
|
rootName: root.name,
|
|
1175
1193
|
};
|
|
1176
1194
|
};
|
package/src/evaluate.ts
CHANGED
|
@@ -1177,7 +1177,9 @@ const evaluateLocalIdentifier = (name: string, expression: Expression, context:
|
|
|
1177
1177
|
}
|
|
1178
1178
|
const builtin = context.environment.builtins.get(name);
|
|
1179
1179
|
if (builtin?.arity === 0) return builtin.evaluate([], context);
|
|
1180
|
-
throw new TlaEvaluationError(
|
|
1180
|
+
throw new TlaEvaluationError(
|
|
1181
|
+
`In evaluation, the identifier ${name} is either undefined or not an operator.\n${describeRange(expression)}`,
|
|
1182
|
+
);
|
|
1181
1183
|
};
|
|
1182
1184
|
|
|
1183
1185
|
export const getReevaluatedDefinitions = (
|