tla-ts 0.0.10-dev.3a85c3a9e → 0.0.10-dev.5ffc55ce5
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 +35 -35
- package/dist/deciders.js +29 -29
- 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 +25 -25
- package/dist/prove.js +57 -57
- package/dist/run.cjs +32 -34
- package/dist/run.js +31 -33
- 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/bags.ts +47 -28
- package/src/check-trace.ts +2 -16
- package/src/check.ts +143 -61
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +4 -5
- package/src/cli/tlc.ts +26 -7
- package/src/dfid.ts +9 -2
- package/src/environment.ts +28 -5
- package/src/evaluate.ts +9 -3
- package/src/exit-codes.ts +2 -0
- package/src/liveness-checker.ts +45 -4
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/prover/smt/solver/ast.ts +1 -1
- package/src/prover/smt/solver/context.ts +6 -2
- package/src/prover/smt/solver/euf/egraph.ts +1 -1
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/goal.ts +2 -0
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/lp/containers.ts +7 -1
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
- package/src/prover/smt/solver/lp/nex.ts +2 -1
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -1
- package/src/prover/smt/solver/lp/nla-core.ts +26 -6
- package/src/prover/smt/solver/lp/nla-grobner.ts +156 -79
- package/src/prover/smt/solver/lp/nra-solver.ts +138 -95
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -289
- package/src/prover/smt/solver/muz/dl-context.ts +8 -2
- package/src/prover/smt/solver/muz/spacer-context.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +194 -89
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +464 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2400 -680
- package/src/prover/smt/solver/nlsat/solver.ts +74 -71
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +40 -17
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-solver.ts +2 -3
- package/src/prover/smt/solver/rlimit.ts +13 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +2 -1
- package/src/prover/smt/solver/seq-derive.ts +3 -6
- package/src/prover/smt/solver/smtlib-parser.ts +10 -10
- package/src/prover/smt/solver/smtlib-script.ts +91 -28
- package/src/prover/smt/solver/tactic.ts +14 -5
- package/src/prover/smt/solver/theory-lra-internalize.ts +8 -0
- package/src/prover/zenon/equality-rules.ts +24 -0
- package/src/prover/zenon/expr.ts +21 -0
- package/src/prover/zenon/index-table.ts +2 -0
- package/src/prover/zenon/rules.ts +2 -1
- package/src/resolve.ts +2 -3
- package/src/runtime.ts +6 -0
- package/src/sany/generator-expressions.ts +6 -13
- package/src/search.ts +67 -29
- package/src/simulate.ts +3 -0
- package/src/standard-definitions.ts +4 -0
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlcext-operators.ts +61 -16
- package/src/tlc/trace-spec.ts +2 -3
package/src/resolve.ts
CHANGED
|
@@ -850,7 +850,7 @@ const resolveDefinitions = (
|
|
|
850
850
|
range: definition.location.range,
|
|
851
851
|
parent: current,
|
|
852
852
|
};
|
|
853
|
-
if (isInstantiated(definition)) return local;
|
|
853
|
+
if (isInstantiated(definition)) return { ...local, params: getParamArities(definition) };
|
|
854
854
|
const isInstanced = instances.some((instance) => instance.location === definition.location);
|
|
855
855
|
const isGenerated = unit.isGenerated || definition.isLocal || isKey(definition.name);
|
|
856
856
|
const inner = isInstanced
|
|
@@ -899,7 +899,6 @@ const isInstanceArityReported = (
|
|
|
899
899
|
return true;
|
|
900
900
|
};
|
|
901
901
|
|
|
902
|
-
// Deviation from SANY: an operator whose parameters tla-ts does not know takes any argument.
|
|
903
902
|
const resolveApply = (
|
|
904
903
|
expression: Expression & { kind: "Apply" },
|
|
905
904
|
scope: LocalName | undefined,
|
|
@@ -930,7 +929,7 @@ const resolveApply = (
|
|
|
930
929
|
const expected = params[index] ?? 0;
|
|
931
930
|
const range = arg.location.range;
|
|
932
931
|
if (expected === 0) {
|
|
933
|
-
// Deviation from SANY: SANY
|
|
932
|
+
// Deviation from SANY: SANY names its internal node kind here, where tla-ts words it as for a name.
|
|
934
933
|
if (arg.kind === "Lambda" && arg.operator !== undefined) {
|
|
935
934
|
report(range, `The operator ${arg.operator} requires 1 arguments.`);
|
|
936
935
|
} else if (arg.kind === "Lambda" && range) {
|
package/src/runtime.ts
CHANGED
|
@@ -19,13 +19,16 @@ export interface CheckerRuntime {
|
|
|
19
19
|
| undefined;
|
|
20
20
|
evaluateAtStartup: <Result>(evaluate: () => Result) => Result;
|
|
21
21
|
pause: (() => void) | undefined;
|
|
22
|
+
readLine: (() => string | undefined) | undefined;
|
|
22
23
|
warn: (code: number, text: string) => void;
|
|
23
24
|
isWarningEnabled: boolean;
|
|
24
25
|
isTool: boolean;
|
|
25
26
|
version: TlcVersion;
|
|
26
27
|
seed: bigint;
|
|
27
28
|
isSeen: (state: Value[]) => boolean;
|
|
29
|
+
markExplored: ((state: Value[]) => void) | undefined;
|
|
28
30
|
getSuccessorAction: (state: Value[], next: Value[]) => SpecAction | undefined;
|
|
31
|
+
toRecord: (state: Value[]) => Record<string, Value>;
|
|
29
32
|
generatedStates: number;
|
|
30
33
|
distinctStates: number;
|
|
31
34
|
initialStates: number;
|
|
@@ -53,7 +56,9 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
53
56
|
counterExample: undefined,
|
|
54
57
|
deferred: undefined,
|
|
55
58
|
isSeen: () => false,
|
|
59
|
+
markExplored: undefined,
|
|
56
60
|
getSuccessorAction: () => undefined,
|
|
61
|
+
toRecord: () => ({}),
|
|
57
62
|
setLivenessSource: () => {},
|
|
58
63
|
getCurrentState: () => undefined,
|
|
59
64
|
getFingerprint: getTlcFingerprint,
|
|
@@ -77,6 +82,7 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
77
82
|
}
|
|
78
83
|
},
|
|
79
84
|
pause: undefined,
|
|
85
|
+
readLine: undefined,
|
|
80
86
|
warn: () => {},
|
|
81
87
|
isWarningEnabled: true,
|
|
82
88
|
isTool: false,
|
|
@@ -93,18 +93,6 @@ const isOperatorArgument = (argument: Expression) => {
|
|
|
93
93
|
return OPERATOR_ARGUMENT_KINDS.has(argument.kind) || (items !== undefined && isGeneralId(items));
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
const POSTFIX_OPERATOR_TEXTS = new Set(["'", "^+", "^*", "^#"]);
|
|
97
|
-
|
|
98
|
-
const getOperatorNodeKind = (
|
|
99
|
-
expression: Expression & { kind: "OperatorReference" | "Lambda" },
|
|
100
|
-
text: string,
|
|
101
|
-
) => {
|
|
102
|
-
if (POSTFIX_OPERATOR_TEXTS.has(text)) return "N_GenPostfixOp";
|
|
103
|
-
return expression.kind === "Lambda" || text === "~" || text === "-."
|
|
104
|
-
? "N_GenNonExpPrefixOp"
|
|
105
|
-
: "N_GenInfixOp";
|
|
106
|
-
};
|
|
107
|
-
|
|
108
96
|
const locateSelectorItems = (file: SourceFile, items: SelectorItem[], span: TokenSpan) => {
|
|
109
97
|
let cursor = span.start;
|
|
110
98
|
return items.map((item): SelectorItem => {
|
|
@@ -724,11 +712,16 @@ export const generateExpression = (
|
|
|
724
712
|
case "Lambda": {
|
|
725
713
|
const text =
|
|
726
714
|
generation.file.tokens[getExpressionSpan(generation.file, expression).start].text;
|
|
715
|
+
const name = expression.operator ?? text;
|
|
716
|
+
// Deviation from SANY: Generator#generateExpression names its internal node kind here, where tla-ts words it as for a name.
|
|
717
|
+
const symbol = resolveSymbol(generation.contexts, resolveSynonym(name));
|
|
727
718
|
generation.addError(
|
|
728
719
|
location,
|
|
729
720
|
text === "LAMBDA"
|
|
730
721
|
? "LAMBDA expression used where an expression is required."
|
|
731
|
-
:
|
|
722
|
+
: symbol === undefined
|
|
723
|
+
? `Could not find declaration or definition of symbol '${name}'.`
|
|
724
|
+
: `The operator ${name} requires ${getSymbolArity(symbol)} arguments.`,
|
|
732
725
|
);
|
|
733
726
|
return { ...createNullNode(generation), nullKind: "absent" };
|
|
734
727
|
}
|
package/src/search.ts
CHANGED
|
@@ -28,7 +28,11 @@ import {
|
|
|
28
28
|
isExpressionImpure,
|
|
29
29
|
isImpureDefinition,
|
|
30
30
|
} from "./dependencies";
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
createEnvironment,
|
|
33
|
+
type ResolvedModuleOperator,
|
|
34
|
+
type RuntimeInvariant,
|
|
35
|
+
} from "./environment";
|
|
32
36
|
import {
|
|
33
37
|
isStackOverflow,
|
|
34
38
|
TlaConfigError,
|
|
@@ -95,26 +99,34 @@ import {
|
|
|
95
99
|
type Value,
|
|
96
100
|
} from "./values";
|
|
97
101
|
|
|
98
|
-
interface
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
export interface CliSettings {
|
|
103
|
+
readLine?: () => string | undefined;
|
|
104
|
+
runtimeInvariants?: RuntimeInvariant[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface EnvironmentSettings
|
|
108
|
+
extends
|
|
109
|
+
Pick<
|
|
110
|
+
CheckOptions,
|
|
111
|
+
| "source"
|
|
112
|
+
| "loadModule"
|
|
113
|
+
| "loadClass"
|
|
114
|
+
| "readFile"
|
|
115
|
+
| "writeFile"
|
|
116
|
+
| "makeDirectory"
|
|
117
|
+
| "seed"
|
|
118
|
+
| "isTool"
|
|
119
|
+
| "traceSpec"
|
|
120
|
+
| "isSanyReported"
|
|
121
|
+
| "isWarningEnabled"
|
|
122
|
+
| "version"
|
|
123
|
+
| "moduleOperators"
|
|
124
|
+
| "fingerprintPolynomial"
|
|
125
|
+
| "maxSetSize"
|
|
126
|
+
| "isLazyValueExpanded"
|
|
127
|
+
| "isViewPrinted"
|
|
128
|
+
>,
|
|
129
|
+
CliSettings {}
|
|
118
130
|
|
|
119
131
|
interface NamedExpression {
|
|
120
132
|
name: string;
|
|
@@ -853,7 +865,12 @@ export const createCheckEnvironment = (
|
|
|
853
865
|
isStringOrderFrozen = false,
|
|
854
866
|
) => {
|
|
855
867
|
const order = createTlcOrder(options.source, options.loadModule);
|
|
856
|
-
setStringOrder(
|
|
868
|
+
setStringOrder(
|
|
869
|
+
order.getStringOrder(
|
|
870
|
+
config,
|
|
871
|
+
(options.runtimeInvariants ?? []).flatMap((invariant) => invariant.module ?? []),
|
|
872
|
+
),
|
|
873
|
+
);
|
|
857
874
|
setValueOptions(options);
|
|
858
875
|
setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
|
|
859
876
|
if (isStringOrderFrozen) freezeStringOrder();
|
|
@@ -875,6 +892,8 @@ export const createCheckEnvironment = (
|
|
|
875
892
|
isWarningEnabled: options.isWarningEnabled,
|
|
876
893
|
version: options.version,
|
|
877
894
|
moduleOperators: options.moduleOperators,
|
|
895
|
+
readLine: options.readLine,
|
|
896
|
+
runtimeInvariants: options.runtimeInvariants,
|
|
878
897
|
});
|
|
879
898
|
return { order, specification };
|
|
880
899
|
};
|
|
@@ -900,6 +919,7 @@ export const prepareSearch = (options: CheckOptions) => {
|
|
|
900
919
|
() => created.order.getDeclarationOrder("variable"),
|
|
901
920
|
options.onProgress,
|
|
902
921
|
specification.moduleOperators,
|
|
922
|
+
specification.runtimeInvariants,
|
|
903
923
|
);
|
|
904
924
|
return { config, specification, environment, search, getDescription };
|
|
905
925
|
};
|
|
@@ -940,6 +960,7 @@ export const createSearch = (
|
|
|
940
960
|
getVariableOrder: () => string[],
|
|
941
961
|
onProgress?: CheckOptions["onProgress"],
|
|
942
962
|
moduleOperators: ResolvedModuleOperator[] = [],
|
|
963
|
+
runtimeInvariants: RuntimeInvariant[] = [],
|
|
943
964
|
): Search | undefined => {
|
|
944
965
|
const getModuleOperators = (kind: ResolvedModuleOperator["kind"]) =>
|
|
945
966
|
moduleOperators
|
|
@@ -968,12 +989,12 @@ export const createSearch = (
|
|
|
968
989
|
text: `Implied-temporal checking is a tautology.\nThe temporal formula ${live} at ${formatRange(liveRange)} equals\nthe fairness constraints of the behavior specification ${specName} at ${formatRange(specRange)}.\nTherefore, checking whether ${specName} => ${live} using TLC will never result in a violation of ${live}.`,
|
|
969
990
|
});
|
|
970
991
|
}
|
|
971
|
-
const
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
992
|
+
const checkedInvariants = getStateChecks(
|
|
993
|
+
[...configInvariants, ...properties.invariants],
|
|
994
|
+
environment,
|
|
995
|
+
);
|
|
975
996
|
const isCheckingBehaviors =
|
|
976
|
-
|
|
997
|
+
checkedInvariants.length > 0 ||
|
|
977
998
|
properties.actionProperties.length > 0 ||
|
|
978
999
|
properties.liveness.length > 0;
|
|
979
1000
|
if (
|
|
@@ -991,6 +1012,22 @@ export const createSearch = (
|
|
|
991
1012
|
if (spec.next === undefined && isCheckingBehaviors) {
|
|
992
1013
|
throw new TlaConfigError("The configuration file did not specify the next state predicate.");
|
|
993
1014
|
}
|
|
1015
|
+
const runtimeChecks = getStateChecks(
|
|
1016
|
+
runtimeInvariants.map((invariant) => {
|
|
1017
|
+
const definition = getDefinition(invariant.name, environment);
|
|
1018
|
+
return {
|
|
1019
|
+
name: invariant.name,
|
|
1020
|
+
expression:
|
|
1021
|
+
definition?.kind === "Operator" ? definition.body : createIdentifier(invariant.name),
|
|
1022
|
+
scope: undefined,
|
|
1023
|
+
};
|
|
1024
|
+
}),
|
|
1025
|
+
environment,
|
|
1026
|
+
);
|
|
1027
|
+
const invariants = [...checkedInvariants, ...runtimeChecks];
|
|
1028
|
+
const invariantPredicates = [
|
|
1029
|
+
...new Map(invariants.map((invariant) => [invariant.predicate, invariant])).values(),
|
|
1030
|
+
];
|
|
994
1031
|
const namedConstraints = getNamedExpressions(
|
|
995
1032
|
"constraint",
|
|
996
1033
|
[...config.constraints, ...getModuleOperators("constraint").map((operator) => operator.name)],
|
|
@@ -1186,6 +1223,7 @@ export const createSearch = (
|
|
|
1186
1223
|
? record
|
|
1187
1224
|
: setViewText(record, () => getViewText(view.expression, state));
|
|
1188
1225
|
};
|
|
1226
|
+
runtime.toRecord = toRecord;
|
|
1189
1227
|
return {
|
|
1190
1228
|
properties,
|
|
1191
1229
|
spec,
|
|
@@ -1289,8 +1327,8 @@ export const createSearch = (
|
|
|
1289
1327
|
return view === undefined ? representative : [getViewValue(view.expression, representative)];
|
|
1290
1328
|
},
|
|
1291
1329
|
findViolatedInvariant: (state, parent) => {
|
|
1292
|
-
|
|
1293
|
-
const violated =
|
|
1330
|
+
const checked = isCoveredHeld(coveredInvariants, state) ? runtimeChecks : invariants;
|
|
1331
|
+
const violated = checked.find((invariant) => isViolated(invariant, state, parent));
|
|
1294
1332
|
if (violated) violatingStates.add(state);
|
|
1295
1333
|
return violated;
|
|
1296
1334
|
},
|
package/src/simulate.ts
CHANGED
|
@@ -249,6 +249,8 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
249
249
|
const nextActions = description.actions;
|
|
250
250
|
let traceCount = 0;
|
|
251
251
|
let currentTrace = 0;
|
|
252
|
+
let evaluatedAction: SpecAction | undefined;
|
|
253
|
+
runtime.getSuccessorAction = () => evaluatedAction;
|
|
252
254
|
runtime.getLevel = (state) => nodes.get(state)?.level ?? 0;
|
|
253
255
|
runtime.getBehavior = (state) => {
|
|
254
256
|
const node = nodes.get(state);
|
|
@@ -486,6 +488,7 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
486
488
|
const successors: TraceNode[] = [];
|
|
487
489
|
let failure: WorkerError | undefined;
|
|
488
490
|
runtime.deferred = undefined;
|
|
491
|
+
evaluatedAction = action;
|
|
489
492
|
try {
|
|
490
493
|
forEachSuccessor(
|
|
491
494
|
action.expression,
|
|
@@ -81,6 +81,10 @@ const SIGNATURES: Signature[] = [
|
|
|
81
81
|
["RandomSubset", 0, [0, 0], [2, 2], [1, 1]],
|
|
82
82
|
["RandomSetOfSubsets", 0, [0, 0, 0], [2, 3, 2], [1, 0, 1]],
|
|
83
83
|
["TestRandomSetOfSubsets", 0, [0, 0, 0], [2, 3, 2], [1, 0, 1]],
|
|
84
|
+
["_Track", 0, [0, 0], [3, 2], [0, 0]],
|
|
85
|
+
["_Counts", 0, [], [], []],
|
|
86
|
+
["_CheckName", 0, [0], [2], [1]],
|
|
87
|
+
["_PrintCounts", 0, [], [], []],
|
|
84
88
|
];
|
|
85
89
|
|
|
86
90
|
export const STANDARD_LEVELS = new Map(
|
package/src/tlc/order.ts
CHANGED
|
@@ -444,7 +444,11 @@ const createContexts = (getParsed: ModuleSet) => {
|
|
|
444
444
|
};
|
|
445
445
|
};
|
|
446
446
|
|
|
447
|
-
const getStringOrder = (
|
|
447
|
+
const getStringOrder = (
|
|
448
|
+
getParsed: ModuleSet,
|
|
449
|
+
config: ModelConfig,
|
|
450
|
+
runtimeModules: string[],
|
|
451
|
+
): string[] => {
|
|
448
452
|
const order = new Set<string>();
|
|
449
453
|
const intern = (text: string) => {
|
|
450
454
|
order.add(text);
|
|
@@ -541,12 +545,19 @@ const getStringOrder = (getParsed: ModuleSet, config: ModelConfig): string[] =>
|
|
|
541
545
|
});
|
|
542
546
|
};
|
|
543
547
|
analyze(undefined);
|
|
548
|
+
runtimeModules.forEach((name) => {
|
|
549
|
+
const tokens = getUnitTokens(name);
|
|
550
|
+
getParsedTexts(tokens).forEach(intern);
|
|
551
|
+
tokens.forEach((token) => {
|
|
552
|
+
if (token.kind === "String") intern(token.text);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
544
555
|
TLC_RUNTIME_STRINGS.forEach(intern);
|
|
545
556
|
return [...order];
|
|
546
557
|
};
|
|
547
558
|
|
|
548
559
|
export interface TlcOrder {
|
|
549
|
-
getStringOrder: (config: ModelConfig) => string[];
|
|
560
|
+
getStringOrder: (config: ModelConfig, runtimeModules: string[]) => string[];
|
|
550
561
|
getDeclarationOrder: (kind: "variable" | "constant") => string[];
|
|
551
562
|
createDefinitionOrder: () => (name: string | undefined) => string[];
|
|
552
563
|
parseModule: (source: string) => Module;
|
|
@@ -558,7 +569,7 @@ export const createTlcOrder = (source: string, loadModule: ModuleLoader): TlcOrd
|
|
|
558
569
|
let contexts: ReturnType<typeof createContexts> | undefined;
|
|
559
570
|
const getContexts = () => (contexts ??= createContexts(getParsed));
|
|
560
571
|
return {
|
|
561
|
-
getStringOrder: (config) => getStringOrder(getParsed, config),
|
|
572
|
+
getStringOrder: (config, runtimeModules) => getStringOrder(getParsed, config, runtimeModules),
|
|
562
573
|
getDeclarationOrder: (kind) =>
|
|
563
574
|
getContexts()
|
|
564
575
|
.getContext(undefined)
|
|
@@ -7,7 +7,13 @@ import {
|
|
|
7
7
|
getThunk,
|
|
8
8
|
getValue,
|
|
9
9
|
} from "../builtins";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
formatRange,
|
|
12
|
+
TlaEndOfInputError,
|
|
13
|
+
TlaEvaluationError,
|
|
14
|
+
TlaModuleError,
|
|
15
|
+
TlaUnsupportedError,
|
|
16
|
+
} from "../errors";
|
|
11
17
|
import { getTlcFingerprint } from "./fingerprint";
|
|
12
18
|
import { formatMessage, formatNestedMessage, MESSAGE_CODE, MESSAGE_LEVEL } from "./messages";
|
|
13
19
|
import {
|
|
@@ -31,6 +37,7 @@ import {
|
|
|
31
37
|
createRecord,
|
|
32
38
|
createSet,
|
|
33
39
|
createTuple,
|
|
40
|
+
formatState,
|
|
34
41
|
formatValue,
|
|
35
42
|
getFingerprintError,
|
|
36
43
|
getSequenceElements,
|
|
@@ -256,10 +263,13 @@ export const createTlcExtOperators = (
|
|
|
256
263
|
defineOperator("TLCNoOp", 1, (args) => getValue(args, 0, "TLCNoOp")),
|
|
257
264
|
{
|
|
258
265
|
...defineLazyOperator("PickSuccessor", 1, (args, context) => {
|
|
259
|
-
// Deviation from TLC: TLCExt#pickSuccessor fingerprints a partial successor and fails, where TLCExt.tla promises TRUE.
|
|
260
266
|
const next = context?.next ?? (context?.environment.variables ?? []).map(() => undefined);
|
|
261
|
-
|
|
262
|
-
if (
|
|
267
|
+
// A simulation remembers no states, so TLC evaluates the guard before it looks at the successor.
|
|
268
|
+
if (runtime.getSimulationValue === undefined) {
|
|
269
|
+
// Deviation from TLC: TLCExt#pickSuccessor fingerprints a partial successor and fails, where TLCExt.tla promises TRUE.
|
|
270
|
+
if (!isCompleteState(next)) return true;
|
|
271
|
+
if (context?.next && runtime.isSeen(next)) return true;
|
|
272
|
+
}
|
|
263
273
|
const guard = getOperator(args, 0, "PickSuccessor");
|
|
264
274
|
const isPicked = guard.call([]);
|
|
265
275
|
if (typeof isPicked !== "boolean") {
|
|
@@ -267,20 +277,55 @@ export const createTlcExtOperators = (
|
|
|
267
277
|
`In evaluating TLCExt!PickSuccessor, a non-boolean expression (${getKindString(isPicked)}) was used as the condition of an IF.\n${guard.expression ? describeNode(guard.expression) : ""}`,
|
|
268
278
|
);
|
|
269
279
|
}
|
|
270
|
-
if (
|
|
280
|
+
if (
|
|
281
|
+
isPicked ||
|
|
282
|
+
!context?.next ||
|
|
283
|
+
!isCompleteState(next) ||
|
|
284
|
+
!context.state ||
|
|
285
|
+
!isCompleteState(context.state)
|
|
286
|
+
) {
|
|
271
287
|
return true;
|
|
272
288
|
}
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
289
|
+
const state = context.state;
|
|
290
|
+
const action = runtime.getSuccessorAction(state, next);
|
|
291
|
+
const printOverride = (text: string) =>
|
|
292
|
+
print(
|
|
293
|
+
formatMessage(
|
|
294
|
+
runtime.isTool,
|
|
295
|
+
MESSAGE_CODE.moduleOverrideStdout,
|
|
296
|
+
MESSAGE_LEVEL.none,
|
|
297
|
+
text,
|
|
298
|
+
),
|
|
299
|
+
);
|
|
300
|
+
while (true) {
|
|
301
|
+
printOverride(
|
|
302
|
+
`Extend behavior of length ${runtime.getLevel(state)} with a "${action?.name}" step [<Action ${action?.location.range && formatRange(action.location.range)}>]? (Yes/no/explored/states/diff):`,
|
|
303
|
+
);
|
|
304
|
+
const answer = runtime.readLine?.();
|
|
305
|
+
// Deviation from TLC: at the end of standard input, TLC's Scanner leaks a NoSuchElementException.
|
|
306
|
+
if (answer === undefined) throw new TlaEndOfInputError();
|
|
307
|
+
if (/^[\0-\x20]*$/.test(answer) || answer.toLowerCase().startsWith("y")) return true;
|
|
308
|
+
if (answer[0] === "s") {
|
|
309
|
+
printOverride(
|
|
310
|
+
`${formatState(runtime.toRecord(state)).trimEnd()}\n~>\n${formatState(runtime.toRecord(next)).trimEnd()}`,
|
|
311
|
+
);
|
|
312
|
+
} else if (answer[0] === "d") {
|
|
313
|
+
printOverride(formatState(runtime.toRecord(next), runtime.toRecord(state)));
|
|
314
|
+
} else if (answer[0] === "e") {
|
|
315
|
+
if (runtime.markExplored) {
|
|
316
|
+
runtime.markExplored(next);
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
if (runtime.getSimulationValue === undefined) {
|
|
320
|
+
throw new TlaUnsupportedError(
|
|
321
|
+
"tla-ts can't mark a state explored while it searches depth first.",
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
printOverride(
|
|
325
|
+
"Marking a state explored is unsupported by the current TLC mode. Is TLC running in simulation mode?",
|
|
326
|
+
);
|
|
327
|
+
} else if (answer[0] === "n") return false;
|
|
328
|
+
}
|
|
284
329
|
}),
|
|
285
330
|
isActionLevel: true,
|
|
286
331
|
},
|
package/src/tlc/trace-spec.ts
CHANGED
|
@@ -180,9 +180,8 @@ ${lassoStep}${variables
|
|
|
180
180
|
\\* IN J!JsonSerialize("${input.module}.json", _TETrace)
|
|
181
181
|
|
|
182
182
|
`;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const view = isViewed
|
|
183
|
+
// MCError#isLassoWithDuplicates counts the state a lasso goes back to, so TLC views every lasso.
|
|
184
|
+
const view = isLasso
|
|
186
185
|
? {
|
|
187
186
|
config: "\nVIEW\n _view\n",
|
|
188
187
|
definition: `\n_view ==\n${INDENT}<<${variables.join(", ")}, IF TLCGet("level") = ${LASSO_END} + 1 THEN ${LASSO_START} ELSE TLCGet("level")>>\n`,
|