tla-ts 0.0.10-dev.b4a856304 → 0.0.10-dev.f16792fed
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.cjs +1 -1
- package/dist/index.d.cts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +48 -48
- package/dist/prove.js +29 -29
- package/dist/run.cjs +40 -40
- package/dist/run.js +31 -31
- package/dist/transfer.cjs +36 -36
- package/dist/transfer.js +40 -40
- package/package.json +1 -1
- package/src/ast.ts +0 -5
- package/src/bags.ts +2 -5
- package/src/builtins.ts +1 -8
- package/src/check.ts +128 -193
- package/src/cli/options.ts +1 -1
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +8 -7
- package/src/cli/shared.ts +0 -4
- package/src/cli/tlc-arguments.ts +24 -30
- package/src/cli/tlc-usage.ts +2 -3
- package/src/coverage.ts +3 -8
- package/src/evaluate.ts +26 -102
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -9
- package/src/json-reader.ts +1 -2
- package/src/json.ts +4 -11
- package/src/levels.ts +7 -15
- package/src/lexer.ts +72 -83
- package/src/liveness-checker.ts +77 -106
- package/src/liveness.ts +10 -34
- package/src/parallel.ts +26 -33
- package/src/parser.ts +163 -226
- package/src/pcal/ast.ts +53 -65
- package/src/pcal/parse.ts +144 -191
- package/src/pcal/tokenize.ts +91 -115
- package/src/pcal/translate.ts +83 -98
- package/src/pcal/validate.ts +48 -50
- package/src/pretty-print.ts +6 -6
- package/src/randomization.ts +1 -4
- package/src/resolve.ts +12 -70
- package/src/runtime.ts +11 -18
- package/src/sany/builtins.ts +1 -3
- package/src/sany/generator.ts +74 -127
- package/src/sany/levels.ts +5 -9
- package/src/sany/lexer.ts +40 -44
- package/src/sany/linter.ts +0 -1
- package/src/sany/nodes.ts +4 -10
- package/src/search.ts +1 -1
- package/src/simulate.ts +50 -59
- package/src/spec-description.ts +23 -34
- package/src/standard-definitions.ts +0 -3
- package/src/standard-modules.ts +1 -12
- package/src/state-graph.ts +3 -15
- package/src/subexpressions.ts +38 -47
- package/src/successors.ts +14 -35
- package/src/symmetry.ts +4 -19
- package/src/tlc/fingerprint.ts +15 -21
- package/src/tlc/jar-data.ts +0 -1
- package/src/tlc/messages.ts +2 -21
- package/src/tlc/order.ts +22 -47
- package/src/tlc/random.ts +18 -30
- package/src/tlc/replay.ts +13 -33
- package/src/tlc/summary.ts +36 -45
- package/src/tlc/tlc-operators.ts +4 -14
- package/src/tlc/tlcext-operators.ts +11 -15
- package/src/tlc/trace-spec.ts +4 -9
- package/src/tlc/value-stream.ts +9 -13
- package/src/tlc/version.ts +0 -1
- package/src/values.ts +74 -186
package/src/sany/generator.ts
CHANGED
|
@@ -247,9 +247,6 @@ const getProofInstances = (proof: Proof | undefined): Instance[] =>
|
|
|
247
247
|
...getProofInstances(step.proof),
|
|
248
248
|
]);
|
|
249
249
|
|
|
250
|
-
// SANY resolves a top-level INSTANCE to an inner module only when the module's first top-level
|
|
251
|
-
// INSTANCE follows the inner module, and otherwise looks for a file. It looks for a file for an
|
|
252
|
-
// INSTANCE in a LET or a proof step too, where tla-ts takes an inner module defined before it.
|
|
253
250
|
const isInternalInstance = (module: Module, instance: Instance) => {
|
|
254
251
|
const seen = new Set<string>();
|
|
255
252
|
for (const unit of module.units) {
|
|
@@ -276,13 +273,10 @@ interface LabelScope {
|
|
|
276
273
|
params: FormalParamNode[][];
|
|
277
274
|
}
|
|
278
275
|
|
|
279
|
-
// SANY looks at a module's own EXTENDS and INSTANCEs before those of its inner modules.
|
|
280
276
|
const getDependencies = (module: Module) => {
|
|
281
277
|
const extendees: string[] = [];
|
|
282
278
|
const instancees: string[] = [];
|
|
283
279
|
const importers = new Map<string, string>();
|
|
284
|
-
// A module knows the inner modules defined before it in its enclosing modules and those of the
|
|
285
|
-
// modules it extends, but not itself.
|
|
286
280
|
const visit = (current: Module, context: Map<string, Module>) => {
|
|
287
281
|
const isRoot = current === module;
|
|
288
282
|
const addImports = (names: string[], imports: string[]) =>
|
|
@@ -344,7 +338,6 @@ const OPERATOR_ARGUMENT_KINDS = new Set<Expression["kind"]>([
|
|
|
344
338
|
"Lambda",
|
|
345
339
|
]);
|
|
346
340
|
|
|
347
|
-
// A name such as K(1)!C, whose last part takes no arguments, is a GeneralId too.
|
|
348
341
|
const isOperatorArgument = (argument: Expression) => {
|
|
349
342
|
const items = argument.kind === "Apply" ? getSelectorItems(argument) : undefined;
|
|
350
343
|
return OPERATOR_ARGUMENT_KINDS.has(argument.kind) || (items !== undefined && isGeneralId(items));
|
|
@@ -402,7 +395,6 @@ const NESTED_FIRST_CHILD_KINDS = new Set([
|
|
|
402
395
|
|
|
403
396
|
const POSTFIX_OPERATOR_TEXTS = new Set(["'", "^+", "^*", "^#"]);
|
|
404
397
|
|
|
405
|
-
// SANY's parser reads a prefix operator other than ~ and -. as a LAMBDA.
|
|
406
398
|
const getOperatorNodeKind = (
|
|
407
399
|
expression: Expression & { kind: "OperatorReference" | "Lambda" },
|
|
408
400
|
text: string,
|
|
@@ -423,10 +415,9 @@ export const generateSanySpecification = (
|
|
|
423
415
|
addSanyMessage(messages, { location, text, isWarning: false });
|
|
424
416
|
const addWarning = (location: SanyLocation | undefined, text: string) =>
|
|
425
417
|
addSanyMessage(messages, { location, text, isWarning: true });
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
const nullApplication = { id: 0 };
|
|
418
|
+
let lastId = options.version === "1.7.4" ? -1 : 0;
|
|
419
|
+
const getId = () => ++lastId;
|
|
420
|
+
let nullApplicationId = 0;
|
|
430
421
|
|
|
431
422
|
const addSymbol = (table: SymbolTable, symbol: SymbolNode) => {
|
|
432
423
|
const binding = resolveSymbol(table, symbol.name);
|
|
@@ -439,7 +430,6 @@ export const generateSanySpecification = (
|
|
|
439
430
|
symbol.kind === "FormalParam" ||
|
|
440
431
|
getSymbolKind(binding) !== getSymbolKind(symbol) ||
|
|
441
432
|
getSymbolArity(binding) !== getSymbolArity(symbol);
|
|
442
|
-
// TLC 1.7.4's SANY reports a conflict before the redefinition of a built-in operator.
|
|
443
433
|
const isBuiltIn = binding.kind === "OpDef" && binding.defKind === "BuiltIn";
|
|
444
434
|
if (isBuiltIn && !(isConflict && options.version === "1.7.4")) {
|
|
445
435
|
addError(
|
|
@@ -460,8 +450,7 @@ export const generateSanySpecification = (
|
|
|
460
450
|
);
|
|
461
451
|
}
|
|
462
452
|
};
|
|
463
|
-
// Context's static initializer
|
|
464
|
-
// again; TLC 1.7.4's SANY creates them only once.
|
|
453
|
+
// SANY creates the builtins twice, in Context's static initializer and in frontEndInitialize.
|
|
465
454
|
if (options.version !== "1.7.4") createBuiltins(getId);
|
|
466
455
|
const builtins = createBuiltins(getId);
|
|
467
456
|
getId();
|
|
@@ -525,8 +514,6 @@ export const generateSanySpecification = (
|
|
|
525
514
|
path.pop();
|
|
526
515
|
order.push(name);
|
|
527
516
|
};
|
|
528
|
-
// SANY resolves the first unresolved name from the root, every extended module before any
|
|
529
|
-
// instantiated one, each in the context of the module that names it.
|
|
530
517
|
const resolutions = new Set<string>();
|
|
531
518
|
const isResolved = (importer: string, name: string) => resolutions.has(`${importer} ${name}`);
|
|
532
519
|
const findUnresolved = (
|
|
@@ -564,7 +551,6 @@ export const generateSanySpecification = (
|
|
|
564
551
|
}
|
|
565
552
|
};
|
|
566
553
|
const rootName = options.rootFileName ?? parseSource("", rootSource).name;
|
|
567
|
-
// The post conditions' modules join the root module's own extendees, before its inner modules'.
|
|
568
554
|
const getModuleDependencies = (name: string, module: Module) => {
|
|
569
555
|
const dependencies = getDependencies(module);
|
|
570
556
|
if (name !== rootName || options.rootExtendees === undefined) return dependencies;
|
|
@@ -730,9 +716,8 @@ export const generateSanySpecification = (
|
|
|
730
716
|
location,
|
|
731
717
|
});
|
|
732
718
|
|
|
733
|
-
// nullOAN has no syntax tree node, so SANY locates it at the builtins.
|
|
734
719
|
const createNullNode = (): OpApplNode => ({
|
|
735
|
-
...createOpAppl(getBuiltin("$Nop"), [], BUILTIN_LOCATION, {},
|
|
720
|
+
...createOpAppl(getBuiltin("$Nop"), [], BUILTIN_LOCATION, {}, nullApplicationId),
|
|
736
721
|
isNull: true,
|
|
737
722
|
});
|
|
738
723
|
|
|
@@ -756,10 +741,10 @@ export const generateSanySpecification = (
|
|
|
756
741
|
location,
|
|
757
742
|
});
|
|
758
743
|
|
|
759
|
-
const createOpArg = (
|
|
744
|
+
const createOpArg = (operator: SymbolNode, location: SanyLocation): OpArgNode => ({
|
|
760
745
|
...createLevelFields(getId()),
|
|
761
746
|
kind: "OpArg",
|
|
762
|
-
op,
|
|
747
|
+
op: operator,
|
|
763
748
|
location,
|
|
764
749
|
});
|
|
765
750
|
|
|
@@ -773,8 +758,6 @@ export const generateSanySpecification = (
|
|
|
773
758
|
return symbol;
|
|
774
759
|
};
|
|
775
760
|
|
|
776
|
-
// A definition's parameter count differs from its arity only where its RECURSIVE declaration
|
|
777
|
-
// gives another.
|
|
778
761
|
const matchArguments = (
|
|
779
762
|
operator: SymbolNode,
|
|
780
763
|
operands: ExprOrOpArgNode[],
|
|
@@ -871,21 +854,21 @@ export const generateSanySpecification = (
|
|
|
871
854
|
});
|
|
872
855
|
|
|
873
856
|
const locateSelectorItems = (items: SelectorItem[], span: TokenSpan) => {
|
|
874
|
-
|
|
857
|
+
let cursor = span.start;
|
|
875
858
|
return items.map((item): SelectorItem => {
|
|
876
859
|
const text = item.op === "Name" ? item.name : item.op === "Null" ? "(" : String(item.op);
|
|
877
|
-
const index = findToken(file, cursor
|
|
860
|
+
const index = findToken(file, cursor, span.end, text);
|
|
878
861
|
if (index === -1) return item;
|
|
879
862
|
if (item.op === "Null") {
|
|
880
863
|
const close = getMatchingIndex(file, index);
|
|
881
|
-
cursor
|
|
864
|
+
cursor = close + 1;
|
|
882
865
|
return { ...item, location: getSpanLocation(file, { start: index, end: close }) };
|
|
883
866
|
}
|
|
884
|
-
cursor
|
|
867
|
+
cursor = index + 1;
|
|
885
868
|
const location = getTokenLocation(file, index);
|
|
886
869
|
if (item.args === undefined || !isToken(file, index + 1, "(")) return { ...item, location };
|
|
887
870
|
const close = getMatchingIndex(file, index + 1);
|
|
888
|
-
cursor
|
|
871
|
+
cursor = close + 1;
|
|
889
872
|
return {
|
|
890
873
|
...item,
|
|
891
874
|
location,
|
|
@@ -924,7 +907,6 @@ export const generateSanySpecification = (
|
|
|
924
907
|
if (recursive) recursive.node.operator = getBuiltin("$RecursiveFcnSpec");
|
|
925
908
|
};
|
|
926
909
|
|
|
927
|
-
// tla-ts expands \A x, y \in S into a bound per name that shares the set; SANY keeps one group.
|
|
928
910
|
const getBoundGroups = (bounds: Bound[]) =>
|
|
929
911
|
bounds.reduce<Bound[][]>((groups, bound) => {
|
|
930
912
|
const last = groups[groups.length - 1];
|
|
@@ -938,7 +920,6 @@ export const generateSanySpecification = (
|
|
|
938
920
|
return groups;
|
|
939
921
|
}, []);
|
|
940
922
|
|
|
941
|
-
// SANY generates every bounding set before it declares the symbols.
|
|
942
923
|
const generateBounds = (bounds: Bound[], searchStart: number) =>
|
|
943
924
|
generateBoundsWithRanges(
|
|
944
925
|
bounds,
|
|
@@ -954,6 +935,19 @@ export const generateSanySpecification = (
|
|
|
954
935
|
return node;
|
|
955
936
|
};
|
|
956
937
|
|
|
938
|
+
const generateBoundApplication = (
|
|
939
|
+
name: string,
|
|
940
|
+
bounds: Bound[],
|
|
941
|
+
searchStart: number,
|
|
942
|
+
body: Expression,
|
|
943
|
+
location: SanyLocation,
|
|
944
|
+
) =>
|
|
945
|
+
withContext(createContext(), () => {
|
|
946
|
+
const symbols = generateBounds(bounds, searchStart);
|
|
947
|
+
const operand = generateWithParams(symbols.bounded.flat(), body);
|
|
948
|
+
return applyBuiltin(name, [operand], location, symbols);
|
|
949
|
+
});
|
|
950
|
+
|
|
957
951
|
const generateLambda = (expression: Expression & { kind: "Lambda" }): OpDefNode => {
|
|
958
952
|
const span = getExpressionSpan(file, expression);
|
|
959
953
|
const nameIndexes = findNameTokens(file, span.start, span.end, expression.params);
|
|
@@ -972,7 +966,6 @@ export const generateSanySpecification = (
|
|
|
972
966
|
});
|
|
973
967
|
};
|
|
974
968
|
|
|
975
|
-
// tla-ts desugars an operator symbol argument, such as SUBSET or -., into a LAMBDA naming it.
|
|
976
969
|
const getOperatorArgumentName = (argument: Expression) =>
|
|
977
970
|
argument.kind === "OperatorReference"
|
|
978
971
|
? argument.operator
|
|
@@ -1069,7 +1062,6 @@ export const generateSanySpecification = (
|
|
|
1069
1062
|
return createNullNode();
|
|
1070
1063
|
};
|
|
1071
1064
|
|
|
1072
|
-
// A /\ B /\ C nests as ((A /\ B) /\ C) in SANY; tla-ts flattens it.
|
|
1073
1065
|
const generateJunction = (expression: Expression & { kind: "And" | "Or" }) => {
|
|
1074
1066
|
const location = getLocation(expression);
|
|
1075
1067
|
if (expression.isBulleted) {
|
|
@@ -1134,21 +1126,21 @@ export const generateSanySpecification = (
|
|
|
1134
1126
|
const operands: ExprOrOpArgNode[] = [generateExpression(expression.function)];
|
|
1135
1127
|
const exceptNode = applyBuiltin("$Except", operands, location);
|
|
1136
1128
|
const functionSpan = getExpressionSpan(file, expression.function);
|
|
1137
|
-
|
|
1129
|
+
let cursor = findToken(file, functionSpan.end + 1, span.end, "EXCEPT") + 1;
|
|
1138
1130
|
expression.updates.forEach((update) => {
|
|
1139
|
-
const bang = findToken(file, cursor
|
|
1131
|
+
const bang = findToken(file, cursor, span.end, "!");
|
|
1140
1132
|
const valueSpan = getParenthesizedSpan(file, getExpressionSpan(file, update.value));
|
|
1141
1133
|
const specLocation = getSpanLocation(file, { start: bang, end: valueSpan.end });
|
|
1142
|
-
|
|
1134
|
+
let pathCursor = bang + 1;
|
|
1143
1135
|
const components = update.path.map((step): ExprNode => {
|
|
1144
1136
|
if (step.kind === "Field") {
|
|
1145
|
-
const nameIndex = findNameOrKeyword(pathCursor
|
|
1146
|
-
pathCursor
|
|
1137
|
+
const nameIndex = findNameOrKeyword(pathCursor, step.name);
|
|
1138
|
+
pathCursor = nameIndex + 1;
|
|
1147
1139
|
return createString(step.name, getTokenLocation(file, nameIndex));
|
|
1148
1140
|
}
|
|
1149
|
-
const open = findToken(file, pathCursor
|
|
1141
|
+
const open = findToken(file, pathCursor, span.end, "[");
|
|
1150
1142
|
const close = getMatchingIndex(file, open);
|
|
1151
|
-
pathCursor
|
|
1143
|
+
pathCursor = close + 1;
|
|
1152
1144
|
if (step.args.length === 1) return generateExpression(step.args[0]);
|
|
1153
1145
|
return applyBuiltin(
|
|
1154
1146
|
"$Tuple",
|
|
@@ -1164,7 +1156,7 @@ export const generateSanySpecification = (
|
|
|
1164
1156
|
exceptSpecStack.pop();
|
|
1165
1157
|
exceptStack.pop();
|
|
1166
1158
|
operands.push(pair);
|
|
1167
|
-
cursor
|
|
1159
|
+
cursor = valueSpan.end + 1;
|
|
1168
1160
|
});
|
|
1169
1161
|
return exceptNode;
|
|
1170
1162
|
};
|
|
@@ -1181,11 +1173,11 @@ export const generateSanySpecification = (
|
|
|
1181
1173
|
expression: Expression & { kind: "Record" | "RecordSet" },
|
|
1182
1174
|
) => {
|
|
1183
1175
|
const span = getExpressionSpan(file, expression);
|
|
1184
|
-
|
|
1176
|
+
let cursor = span.start + 1;
|
|
1185
1177
|
const pairs = expression.fields.map((field, fieldIndex) => {
|
|
1186
|
-
const nameIndex = findNameOrKeyword(cursor
|
|
1178
|
+
const nameIndex = findNameOrKeyword(cursor, field.name);
|
|
1187
1179
|
const valueSpan = getParenthesizedSpan(file, getExpressionSpan(file, field.value));
|
|
1188
|
-
cursor
|
|
1180
|
+
cursor = valueSpan.end + 1;
|
|
1189
1181
|
if (expression.fields.slice(0, fieldIndex).some((other) => other.name === field.name)) {
|
|
1190
1182
|
addError(getTokenLocation(file, nameIndex), "Non-unique fields in constructor.");
|
|
1191
1183
|
}
|
|
@@ -1208,7 +1200,6 @@ export const generateSanySpecification = (
|
|
|
1208
1200
|
column: file.tokens[index].column,
|
|
1209
1201
|
});
|
|
1210
1202
|
|
|
1211
|
-
// The syntax tree of a LET leaves out its RECURSIVE declarations, so read them from the tokens.
|
|
1212
1203
|
const getRecursiveDeclarations = (start: number) => {
|
|
1213
1204
|
const declarations: Declaration[] = [];
|
|
1214
1205
|
let index = start;
|
|
@@ -1303,7 +1294,6 @@ export const generateSanySpecification = (
|
|
|
1303
1294
|
const names = pattern.kind === "Name" ? [pattern.name] : pattern.names;
|
|
1304
1295
|
if (expression.set === undefined) {
|
|
1305
1296
|
const indexes = findNameTokens(file, span.start, span.end, names);
|
|
1306
|
-
// SANY locates the symbol of CHOOSE x : P at the CHOOSE keyword.
|
|
1307
1297
|
const params = names.map((name, index) =>
|
|
1308
1298
|
createFormalParam(
|
|
1309
1299
|
name,
|
|
@@ -1342,7 +1332,6 @@ export const generateSanySpecification = (
|
|
|
1342
1332
|
return undefined;
|
|
1343
1333
|
}
|
|
1344
1334
|
const span = getExpressionSpan(file, expression);
|
|
1345
|
-
// SANY reports an operator applied like a function, as in op(a, b), as an unknown operator.
|
|
1346
1335
|
if (
|
|
1347
1336
|
file.tokens[span.start].text === expression.operator &&
|
|
1348
1337
|
isToken(file, span.start + 1, "(")
|
|
@@ -1455,19 +1444,14 @@ export const generateSanySpecification = (
|
|
|
1455
1444
|
case "Let":
|
|
1456
1445
|
return generateLet(expression);
|
|
1457
1446
|
case "Forall":
|
|
1458
|
-
case "Exists":
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
location,
|
|
1467
|
-
bounds,
|
|
1468
|
-
);
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1447
|
+
case "Exists":
|
|
1448
|
+
return generateBoundApplication(
|
|
1449
|
+
expression.kind === "Forall" ? "$BoundedForall" : "$BoundedExists",
|
|
1450
|
+
expression.bounds,
|
|
1451
|
+
getExpressionSpan(file, expression).start,
|
|
1452
|
+
expression.body,
|
|
1453
|
+
location,
|
|
1454
|
+
);
|
|
1471
1455
|
case "UnboundedQuantifier": {
|
|
1472
1456
|
const span = getExpressionSpan(file, expression);
|
|
1473
1457
|
const bodySpan = getExpressionSpan(file, expression.body);
|
|
@@ -1506,22 +1490,22 @@ export const generateSanySpecification = (
|
|
|
1506
1490
|
return applyBuiltin("$SubsetOf", [body], location, bounds);
|
|
1507
1491
|
});
|
|
1508
1492
|
}
|
|
1509
|
-
case "SetMap":
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
case "FunctionConstruction":
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1493
|
+
case "SetMap":
|
|
1494
|
+
return generateBoundApplication(
|
|
1495
|
+
"$SetOfAll",
|
|
1496
|
+
expression.bounds,
|
|
1497
|
+
getExpressionSpan(file, expression.expression).end + 1,
|
|
1498
|
+
expression.expression,
|
|
1499
|
+
location,
|
|
1500
|
+
);
|
|
1501
|
+
case "FunctionConstruction":
|
|
1502
|
+
return generateBoundApplication(
|
|
1503
|
+
"$FcnConstructor",
|
|
1504
|
+
expression.bounds,
|
|
1505
|
+
getExpressionSpan(file, expression).start,
|
|
1506
|
+
expression.body,
|
|
1507
|
+
location,
|
|
1508
|
+
);
|
|
1525
1509
|
case "FunctionSet":
|
|
1526
1510
|
return applyBuiltin(
|
|
1527
1511
|
"$SetOfFcns",
|
|
@@ -1551,7 +1535,6 @@ export const generateSanySpecification = (
|
|
|
1551
1535
|
}
|
|
1552
1536
|
case "FunctionApplication": {
|
|
1553
1537
|
const functionNode = generateExpression(expression.function);
|
|
1554
|
-
// SANY leaves the whole application null, without generating its arguments.
|
|
1555
1538
|
if (isAbsent(functionNode)) return functionNode;
|
|
1556
1539
|
checkRecursion(functionNode);
|
|
1557
1540
|
const operator = functionNode.kind === "OpAppl" ? functionNode.operator : undefined;
|
|
@@ -1624,14 +1607,14 @@ export const generateSanySpecification = (
|
|
|
1624
1607
|
ranges: ExprNode[],
|
|
1625
1608
|
): BoundSymbols => {
|
|
1626
1609
|
const groups = getBoundGroups(bounds);
|
|
1627
|
-
|
|
1610
|
+
let cursor = searchStart;
|
|
1628
1611
|
const bounded = groups.map((group) => {
|
|
1629
1612
|
const setSpan = getExpressionSpan(file, group[0].set);
|
|
1630
1613
|
const names = group.flatMap((bound) =>
|
|
1631
1614
|
bound.pattern.kind === "Name" ? [bound.pattern.name] : bound.pattern.names,
|
|
1632
1615
|
);
|
|
1633
|
-
const indexes = findNameTokens(file, cursor
|
|
1634
|
-
cursor
|
|
1616
|
+
const indexes = findNameTokens(file, cursor, setSpan.start, names);
|
|
1617
|
+
cursor = setSpan.end + 1;
|
|
1635
1618
|
return names.map((name, index) =>
|
|
1636
1619
|
createFormalParam(name, 0, getTokenLocation(file, indexes[index]), true),
|
|
1637
1620
|
);
|
|
@@ -1650,7 +1633,6 @@ export const generateSanySpecification = (
|
|
|
1650
1633
|
addError(location, "Label not in definition or proof step.");
|
|
1651
1634
|
return createNullNode();
|
|
1652
1635
|
}
|
|
1653
|
-
// No label may lie in the scope of a declaration of a nested ASSUME/PROVE.
|
|
1654
1636
|
if (assumeProveState.isDeclared.slice(2, assumeProveState.depth + 1).some(Boolean)) {
|
|
1655
1637
|
addError(location, "Label not allowed within scope of declaration in nested ASSUME/PROVE.");
|
|
1656
1638
|
return createNullNode();
|
|
@@ -1716,14 +1698,13 @@ export const generateSanySpecification = (
|
|
|
1716
1698
|
span: TokenSpan,
|
|
1717
1699
|
isAdded: boolean,
|
|
1718
1700
|
) => {
|
|
1719
|
-
|
|
1701
|
+
let cursor = span.start;
|
|
1720
1702
|
return definition.params.map((param) => {
|
|
1721
1703
|
const index = param.location
|
|
1722
1704
|
? getTokenIndex(file, param.location)
|
|
1723
|
-
: findNameOrKeyword(cursor
|
|
1705
|
+
: findNameOrKeyword(cursor, param.name);
|
|
1724
1706
|
const paramSpan = getOperatorSpan(index, param.arity);
|
|
1725
|
-
cursor
|
|
1726
|
-
// SANY keeps the spelling of a prefix parameter, so ~ _ does not redefine \lnot.
|
|
1707
|
+
cursor = paramSpan.end + 1;
|
|
1727
1708
|
const isPrefix = param.arity === 1 && isToken(file, index + 1, "_");
|
|
1728
1709
|
return createFormalParam(
|
|
1729
1710
|
isPrefix ? (file.tokens[index].spelling ?? param.name) : resolveSynonym(param.name),
|
|
@@ -1766,7 +1747,6 @@ export const generateSanySpecification = (
|
|
|
1766
1747
|
`Definition of ${existing.name} has different arity than its RECURSIVE declaration.`,
|
|
1767
1748
|
);
|
|
1768
1749
|
}
|
|
1769
|
-
// SANY sets the parameters before it analyzes the body.
|
|
1770
1750
|
existing.params = params;
|
|
1771
1751
|
}
|
|
1772
1752
|
} else if (existing !== undefined) {
|
|
@@ -1871,7 +1851,6 @@ export const generateSanySpecification = (
|
|
|
1871
1851
|
: existing.kind === "OpDef" && (isRecursive || !isPendingRecursive)
|
|
1872
1852
|
? existing
|
|
1873
1853
|
: undefined;
|
|
1874
|
-
// A function whose RECURSIVE declaration has parameters stays undefined.
|
|
1875
1854
|
if (isRecursive) {
|
|
1876
1855
|
if (existing.arity === 0) endOpDefNode(existing, node, location, preComments);
|
|
1877
1856
|
} else if (existing === undefined && definitionNode !== undefined) {
|
|
@@ -1884,7 +1863,6 @@ export const generateSanySpecification = (
|
|
|
1884
1863
|
}
|
|
1885
1864
|
functions.unshift({ name: definition.name, node });
|
|
1886
1865
|
pushLabelScope();
|
|
1887
|
-
// The bound identifiers are bound in the body only of a function with an OpDefNode.
|
|
1888
1866
|
const generateBody = () => generateWithParams(bounds.bounded.flat(), definition.body);
|
|
1889
1867
|
const body =
|
|
1890
1868
|
definitionNode === undefined ? generateBody() : withContext(context, generateBody);
|
|
@@ -1936,8 +1914,6 @@ export const generateSanySpecification = (
|
|
|
1936
1914
|
state.unresolvedSum -= state.unresolvedCount[state.curLevel];
|
|
1937
1915
|
};
|
|
1938
1916
|
|
|
1939
|
-
// Implicit substitutions in the order of the instantiated module's Hashtable, then the explicit
|
|
1940
|
-
// WITH substitutions.
|
|
1941
1917
|
const processSubstitutions = (
|
|
1942
1918
|
instance: Instance,
|
|
1943
1919
|
instanceeContext: Context,
|
|
@@ -1963,7 +1939,6 @@ export const generateSanySpecification = (
|
|
|
1963
1939
|
},
|
|
1964
1940
|
];
|
|
1965
1941
|
});
|
|
1966
|
-
// SANY locates an arity error at its builtins for the nullOpArg it substitutes after an error.
|
|
1967
1942
|
const checkArity = (target: OpDeclNode, substitute: ExprOrOpArgNode) => {
|
|
1968
1943
|
const arity = substitute.kind === "OpArg" ? getSymbolArity(substitute.op) : 0;
|
|
1969
1944
|
if (arity !== target.arity) {
|
|
@@ -1974,12 +1949,11 @@ export const generateSanySpecification = (
|
|
|
1974
1949
|
}
|
|
1975
1950
|
};
|
|
1976
1951
|
const span = getDefinitionSpan(instance);
|
|
1977
|
-
|
|
1952
|
+
let cursor = findToken(file, span.start, span.end, "WITH") + 1;
|
|
1978
1953
|
instance.substitutions.forEach((substitution) => {
|
|
1979
|
-
const targetIndex = findToken(file, cursor
|
|
1980
|
-
// The next target follows this substitution's expression, which may name it too.
|
|
1954
|
+
const targetIndex = findToken(file, cursor, span.end, substitution.name);
|
|
1981
1955
|
if (targetIndex !== -1) {
|
|
1982
|
-
cursor
|
|
1956
|
+
cursor = getExpressionSpan(file, substitution.expression).end + 1;
|
|
1983
1957
|
}
|
|
1984
1958
|
const target = getContextSymbol(instanceeContext, resolveSynonym(substitution.name));
|
|
1985
1959
|
if (target?.kind !== "OpDecl") {
|
|
@@ -2005,7 +1979,6 @@ export const generateSanySpecification = (
|
|
|
2005
1979
|
existing.isImplicit = false;
|
|
2006
1980
|
} else substs.push({ op: target, expr: substitute, isImplicit: false });
|
|
2007
1981
|
});
|
|
2008
|
-
// TLC 1.7.4's SANY checks the arity of only the substitutions that the INSTANCE writes.
|
|
2009
1982
|
substs
|
|
2010
1983
|
.filter((subst) => subst.isImplicit && options.version !== "1.7.4")
|
|
2011
1984
|
.forEach((subst) => checkArity(subst.op, subst.expr));
|
|
@@ -2150,12 +2123,9 @@ export const generateSanySpecification = (
|
|
|
2150
2123
|
preComments,
|
|
2151
2124
|
});
|
|
2152
2125
|
addSymbol(symbolTable, moduleDefinition);
|
|
2153
|
-
// TLC 1.7.4's SANY leaves the definition out of the definitions of a LET.
|
|
2154
2126
|
if (options.version !== "1.7.4") definitions?.push(moduleDefinition);
|
|
2155
2127
|
};
|
|
2156
2128
|
|
|
2157
|
-
// An INSTANCE proof step is located at the step's body and adds no theorem definitions or
|
|
2158
|
-
// instance to the module.
|
|
2159
2129
|
const generateInstance = (
|
|
2160
2130
|
instance: Instance,
|
|
2161
2131
|
isTopLevel = true,
|
|
@@ -2204,8 +2174,6 @@ export const generateSanySpecification = (
|
|
|
2204
2174
|
currentModule.definitions.push(node);
|
|
2205
2175
|
setRecursionFields(node);
|
|
2206
2176
|
});
|
|
2207
|
-
// SANY reuses a theorem of a parameter-free module without adding it to the symbol table when
|
|
2208
|
-
// the instantiated module has parameters.
|
|
2209
2177
|
getHashtableValues(instanceeContext.table).forEach((symbol) => {
|
|
2210
2178
|
if (symbol.kind !== "ThmOrAssumpDef" || symbol.isLocal) return;
|
|
2211
2179
|
const copyFrom = (module: ModuleNode, body: LevelNode) => {
|
|
@@ -2290,15 +2258,12 @@ export const generateSanySpecification = (
|
|
|
2290
2258
|
if (expression.kind === "Apply") return getApplicationKind(expression, span);
|
|
2291
2259
|
return SYNTAX_KINDS.get(expression.kind);
|
|
2292
2260
|
};
|
|
2293
|
-
// Generator.genIdToSelector takes a childless first child for an empty prefix of a name.
|
|
2294
2261
|
const hasChildlessFirstChild = (expression: Expression, span: TokenSpan) => {
|
|
2295
2262
|
if (expression.kind === "String" && !isParenthesized(span)) return false;
|
|
2296
2263
|
if (expression.kind === "Identifier" && !expression.name.includes("!")) return true;
|
|
2297
2264
|
const kind = getSyntaxKind(expression, span);
|
|
2298
2265
|
return kind === undefined || NESTED_FIRST_CHILD_KINDS.has(kind) ? undefined : true;
|
|
2299
2266
|
};
|
|
2300
|
-
// Generator.genIdToSelector reads a DEF entry that isn't a name as one: its first child as the
|
|
2301
|
-
// prefix and its second as the last part.
|
|
2302
2267
|
const getDefEntryParts = (
|
|
2303
2268
|
expression: Expression,
|
|
2304
2269
|
span: TokenSpan,
|
|
@@ -2387,7 +2352,6 @@ export const generateSanySpecification = (
|
|
|
2387
2352
|
}
|
|
2388
2353
|
return undefined;
|
|
2389
2354
|
};
|
|
2390
|
-
// False where SANY's reading of the entry isn't modeled.
|
|
2391
2355
|
const reportDefEntry = (expression: Expression) => {
|
|
2392
2356
|
const span = getParenthesizedSpan(file, getExpressionSpan(file, expression));
|
|
2393
2357
|
const isName =
|
|
@@ -2423,8 +2387,6 @@ export const generateSanySpecification = (
|
|
|
2423
2387
|
false,
|
|
2424
2388
|
true,
|
|
2425
2389
|
);
|
|
2426
|
-
// SANY rejects a proof step name in a DEF clause and leaves out an entry it rejects.
|
|
2427
|
-
// Errors.addMessage drops the message when selectorToNode already reported it.
|
|
2428
2390
|
const isDefinition =
|
|
2429
2391
|
symbol.kind === "OpDef" ||
|
|
2430
2392
|
(symbol.kind === "ThmOrAssumpDef" && !symbol.name.startsWith("<"));
|
|
@@ -2435,7 +2397,6 @@ export const generateSanySpecification = (
|
|
|
2435
2397
|
return [symbol];
|
|
2436
2398
|
});
|
|
2437
2399
|
|
|
2438
|
-
// SANY rejects a BY, USE or HIDE with nothing after its keyword before it reads the facts.
|
|
2439
2400
|
const checkKeywordOnly = (
|
|
2440
2401
|
statement: UseOrHide | Extract<Proof, { kind: "By" }>,
|
|
2441
2402
|
location: SanyLocation,
|
|
@@ -2450,7 +2411,6 @@ export const generateSanySpecification = (
|
|
|
2450
2411
|
const facts = generateFacts(use.facts);
|
|
2451
2412
|
const defs = generateDefs(use.defs);
|
|
2452
2413
|
if (facts.length + defs.length === 0) addError(location, "Empty USE or HIDE statement.");
|
|
2453
|
-
// A HIDE cites facts by name only.
|
|
2454
2414
|
if (use.kind === "Hide") {
|
|
2455
2415
|
facts
|
|
2456
2416
|
.filter((fact) => fact.kind === "OpAppl" && fact.operator.kind !== "ThmOrAssumpDef")
|
|
@@ -2472,7 +2432,6 @@ export const generateSanySpecification = (
|
|
|
2472
2432
|
};
|
|
2473
2433
|
};
|
|
2474
2434
|
|
|
2475
|
-
// SANY generates the set before it declares the symbol.
|
|
2476
2435
|
const generateNewSymbol = (symbol: NewSymbol): NewSymbNode => {
|
|
2477
2436
|
const span = getUnitSpan(symbol.location);
|
|
2478
2437
|
const set = symbol.set && generateExpression(symbol.set);
|
|
@@ -2579,7 +2538,6 @@ export const generateSanySpecification = (
|
|
|
2579
2538
|
return node;
|
|
2580
2539
|
};
|
|
2581
2540
|
|
|
2582
|
-
// SANY numbers the ThmOrAssumpDefNode before it generates what it asserts.
|
|
2583
2541
|
const createTheoremDefinition = (
|
|
2584
2542
|
id: number,
|
|
2585
2543
|
name: string,
|
|
@@ -2684,10 +2642,7 @@ export const generateSanySpecification = (
|
|
|
2684
2642
|
symbolTable.contexts.push(proofContext);
|
|
2685
2643
|
const instances: InstanceNode[] = [];
|
|
2686
2644
|
const sufficesContexts: Context[] = [];
|
|
2687
|
-
|
|
2688
|
-
const infixStep: { previousRight: ExprOrOpArgNode | undefined } = {
|
|
2689
|
-
previousRight: undefined,
|
|
2690
|
-
};
|
|
2645
|
+
let previousRight: ExprOrOpArgNode | undefined;
|
|
2691
2646
|
const generateOtherStep = (
|
|
2692
2647
|
body: ProofStep["body"],
|
|
2693
2648
|
stepSpan: TokenSpan,
|
|
@@ -2733,11 +2688,9 @@ export const generateSanySpecification = (
|
|
|
2733
2688
|
}
|
|
2734
2689
|
if (step.name !== undefined) pushLabelScope();
|
|
2735
2690
|
const definitionId = step.name === undefined ? undefined : getId();
|
|
2736
|
-
if (body.kind !== "Assert")
|
|
2691
|
+
if (body.kind !== "Assert") previousRight = undefined;
|
|
2737
2692
|
const otherStep = generateOtherStep(body, stepSpan, bodySpan);
|
|
2738
2693
|
if (otherStep !== undefined) {
|
|
2739
|
-
// SANY puts a definition for a named step that asserts nothing in the symbol table, for a DEF
|
|
2740
|
-
// clause to name.
|
|
2741
2694
|
if (step.name !== undefined) {
|
|
2742
2695
|
addSymbol(
|
|
2743
2696
|
symbolTable,
|
|
@@ -2753,7 +2706,7 @@ export const generateSanySpecification = (
|
|
|
2753
2706
|
return otherStep;
|
|
2754
2707
|
}
|
|
2755
2708
|
const isAssumeProve = body.kind === "Assert" && body.statement.kind === "AssumeProve";
|
|
2756
|
-
if (isAssumeProve)
|
|
2709
|
+
if (isAssumeProve) previousRight = undefined;
|
|
2757
2710
|
const isSuffices = body.kind === "Assert" && body.isSuffices;
|
|
2758
2711
|
const assumeContext = createContext();
|
|
2759
2712
|
const generateAssertion = (statement: Expression | AssumeProve): LevelNode => {
|
|
@@ -2772,7 +2725,6 @@ export const generateSanySpecification = (
|
|
|
2772
2725
|
const expression = generateExpression(statement);
|
|
2773
2726
|
return applyBuiltin("$Suffices", [expression], getSpanLocation(file, bodySpan));
|
|
2774
2727
|
}
|
|
2775
|
-
const previousRight = infixStep.previousRight;
|
|
2776
2728
|
const isAtStep =
|
|
2777
2729
|
previousRight !== undefined &&
|
|
2778
2730
|
statement.kind === "Apply" &&
|
|
@@ -2788,7 +2740,7 @@ export const generateSanySpecification = (
|
|
|
2788
2740
|
)
|
|
2789
2741
|
: generateExpression(statement);
|
|
2790
2742
|
const right = expression.kind === "OpAppl" ? expression.operands[1] : undefined;
|
|
2791
|
-
|
|
2743
|
+
previousRight = isInfixExpression(statement) ? right : undefined;
|
|
2792
2744
|
return expression;
|
|
2793
2745
|
};
|
|
2794
2746
|
const generated =
|
|
@@ -2919,8 +2871,6 @@ export const generateSanySpecification = (
|
|
|
2919
2871
|
|
|
2920
2872
|
const createDeclaration = (declaration: Declaration, declKind: number): OpDeclNode => {
|
|
2921
2873
|
const span = getDeclarationSpan(declaration);
|
|
2922
|
-
// Generator.processParameters makes this check of a constant too, of its syntax node's name,
|
|
2923
|
-
// which is never @.
|
|
2924
2874
|
if (declaration.name === "@" && declKind === VARIABLE_DECL_KIND) {
|
|
2925
2875
|
addError(getSpanLocation(file, span), "Attempted to declare '@' as a variable.");
|
|
2926
2876
|
}
|
|
@@ -2943,8 +2893,6 @@ export const generateSanySpecification = (
|
|
|
2943
2893
|
return node;
|
|
2944
2894
|
};
|
|
2945
2895
|
|
|
2946
|
-
// The extended module's symbols join in the order they joined it, apart from LOCAL ones and
|
|
2947
|
-
// those already present.
|
|
2948
2896
|
ast.extends.forEach((name) => {
|
|
2949
2897
|
const extendee = getModule(name);
|
|
2950
2898
|
currentModule.extendees.push(extendee);
|
|
@@ -3047,10 +2995,9 @@ export const generateSanySpecification = (
|
|
|
3047
2995
|
const modules = order.map((name) => {
|
|
3048
2996
|
options.onAnalyze?.(name);
|
|
3049
2997
|
// Each module's Generator creates its nullODN, nullOAN, nullOpArg and nullLabelNode.
|
|
3050
|
-
|
|
2998
|
+
nullApplicationId = Array.from({ length: 4 }, getId)[1];
|
|
3051
2999
|
const entry = getSource(name, undefined);
|
|
3052
3000
|
const context = createContext();
|
|
3053
|
-
// SANY's global context lists its builtins from the last to the first.
|
|
3054
3001
|
builtins.toReversed().forEach((builtin) => addToContext(context, builtin));
|
|
3055
3002
|
const module = generateModule(entry.module, entry.file, undefined, {
|
|
3056
3003
|
contexts: [context],
|