tla-ts 0.0.3-dev.07eab97 → 0.0.3-dev.0e500e5
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 +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +13 -13
- package/dist/run-cli.js +22 -22
- package/dist/transfer.cjs +24 -14
- package/dist/transfer.js +24 -14
- package/package.json +1 -1
- package/src/ast.ts +20 -3
- package/src/environment.ts +135 -45
- package/src/errors.ts +25 -3
- package/src/levels.ts +30 -26
- package/src/parser.ts +95 -34
- package/src/resolve.ts +844 -383
- package/src/run-cli.ts +5 -2
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/standard-ranges.ts +116 -0
- package/src/subexpressions.ts +25 -13
package/package.json
CHANGED
package/src/ast.ts
CHANGED
|
@@ -33,9 +33,12 @@ export interface StringExpression {
|
|
|
33
33
|
location: SourceLocation;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// selectorRanges holds the range of each part of a name such as foo!lab, where SANY reports an
|
|
37
|
+
// error in selecting that part.
|
|
36
38
|
export interface IdentifierExpression {
|
|
37
39
|
kind: "Identifier";
|
|
38
40
|
name: string;
|
|
41
|
+
selectorRanges?: SourceRange[];
|
|
39
42
|
location: SourceLocation;
|
|
40
43
|
resolution?: LocalResolution;
|
|
41
44
|
}
|
|
@@ -49,6 +52,7 @@ export interface ApplyExpression {
|
|
|
49
52
|
argumentCounts?: number[];
|
|
50
53
|
// The range of the parenthesized arguments of a named operator, where SANY reports their count.
|
|
51
54
|
argumentsRange?: SourceRange;
|
|
55
|
+
selectorRanges?: SourceRange[];
|
|
52
56
|
location: SourceLocation;
|
|
53
57
|
resolution?: LocalResolution;
|
|
54
58
|
}
|
|
@@ -62,6 +66,7 @@ export interface OperatorReferenceExpression {
|
|
|
62
66
|
export interface LambdaExpression {
|
|
63
67
|
kind: "Lambda";
|
|
64
68
|
params: string[];
|
|
69
|
+
paramRanges?: SourceRange[];
|
|
65
70
|
body: Expression;
|
|
66
71
|
location: SourceLocation;
|
|
67
72
|
}
|
|
@@ -119,7 +124,10 @@ export interface LetExpression {
|
|
|
119
124
|
location: SourceLocation;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
|
-
|
|
127
|
+
// ranges holds the range of each name the pattern binds.
|
|
128
|
+
export type BoundPattern =
|
|
129
|
+
| { kind: "Name"; name: string; ranges?: SourceRange[] }
|
|
130
|
+
| { kind: "Tuple"; names: string[]; ranges?: SourceRange[] };
|
|
123
131
|
|
|
124
132
|
export interface Bound {
|
|
125
133
|
pattern: BoundPattern;
|
|
@@ -137,6 +145,7 @@ export interface UnboundedQuantifierExpression {
|
|
|
137
145
|
kind: "UnboundedQuantifier";
|
|
138
146
|
quantifier: "Forall" | "Exists";
|
|
139
147
|
names: string[];
|
|
148
|
+
nameRanges?: SourceRange[];
|
|
140
149
|
isTemporal?: boolean;
|
|
141
150
|
body: Expression;
|
|
142
151
|
location: SourceLocation;
|
|
@@ -283,6 +292,7 @@ export type Selector =
|
|
|
283
292
|
export interface SubexpressionExpression {
|
|
284
293
|
kind: "Subexpression";
|
|
285
294
|
selectors: Selector[];
|
|
295
|
+
selectorRanges?: SourceRange[];
|
|
286
296
|
location: SourceLocation;
|
|
287
297
|
}
|
|
288
298
|
|
|
@@ -387,6 +397,7 @@ export interface NewSymbol {
|
|
|
387
397
|
arity: number;
|
|
388
398
|
level: "Constant" | "Variable" | "State" | "Action" | "Temporal";
|
|
389
399
|
set: Expression | undefined;
|
|
400
|
+
nameRange?: SourceRange;
|
|
390
401
|
location: SourceLocation;
|
|
391
402
|
}
|
|
392
403
|
|
|
@@ -438,9 +449,15 @@ export type StepBody =
|
|
|
438
449
|
| Instance
|
|
439
450
|
| DefineStep
|
|
440
451
|
| { kind: "Have"; expression: Expression }
|
|
441
|
-
| { kind: "Take"; names: string[]; bounds: Bound[] }
|
|
452
|
+
| { kind: "Take"; names: string[]; nameRanges?: SourceRange[]; bounds: Bound[] }
|
|
442
453
|
| { kind: "Witness"; expressions: Expression[] }
|
|
443
|
-
| {
|
|
454
|
+
| {
|
|
455
|
+
kind: "Pick";
|
|
456
|
+
names: string[];
|
|
457
|
+
nameRanges?: SourceRange[];
|
|
458
|
+
bounds: Bound[];
|
|
459
|
+
body: Expression;
|
|
460
|
+
}
|
|
444
461
|
| { kind: "Case"; expression: Expression }
|
|
445
462
|
| { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
|
|
446
463
|
| { kind: "Qed" };
|
package/src/environment.ts
CHANGED
|
@@ -14,10 +14,13 @@ import type { ConfigValue, ModelConfig } from "./config";
|
|
|
14
14
|
import type { FileSystem } from "./json";
|
|
15
15
|
import {
|
|
16
16
|
createSanyError,
|
|
17
|
+
formatRange,
|
|
18
|
+
formatSanyWarnings,
|
|
17
19
|
TlaConfigError,
|
|
18
20
|
TlaEvaluationError,
|
|
19
21
|
TlaModuleError,
|
|
20
22
|
TlaSyntaxError,
|
|
23
|
+
type SanyError,
|
|
21
24
|
} from "./errors";
|
|
22
25
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
23
26
|
import {
|
|
@@ -38,18 +41,24 @@ import {
|
|
|
38
41
|
import { overrideDefinitions } from "./java-overrides";
|
|
39
42
|
import { extractModule, parseModule } from "./parser";
|
|
40
43
|
import {
|
|
41
|
-
checkRedefinitions,
|
|
42
44
|
getArity,
|
|
43
45
|
isBefore,
|
|
46
|
+
isTheoremDefinition,
|
|
44
47
|
KEY_SEPARATOR,
|
|
45
48
|
LOCAL_RESOLUTION,
|
|
49
|
+
MODULE_START,
|
|
46
50
|
resolveModule,
|
|
47
51
|
resolveSubstitutions,
|
|
52
|
+
type ModuleReport,
|
|
48
53
|
type ModuleSymbol,
|
|
54
|
+
type ModuleUnit,
|
|
55
|
+
type SymbolKind,
|
|
49
56
|
type Symbols,
|
|
50
57
|
} from "./resolve";
|
|
51
58
|
import { createRuntime } from "./runtime";
|
|
59
|
+
import { parseModuleFile } from "./sany-parse-error";
|
|
52
60
|
import { CORE_OPERATORS, getStandardModule, STANDARD_DEPENDENCIES } from "./standard-modules";
|
|
61
|
+
import { getStandardRange } from "./standard-ranges";
|
|
53
62
|
import { resolveInstanceSubexpressions, resolveModuleSubexpressions } from "./subexpressions";
|
|
54
63
|
import { checkModuleLevels, createLevelAnalyzer } from "./levels";
|
|
55
64
|
import { createInstanceChecker, type InstanceCheck } from "./substitution-levels";
|
|
@@ -131,6 +140,22 @@ const createModuleRedefinedError = (module: Module) =>
|
|
|
131
140
|
`Multiply-defined module '${module.name}' at line ${module.location.line}, column ${module.location.column}`,
|
|
132
141
|
);
|
|
133
142
|
|
|
143
|
+
const getModuleRedefinition = (module: Module, existing: Module): SanyError | undefined =>
|
|
144
|
+
module.location.range &&
|
|
145
|
+
existing.location.range && {
|
|
146
|
+
location: formatRange(module.location.range),
|
|
147
|
+
message: `Multiply-defined module '${module.name}': this definition or declaration conflicts \nwith the one at ${formatRange(existing.location.range)}.`,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Context.kindOfNode names a definition or a parameter a definition, and any other symbol a
|
|
151
|
+
// declaration.
|
|
152
|
+
const getNodeWord = (kind: SymbolKind) =>
|
|
153
|
+
["Builtin", "Definition", "Instance", "Parameter"].includes(kind) ? "definition" : "declaration";
|
|
154
|
+
|
|
155
|
+
// The Java class of the node SANY binds a symbol to.
|
|
156
|
+
const getNodeClass = (kind: SymbolKind) =>
|
|
157
|
+
kind === "Theorem" ? "ThmOrAssumpDefNode" : getNodeWord(kind);
|
|
158
|
+
|
|
134
159
|
const createLocalFunction = (definition: Definition, key: string): Definition => ({
|
|
135
160
|
kind: "Operator",
|
|
136
161
|
name: key,
|
|
@@ -245,6 +270,8 @@ export const createEnvironment = (
|
|
|
245
270
|
const copyCount = { value: 0 };
|
|
246
271
|
const createName = (name: string) => `${name}#${copyCount.value++}`;
|
|
247
272
|
const instanceChecks: InstanceCheck[] = [];
|
|
273
|
+
// The warnings SANY reports for the spec.
|
|
274
|
+
const warnings: SanyError[] = [];
|
|
248
275
|
const checkInstance = createInstanceChecker((name) => {
|
|
249
276
|
const linked = checkedModules.get(name) ?? getLinkedModule(name, name);
|
|
250
277
|
return {
|
|
@@ -276,7 +303,12 @@ export const createEnvironment = (
|
|
|
276
303
|
);
|
|
277
304
|
standardModule.operators.forEach((operator) => {
|
|
278
305
|
builtins.set(operator.name, operator);
|
|
279
|
-
exported.set(operator.name, {
|
|
306
|
+
exported.set(operator.name, {
|
|
307
|
+
key: operator.name,
|
|
308
|
+
arity: operator.arity,
|
|
309
|
+
kind: "Definition",
|
|
310
|
+
range: getStandardRange(name, operator.name) ?? exported.get(operator.name)?.range,
|
|
311
|
+
});
|
|
280
312
|
});
|
|
281
313
|
standardExports.set(name, exported);
|
|
282
314
|
return exported;
|
|
@@ -326,7 +358,7 @@ export const createEnvironment = (
|
|
|
326
358
|
],
|
|
327
359
|
true,
|
|
328
360
|
);
|
|
329
|
-
const module =
|
|
361
|
+
const module = parseModuleFile(source, name);
|
|
330
362
|
if (module.name !== name) {
|
|
331
363
|
throw createSanyError(
|
|
332
364
|
[
|
|
@@ -362,6 +394,9 @@ export const createEnvironment = (
|
|
|
362
394
|
loading.pop();
|
|
363
395
|
linking.pop();
|
|
364
396
|
const duplicate = nested.find((module) => closure.has(module.name));
|
|
397
|
+
const loaded = duplicate && linkedModules.get(duplicate.name);
|
|
398
|
+
const redefinition = loaded && getModuleRedefinition(duplicate, loaded.module);
|
|
399
|
+
if (redefinition) throw createSanyError([redefinition], false, undefined, warnings);
|
|
365
400
|
if (duplicate) throw createModuleRedefinedError(duplicate);
|
|
366
401
|
return { linked, closure };
|
|
367
402
|
};
|
|
@@ -382,12 +417,7 @@ export const createEnvironment = (
|
|
|
382
417
|
const instantiate = (
|
|
383
418
|
instance: Instance,
|
|
384
419
|
module: Module,
|
|
385
|
-
unit:
|
|
386
|
-
imported: Symbols;
|
|
387
|
-
importedAt: Map<string, SourceLocation>;
|
|
388
|
-
definitions: Map<string, Definition>;
|
|
389
|
-
getKey: (definition: Definition) => string;
|
|
390
|
-
},
|
|
420
|
+
unit: ModuleUnit,
|
|
391
421
|
isParameterFree: boolean,
|
|
392
422
|
nested: LinkedModule | undefined,
|
|
393
423
|
): Symbols => {
|
|
@@ -395,7 +425,10 @@ export const createEnvironment = (
|
|
|
395
425
|
if (standardSymbols) {
|
|
396
426
|
if (instance.name === undefined) return standardSymbols;
|
|
397
427
|
return new Map(
|
|
398
|
-
[...standardSymbols].map(([name, symbol]) => [
|
|
428
|
+
[...standardSymbols].map(([name, symbol]) => [
|
|
429
|
+
`${instance.name}!${name}`,
|
|
430
|
+
{ key: symbol.key, arity: symbol.arity, kind: symbol.kind },
|
|
431
|
+
]),
|
|
399
432
|
);
|
|
400
433
|
}
|
|
401
434
|
const linked = nested ?? getLinkedModule(instance.module, module.name);
|
|
@@ -440,7 +473,13 @@ export const createEnvironment = (
|
|
|
440
473
|
const key = instantiation.getKey(symbol.key);
|
|
441
474
|
if (declarations.length > 0)
|
|
442
475
|
instanceActions.set(key, { name, location: instance.location });
|
|
443
|
-
|
|
476
|
+
// SANY binds a copy of a definition that depends on the parameters at the INSTANCE.
|
|
477
|
+
symbols.set(name, {
|
|
478
|
+
key,
|
|
479
|
+
arity: symbol.arity,
|
|
480
|
+
kind: symbol.kind,
|
|
481
|
+
range: parameterized.get(symbol.key) === true ? instance.location.range : symbol.range,
|
|
482
|
+
});
|
|
444
483
|
return;
|
|
445
484
|
}
|
|
446
485
|
const key = instantiation.getQualifiedKey(symbol.key);
|
|
@@ -451,6 +490,7 @@ export const createEnvironment = (
|
|
|
451
490
|
symbols.set(`${instance.name}!${name}`, {
|
|
452
491
|
key,
|
|
453
492
|
arity: symbol.arity + instance.params.length,
|
|
493
|
+
kind: symbol.kind,
|
|
454
494
|
});
|
|
455
495
|
});
|
|
456
496
|
return symbols;
|
|
@@ -632,26 +672,54 @@ export const createEnvironment = (
|
|
|
632
672
|
const visible: Symbols = new Map([
|
|
633
673
|
...CORE_OPERATORS.map((operator): [string, ModuleSymbol] => [
|
|
634
674
|
operator.name,
|
|
635
|
-
{ key: operator.name, arity: operator.arity },
|
|
675
|
+
{ key: operator.name, arity: operator.arity, kind: "Builtin" },
|
|
636
676
|
]),
|
|
637
677
|
...scope.symbols,
|
|
638
678
|
]);
|
|
679
|
+
const extendsReport: ModuleReport = { location: MODULE_START, errors: [], warnings: [] };
|
|
680
|
+
const reports = [extendsReport];
|
|
681
|
+
// Context.mergeExtendContext keeps the first of the symbols the extended modules share by name,
|
|
682
|
+
// and warns of two definitions or two declarations but rejects a definition and a declaration.
|
|
683
|
+
const mergeExtended = (symbols: Symbols) =>
|
|
684
|
+
symbols.forEach((symbol, name) => {
|
|
685
|
+
const current = exported.get(name);
|
|
686
|
+
if (!current) {
|
|
687
|
+
visible.set(name, symbol);
|
|
688
|
+
exported.set(name, symbol);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (
|
|
692
|
+
!current.range ||
|
|
693
|
+
!symbol.range ||
|
|
694
|
+
formatRange(current.range) === formatRange(symbol.range)
|
|
695
|
+
) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const location = formatRange(symbol.range);
|
|
699
|
+
const existing = formatRange(current.range);
|
|
700
|
+
if (getNodeClass(current.kind) === getNodeClass(symbol.kind)) {
|
|
701
|
+
extendsReport.warnings.push({
|
|
702
|
+
location,
|
|
703
|
+
message: `Warning: the ${getNodeWord(current.kind)} of '${name}' conflicts with \nits ${getNodeWord(current.kind)} at ${existing}.`,
|
|
704
|
+
});
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
extendsReport.errors.push({
|
|
708
|
+
location,
|
|
709
|
+
message: `The ${getNodeWord(symbol.kind)} of '${name}' conflicts with \nits ${getNodeWord(current.kind)} at ${existing}.`,
|
|
710
|
+
});
|
|
711
|
+
});
|
|
639
712
|
const exported: Symbols = new Map();
|
|
640
713
|
const modules = new Map<string, LinkedModule>();
|
|
641
714
|
const extended: LinkedModule[] = [];
|
|
642
715
|
const constants = [...parsed.constants];
|
|
643
716
|
const variables = parsed.variables.map((variable) => variable.name);
|
|
644
717
|
const variableLocations = parsed.variables.map((variable) => variable.location);
|
|
645
|
-
const addSymbols = (symbols: Symbols, isExported: boolean) =>
|
|
646
|
-
symbols.forEach((symbol, name) => {
|
|
647
|
-
visible.set(name, symbol);
|
|
648
|
-
if (isExported) exported.set(name, symbol);
|
|
649
|
-
});
|
|
650
718
|
parsed.extends.forEach((name) => {
|
|
651
719
|
const nested = scope.modules.get(name);
|
|
652
720
|
const standardSymbols = nested ? undefined : getStandardSymbols(name);
|
|
653
721
|
if (standardSymbols) {
|
|
654
|
-
|
|
722
|
+
mergeExtended(standardSymbols);
|
|
655
723
|
return;
|
|
656
724
|
}
|
|
657
725
|
const linked = nested ?? getLinkedModule(name, parsed.name);
|
|
@@ -665,53 +733,72 @@ export const createEnvironment = (
|
|
|
665
733
|
variables.push(variable);
|
|
666
734
|
variableLocations.push(linked.variableLocations[index]);
|
|
667
735
|
});
|
|
668
|
-
|
|
736
|
+
mergeExtended(linked.exported);
|
|
669
737
|
linked.modules.forEach((module, moduleName) => modules.set(moduleName, module));
|
|
670
738
|
extended.push(linked);
|
|
671
739
|
});
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
740
|
+
const bound = new Map(visible);
|
|
741
|
+
const declarations = [
|
|
742
|
+
...parsed.constants.map((constant) => ({ ...constant, kind: "Constant" as const })),
|
|
743
|
+
...parsed.variables.map((variable) => ({ ...variable, kind: "Variable" as const })),
|
|
744
|
+
];
|
|
745
|
+
const getDeclarationSymbol = (declaration: (typeof declarations)[number]): ModuleSymbol => ({
|
|
746
|
+
key: declaration.name,
|
|
747
|
+
arity: declaration.arity,
|
|
748
|
+
kind: declaration.kind,
|
|
749
|
+
range: declaration.location.range,
|
|
750
|
+
});
|
|
751
|
+
declarations.forEach((declaration) =>
|
|
752
|
+
exported.set(declaration.name, getDeclarationSymbol(declaration)),
|
|
681
753
|
);
|
|
754
|
+
const getDefinitionSymbol = (definition: Definition): ModuleSymbol => ({
|
|
755
|
+
key: getKey(definition),
|
|
756
|
+
arity: getArity(definition),
|
|
757
|
+
kind: isTheoremDefinition(parsed, definition) ? "Theorem" : "Definition",
|
|
758
|
+
range: definition.location.range,
|
|
759
|
+
});
|
|
682
760
|
const isParameterFree = constants.length === 0 && variables.length === 0;
|
|
683
761
|
const getKey = (definition: Definition) =>
|
|
684
762
|
parsed === root ? definition.name : `${definition.name}${KEY_SEPARATOR}${scope.id}`;
|
|
685
|
-
const
|
|
686
|
-
const getUnit = (module: Module) => ({
|
|
763
|
+
const instanced = new Map<Instance, Symbols>();
|
|
764
|
+
const getUnit = (module: Module): ModuleUnit => ({
|
|
687
765
|
imported: visible,
|
|
688
|
-
|
|
689
|
-
|
|
766
|
+
bound,
|
|
767
|
+
// SANY keeps the first of two definitions of a name.
|
|
768
|
+
definitions: new Map(
|
|
769
|
+
module.definitions.toReversed().map((definition) => [definition.name, definition]),
|
|
770
|
+
),
|
|
690
771
|
getKey,
|
|
772
|
+
instanced,
|
|
773
|
+
reports,
|
|
774
|
+
warnings,
|
|
691
775
|
});
|
|
692
776
|
const getVisibleModules = () => new Map([...scope.modules, ...modules]);
|
|
693
777
|
const getSymbolsBefore = (location: SourceLocation): Symbols =>
|
|
694
778
|
new Map([
|
|
695
779
|
...visible,
|
|
696
|
-
...
|
|
697
|
-
...parsed.constants.map((constant) => ({ ...constant, kind: "Constant" as const })),
|
|
698
|
-
...parsed.variables.map((variable) => ({ ...variable, kind: "Variable" as const })),
|
|
699
|
-
]
|
|
780
|
+
...declarations
|
|
700
781
|
.filter((declaration) => isBefore(declaration.location, location))
|
|
701
782
|
.map((declaration): [string, ModuleSymbol] => [
|
|
702
783
|
declaration.name,
|
|
703
|
-
|
|
784
|
+
getDeclarationSymbol(declaration),
|
|
704
785
|
]),
|
|
705
786
|
...parsed.definitions
|
|
706
787
|
.filter((definition) => isBefore(definition.location, location))
|
|
707
788
|
.map((definition): [string, ModuleSymbol] => [
|
|
708
789
|
definition.name,
|
|
709
|
-
|
|
790
|
+
getDefinitionSymbol(definition),
|
|
710
791
|
]),
|
|
711
792
|
]);
|
|
712
793
|
const linkNested = (nested: Module) => {
|
|
713
794
|
const visibleModules = getVisibleModules();
|
|
714
|
-
|
|
795
|
+
const existing = visibleModules.get(nested.name);
|
|
796
|
+
const redefinition = existing && getModuleRedefinition(nested, existing.module);
|
|
797
|
+
if (redefinition) {
|
|
798
|
+
reports.push({ location: nested.location, errors: [redefinition], warnings: [] });
|
|
799
|
+
} else if (existing) {
|
|
800
|
+
throw createModuleRedefinedError(nested);
|
|
801
|
+
}
|
|
715
802
|
scope.nested.push(nested);
|
|
716
803
|
const linked = linkModule(nested, {
|
|
717
804
|
id: `${scope.id}/${nested.name}`,
|
|
@@ -719,7 +806,7 @@ export const createEnvironment = (
|
|
|
719
806
|
modules: visibleModules,
|
|
720
807
|
nested: scope.nested,
|
|
721
808
|
});
|
|
722
|
-
modules.set(nested.name, linked);
|
|
809
|
+
if (!existing) modules.set(nested.name, linked);
|
|
723
810
|
if (!nestedModules.has(nested.name)) nestedModules.set(nested.name, linked);
|
|
724
811
|
};
|
|
725
812
|
[
|
|
@@ -733,10 +820,12 @@ export const createEnvironment = (
|
|
|
733
820
|
isParameterFree,
|
|
734
821
|
getVisibleModules().get(instance.module),
|
|
735
822
|
);
|
|
736
|
-
|
|
737
|
-
|
|
823
|
+
instanced.set(instance, symbols);
|
|
824
|
+
symbols.forEach((symbol, name) => {
|
|
825
|
+
if (visible.has(name)) return;
|
|
826
|
+
visible.set(name, symbol);
|
|
827
|
+
if (!instance.isLocal) exported.set(name, symbol);
|
|
738
828
|
});
|
|
739
|
-
addSymbols(symbols, !instance.isLocal);
|
|
740
829
|
},
|
|
741
830
|
})),
|
|
742
831
|
...parsed.modules.map((nested) => ({
|
|
@@ -746,7 +835,6 @@ export const createEnvironment = (
|
|
|
746
835
|
]
|
|
747
836
|
.sort((left, right) => (isBefore(left.location, right.location) ? -1 : 1))
|
|
748
837
|
.forEach((unit) => unit.link());
|
|
749
|
-
checkRedefinitions(parsed, getUnit(parsed));
|
|
750
838
|
const isInstancedAfterDefinition = (nested: Module) => {
|
|
751
839
|
const first = parsed.instances.find((instance) => instance.module === nested.name);
|
|
752
840
|
return first !== undefined && isBefore(nested.location, first.location);
|
|
@@ -767,7 +855,7 @@ export const createEnvironment = (
|
|
|
767
855
|
const key = getKey(definition);
|
|
768
856
|
definitions.set(key, definition);
|
|
769
857
|
parameterized.set(key, !isParameterFree);
|
|
770
|
-
const symbol =
|
|
858
|
+
const symbol = getDefinitionSymbol(definition);
|
|
771
859
|
visible.set(definition.name, symbol);
|
|
772
860
|
if (!definition.isLocal) exported.set(definition.name, symbol);
|
|
773
861
|
});
|
|
@@ -795,12 +883,14 @@ export const createEnvironment = (
|
|
|
795
883
|
instanceChecks
|
|
796
884
|
.splice(firstCheck)
|
|
797
885
|
.map((check) => ({ location: check.location, check: () => checkInstance(check) })),
|
|
886
|
+
warnings,
|
|
798
887
|
);
|
|
799
888
|
linkedList.push(linked);
|
|
800
889
|
return linked;
|
|
801
890
|
};
|
|
802
891
|
|
|
803
892
|
const linkedRoot = linkTopLevel(root).linked;
|
|
893
|
+
if (warnings.length > 0) options.print(formatSanyWarnings(warnings));
|
|
804
894
|
const getRootKey = (name: string) => linkedRoot.visible.get(name)?.key ?? name;
|
|
805
895
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
806
896
|
const definition = definitions.get(symbol.key);
|
package/src/errors.ts
CHANGED
|
@@ -34,10 +34,14 @@ export interface SanyError {
|
|
|
34
34
|
message: string;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// The errors SANY reports for a spec. A fatal error stops it
|
|
37
|
+
// The errors SANY reports for a spec, and the warnings it prints before them. A fatal error stops it
|
|
38
|
+
// before semantic analysis. SANY's parser prints its message for a module it rejects before the
|
|
39
|
+
// report.
|
|
38
40
|
export interface SanyReport {
|
|
39
41
|
errors: SanyError[];
|
|
42
|
+
warnings: SanyError[];
|
|
40
43
|
isFatal: boolean;
|
|
44
|
+
parseError?: string;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
export class TlaSyntaxError extends TlaError {
|
|
@@ -52,14 +56,32 @@ export class TlaSyntaxError extends TlaError {
|
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
export const createSanyError = (
|
|
59
|
+
export const createSanyError = (
|
|
60
|
+
errors: SanyError[],
|
|
61
|
+
isFatal = false,
|
|
62
|
+
parseError?: string,
|
|
63
|
+
warnings: SanyError[] = [],
|
|
64
|
+
) =>
|
|
56
65
|
new TlaSyntaxError(
|
|
57
66
|
errors.map((error) => `${error.location}\n\n${error.message}`).join("\n\n"),
|
|
58
67
|
undefined,
|
|
59
68
|
undefined,
|
|
60
|
-
{ errors, isFatal },
|
|
69
|
+
{ errors, warnings, isFatal, parseError },
|
|
61
70
|
);
|
|
62
71
|
|
|
72
|
+
// How SANY prints the warnings it reports, which do not stop TLC.
|
|
73
|
+
export const formatSanyWarnings = (warnings: SanyError[]) =>
|
|
74
|
+
`*** Warnings: ${warnings.length}\n\n${warnings.map((warning) => `${warning.location}\n\n${warning.message}\n\n\n`).join("\n")}`;
|
|
75
|
+
|
|
76
|
+
// SANY's message for a module its parser rejects, such as a "***Parse Error***" with the
|
|
77
|
+
// productions it was in.
|
|
78
|
+
export class TlaParseError extends TlaError {
|
|
79
|
+
constructor(message: string) {
|
|
80
|
+
super(message);
|
|
81
|
+
this.name = "TlaParseError";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
63
85
|
export const formatRange = (range: SourceRange) =>
|
|
64
86
|
`line ${range.start.line}, col ${range.start.column} to line ${range.end.line}, col ${range.end.column} of module ${range.module}`;
|
|
65
87
|
|
package/src/levels.ts
CHANGED
|
@@ -885,6 +885,7 @@ export const checkModuleLevels = (
|
|
|
885
885
|
module: Module,
|
|
886
886
|
context: LevelContext,
|
|
887
887
|
instances: { location: SourceLocation; check: () => void }[],
|
|
888
|
+
warnings: SanyError[],
|
|
888
889
|
) => {
|
|
889
890
|
const analyzer = createLevelAnalyzer(context);
|
|
890
891
|
const getLevel = (expressions: Expression[]) =>
|
|
@@ -956,31 +957,34 @@ export const checkModuleLevels = (
|
|
|
956
957
|
...(step.proof?.kind === "Steps" && isTemporal() ? checkTemporalGoal(step.proof) : []),
|
|
957
958
|
];
|
|
958
959
|
});
|
|
959
|
-
collectSemanticErrors(
|
|
960
|
-
|
|
961
|
-
.
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
960
|
+
collectSemanticErrors(
|
|
961
|
+
[
|
|
962
|
+
...module.definitions
|
|
963
|
+
.filter((definition) => !definition.name.includes("!"))
|
|
964
|
+
.map((definition) => ({
|
|
965
|
+
location: definition.location,
|
|
966
|
+
check: () => analyzer.analyzeDefinition(definition, new Map()),
|
|
967
|
+
})),
|
|
968
|
+
...module.assumptions.map((assumption) => ({
|
|
969
|
+
location: assumption.location,
|
|
970
|
+
check: () => analyzer.analyze(assumption.expression, new Map()),
|
|
971
|
+
})),
|
|
972
|
+
...module.theorems.map((theorem) => ({
|
|
973
|
+
location: theorem.location,
|
|
974
|
+
check: () => {
|
|
975
|
+
const data =
|
|
976
|
+
theorem.statement.kind === "AssumeProve"
|
|
977
|
+
? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
|
|
978
|
+
: analyzer.analyze(theorem.statement, new Map());
|
|
979
|
+
const errors = [
|
|
980
|
+
...checkProof(theorem.proof),
|
|
981
|
+
...(data.level === TEMPORAL_LEVEL ? checkTemporalGoal(theorem.proof) : []),
|
|
982
|
+
];
|
|
983
|
+
if (errors.length > 0) throw createSanyError(errors);
|
|
984
|
+
},
|
|
965
985
|
})),
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
...module.theorems.map((theorem) => ({
|
|
971
|
-
location: theorem.location,
|
|
972
|
-
check: () => {
|
|
973
|
-
const data =
|
|
974
|
-
theorem.statement.kind === "AssumeProve"
|
|
975
|
-
? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
|
|
976
|
-
: analyzer.analyze(theorem.statement, new Map());
|
|
977
|
-
const errors = [
|
|
978
|
-
...checkProof(theorem.proof),
|
|
979
|
-
...(data.level === TEMPORAL_LEVEL ? checkTemporalGoal(theorem.proof) : []),
|
|
980
|
-
];
|
|
981
|
-
if (errors.length > 0) throw createSanyError(errors);
|
|
982
|
-
},
|
|
983
|
-
})),
|
|
984
|
-
...instances,
|
|
985
|
-
]);
|
|
986
|
+
...instances,
|
|
987
|
+
],
|
|
988
|
+
warnings,
|
|
989
|
+
);
|
|
986
990
|
};
|