tla-ts 0.0.3-dev.b74f28c → 0.0.3-dev.e927a09
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 +11 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +3 -2
- package/dist/run-cli.js +3 -2
- package/dist/transfer.cjs +19 -15
- package/dist/transfer.js +19 -15
- package/package.json +1 -1
- package/src/ast.ts +90 -0
- package/src/check.ts +78 -31
- package/src/codegen.ts +9 -19
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +10 -10
- package/src/errors.ts +5 -0
- package/src/evaluate.ts +75 -135
- package/src/exit-codes.ts +20 -30
- package/src/instances.ts +12 -11
- package/src/levels.ts +8 -8
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +710 -0
- package/src/liveness.ts +5 -523
- package/src/parallel-worker.ts +5 -1
- package/src/parallel.ts +15 -2
- package/src/parser.ts +12 -1
- package/src/resolve.ts +16 -15
- package/src/run-cli.ts +9 -2
- package/src/runtime.ts +1 -1
- package/src/spec-description.ts +7 -2
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +17 -9
- package/src/tlc-ext.ts +2 -10
- package/src/tlc-order.ts +17 -3
package/src/run-cli.ts
CHANGED
|
@@ -113,6 +113,11 @@ const printTrace = (trace: TraceStep[], heading = "Error: The behavior up to thi
|
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
+
const getTemporalHeadline = (names: string[]) =>
|
|
117
|
+
names.length === 1
|
|
118
|
+
? `Error: Temporal property ${names[0]} was violated.\n`
|
|
119
|
+
: `Error: Temporal properties ${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${names[names.length - 1]} were violated.\n`;
|
|
120
|
+
|
|
116
121
|
const printResult = (result: CheckResult) => {
|
|
117
122
|
if (result.failure) {
|
|
118
123
|
console.log(`Error: ${result.failure.message}`);
|
|
@@ -140,10 +145,10 @@ const printResult = (result: CheckResult) => {
|
|
|
140
145
|
"invariant-violation": isInitial
|
|
141
146
|
? `Error: Invariant ${name} is violated by the initial state:`
|
|
142
147
|
: `Error: Invariant ${name} is violated.`,
|
|
143
|
-
"property-violation":
|
|
148
|
+
"property-violation": getTemporalHeadline(violation.properties ?? [name]),
|
|
144
149
|
"liveness-violation":
|
|
145
150
|
loopStart !== undefined
|
|
146
|
-
?
|
|
151
|
+
? getTemporalHeadline(violation.properties ?? [name])
|
|
147
152
|
: isInitial
|
|
148
153
|
? `Error: Property ${name} is violated by the initial state:`
|
|
149
154
|
: `Error: Action property ${name} is violated.`,
|
|
@@ -152,6 +157,8 @@ const printResult = (result: CheckResult) => {
|
|
|
152
157
|
if (violation.counts) console.log(violation.counts);
|
|
153
158
|
console.log(headline);
|
|
154
159
|
if (isInitial) printState(violation.trace[0].state);
|
|
160
|
+
else if (result.status === "property-violation")
|
|
161
|
+
printTrace(violation.trace, "Error: The following behavior constitutes a counter-example:\n");
|
|
155
162
|
else if (loopStart === undefined) printTrace(violation.trace);
|
|
156
163
|
else {
|
|
157
164
|
printTrace(violation.trace, "Error: The following behavior constitutes a counter-example:\n");
|
package/src/runtime.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface CheckerRuntime {
|
|
|
6
6
|
getBehavior: (state: Value[]) => Value[][];
|
|
7
7
|
getSpecification: () => Value;
|
|
8
8
|
counterExample: Value | undefined;
|
|
9
|
-
setLivenessSource: (index: number) => void;
|
|
9
|
+
setLivenessSource: (index: number | undefined) => void;
|
|
10
10
|
getCurrentState: () => Value[] | undefined;
|
|
11
11
|
getFingerprint: (state: Value[]) => bigint;
|
|
12
12
|
getRandom: () => JavaRandom;
|
package/src/spec-description.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
isLocallyResolved,
|
|
3
|
+
type Definition,
|
|
4
|
+
type Expression,
|
|
5
|
+
type SourceLocation,
|
|
6
|
+
type SourceRange,
|
|
7
|
+
} from "./ast";
|
|
2
8
|
import type { ModelConfig } from "./config";
|
|
3
9
|
import type { InstanceAction } from "./environment";
|
|
4
10
|
import { TlaError } from "./errors";
|
|
@@ -10,7 +16,6 @@ import {
|
|
|
10
16
|
formatRange,
|
|
11
17
|
getDefinition,
|
|
12
18
|
isConstantLevel,
|
|
13
|
-
isLocallyResolved,
|
|
14
19
|
lookupScope,
|
|
15
20
|
resolveGlobalOperator,
|
|
16
21
|
type Closure,
|
package/src/subexpressions.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
type Bound,
|
|
4
|
+
type Definition,
|
|
5
|
+
type Expression,
|
|
6
|
+
type Instance,
|
|
7
|
+
type Module,
|
|
8
|
+
type OperatorParam,
|
|
9
|
+
type Selector,
|
|
10
|
+
type SourceLocation,
|
|
10
11
|
} from "./ast";
|
|
11
12
|
import { TlaSyntaxError } from "./errors";
|
|
12
|
-
import { getChildren } from "./evaluate";
|
|
13
13
|
import { getSourceName, mapChildren, mapDefinition } from "./instances";
|
|
14
14
|
import { getArity, getBoundNames, getPatternNames, LOCAL_RESOLUTION } from "./resolve";
|
|
15
15
|
|
package/src/successors.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
isLocallyResolved,
|
|
4
|
+
type Bound,
|
|
5
|
+
type Definition,
|
|
6
|
+
type Expression,
|
|
7
|
+
} from "./ast";
|
|
2
8
|
import { getReadVariables } from "./dependencies";
|
|
3
|
-
import { TlaEvaluationError } from "./errors";
|
|
9
|
+
import { TlaEvaluationError, UNEXPECTED_EXCEPTION } from "./errors";
|
|
4
10
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
5
11
|
import {
|
|
6
12
|
describeLocation,
|
|
13
|
+
describeRange,
|
|
7
14
|
bindArgument,
|
|
8
15
|
bindDefinitions,
|
|
9
16
|
bindOperatorArguments,
|
|
@@ -13,14 +20,12 @@ import {
|
|
|
13
20
|
expectBoolean,
|
|
14
21
|
forEachBinding,
|
|
15
22
|
getBoundsDomain,
|
|
16
|
-
getChildren,
|
|
17
23
|
getDefinition,
|
|
18
24
|
getEnumeratedElements,
|
|
19
25
|
getReevaluatedDefinitions,
|
|
20
26
|
lookupScope,
|
|
21
27
|
resolveApplyOperator,
|
|
22
28
|
resolveGlobalOperator,
|
|
23
|
-
isLocallyResolved,
|
|
24
29
|
type Context,
|
|
25
30
|
type Environment,
|
|
26
31
|
type Scope,
|
|
@@ -804,7 +809,9 @@ const compileAction = (
|
|
|
804
809
|
);
|
|
805
810
|
const body = arm?.body ?? other;
|
|
806
811
|
if (!body)
|
|
807
|
-
throw new TlaEvaluationError(
|
|
812
|
+
throw new TlaEvaluationError(
|
|
813
|
+
`${UNEXPECTED_EXCEPTION}In computing next states, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
|
|
814
|
+
);
|
|
808
815
|
body(run, scope, partial, action, isFixed, onComplete);
|
|
809
816
|
};
|
|
810
817
|
}
|
|
@@ -913,18 +920,19 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
913
920
|
);
|
|
914
921
|
}
|
|
915
922
|
const environment = context.environment;
|
|
916
|
-
const
|
|
923
|
+
const run: Run = { environment, isInit: false, current: state, isStopped: false };
|
|
924
|
+
// TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
|
|
917
925
|
getRunner(expression, environment, false)(
|
|
918
|
-
|
|
926
|
+
run,
|
|
919
927
|
context.scope,
|
|
920
928
|
getEmptyState(environment),
|
|
921
929
|
undefined,
|
|
922
930
|
false,
|
|
923
931
|
() => {
|
|
924
|
-
|
|
932
|
+
run.isStopped = true;
|
|
925
933
|
},
|
|
926
934
|
);
|
|
927
|
-
return
|
|
935
|
+
return run.isStopped;
|
|
928
936
|
};
|
|
929
937
|
|
|
930
938
|
export const forEachInitialState = (
|
package/src/tlc-ext.ts
CHANGED
|
@@ -10,16 +10,8 @@ import {
|
|
|
10
10
|
} from "./builtins";
|
|
11
11
|
import { TlaEvaluationError, TlaModuleError, TlaUnsupportedError } from "./errors";
|
|
12
12
|
import { getTlcFingerprint } from "./tlc-random";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
expectBoolean,
|
|
16
|
-
getChildren,
|
|
17
|
-
getDefinition,
|
|
18
|
-
isLocallyResolved,
|
|
19
|
-
type Builtin,
|
|
20
|
-
type Environment,
|
|
21
|
-
} from "./evaluate";
|
|
22
|
-
import type { Definition, Expression } from "./ast";
|
|
13
|
+
import { evaluate, expectBoolean, getDefinition, type Builtin, type Environment } from "./evaluate";
|
|
14
|
+
import { getChildren, isLocallyResolved, type Definition, type Expression } from "./ast";
|
|
23
15
|
import type { TraceStep } from "./check";
|
|
24
16
|
import {
|
|
25
17
|
getNamedRegisters,
|
package/src/tlc-order.ts
CHANGED
|
@@ -184,9 +184,18 @@ const isAdjacent = (left: Token, right: Token | undefined) =>
|
|
|
184
184
|
right.line === left.line &&
|
|
185
185
|
right.column === left.column + left.text.length;
|
|
186
186
|
|
|
187
|
+
const STRING_ESCAPES: Record<string, string> = {
|
|
188
|
+
"\\": "\\\\",
|
|
189
|
+
'"': '\\"',
|
|
190
|
+
"\n": "\\n",
|
|
191
|
+
"\t": "\\t",
|
|
192
|
+
"\r": "\\r",
|
|
193
|
+
"\f": "\\f",
|
|
194
|
+
};
|
|
195
|
+
|
|
187
196
|
// The texts SANY interns while parsing, in order. SANY reads a proof step label such as <1>2 and
|
|
188
|
-
// a module header such as ---- MODULE as one token
|
|
189
|
-
// during semantic analysis.
|
|
197
|
+
// a module header such as ---- MODULE as one token. It interns a string literal as written, quotes
|
|
198
|
+
// included, and interns the literal's contents only during semantic analysis.
|
|
190
199
|
const getParsedTexts = (tokens: Token[]) => {
|
|
191
200
|
const texts: string[] = [];
|
|
192
201
|
for (let index = 0; index < tokens.length; index++) {
|
|
@@ -202,7 +211,12 @@ const getParsedTexts = (tokens: Token[]) => {
|
|
|
202
211
|
continue;
|
|
203
212
|
}
|
|
204
213
|
const isHeader = token.text === "MODULE" && tokens[index - 1]?.kind === "Separator";
|
|
205
|
-
if (
|
|
214
|
+
if (isHeader) continue;
|
|
215
|
+
texts.push(
|
|
216
|
+
token.kind === "String"
|
|
217
|
+
? `"${token.text.replace(/[\\"\n\t\r\f]/g, (character) => STRING_ESCAPES[character])}"`
|
|
218
|
+
: token.text,
|
|
219
|
+
);
|
|
206
220
|
}
|
|
207
221
|
return texts;
|
|
208
222
|
};
|