tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.63a6693bd
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/compile.cjs +6 -6
- package/dist/compile.js +10 -10
- package/dist/deciders.cjs +29 -29
- package/dist/deciders.js +40 -40
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +54 -54
- package/dist/prove.js +52 -52
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +39 -39
- package/dist/transfer.js +41 -41
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +1 -1
- package/src/ast.ts +44 -39
- package/src/builtins.ts +4 -13
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +152 -518
- package/src/cli/options.ts +6 -31
- package/src/cli/shared.ts +1 -1
- package/src/cli/tlapm.ts +14 -13
- package/src/cli/tlc-arguments.ts +222 -210
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +1 -1
- package/src/cli/tlc.ts +34 -701
- package/src/cli/xml-exporter.ts +23 -33
- package/src/codegen.ts +5 -10
- package/src/coverage.ts +3 -10
- package/src/dependencies.ts +8 -13
- package/src/dfid.ts +16 -16
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +45 -333
- package/src/errors.ts +3 -2
- package/src/evaluate.ts +5 -4
- package/src/fingerprints.ts +65 -1
- package/src/instances.ts +47 -10
- package/src/java-hash.ts +7 -0
- package/src/json.ts +4 -7
- package/src/levels.ts +39 -42
- package/src/liveness-checker.ts +24 -37
- package/src/liveness.ts +47 -54
- package/src/obligations/action.ts +4 -11
- package/src/obligations/anonymize.ts +4 -2
- package/src/obligations/expression.ts +18 -2
- package/src/obligations/generate.ts +45 -38
- package/src/obligations/index.ts +2 -2
- package/src/obligations/module.ts +27 -38
- package/src/obligations/normalize.ts +2 -1
- package/src/obligations/simplify.ts +39 -44
- package/src/obligations/source.ts +47 -57
- package/src/obligations/temporal.ts +5 -5
- package/src/parallel-worker.ts +10 -30
- package/src/parallel.ts +22 -45
- package/src/parser.ts +19 -34
- package/src/prover/decide-pool.ts +3 -3
- package/src/prover/deciders.ts +3 -3
- package/src/prover/isabelle/encode.ts +1 -1
- package/src/prover/isabelle/isar/inner-syntax.ts +9 -4
- package/src/prover/isabelle/isar/method.ts +14 -25
- package/src/prover/isabelle/isar/theory.ts +11 -10
- package/src/prover/isabelle/isar/type-check.ts +6 -6
- package/src/prover/isabelle/provers/blast/blast.ts +7 -63
- package/src/prover/isabelle/provers/hypsubst.ts +17 -26
- package/src/prover/isabelle/pure/bicompose.ts +9 -25
- package/src/prover/isabelle/pure/conv.ts +2 -8
- package/src/prover/isabelle/pure/drule.ts +9 -2
- package/src/prover/isabelle/pure/logic.ts +1 -1
- package/src/prover/isabelle/pure/raw-simplifier.ts +4 -13
- package/src/prover/isabelle/pure/rewriter.ts +5 -9
- package/src/prover/isabelle/pure/table.ts +2 -1
- package/src/prover/isabelle/pure/tactical.ts +42 -35
- package/src/prover/isabelle/pure/thm.ts +14 -11
- package/src/prover/isabelle/tla/classical-setup.ts +17 -14
- package/src/prover/isabelle/tla/context.ts +7 -2
- package/src/prover/isabelle/tla/logic.ts +10 -21
- package/src/prover/isabelle/tla/simpdata.ts +1 -10
- package/src/prover/prep/action.ts +11 -19
- package/src/prover/prep/fingerprint.ts +2 -5
- package/src/prover/prep/methods.ts +24 -3
- package/src/prover/prove.ts +87 -64
- package/src/prover/smt/context.ts +1 -2
- package/src/prover/smt/data.ts +418 -406
- package/src/prover/smt/encode.ts +30 -18
- package/src/prover/smt/rewrite.ts +657 -626
- package/src/prover/smt/solver/ast.ts +0 -22
- package/src/prover/smt/solver/auf-solver.ts +2 -5
- package/src/prover/smt/solver/context.ts +3 -3
- package/src/prover/smt/solver/e-matching.ts +1 -1
- package/src/prover/smt/solver/expr-safe-replace.ts +1 -1
- package/src/prover/smt/solver/internalizer.ts +1 -2
- package/src/prover/smt/solver/lp/dioph-eq.ts +1 -8
- package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -1
- package/src/prover/smt/solver/lp/nla-core.ts +2 -6
- package/src/prover/smt/solver/mam-compiler.ts +4 -2
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-finder.ts +12 -17
- package/src/prover/smt/solver/model-macro-solver.ts +11 -19
- package/src/prover/smt/solver/nlsat/algebraic.ts +9 -9
- package/src/prover/smt/solver/nlsat/atoms.ts +20 -4
- package/src/prover/smt/solver/nlsat/explain.ts +7 -22
- package/src/prover/smt/solver/nlsat/levelwise.ts +1 -6
- package/src/prover/smt/solver/nlsat/polynomial.ts +12 -3
- package/src/prover/smt/solver/nlsat/solver.ts +12 -24
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -1
- package/src/prover/smt/solver/proto-model.ts +0 -4
- package/src/prover/smt/solver/quantifier-analyzer.ts +10 -10
- package/src/prover/smt/solver/quantifier-manager.ts +1 -5
- package/src/prover/smt/solver/smtlib-parser.ts +78 -94
- package/src/prover/smt/solver/theory-lra-bounds.ts +1 -2
- package/src/prover/smt/solver/theory-lra-internalize.ts +5 -16
- package/src/prover/tlapm/cache.ts +28 -18
- package/src/prover/tlapm/tlapm.ts +15 -9
- package/src/prover/verdict.ts +7 -0
- package/src/prover/zenon/check/check.ts +1 -2
- package/src/prover/zenon/check/records.ts +1 -1
- package/src/prover/zenon/check/relations.ts +2 -1
- package/src/prover/zenon/check/rewrites.ts +2 -15
- package/src/prover/zenon/check/sets.ts +40 -58
- package/src/prover/zenon/check/terms.ts +1 -2
- package/src/prover/zenon/eqrel.ts +2 -0
- package/src/prover/zenon/expr.ts +7 -0
- package/src/prover/zenon/index-table.ts +9 -19
- package/src/prover/zenon/isar.ts +35 -35
- package/src/prover/zenon/llproof.ts +2 -11
- package/src/prover/zenon/mltoll.ts +12 -28
- package/src/prover/zenon/parse.ts +3 -6
- package/src/prover/zenon/search.ts +4 -14
- package/src/prover/zenon/tla/functions.ts +2 -2
- package/src/prover/zenon/tla/llproof.ts +9 -11
- package/src/prover/zenon/tla/records.ts +1 -6
- package/src/prover/zenon/tla/sets.ts +15 -14
- package/src/prover/zenon/tla/tla.ts +7 -6
- package/src/resolve.ts +55 -72
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +155 -2625
- package/src/sany/lexer.ts +17 -16
- package/src/sany/nodes.ts +6 -13
- package/src/sany/report.ts +3 -6
- package/src/sany/selectors.ts +35 -38
- package/src/sany/xml.ts +23 -55
- package/src/search.ts +65 -27
- package/src/simulate.ts +157 -133
- package/src/spec-description.ts +33 -48
- package/src/standard-modules.ts +16 -32
- package/src/state-graph.ts +2 -7
- package/src/substitution-levels.ts +5 -4
- package/src/successors.ts +5 -7
- package/src/tlc/messages.ts +20 -15
- package/src/tlc/order.ts +2 -9
- package/src/tlc/random.ts +4 -4
- package/src/tlc/replay.ts +8 -15
- package/src/tlc/tlc-operators.ts +2 -3
- package/src/tlc/trace-spec.ts +25 -45
- package/src/typescript/actions.ts +2 -4
- package/src/typescript/collections.ts +34 -20
- package/src/typescript/compile.ts +1 -3
- package/src/typescript/formula.ts +5 -3
- package/src/typescript/model.ts +4 -5
- package/src/typescript/steps.ts +20 -18
- package/src/values.ts +63 -158
package/src/environment.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getChildren,
|
|
3
|
+
getDefinitionExpressions,
|
|
4
|
+
getReferencedName,
|
|
3
5
|
type Assumption,
|
|
4
6
|
type Declaration,
|
|
5
7
|
type Definition,
|
|
@@ -10,7 +12,8 @@ import {
|
|
|
10
12
|
type SourceLocation,
|
|
11
13
|
} from "./ast";
|
|
12
14
|
import type { ModuleOperator } from "./check";
|
|
13
|
-
import type {
|
|
15
|
+
import type { ModelConfig } from "./config";
|
|
16
|
+
import { applyConfig, type CopySource } from "./environment-config";
|
|
14
17
|
import type { FileSystem } from "./json";
|
|
15
18
|
import {
|
|
16
19
|
createSanyError,
|
|
@@ -19,27 +22,24 @@ import {
|
|
|
19
22
|
formatSanyWarnings,
|
|
20
23
|
TlaConfigError,
|
|
21
24
|
TlaEvaluationError,
|
|
22
|
-
TlaFeatureUnsupportedError,
|
|
23
|
-
TlaModuleError,
|
|
24
25
|
TlaSyntaxError,
|
|
25
|
-
UNEXPECTED_EXCEPTION,
|
|
26
26
|
type SanyError,
|
|
27
27
|
} from "./errors";
|
|
28
|
-
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
29
28
|
import {
|
|
30
29
|
bindOperatorArguments,
|
|
31
30
|
createBigNumberError,
|
|
32
31
|
createRealNumberError,
|
|
33
32
|
evaluate,
|
|
34
33
|
getDefinition,
|
|
34
|
+
getDefinitionClosure,
|
|
35
35
|
type Builtin,
|
|
36
36
|
type BuiltinArgument,
|
|
37
|
-
type Closure,
|
|
38
37
|
type Context,
|
|
39
38
|
type Environment,
|
|
40
39
|
} from "./evaluate";
|
|
41
40
|
import {
|
|
42
41
|
createInstantiation,
|
|
42
|
+
createLocalAlias,
|
|
43
43
|
createLocalArguments,
|
|
44
44
|
createLocalIdentifier,
|
|
45
45
|
getEnabledVariableName,
|
|
@@ -70,9 +70,10 @@ import { getSanyParseError } from "./sany/parse-error";
|
|
|
70
70
|
import {
|
|
71
71
|
CORE_OPERATORS,
|
|
72
72
|
getJavaOverrides,
|
|
73
|
-
|
|
73
|
+
getStandardOperators,
|
|
74
74
|
getTraceSpecArithmetic,
|
|
75
75
|
STANDARD_DEPENDENCIES,
|
|
76
|
+
STANDARD_EXTENDS,
|
|
76
77
|
} from "./standard-modules";
|
|
77
78
|
import { getStandardRange, STANDARD_LEVELS } from "./standard-definitions";
|
|
78
79
|
import { resolveInstanceSubexpressions, resolveModuleSubexpressions } from "./subexpressions";
|
|
@@ -81,15 +82,7 @@ import { createInstanceChecker, type InstanceCheck } from "./substitution-levels
|
|
|
81
82
|
import { isEvalException } from "./tlc/messages";
|
|
82
83
|
import { createDefinitionFacts } from "./dependencies";
|
|
83
84
|
import { createTlcOrder, type TlcOrder } from "./tlc/order";
|
|
84
|
-
import {
|
|
85
|
-
isTlcInteger,
|
|
86
|
-
createModelValue,
|
|
87
|
-
formatValue,
|
|
88
|
-
valuesEqual,
|
|
89
|
-
toFiniteSet,
|
|
90
|
-
type Value,
|
|
91
|
-
markNormalized,
|
|
92
|
-
} from "./values";
|
|
85
|
+
import { isTlcInteger, type Value } from "./values";
|
|
93
86
|
import type { TlcVersion } from "./tlc/version";
|
|
94
87
|
|
|
95
88
|
interface EnvironmentOptions {
|
|
@@ -130,46 +123,7 @@ export interface InstanceAction {
|
|
|
130
123
|
|
|
131
124
|
const ANNOTATED_OVERRIDE_MODULES = new Set(["IOUtils", "Json", "TLCExt"]);
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
switch (value.kind) {
|
|
135
|
-
case "Number":
|
|
136
|
-
// Deviation from TLC: ModelConfig#parseValue lets Integer.parseInt fail on a number too big, where tla-ts reports it as TLC reports such a number in a module.
|
|
137
|
-
if (!isTlcInteger(value.value)) {
|
|
138
|
-
throw setExitCode(
|
|
139
|
-
new TlaModuleError(`TLC can't handle a number this big.\n${value.value}`),
|
|
140
|
-
EXIT_STATUS.error,
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
return value.value;
|
|
144
|
-
case "String":
|
|
145
|
-
case "Boolean":
|
|
146
|
-
return value.value;
|
|
147
|
-
case "ModelValue":
|
|
148
|
-
return createModelValue(value.name);
|
|
149
|
-
case "Set":
|
|
150
|
-
return toFiniteSet({ kind: "MixedSet", elements: value.elements.map(toValue) });
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const toConstantValue = (value: ConfigValue) => {
|
|
155
|
-
try {
|
|
156
|
-
return toValue(value);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (
|
|
159
|
-
!(error instanceof TlaEvaluationError) ||
|
|
160
|
-
error instanceof TlaModuleError ||
|
|
161
|
-
error instanceof TlaFeatureUnsupportedError
|
|
162
|
-
) {
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
throw setExitCode(
|
|
166
|
-
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`),
|
|
167
|
-
EXIT_STATUS.error,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
interface LinkedModule {
|
|
126
|
+
export interface LinkedModule {
|
|
173
127
|
module: Module;
|
|
174
128
|
constants: Declaration[];
|
|
175
129
|
variables: string[];
|
|
@@ -253,42 +207,14 @@ const createLocalFunction = (definition: Definition, key: string): Definition =>
|
|
|
253
207
|
location: definition.location,
|
|
254
208
|
});
|
|
255
209
|
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
evaluate: (args) => {
|
|
263
|
-
const row = rows.find((candidate) => {
|
|
264
|
-
if (candidate[0].length !== args.length) {
|
|
265
|
-
throw new TlaEvaluationError(
|
|
266
|
-
`Attempted to apply the operator ${table}\nwith wrong number of arguments.`,
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
return candidate[0].every((value, index) => {
|
|
270
|
-
const argument = args[index];
|
|
271
|
-
return (
|
|
272
|
-
!(typeof argument === "object" && argument.kind === "Operator") &&
|
|
273
|
-
valuesEqual(value, argument)
|
|
274
|
-
);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
if (row) return row[1];
|
|
278
|
-
throw new TlaEvaluationError(
|
|
279
|
-
`Attempted to apply operator:\n${table}\nto arguments (${args.map((argument) => (typeof argument === "object" && argument.kind === "Operator" ? argument.name : formatValue(argument))).join(", ")}), which is undefined.`,
|
|
280
|
-
);
|
|
281
|
-
},
|
|
282
|
-
evaluateUnary: undefined,
|
|
283
|
-
evaluateBinary: undefined,
|
|
284
|
-
};
|
|
210
|
+
const mentionsName = (expression: Expression, names: Set<string>): boolean => {
|
|
211
|
+
const name = getReferencedName(expression);
|
|
212
|
+
return (
|
|
213
|
+
(name !== undefined && names.has(name)) ||
|
|
214
|
+
getChildren(expression).some((child) => mentionsName(child, names))
|
|
215
|
+
);
|
|
285
216
|
};
|
|
286
217
|
|
|
287
|
-
const mentionsName = (expression: Expression, names: Set<string>): boolean =>
|
|
288
|
-
(expression.kind === "Identifier" && names.has(expression.name)) ||
|
|
289
|
-
(expression.kind === "Apply" && names.has(expression.operator)) ||
|
|
290
|
-
getChildren(expression).some((child) => mentionsName(child, names));
|
|
291
|
-
|
|
292
218
|
const getVariableIndex = (variables: string[], declared: string[]) => {
|
|
293
219
|
const index = new Map(variables.map((name, position) => [name, position]));
|
|
294
220
|
new Set(declared).forEach((name) =>
|
|
@@ -323,7 +249,7 @@ export const createEnvironment = (
|
|
|
323
249
|
const root = order.parseModule(options.source);
|
|
324
250
|
const definitions = new Map<string, Definition>();
|
|
325
251
|
const parameterized = new Map<string, boolean>();
|
|
326
|
-
const copySources = new Map<string,
|
|
252
|
+
const copySources = new Map<string, CopySource>();
|
|
327
253
|
const substitutedDefinitions = new Set<Definition>();
|
|
328
254
|
const instanceParams = new Set<OperatorParam>();
|
|
329
255
|
const builtins = new Map<string, Builtin>(
|
|
@@ -372,16 +298,16 @@ export const createEnvironment = (
|
|
|
372
298
|
const addStandardModule = (name: string): Symbols | undefined => {
|
|
373
299
|
const cached = standardExports.get(name);
|
|
374
300
|
if (cached) return cached;
|
|
375
|
-
const
|
|
376
|
-
if (!
|
|
301
|
+
const operators = getStandardOperators(name, options.print, runtime, options.files, builtins);
|
|
302
|
+
if (!operators) return undefined;
|
|
377
303
|
STANDARD_DEPENDENCIES.get(name)?.forEach(addStandardModule);
|
|
378
304
|
const exported: Symbols = new Map();
|
|
379
|
-
|
|
305
|
+
STANDARD_EXTENDS.get(name)?.forEach((extended) =>
|
|
380
306
|
addStandardModule(extended)?.forEach((symbol, symbolName) =>
|
|
381
307
|
exported.set(symbolName, symbol),
|
|
382
308
|
),
|
|
383
309
|
);
|
|
384
|
-
|
|
310
|
+
operators.forEach((operator) => {
|
|
385
311
|
builtins.set(operator.name, operator);
|
|
386
312
|
exported.set(operator.name, {
|
|
387
313
|
key: operator.name,
|
|
@@ -410,11 +336,7 @@ export const createEnvironment = (
|
|
|
410
336
|
|
|
411
337
|
const rejectModuleLiterals = (module: Module): Module => {
|
|
412
338
|
rejectLiterals([
|
|
413
|
-
...module.definitions.flatMap(
|
|
414
|
-
definition.kind === "Function"
|
|
415
|
-
? [...definition.bounds.map((bound) => bound.set), definition.body]
|
|
416
|
-
: [definition.body],
|
|
417
|
-
),
|
|
339
|
+
...module.definitions.flatMap(getDefinitionExpressions),
|
|
418
340
|
...module.assumptions.map((assumption) => assumption.expression),
|
|
419
341
|
...module.theorems.flatMap((theorem) =>
|
|
420
342
|
theorem.statement.kind === "AssumeProve" ? [] : [theorem.statement],
|
|
@@ -504,16 +426,9 @@ export const createEnvironment = (
|
|
|
504
426
|
if (definition?.kind !== "Operator" || !context || expressions.length !== args.length) {
|
|
505
427
|
throw new TlaEvaluationError(`No definition of ${operator} to fall back to`);
|
|
506
428
|
}
|
|
507
|
-
const closure: Closure = {
|
|
508
|
-
kind: "Closure",
|
|
509
|
-
name: definition.name,
|
|
510
|
-
params: definition.params,
|
|
511
|
-
body: definition.body,
|
|
512
|
-
scope: undefined,
|
|
513
|
-
};
|
|
514
429
|
return evaluate(definition.body, {
|
|
515
430
|
environment: context.environment,
|
|
516
|
-
scope: bindOperatorArguments(
|
|
431
|
+
scope: bindOperatorArguments(getDefinitionClosure(definition), expressions, context),
|
|
517
432
|
state: context.state,
|
|
518
433
|
next: context.next,
|
|
519
434
|
isKeepLazy: context.isKeepLazy,
|
|
@@ -671,30 +586,6 @@ export const createEnvironment = (
|
|
|
671
586
|
);
|
|
672
587
|
};
|
|
673
588
|
|
|
674
|
-
const createLocalAlias = (
|
|
675
|
-
name: string,
|
|
676
|
-
key: string,
|
|
677
|
-
params: OperatorParam[],
|
|
678
|
-
forwarded: OperatorParam[],
|
|
679
|
-
location: SourceLocation,
|
|
680
|
-
): Definition => ({
|
|
681
|
-
kind: "Operator",
|
|
682
|
-
name,
|
|
683
|
-
params,
|
|
684
|
-
body:
|
|
685
|
-
forwarded.length === 0
|
|
686
|
-
? { kind: "Identifier", name: key, location }
|
|
687
|
-
: {
|
|
688
|
-
kind: "Apply",
|
|
689
|
-
operator: key,
|
|
690
|
-
args: createLocalArguments(forwarded, location),
|
|
691
|
-
location,
|
|
692
|
-
},
|
|
693
|
-
isLocal: true,
|
|
694
|
-
isRecursive: false,
|
|
695
|
-
location,
|
|
696
|
-
});
|
|
697
|
-
|
|
698
589
|
const createArgumentParams = (arity: number) =>
|
|
699
590
|
Array.from({ length: arity }, (_value, index) => ({ name: `argument${index}`, arity: 0 }));
|
|
700
591
|
|
|
@@ -1135,7 +1026,6 @@ export const createEnvironment = (
|
|
|
1135
1026
|
);
|
|
1136
1027
|
linkOrder.push(...linkOrder.splice(linkOrder.indexOf(linkedRoot), 1));
|
|
1137
1028
|
if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
|
|
1138
|
-
const getRootKey = (name: string) => linkedRoot.visible.get(name)?.key ?? name;
|
|
1139
1029
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
1140
1030
|
const definition = definitions.get(symbol.key);
|
|
1141
1031
|
if (definition && symbol.key !== name) definitions.set(name, definition);
|
|
@@ -1158,208 +1048,30 @@ export const createEnvironment = (
|
|
|
1158
1048
|
const declaredConstants = linkedRoot.constants.map((constant) => constant.name);
|
|
1159
1049
|
const variables = linkedRoot.variables;
|
|
1160
1050
|
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
? definition.params.length
|
|
1181
|
-
: (linkedRoot.constants.find((constant) => constant.name === key)?.arity ??
|
|
1182
|
-
builtins.get(key)?.arity ??
|
|
1183
|
-
0);
|
|
1184
|
-
};
|
|
1185
|
-
const constants = new Map<string, Value>();
|
|
1186
|
-
const operatorKeys = new Set<string>();
|
|
1187
|
-
const setOperator = (key: string, operator: Builtin) => {
|
|
1188
|
-
builtins.set(key, operator);
|
|
1189
|
-
definitions.delete(key);
|
|
1190
|
-
constants.delete(key);
|
|
1191
|
-
operatorKeys.add(key);
|
|
1192
|
-
};
|
|
1193
|
-
config.constants
|
|
1194
|
-
.filter((assignment) => assignment.args === undefined)
|
|
1195
|
-
.forEach((assignment) => {
|
|
1196
|
-
const value = toConstantValue(assignment.value);
|
|
1197
|
-
markNormalized(value);
|
|
1198
|
-
getScopedKeys(assignment).forEach((key) => {
|
|
1199
|
-
const arity = getKeyArity(key);
|
|
1200
|
-
if (arity === 0) constants.set(key, value);
|
|
1201
|
-
else
|
|
1202
|
-
setOperator(key, {
|
|
1203
|
-
kind: "Builtin",
|
|
1204
|
-
name: key,
|
|
1205
|
-
arity,
|
|
1206
|
-
evaluate: () => value,
|
|
1207
|
-
evaluateUnary: undefined,
|
|
1208
|
-
evaluateBinary: undefined,
|
|
1209
|
-
isLazy: true,
|
|
1210
|
-
});
|
|
1211
|
-
});
|
|
1212
|
-
});
|
|
1213
|
-
const tables = new Map<string, { name: string; module?: string; rows: [Value[], Value][] }>();
|
|
1214
|
-
config.constants.forEach((assignment) => {
|
|
1215
|
-
if (assignment.args === undefined) return;
|
|
1216
|
-
const tableKey = `${assignment.module ?? ""}!${assignment.name}`;
|
|
1217
|
-
const table = tables.get(tableKey) ?? {
|
|
1218
|
-
name: assignment.name,
|
|
1219
|
-
module: assignment.module,
|
|
1220
|
-
rows: [],
|
|
1221
|
-
};
|
|
1222
|
-
if (table.rows.length > 0 && table.rows[0][0].length !== assignment.args.length) {
|
|
1223
|
-
throw new TlaConfigError(
|
|
1224
|
-
`The arity of the operator ${assignment.name} is inconsistent in the configuration file.`,
|
|
1225
|
-
);
|
|
1226
|
-
}
|
|
1227
|
-
table.rows.push([assignment.args.map(toValue), toValue(assignment.value)]);
|
|
1228
|
-
tables.set(tableKey, table);
|
|
1229
|
-
});
|
|
1230
|
-
tables.forEach((table) =>
|
|
1231
|
-
getScopedKeys(table).forEach((key) =>
|
|
1232
|
-
setOperator(key, createOperatorTable(table.name, getKeyArity(key), table.rows)),
|
|
1233
|
-
),
|
|
1234
|
-
);
|
|
1235
|
-
const substitutions = new Map(
|
|
1236
|
-
config.substitutions.flatMap((substitution) =>
|
|
1237
|
-
getSubstitutedKeys(substitution).map((key): [string, string] => [
|
|
1238
|
-
key,
|
|
1239
|
-
getRootKey(substitution.target),
|
|
1240
|
-
]),
|
|
1051
|
+
const applied = applyConfig(config, {
|
|
1052
|
+
root: linkedRoot,
|
|
1053
|
+
moduleSymbols: new Map([
|
|
1054
|
+
...standardExports,
|
|
1055
|
+
...[...linkedModules].map(([name, linked]): [string, Symbols] => [name, linked.visible]),
|
|
1056
|
+
[root.name, linkedRoot.visible],
|
|
1057
|
+
]),
|
|
1058
|
+
definitions,
|
|
1059
|
+
builtins,
|
|
1060
|
+
copySources,
|
|
1061
|
+
operatorConstants: new Map(
|
|
1062
|
+
moduleOperators.flatMap((operator) =>
|
|
1063
|
+
getLinkedModule(operator.module, root.name).constants.flatMap(
|
|
1064
|
+
(constant): [string, Value][] => {
|
|
1065
|
+
const value = operator.constants?.[constant.name];
|
|
1066
|
+
return value === undefined ? [] : [[constant.name, value]];
|
|
1067
|
+
},
|
|
1068
|
+
),
|
|
1069
|
+
),
|
|
1241
1070
|
),
|
|
1242
|
-
|
|
1243
|
-
[...substitutions.keys()].forEach((key) => constants.delete(key));
|
|
1244
|
-
const checkSubstitutionTarget = (name: string, target: string, arity: number | undefined) => {
|
|
1245
|
-
const targetKey = getRootKey(target);
|
|
1246
|
-
const definition = definitions.get(targetKey);
|
|
1247
|
-
const isDefined =
|
|
1248
|
-
definition !== undefined ||
|
|
1249
|
-
builtins.has(targetKey) ||
|
|
1250
|
-
constants.has(targetKey) ||
|
|
1251
|
-
declaredConstants.includes(target) ||
|
|
1252
|
-
variables.includes(target);
|
|
1253
|
-
if (!isDefined) {
|
|
1254
|
-
throw new TlaConfigError(
|
|
1255
|
-
`The configuration file substitutes for ${name} with the undefined identifier ${target}.`,
|
|
1256
|
-
);
|
|
1257
|
-
}
|
|
1258
|
-
if (definition?.kind === "Operator" && definition.params.length !== arity) {
|
|
1259
|
-
throw new TlaConfigError(
|
|
1260
|
-
`The configuration file substitutes for ${name} with ${target} of different number of arguments.`,
|
|
1261
|
-
);
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
config.substitutions
|
|
1265
|
-
.filter((substitution) => substitution.module === undefined)
|
|
1266
|
-
.forEach((substitution) => {
|
|
1267
|
-
const name = substitution.name;
|
|
1268
|
-
const target = substitution.target;
|
|
1269
|
-
if (!declaredConstants.includes(name) && !linkedRoot.visible.has(name)) {
|
|
1270
|
-
throw new TlaConfigError(
|
|
1271
|
-
`In the configuration file, the identifier ${name} does not appear in the specification.`,
|
|
1272
|
-
);
|
|
1273
|
-
}
|
|
1274
|
-
if (config.substitutions.some((other) => other.name === target)) {
|
|
1275
|
-
throw new TlaConfigError(
|
|
1276
|
-
`In the configuration file, the identifier ${target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
|
|
1277
|
-
);
|
|
1278
|
-
}
|
|
1279
|
-
checkSubstitutionTarget(
|
|
1280
|
-
name,
|
|
1281
|
-
target,
|
|
1282
|
-
linkedRoot.constants.find((constant) => constant.name === name)?.arity ??
|
|
1283
|
-
linkedRoot.visible.get(name)?.arity,
|
|
1284
|
-
);
|
|
1285
|
-
});
|
|
1286
|
-
const scopedSubstitutions = config.substitutions.filter(
|
|
1287
|
-
(substitution) => substitution.module !== undefined,
|
|
1288
|
-
);
|
|
1289
|
-
[...moduleSymbols.keys()].forEach((name) => {
|
|
1290
|
-
const inModule = scopedSubstitutions.filter((substitution) => substitution.module === name);
|
|
1291
|
-
inModule.forEach((substitution) => {
|
|
1292
|
-
const symbol = getScopedSymbol(substitution);
|
|
1293
|
-
if (!symbol) return;
|
|
1294
|
-
if (inModule.some((other) => other.name === substitution.target)) {
|
|
1295
|
-
throw new TlaConfigError(
|
|
1296
|
-
`In the configuration file, the identifier ${substitution.target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
|
|
1297
|
-
);
|
|
1298
|
-
}
|
|
1299
|
-
checkSubstitutionTarget(substitution.name, substitution.target, symbol.arity);
|
|
1300
|
-
});
|
|
1301
|
-
const missing = inModule.find((substitution) => !getScopedSymbol(substitution));
|
|
1302
|
-
if (missing) {
|
|
1303
|
-
throw new TlaConfigError(
|
|
1304
|
-
`In the configuration file, the identifier ${missing.name} does not appear in the specification.`,
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
});
|
|
1308
|
-
const unknownModule = scopedSubstitutions.find(
|
|
1309
|
-
(substitution) => !moduleSymbols.has(substitution.module ?? ""),
|
|
1310
|
-
);
|
|
1311
|
-
if (unknownModule) {
|
|
1312
|
-
throw new TlaConfigError(
|
|
1313
|
-
`In the configuration file, the module name ${unknownModule.module} is not a module in the specification.`,
|
|
1314
|
-
);
|
|
1315
|
-
}
|
|
1316
|
-
const scopedKeys = new Set(
|
|
1317
|
-
[...config.constants, ...config.substitutions]
|
|
1318
|
-
.filter((item) => item.module !== undefined)
|
|
1319
|
-
.flatMap(getScopedKeys),
|
|
1320
|
-
);
|
|
1321
|
-
const getOverride = (
|
|
1322
|
-
key: string,
|
|
1323
|
-
prefix: number,
|
|
1324
|
-
): { key: string; prefix: number } | undefined => {
|
|
1325
|
-
if (scopedKeys.has(key)) return { key, prefix };
|
|
1326
|
-
const copy = copySources.get(key);
|
|
1327
|
-
return copy && getOverride(copy.source, prefix + copy.prefix);
|
|
1328
|
-
};
|
|
1329
|
-
copySources.forEach((copy, key) => {
|
|
1330
|
-
const override = getOverride(copy.source, copy.prefix);
|
|
1331
|
-
const definition = definitions.get(key);
|
|
1332
|
-
if (!override || !definition) return;
|
|
1333
|
-
const params = definition.kind === "Operator" ? definition.params : [];
|
|
1334
|
-
const alias = createLocalAlias(
|
|
1335
|
-
key,
|
|
1336
|
-
override.key,
|
|
1337
|
-
params,
|
|
1338
|
-
params.slice(override.prefix),
|
|
1339
|
-
definition.location,
|
|
1340
|
-
);
|
|
1341
|
-
definitions.set(key, alias);
|
|
1342
|
-
linkedRoot.visible.forEach((symbol, name) => {
|
|
1343
|
-
if (symbol.key === key && name !== key) definitions.set(name, alias);
|
|
1344
|
-
});
|
|
1071
|
+
order,
|
|
1345
1072
|
});
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
const value = operator.constants?.[constant.name];
|
|
1349
|
-
if (value !== undefined) constants.set(constant.name, value);
|
|
1350
|
-
}),
|
|
1351
|
-
);
|
|
1352
|
-
const unassigned = declaredConstants.filter(
|
|
1353
|
-
(name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
|
|
1354
|
-
);
|
|
1355
|
-
if (unassigned.length > 0) {
|
|
1356
|
-
const name =
|
|
1357
|
-
order.getDeclarationOrder("constant").find((constant) => unassigned.includes(constant)) ??
|
|
1358
|
-
unassigned[0];
|
|
1359
|
-
throw new TlaConfigError(
|
|
1360
|
-
`The constant parameter ${name} is not assigned a value by the configuration file.`,
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1073
|
+
const constants = applied.constants;
|
|
1074
|
+
const substitutions = applied.substitutions;
|
|
1363
1075
|
|
|
1364
1076
|
if (traceFile !== undefined) {
|
|
1365
1077
|
builtins.forEach((builtin, name) => {
|
package/src/errors.ts
CHANGED
|
@@ -216,8 +216,6 @@ export class TlaWarningAsError extends TlaEvaluationError {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
export class TlaNullPointerError extends TlaEvaluationError {}
|
|
220
|
-
|
|
221
219
|
export class TlaIllegalStateError extends TlaEvaluationError {
|
|
222
220
|
state: (Value | undefined)[];
|
|
223
221
|
|
|
@@ -281,6 +279,9 @@ export class TlaIsabelleError {
|
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
|
|
282
|
+
export const isIsabelleError = (error: unknown, exception: IsabelleException): boolean =>
|
|
283
|
+
error instanceof TlaIsabelleError && error.exception === exception;
|
|
284
|
+
|
|
284
285
|
export class TlaUnsupportedError extends TlaError {
|
|
285
286
|
constructor(message: string, cause?: unknown) {
|
|
286
287
|
super(message, cause);
|
package/src/evaluate.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getChildren,
|
|
3
|
+
getReferencedName,
|
|
3
4
|
isLocallyResolved,
|
|
4
5
|
type Bound,
|
|
5
6
|
type BoundPattern,
|
|
@@ -872,7 +873,7 @@ const forceThunk = (thunk: Thunk, context: Context) => {
|
|
|
872
873
|
return value;
|
|
873
874
|
};
|
|
874
875
|
|
|
875
|
-
const getDefinitionClosure = (definition: Definition & { kind: "Operator" }): Closure => ({
|
|
876
|
+
export const getDefinitionClosure = (definition: Definition & { kind: "Operator" }): Closure => ({
|
|
876
877
|
kind: "Closure",
|
|
877
878
|
name: definition.name,
|
|
878
879
|
params: definition.params,
|
|
@@ -1212,7 +1213,7 @@ const isRebindable = (value: Value): value is RebindableFilteredSet | Rebindable
|
|
|
1212
1213
|
(value.kind === "FilteredSet" || value.kind === "LazyFunction") &&
|
|
1213
1214
|
"rebind" in value;
|
|
1214
1215
|
|
|
1215
|
-
const toNextContext = (context: Context): Context => ({
|
|
1216
|
+
export const toNextContext = (context: Context): Context => ({
|
|
1216
1217
|
environment: context.environment,
|
|
1217
1218
|
scope: context.scope,
|
|
1218
1219
|
state: context.next,
|
|
@@ -1666,8 +1667,8 @@ const getScopeNames = (expression: Expression) => {
|
|
|
1666
1667
|
const names = new Set<string>();
|
|
1667
1668
|
const visit = (node: Expression): boolean => {
|
|
1668
1669
|
if (node.kind === "Subexpression") return false;
|
|
1669
|
-
|
|
1670
|
-
if (
|
|
1670
|
+
const name = getReferencedName(node);
|
|
1671
|
+
if (name !== undefined) names.add(name);
|
|
1671
1672
|
if (node.kind === "ExceptAt") names.add(EXCEPT_AT);
|
|
1672
1673
|
return getChildren(node).every(visit);
|
|
1673
1674
|
};
|
package/src/fingerprints.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getValueFingerprint, getValueHash, type Value } from "./values";
|
|
1
|
+
import { combineHash, getValueFingerprint, getValueHash, isSameValue, type Value } from "./values";
|
|
2
2
|
|
|
3
3
|
const EMPTY = 0;
|
|
4
4
|
const INITIAL_CAPACITY = 1 << 12;
|
|
@@ -59,6 +59,70 @@ export const createFingerprintTable = (): FingerprintTable => {
|
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
export interface StateTable {
|
|
63
|
+
slots: Int32Array;
|
|
64
|
+
size: number;
|
|
65
|
+
shift: number;
|
|
66
|
+
states: Value[][];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// A Map holds at most 2^24 entries, so an open-addressing table keeps each hash and index + 1.
|
|
70
|
+
export const createStateTable = (states: Value[][]): StateTable => ({
|
|
71
|
+
slots: new Int32Array(1 << 17),
|
|
72
|
+
size: 0,
|
|
73
|
+
shift: 16,
|
|
74
|
+
states,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const getStateHash = (state: Value[]) => {
|
|
78
|
+
let hash = 0x811c9dc5;
|
|
79
|
+
for (let index = 0; index < state.length; index++)
|
|
80
|
+
hash = combineHash(hash, getValueHash(state[index]));
|
|
81
|
+
return hash & 0x3fffffff;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const isSameState = (stored: Value[], state: Value[]) => {
|
|
85
|
+
for (let position = 0; position < state.length; position++) {
|
|
86
|
+
if (!isSameValue(stored[position], state[position])) return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const getSlot = (table: StateTable, hash: number) =>
|
|
92
|
+
(Math.imul(hash, 0x9e3779b1) >>> table.shift) << 1;
|
|
93
|
+
|
|
94
|
+
export const findStateIndex = (table: StateTable, hash: number, state: Value[]) => {
|
|
95
|
+
const mask = table.slots.length - 1;
|
|
96
|
+
for (let slot = getSlot(table, hash); ; slot = (slot + 2) & mask) {
|
|
97
|
+
const entry = table.slots[slot + 1];
|
|
98
|
+
if (entry === 0) return -1;
|
|
99
|
+
if (table.slots[slot] === hash && isSameState(table.states[entry - 1], state)) {
|
|
100
|
+
return entry - 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const insertSeenState = (table: StateTable, hash: number, entry: number) => {
|
|
106
|
+
const mask = table.slots.length - 1;
|
|
107
|
+
let slot = getSlot(table, hash);
|
|
108
|
+
while (table.slots[slot + 1] !== 0) slot = (slot + 2) & mask;
|
|
109
|
+
table.slots[slot] = hash;
|
|
110
|
+
table.slots[slot + 1] = entry;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const markSeenState = (table: StateTable, hash: number, index: number) => {
|
|
114
|
+
table.size++;
|
|
115
|
+
if (table.size * 4 > table.slots.length) {
|
|
116
|
+
const slots = table.slots;
|
|
117
|
+
table.slots = new Int32Array(slots.length * 2);
|
|
118
|
+
table.shift--;
|
|
119
|
+
for (let slot = 0; slot < slots.length; slot += 2) {
|
|
120
|
+
if (slots[slot + 1] !== 0) insertSeenState(table, slots[slot], slots[slot + 1]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
insertSeenState(table, hash, index + 1);
|
|
124
|
+
};
|
|
125
|
+
|
|
62
126
|
export interface SharedFingerprints {
|
|
63
127
|
slots: BigInt64Array;
|
|
64
128
|
used: Int32Array;
|