tla-ts 0.0.3-dev.e5b05b9 → 0.0.3-dev.e8bef80
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +150 -48
- package/dist/index.d.ts +150 -48
- 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 +1351 -22
- package/dist/run-cli.js +1352 -23
- package/dist/transfer.cjs +83 -43
- package/dist/transfer.js +83 -43
- package/package.json +5 -1
- package/src/ast.ts +28 -4
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -17
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1317 -428
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -21
- package/src/config.ts +226 -207
- package/src/environment.ts +221 -75
- package/src/errors.ts +130 -15
- package/src/evaluate.ts +713 -259
- package/src/exit-codes.ts +6 -24
- package/src/fingerprints.ts +1 -2
- package/src/index.ts +1 -0
- package/src/instances.ts +3 -1
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +6 -1
- package/src/lexer.ts +122 -29
- package/src/live-check.ts +204 -148
- package/src/liveness.ts +191 -122
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +6 -1
- package/src/parallel.ts +57 -6
- package/src/parser.ts +327 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +252 -87
- package/src/run-cli.ts +1162 -200
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +410 -480
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2033 -3015
- package/src/sany-report.ts +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +25 -5
- package/src/standard-modules.ts +172 -129
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +121 -26
- package/src/successors.ts +141 -173
- package/src/symmetry.ts +168 -50
- package/src/tableau.ts +3 -1
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -21
- package/src/tlc-modules.ts +0 -4
- package/src/tlc-order.ts +55 -9
- package/src/tlc-random.ts +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +664 -317
package/src/environment.ts
CHANGED
|
@@ -14,11 +14,11 @@ import type { ConfigValue, ModelConfig } from "./config";
|
|
|
14
14
|
import type { FileSystem } from "./json";
|
|
15
15
|
import {
|
|
16
16
|
createSanyError,
|
|
17
|
+
createMissingModuleError,
|
|
17
18
|
formatRange,
|
|
18
19
|
formatSanyWarnings,
|
|
19
20
|
TlaConfigError,
|
|
20
21
|
TlaEvaluationError,
|
|
21
|
-
TlaModuleError,
|
|
22
22
|
TlaSyntaxError,
|
|
23
23
|
type SanyError,
|
|
24
24
|
} from "./errors";
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
renameLocals,
|
|
39
39
|
withLetInstances,
|
|
40
40
|
} from "./instances";
|
|
41
|
-
import { overrideDefinitions } from "./java-overrides";
|
|
41
|
+
import { overrideDefinitions, type JavaOverride } from "./java-overrides";
|
|
42
42
|
import { extractModule, parseModule } from "./parser";
|
|
43
43
|
import {
|
|
44
44
|
getArity,
|
|
@@ -57,14 +57,20 @@ import {
|
|
|
57
57
|
type Symbols,
|
|
58
58
|
} from "./resolve";
|
|
59
59
|
import { createRuntime } from "./runtime";
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
60
|
+
import { getSanyParseError } from "./sany-parse-error";
|
|
61
|
+
import {
|
|
62
|
+
CORE_OPERATORS,
|
|
63
|
+
getStandardModule,
|
|
64
|
+
getTraceSpecArithmetic,
|
|
65
|
+
STANDARD_DEPENDENCIES,
|
|
66
|
+
} from "./standard-modules";
|
|
62
67
|
import { STANDARD_LEVELS } from "./standard-levels";
|
|
63
68
|
import { getStandardRange } from "./standard-ranges";
|
|
64
69
|
import { resolveInstanceSubexpressions, resolveModuleSubexpressions } from "./subexpressions";
|
|
65
70
|
import { checkModuleLevels, createLevelAnalyzer } from "./levels";
|
|
66
71
|
import { createInstanceChecker, type InstanceCheck } from "./substitution-levels";
|
|
67
|
-
import {
|
|
72
|
+
import { isEvalException } from "./tlc-messages";
|
|
73
|
+
import { createTlcDefinitionOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
68
74
|
import {
|
|
69
75
|
checkInteger,
|
|
70
76
|
createModelValue,
|
|
@@ -72,7 +78,9 @@ import {
|
|
|
72
78
|
formatValue,
|
|
73
79
|
valuesEqual,
|
|
74
80
|
type Value,
|
|
81
|
+
markNormalized,
|
|
75
82
|
} from "./values";
|
|
83
|
+
import type { TlcVersion } from "./tlc-version";
|
|
76
84
|
|
|
77
85
|
interface EnvironmentOptions {
|
|
78
86
|
source: string;
|
|
@@ -81,6 +89,15 @@ interface EnvironmentOptions {
|
|
|
81
89
|
print: (text: string) => void;
|
|
82
90
|
files: FileSystem;
|
|
83
91
|
seed?: bigint;
|
|
92
|
+
// Links the modules without a model, as SANY does, so a declared constant needs no value.
|
|
93
|
+
isUnconfigured?: boolean;
|
|
94
|
+
isTool?: boolean;
|
|
95
|
+
// TLC loads Integers for the binary trace of its trace exploration spec, and Integers' Java
|
|
96
|
+
// methods then compute the arithmetic of Naturals.
|
|
97
|
+
isTraceRecorded?: boolean;
|
|
98
|
+
isSanyReported?: boolean;
|
|
99
|
+
isWarningEnabled?: boolean;
|
|
100
|
+
version?: TlcVersion;
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
interface Specification {
|
|
@@ -88,6 +105,12 @@ interface Specification {
|
|
|
88
105
|
assumptions: Assumption[];
|
|
89
106
|
variableLocations: SourceLocation[];
|
|
90
107
|
instanceActions: Map<string, InstanceAction>;
|
|
108
|
+
// The definitions TLC computes when it starts, in the order it computes them.
|
|
109
|
+
startupDefinitions: Definition[];
|
|
110
|
+
rootConstants: Declaration[];
|
|
111
|
+
rootSymbols: Symbols;
|
|
112
|
+
// The methods of the modules' classes, in the order TLC loads the classes.
|
|
113
|
+
javaOverrides: JavaOverride[];
|
|
91
114
|
}
|
|
92
115
|
|
|
93
116
|
export interface InstanceAction {
|
|
@@ -147,6 +170,28 @@ const getDeclarations = (linked: LinkedModule): Declaration[] => [
|
|
|
147
170
|
})),
|
|
148
171
|
];
|
|
149
172
|
|
|
173
|
+
// Parses the module SANY reads from the file name.tla. A module SANY's parser rejects fails as it
|
|
174
|
+
// does in TLC: SANY's message, then a fatal error that names the module.
|
|
175
|
+
const parseModuleFile = (source: string, name: string) => {
|
|
176
|
+
try {
|
|
177
|
+
return parseModule(source);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (!(error instanceof TlaSyntaxError)) throw error;
|
|
180
|
+
const parseError = getSanyParseError(source);
|
|
181
|
+
if (parseError === undefined) throw error;
|
|
182
|
+
throw createSanyError(
|
|
183
|
+
[
|
|
184
|
+
{
|
|
185
|
+
location: `In module ${name}`,
|
|
186
|
+
message: `Could not parse module ${name} from file ${name}.tla`,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
true,
|
|
190
|
+
parseError,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
150
195
|
const createModuleRedefinedError = (module: Module) =>
|
|
151
196
|
new TlaSyntaxError(
|
|
152
197
|
`Multiply-defined module '${module.name}' at line ${module.location.line}, column ${module.location.column}`,
|
|
@@ -259,11 +304,15 @@ export const createEnvironment = (
|
|
|
259
304
|
const parameterized = new Map<string, boolean>();
|
|
260
305
|
// The definition each instance copy came from, and the instance parameters the copy adds.
|
|
261
306
|
const copySources = new Map<string, { source: string; prefix: number }>();
|
|
307
|
+
const substitutedDefinitions = new Set<Definition>();
|
|
262
308
|
const builtins = new Map<string, Builtin>(
|
|
263
309
|
CORE_OPERATORS.map((operator) => [operator.name, operator]),
|
|
264
310
|
);
|
|
265
311
|
const standardExports = new Map<string, Symbols>();
|
|
266
312
|
const runtime = createRuntime(config.checkDeadlock, options.seed);
|
|
313
|
+
runtime.isWarningEnabled = options.isWarningEnabled ?? true;
|
|
314
|
+
runtime.isTool = options.isTool ?? false;
|
|
315
|
+
runtime.version = options.version ?? "master";
|
|
267
316
|
const linkedModules = new Map<string, LinkedModule>();
|
|
268
317
|
const nestedModules = new Map<string, LinkedModule>();
|
|
269
318
|
// Each module by name, from the time its level checks run.
|
|
@@ -300,13 +349,17 @@ export const createEnvironment = (
|
|
|
300
349
|
};
|
|
301
350
|
});
|
|
302
351
|
const instanceActions = new Map<string, InstanceAction>();
|
|
352
|
+
const instanceNames = new Map<string, string>();
|
|
303
353
|
const qualifiedNames = new Map<string, string>();
|
|
304
354
|
|
|
305
355
|
const addStandardModule = (name: string): Symbols | undefined => {
|
|
306
356
|
const cached = standardExports.get(name);
|
|
307
357
|
if (cached) return cached;
|
|
308
|
-
const standardModule = getStandardModule(name, options.print, runtime, options.files);
|
|
358
|
+
const standardModule = getStandardModule(name, options.print, runtime, options.files, builtins);
|
|
309
359
|
if (!standardModule) return undefined;
|
|
360
|
+
// TLC loads the modules a standard module instantiates too, and the Java methods of each
|
|
361
|
+
// replace the operators of every module, as those of Integers replace those of Naturals.
|
|
362
|
+
STANDARD_DEPENDENCIES.get(name)?.forEach(addStandardModule);
|
|
310
363
|
const exported: Symbols = new Map();
|
|
311
364
|
standardModule.extends.forEach((extended) =>
|
|
312
365
|
addStandardModule(extended)?.forEach((symbol, symbolName) =>
|
|
@@ -361,16 +414,7 @@ export const createEnvironment = (
|
|
|
361
414
|
options.loadModule?.(name) ??
|
|
362
415
|
BUNDLED_MODULES.get(name) ??
|
|
363
416
|
extractModule(options.source, name);
|
|
364
|
-
if (source === undefined)
|
|
365
|
-
throw createSanyError(
|
|
366
|
-
[
|
|
367
|
-
{
|
|
368
|
-
location: `In module ${importer}`,
|
|
369
|
-
message: `Cannot find source file for module ${name} imported in module ${importer}.`,
|
|
370
|
-
},
|
|
371
|
-
],
|
|
372
|
-
true,
|
|
373
|
-
);
|
|
417
|
+
if (source === undefined) throw createMissingModuleError(name, importer);
|
|
374
418
|
const module = parseModuleFile(source, name);
|
|
375
419
|
if (module.name !== name) {
|
|
376
420
|
throw createSanyError(
|
|
@@ -442,15 +486,7 @@ export const createEnvironment = (
|
|
|
442
486
|
nested: LinkedModule | undefined,
|
|
443
487
|
): Symbols => {
|
|
444
488
|
const standardSymbols = nested ? undefined : getStandardSymbols(instance.module);
|
|
445
|
-
if (standardSymbols)
|
|
446
|
-
if (instance.name === undefined) return standardSymbols;
|
|
447
|
-
return new Map(
|
|
448
|
-
[...standardSymbols].map(([name, symbol]) => [
|
|
449
|
-
`${instance.name}!${name}`,
|
|
450
|
-
{ key: symbol.key, arity: symbol.arity, params: symbol.params, kind: symbol.kind },
|
|
451
|
-
]),
|
|
452
|
-
);
|
|
453
|
-
}
|
|
489
|
+
if (standardSymbols) return getStandardInstanceSymbols(instance, standardSymbols);
|
|
454
490
|
const linked = nested ?? getLinkedModule(instance.module, module.name);
|
|
455
491
|
linked.facts.forEach((name) =>
|
|
456
492
|
unit.facts.add(instance.name === undefined ? name : `${instance.name}!${name}`),
|
|
@@ -481,44 +517,81 @@ export const createEnvironment = (
|
|
|
481
517
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
482
518
|
addDefinition: (source, name, create) => {
|
|
483
519
|
const key = createName(`${name}@${module.name}`);
|
|
484
|
-
|
|
520
|
+
const definition = create(key);
|
|
521
|
+
definitions.set(key, definition);
|
|
522
|
+
if (declarations.length > 0) substitutedDefinitions.add(definition);
|
|
523
|
+
if (instance.name !== undefined) {
|
|
524
|
+
instanceNames.set(key, `${instance.name}!${instanceNames.get(source) ?? name}`);
|
|
525
|
+
}
|
|
485
526
|
parameterized.set(key, !isParameterFree);
|
|
486
527
|
copySources.set(key, { source, prefix: instance.params.length });
|
|
487
528
|
return key;
|
|
488
529
|
},
|
|
489
530
|
createName,
|
|
490
531
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
// SANY binds a copy of a definition that depends on the parameters at the INSTANCE.
|
|
500
|
-
symbols.set(name, {
|
|
501
|
-
key,
|
|
502
|
-
arity: symbol.arity,
|
|
503
|
-
params: symbol.params,
|
|
504
|
-
kind: symbol.kind,
|
|
505
|
-
range: parameterized.get(symbol.key) === true ? instance.location.range : symbol.range,
|
|
506
|
-
});
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
const key = instantiation.getQualifiedKey(symbol.key);
|
|
510
|
-
if (declarations.length > 0) {
|
|
511
|
-
instanceActions.set(key, { name: `${instance.name}!${name}`, location: instance.location });
|
|
512
|
-
}
|
|
513
|
-
qualifiedNames.set(key, `${instance.name}!${name}`);
|
|
514
|
-
symbols.set(`${instance.name}!${name}`, {
|
|
515
|
-
key,
|
|
516
|
-
arity: symbol.arity + instance.params.length,
|
|
517
|
-
params: symbol.params && [...instance.params.map((param) => param.arity), ...symbol.params],
|
|
518
|
-
kind: symbol.kind,
|
|
519
|
-
});
|
|
532
|
+
return getInstanceSymbols(instance, linked.exported, declarations, (key, name) => {
|
|
533
|
+
const copy =
|
|
534
|
+
instance.name === undefined
|
|
535
|
+
? instantiation.getKey(key)
|
|
536
|
+
: instantiation.getQualifiedKey(key);
|
|
537
|
+
if (declarations.length > 0) instanceActions.set(copy, { name, location: instance.location });
|
|
538
|
+
if (instance.name !== undefined) qualifiedNames.set(copy, name);
|
|
539
|
+
return copy;
|
|
520
540
|
});
|
|
521
|
-
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const getStandardInstanceSymbols = (instance: Instance, standardSymbols: Symbols): Symbols =>
|
|
544
|
+
instance.name === undefined
|
|
545
|
+
? standardSymbols
|
|
546
|
+
: new Map(
|
|
547
|
+
[...standardSymbols].map(([name, symbol]) => [
|
|
548
|
+
`${instance.name}!${name}`,
|
|
549
|
+
{ key: symbol.key, arity: symbol.arity, params: symbol.params, kind: symbol.kind },
|
|
550
|
+
]),
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
// The names an INSTANCE adds for the definitions of the module it instantiates, each with the key
|
|
554
|
+
// that getKey gives it. SANY binds a copy of a definition that depends on the parameters at the
|
|
555
|
+
// INSTANCE.
|
|
556
|
+
const getInstanceSymbols = (
|
|
557
|
+
instance: Instance,
|
|
558
|
+
exported: Symbols,
|
|
559
|
+
declarations: Declaration[],
|
|
560
|
+
getKey: (key: string, name: string) => string,
|
|
561
|
+
): Symbols => {
|
|
562
|
+
const declared = new Set(declarations.map((declaration) => declaration.name));
|
|
563
|
+
return new Map(
|
|
564
|
+
[...exported]
|
|
565
|
+
.filter(([name]) => !declared.has(name))
|
|
566
|
+
.map(([name, symbol]): [string, ModuleSymbol] => {
|
|
567
|
+
if (instance.name === undefined) {
|
|
568
|
+
return [
|
|
569
|
+
name,
|
|
570
|
+
{
|
|
571
|
+
key: getKey(symbol.key, name),
|
|
572
|
+
arity: symbol.arity,
|
|
573
|
+
params: symbol.params,
|
|
574
|
+
kind: symbol.kind,
|
|
575
|
+
range:
|
|
576
|
+
parameterized.get(symbol.key) === true ? instance.location.range : symbol.range,
|
|
577
|
+
},
|
|
578
|
+
];
|
|
579
|
+
}
|
|
580
|
+
const qualified = `${instance.name}!${name}`;
|
|
581
|
+
return [
|
|
582
|
+
qualified,
|
|
583
|
+
{
|
|
584
|
+
key: getKey(symbol.key, qualified),
|
|
585
|
+
arity: symbol.arity + instance.params.length,
|
|
586
|
+
params: symbol.params && [
|
|
587
|
+
...instance.params.map((param) => param.arity),
|
|
588
|
+
...symbol.params,
|
|
589
|
+
],
|
|
590
|
+
kind: symbol.kind,
|
|
591
|
+
},
|
|
592
|
+
];
|
|
593
|
+
}),
|
|
594
|
+
);
|
|
522
595
|
};
|
|
523
596
|
|
|
524
597
|
const getLocalArguments = (params: OperatorParam[], location: SourceLocation) =>
|
|
@@ -691,8 +764,15 @@ export const createEnvironment = (
|
|
|
691
764
|
return definition ? [{ ...definition, name }] : [];
|
|
692
765
|
});
|
|
693
766
|
|
|
767
|
+
const javaOverrides = new Map<string, JavaOverride[]>();
|
|
694
768
|
const linkModule = (unlinked: Module, scope: ModuleScope): LinkedModule => {
|
|
695
|
-
const
|
|
769
|
+
const overridden = overrideDefinitions(
|
|
770
|
+
unlinked,
|
|
771
|
+
options.loadClass?.(unlinked.name),
|
|
772
|
+
unlinked === root,
|
|
773
|
+
);
|
|
774
|
+
javaOverrides.set(unlinked.name, overridden.overrides);
|
|
775
|
+
const parsed = overridden.module;
|
|
696
776
|
const firstCheck = instanceChecks.length;
|
|
697
777
|
const visible: Symbols = new Map([
|
|
698
778
|
...CORE_OPERATORS.map((operator): [string, ModuleSymbol] => [
|
|
@@ -701,6 +781,8 @@ export const createEnvironment = (
|
|
|
701
781
|
]),
|
|
702
782
|
...scope.symbols,
|
|
703
783
|
]);
|
|
784
|
+
// Where an INSTANCE first made each name it adds visible.
|
|
785
|
+
const importedAt = new Map<string, SourceLocation>();
|
|
704
786
|
const extendsReport: ModuleReport = { location: MODULE_START, errors: [], warnings: [] };
|
|
705
787
|
const reports = [extendsReport];
|
|
706
788
|
// Context.mergeExtendContext keeps the first of the symbols the extended modules share by name,
|
|
@@ -789,8 +871,36 @@ export const createEnvironment = (
|
|
|
789
871
|
const getKey = (definition: Definition) =>
|
|
790
872
|
parsed === root ? definition.name : `${definition.name}${KEY_SEPARATOR}${scope.id}`;
|
|
791
873
|
const instanced = new Map<Instance, Symbols>();
|
|
874
|
+
const getVisibleModules = () => new Map([...scope.modules, ...modules]);
|
|
875
|
+
const isInstancedAfterDefinition = (nested: Module) => {
|
|
876
|
+
const first = parsed.instances.find((instance) => instance.module === nested.name);
|
|
877
|
+
return first !== undefined && isBefore(nested.location, first.location);
|
|
878
|
+
};
|
|
879
|
+
const getLetModule = (instance: Instance) => {
|
|
880
|
+
const own = parsed.modules.find((nested) => nested.name === instance.module);
|
|
881
|
+
if (!own) return getVisibleModules().get(instance.module);
|
|
882
|
+
return isInstancedAfterDefinition(own) ? modules.get(own.name) : undefined;
|
|
883
|
+
};
|
|
792
884
|
const getUnit = (module: Module): ModuleUnit => ({
|
|
793
885
|
imported: visible,
|
|
886
|
+
getInstance: (instance) => {
|
|
887
|
+
const nested = getLetModule(instance);
|
|
888
|
+
const standardSymbols = nested ? undefined : getStandardSymbols(instance.module);
|
|
889
|
+
if (standardSymbols) {
|
|
890
|
+
return {
|
|
891
|
+
declarations: [],
|
|
892
|
+
symbols: getStandardInstanceSymbols(instance, standardSymbols),
|
|
893
|
+
instancer: parsed.name,
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
const linked = nested ?? getLinkedModule(instance.module, parsed.name);
|
|
897
|
+
const declarations = getDeclarations(linked);
|
|
898
|
+
return {
|
|
899
|
+
declarations,
|
|
900
|
+
symbols: getInstanceSymbols(instance, linked.exported, declarations, (key) => key),
|
|
901
|
+
instancer: parsed.name,
|
|
902
|
+
};
|
|
903
|
+
},
|
|
794
904
|
bound,
|
|
795
905
|
// SANY keeps the first of two definitions of a name.
|
|
796
906
|
definitions: new Map(
|
|
@@ -802,10 +912,9 @@ export const createEnvironment = (
|
|
|
802
912
|
reports,
|
|
803
913
|
warnings: scope.warnings,
|
|
804
914
|
});
|
|
805
|
-
|
|
915
|
+
// SANY keeps the first of two symbols of a name.
|
|
806
916
|
const getSymbolsBefore = (location: SourceLocation): Symbols =>
|
|
807
|
-
|
|
808
|
-
...visible,
|
|
917
|
+
[
|
|
809
918
|
...declarations
|
|
810
919
|
.filter((declaration) => isBefore(declaration.location, location))
|
|
811
920
|
.map((declaration): [string, ModuleSymbol] => [
|
|
@@ -818,7 +927,10 @@ export const createEnvironment = (
|
|
|
818
927
|
definition.name,
|
|
819
928
|
getDefinitionSymbol(definition),
|
|
820
929
|
]),
|
|
821
|
-
]
|
|
930
|
+
].reduce(
|
|
931
|
+
(symbols, [name, symbol]) => (symbols.has(name) ? symbols : symbols.set(name, symbol)),
|
|
932
|
+
new Map(visible),
|
|
933
|
+
);
|
|
822
934
|
// Generator.generateModule reports the errors of a nested module and goes on, and then
|
|
823
935
|
// SymbolTable.addModule reports a module already defined.
|
|
824
936
|
const linkNested = (nested: Module) => {
|
|
@@ -856,6 +968,7 @@ export const createEnvironment = (
|
|
|
856
968
|
instanced.set(instance, symbols);
|
|
857
969
|
symbols.forEach((symbol, name) => {
|
|
858
970
|
if (visible.has(name)) return;
|
|
971
|
+
importedAt.set(name, instance.location);
|
|
859
972
|
visible.set(name, symbol);
|
|
860
973
|
if (!instance.isLocal) exported.set(name, symbol);
|
|
861
974
|
});
|
|
@@ -868,15 +981,6 @@ export const createEnvironment = (
|
|
|
868
981
|
]
|
|
869
982
|
.sort((left, right) => (isBefore(left.location, right.location) ? -1 : 1))
|
|
870
983
|
.forEach((unit) => unit.link());
|
|
871
|
-
const isInstancedAfterDefinition = (nested: Module) => {
|
|
872
|
-
const first = parsed.instances.find((instance) => instance.module === nested.name);
|
|
873
|
-
return first !== undefined && isBefore(nested.location, first.location);
|
|
874
|
-
};
|
|
875
|
-
const getLetModule = (instance: Instance) => {
|
|
876
|
-
const own = parsed.modules.find((nested) => nested.name === instance.module);
|
|
877
|
-
if (!own) return getVisibleModules().get(instance.module);
|
|
878
|
-
return isInstancedAfterDefinition(own) ? modules.get(own.name) : undefined;
|
|
879
|
-
};
|
|
880
984
|
const module = resolveModuleSubexpressions(
|
|
881
985
|
withLetInstances(parsed, (instance, lets) =>
|
|
882
986
|
instantiateLocally(instance, lets, parsed.name, getLetModule(instance)),
|
|
@@ -889,6 +993,15 @@ export const createEnvironment = (
|
|
|
889
993
|
definitions.set(key, definition);
|
|
890
994
|
parameterized.set(key, !isParameterFree);
|
|
891
995
|
const symbol = getDefinitionSymbol(definition);
|
|
996
|
+
const importedLocation = importedAt.get(definition.name);
|
|
997
|
+
// SANY binds the name of a fact to a fact the module imports before it.
|
|
998
|
+
if (
|
|
999
|
+
symbol.kind === "Theorem" &&
|
|
1000
|
+
visible.get(definition.name)?.kind === "Theorem" &&
|
|
1001
|
+
(importedLocation === undefined || isBefore(importedLocation, definition.location))
|
|
1002
|
+
) {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
892
1005
|
visible.set(definition.name, symbol);
|
|
893
1006
|
if (!definition.isLocal) exported.set(definition.name, symbol);
|
|
894
1007
|
});
|
|
@@ -930,7 +1043,7 @@ export const createEnvironment = (
|
|
|
930
1043
|
};
|
|
931
1044
|
|
|
932
1045
|
const linkedRoot = linkTopLevel(root).linked;
|
|
933
|
-
if (warnings.length > 0) options.print(formatSanyWarnings(warnings));
|
|
1046
|
+
if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
|
|
934
1047
|
const getRootKey = (name: string) => linkedRoot.visible.get(name)?.key ?? name;
|
|
935
1048
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
936
1049
|
const definition = definitions.get(symbol.key);
|
|
@@ -972,6 +1085,7 @@ export const createEnvironment = (
|
|
|
972
1085
|
.filter((assignment) => assignment.args === undefined)
|
|
973
1086
|
.forEach((assignment) => {
|
|
974
1087
|
const value = toValue(assignment.value);
|
|
1088
|
+
markNormalized(value);
|
|
975
1089
|
getScopedKeys(assignment).forEach((key) => {
|
|
976
1090
|
const arity = getKeyArity(key);
|
|
977
1091
|
if (arity === 0) constants.set(key, value);
|
|
@@ -1094,7 +1208,7 @@ export const createEnvironment = (
|
|
|
1094
1208
|
const unassigned = declaredConstants.filter(
|
|
1095
1209
|
(name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
|
|
1096
1210
|
);
|
|
1097
|
-
if (unassigned.length > 0) {
|
|
1211
|
+
if (unassigned.length > 0 && !options.isUnconfigured) {
|
|
1098
1212
|
// TLC reports the first constant it finds unassigned in SANY's order of declarations.
|
|
1099
1213
|
const name =
|
|
1100
1214
|
getTlcDeclarationOrder(options.source, options.loadModule, "constant").find((constant) =>
|
|
@@ -1105,12 +1219,20 @@ export const createEnvironment = (
|
|
|
1105
1219
|
);
|
|
1106
1220
|
}
|
|
1107
1221
|
|
|
1222
|
+
if (options.isTraceRecorded) {
|
|
1223
|
+
builtins.forEach((builtin, name) => {
|
|
1224
|
+
const replacement = getTraceSpecArithmetic(builtin);
|
|
1225
|
+
if (replacement) builtins.set(name, replacement);
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1108
1229
|
const environment: Environment = {
|
|
1109
1230
|
runtime,
|
|
1110
1231
|
definitions,
|
|
1111
1232
|
builtins,
|
|
1112
1233
|
constants,
|
|
1113
1234
|
substitutions,
|
|
1235
|
+
instanceNames,
|
|
1114
1236
|
variables,
|
|
1115
1237
|
variableIndex: getVariableIndex(
|
|
1116
1238
|
variables,
|
|
@@ -1118,6 +1240,7 @@ export const createEnvironment = (
|
|
|
1118
1240
|
),
|
|
1119
1241
|
definitionValues: new Map(),
|
|
1120
1242
|
constantLevels: new Map(),
|
|
1243
|
+
substitutedDefinitions,
|
|
1121
1244
|
evaluators: new WeakMap(),
|
|
1122
1245
|
};
|
|
1123
1246
|
// TLC evaluates a substitute at startup and rejects it only when that fails and the level bound it
|
|
@@ -1149,18 +1272,41 @@ export const createEnvironment = (
|
|
|
1149
1272
|
analyzer.analyzeDefinition(definition, new Map()).level > 0
|
|
1150
1273
|
? getEvaluationError(definition.body)
|
|
1151
1274
|
: undefined;
|
|
1152
|
-
// TLC adds the reason unless a standard module's Java code failed.
|
|
1153
1275
|
if (error) {
|
|
1276
|
+
// TLC's SpecProcessor adds the message of a TLCRuntimeException, not of an EvalException.
|
|
1277
|
+
const addendum = isEvalException(error) ? "" : ` - specifically: ${error.message}`;
|
|
1154
1278
|
throw new TlaConfigError(
|
|
1155
|
-
`The configuration file substitutes constant ${name} with non-constant ${target}${
|
|
1279
|
+
`The configuration file substitutes constant ${name} with non-constant ${target}${addendum}`,
|
|
1156
1280
|
);
|
|
1157
1281
|
}
|
|
1158
1282
|
});
|
|
1159
|
-
|
|
1283
|
+
// TLC 1.7.4 processes the whole spec before it creates its model checker, which TLCGet reads.
|
|
1284
|
+
if (runtime.version !== "1.7.4") runtime.isStarted = true;
|
|
1285
|
+
// TLC computes the constant definitions of each module in the order SANY finishes the modules,
|
|
1286
|
+
// except those of a module that an INSTANCE gives parameters to.
|
|
1287
|
+
const instantiated = new Set(
|
|
1288
|
+
linkedList.flatMap((linked) => linked.module.instances.map((instance) => instance.module)),
|
|
1289
|
+
);
|
|
1290
|
+
const getDefinitionOrder = createTlcDefinitionOrder(options.source, options.loadModule);
|
|
1160
1291
|
return {
|
|
1161
1292
|
environment,
|
|
1162
1293
|
assumptions,
|
|
1163
1294
|
variableLocations: linkedRoot.variableLocations,
|
|
1164
1295
|
instanceActions,
|
|
1296
|
+
startupDefinitions: linkedList
|
|
1297
|
+
.filter(
|
|
1298
|
+
(linked) => !instantiated.has(linked.module.name) || getDeclarations(linked).length === 0,
|
|
1299
|
+
)
|
|
1300
|
+
.flatMap((linked) =>
|
|
1301
|
+
getDefinitionOrder(linked === linkedRoot ? undefined : linked.module.name).flatMap(
|
|
1302
|
+
(name) => {
|
|
1303
|
+
const definition = definitions.get(linked.visible.get(name)?.key ?? name);
|
|
1304
|
+
return definition ? [definition] : [];
|
|
1305
|
+
},
|
|
1306
|
+
),
|
|
1307
|
+
),
|
|
1308
|
+
rootConstants: linkedRoot.constants,
|
|
1309
|
+
rootSymbols: linkedRoot.visible,
|
|
1310
|
+
javaOverrides: linkedList.flatMap((linked) => javaOverrides.get(linked.module.name) ?? []),
|
|
1165
1311
|
};
|
|
1166
1312
|
};
|