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/instances.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,
|
|
@@ -228,6 +229,16 @@ export const mapChildren = (
|
|
|
228
229
|
}
|
|
229
230
|
};
|
|
230
231
|
|
|
232
|
+
export const forEachChild = (
|
|
233
|
+
expression: Expression,
|
|
234
|
+
visit: (child: Expression, bound: string[]) => void,
|
|
235
|
+
): void => {
|
|
236
|
+
mapChildren(expression, (child, bound) => {
|
|
237
|
+
visit(child, bound);
|
|
238
|
+
return child;
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
|
|
231
242
|
interface Instantiation {
|
|
232
243
|
params: OperatorParam[];
|
|
233
244
|
substitutions: Map<string, Expression>;
|
|
@@ -280,19 +291,13 @@ const isBoundOnce = (replacement: Expression, instantiation: Instantiation) => {
|
|
|
280
291
|
};
|
|
281
292
|
|
|
282
293
|
const getFreeNames = (expression: Expression, bound = new Set<string>()): string[] => {
|
|
283
|
-
const name =
|
|
284
|
-
expression.kind === "Identifier"
|
|
285
|
-
? expression.name
|
|
286
|
-
: expression.kind === "Apply" || expression.kind === "OperatorReference"
|
|
287
|
-
? expression.operator
|
|
288
|
-
: undefined;
|
|
294
|
+
const name = getReferencedName(expression);
|
|
289
295
|
const names = name === undefined || bound.has(name) ? [] : [name];
|
|
290
|
-
|
|
296
|
+
forEachChild(expression, (child, childBound) =>
|
|
291
297
|
names.push(
|
|
292
298
|
...getFreeNames(child, childBound.length === 0 ? bound : new Set([...bound, ...childBound])),
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
});
|
|
299
|
+
),
|
|
300
|
+
);
|
|
296
301
|
return names;
|
|
297
302
|
};
|
|
298
303
|
|
|
@@ -487,6 +492,30 @@ export const createLocalIdentifier = (name: string, location: SourceLocation): E
|
|
|
487
492
|
export const createLocalArguments = (params: OperatorParam[], location: SourceLocation) =>
|
|
488
493
|
params.map((param) => createLocalIdentifier(param.name, location));
|
|
489
494
|
|
|
495
|
+
export const createLocalAlias = (
|
|
496
|
+
name: string,
|
|
497
|
+
key: string,
|
|
498
|
+
params: OperatorParam[],
|
|
499
|
+
forwarded: OperatorParam[],
|
|
500
|
+
location: SourceLocation,
|
|
501
|
+
): Definition => ({
|
|
502
|
+
kind: "Operator",
|
|
503
|
+
name,
|
|
504
|
+
params,
|
|
505
|
+
body:
|
|
506
|
+
forwarded.length === 0
|
|
507
|
+
? { kind: "Identifier", name: key, location }
|
|
508
|
+
: {
|
|
509
|
+
kind: "Apply",
|
|
510
|
+
operator: key,
|
|
511
|
+
args: createLocalArguments(forwarded, location),
|
|
512
|
+
location,
|
|
513
|
+
},
|
|
514
|
+
isLocal: true,
|
|
515
|
+
isRecursive: false,
|
|
516
|
+
location,
|
|
517
|
+
});
|
|
518
|
+
|
|
490
519
|
const getInstanceOperator = (
|
|
491
520
|
key: string,
|
|
492
521
|
params: OperatorParam[],
|
|
@@ -640,6 +669,14 @@ const substitute = (
|
|
|
640
669
|
};
|
|
641
670
|
}
|
|
642
671
|
if (expression.kind === "OperatorReference" && isFree(expression.operator)) {
|
|
672
|
+
const replacement = instantiation.substitutions.get(expression.operator);
|
|
673
|
+
if (
|
|
674
|
+
replacement?.kind === "Identifier" ||
|
|
675
|
+
replacement?.kind === "OperatorReference" ||
|
|
676
|
+
replacement?.kind === "Lambda"
|
|
677
|
+
) {
|
|
678
|
+
return withSubstitutionFrames(replacement, [expression]);
|
|
679
|
+
}
|
|
643
680
|
const copy = getCopy(rewrite, expression.operator);
|
|
644
681
|
if (copy === undefined) return expression;
|
|
645
682
|
const definition = instantiation.getDefinition(expression.operator);
|
package/src/java-hash.ts
ADDED
package/src/json.ts
CHANGED
|
@@ -111,6 +111,8 @@ const toJsonArray = (value: Value) => {
|
|
|
111
111
|
throw createUnsupportedError(value);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
+
const toNdJson = (elements: Value[]) => elements.map((element) => `${toJson(element)}\n`).join("");
|
|
115
|
+
|
|
114
116
|
const toJsonObject = (value: Value) => {
|
|
115
117
|
const className = getJavaClassName(value);
|
|
116
118
|
if (className === "RecordValue") return toObjectJson(toFiniteFunction(value));
|
|
@@ -258,7 +260,7 @@ export const createJsonOperators = (files: FileSystem): Builtin[] => [
|
|
|
258
260
|
throw createModuleArgumentError("second", "ndJsonSerialize", "sequence", value);
|
|
259
261
|
}
|
|
260
262
|
makeParentDirectory(files, path);
|
|
261
|
-
files.writeFile?.(path, elements
|
|
263
|
+
files.writeFile?.(path, toNdJson(elements));
|
|
262
264
|
return true;
|
|
263
265
|
}),
|
|
264
266
|
"public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException",
|
|
@@ -313,12 +315,7 @@ export const createIoUtilsOperators = (
|
|
|
313
315
|
return option;
|
|
314
316
|
});
|
|
315
317
|
checkCharset(charset);
|
|
316
|
-
writeWithOptions(
|
|
317
|
-
files,
|
|
318
|
-
path,
|
|
319
|
-
names,
|
|
320
|
-
elements.map((element) => `${toJson(element)}\n`).join(""),
|
|
321
|
-
);
|
|
318
|
+
writeWithOptions(files, path, names, toNdJson(elements));
|
|
322
319
|
return true;
|
|
323
320
|
}),
|
|
324
321
|
"public static synchronized tlc2.value.impl.Value tlc2.module.Json.textSerialize(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
|
package/src/levels.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
TlaSyntaxError,
|
|
17
17
|
type SanyError,
|
|
18
18
|
} from "./errors";
|
|
19
|
-
import {
|
|
19
|
+
import { forEachChild } from "./instances";
|
|
20
20
|
import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
|
|
21
21
|
import { STANDARD_LEVELS } from "./standard-definitions";
|
|
22
22
|
|
|
@@ -55,11 +55,10 @@ type Resolved =
|
|
|
55
55
|
| { kind: "Declared"; name: string; level: number; arity: number }
|
|
56
56
|
| { kind: "Defined"; levels: OperatorLevels };
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
data: LevelData
|
|
60
|
-
|
|
61
|
-
declared
|
|
62
|
-
}
|
|
58
|
+
type Operand =
|
|
59
|
+
| { kind: "Value"; data: LevelData }
|
|
60
|
+
| { kind: "Operator"; data: OperatorLevels }
|
|
61
|
+
| { kind: "Declared"; data: LevelData; declared: OperatorParam };
|
|
63
62
|
|
|
64
63
|
export const CONSTANT_LEVEL = 0;
|
|
65
64
|
export const VARIABLE_LEVEL = 1;
|
|
@@ -96,6 +95,12 @@ export const putConstraint = (constraints: Map<string, number>, name: string, le
|
|
|
96
95
|
export const putArgConstraint = (constraints: Map<string, number>, key: string, level: number) =>
|
|
97
96
|
constraints.set(key, Math.max(level, constraints.get(key) ?? 0));
|
|
98
97
|
|
|
98
|
+
const mergeConstraints = (data: LevelData, part: LevelData) => {
|
|
99
|
+
part.constraints.forEach((value, key) => putConstraint(data.constraints, key, value));
|
|
100
|
+
part.argConstraints.forEach((value, key) => putArgConstraint(data.argConstraints, key, value));
|
|
101
|
+
part.argParams.forEach((key) => data.argParams.add(key));
|
|
102
|
+
};
|
|
103
|
+
|
|
99
104
|
const createSignature = (
|
|
100
105
|
name: string,
|
|
101
106
|
level: number,
|
|
@@ -231,12 +236,8 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
231
236
|
data.params.add(param);
|
|
232
237
|
data.argParams.add(getArgumentParamKey(name, index, param));
|
|
233
238
|
});
|
|
234
|
-
operand.data.constraints.forEach((value, key) => putConstraint(data.constraints, key, value));
|
|
235
239
|
putArgConstraint(data.argConstraints, getArgumentKey(name, index), operand.data.level);
|
|
236
|
-
operand.data
|
|
237
|
-
putArgConstraint(data.argConstraints, key, value),
|
|
238
|
-
);
|
|
239
|
-
operand.data.argParams.forEach((key) => data.argParams.add(key));
|
|
240
|
+
mergeConstraints(data, operand.data);
|
|
240
241
|
});
|
|
241
242
|
return data;
|
|
242
243
|
};
|
|
@@ -249,7 +250,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
249
250
|
) => {
|
|
250
251
|
const isBound = (name: string) => bound.includes(name);
|
|
251
252
|
operands.forEach((operand, index) => {
|
|
252
|
-
if (operand.
|
|
253
|
+
if (operand.kind !== "Value") return;
|
|
253
254
|
if (operand.data.level > getMaxLevel(operator, index)) {
|
|
254
255
|
throw new TlaSyntaxError(
|
|
255
256
|
`Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
|
|
@@ -300,8 +301,8 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
300
301
|
}),
|
|
301
302
|
);
|
|
302
303
|
operands.forEach((operand, operandIndex) => {
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
if (operand.kind !== "Operator") return;
|
|
305
|
+
const argument = operand.data;
|
|
305
306
|
operands.forEach((other, otherIndex) =>
|
|
306
307
|
argument.formals.forEach((_formal, argumentIndex) => {
|
|
307
308
|
if (!hasCondition(operandIndex, otherIndex, argumentIndex)) return;
|
|
@@ -313,9 +314,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
313
314
|
});
|
|
314
315
|
operator.argParams.forEach((key) => {
|
|
315
316
|
const parameter = parseArgumentParamKey(key);
|
|
316
|
-
const argument = getOperand(parameter.operator)
|
|
317
|
-
if (argument) {
|
|
318
|
-
putConstraint(
|
|
317
|
+
const argument = getOperand(parameter.operator);
|
|
318
|
+
if (argument?.kind === "Operator") {
|
|
319
|
+
putConstraint(
|
|
320
|
+
data.constraints,
|
|
321
|
+
parameter.param,
|
|
322
|
+
getMaxLevel(argument.data, parameter.index),
|
|
323
|
+
);
|
|
319
324
|
}
|
|
320
325
|
});
|
|
321
326
|
|
|
@@ -328,8 +333,8 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
328
333
|
constraints.forEach((value, key) => putArgConstraint(data.argConstraints, key, value)),
|
|
329
334
|
);
|
|
330
335
|
operands.forEach((operand, operandIndex) => {
|
|
336
|
+
if (operand.kind !== "Declared") return;
|
|
331
337
|
const declared = operand.declared;
|
|
332
|
-
if (!declared) return;
|
|
333
338
|
Array.from({ length: declared.arity }, (_value, argumentIndex) =>
|
|
334
339
|
putArgConstraint(
|
|
335
340
|
data.argConstraints,
|
|
@@ -381,15 +386,15 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
381
386
|
);
|
|
382
387
|
return;
|
|
383
388
|
}
|
|
384
|
-
if (argument.
|
|
389
|
+
if (argument.kind === "Declared") {
|
|
385
390
|
data.argParams.add(
|
|
386
391
|
getArgumentParamKey(argument.declared.name, parameter.index, parameter.param),
|
|
387
392
|
);
|
|
388
393
|
}
|
|
389
394
|
});
|
|
390
395
|
operands.forEach((operand, operandIndex) => {
|
|
396
|
+
if (operand.kind !== "Declared") return;
|
|
391
397
|
const declared = operand.declared;
|
|
392
|
-
if (!declared) return;
|
|
393
398
|
operands.forEach((other, otherIndex) =>
|
|
394
399
|
Array.from({ length: declared.arity }, (_value, argumentIndex) => {
|
|
395
400
|
if (!hasCondition(operandIndex, otherIndex, argumentIndex)) return;
|
|
@@ -410,7 +415,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
410
415
|
expression.body,
|
|
411
416
|
scope,
|
|
412
417
|
);
|
|
413
|
-
return {
|
|
418
|
+
return { kind: "Operator", data: operator };
|
|
414
419
|
}
|
|
415
420
|
const name =
|
|
416
421
|
expression.kind === "OperatorReference"
|
|
@@ -424,16 +429,16 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
424
429
|
resolved.kind === "Defined" &&
|
|
425
430
|
(resolved.levels.formals.length > 0 || expression.kind === "OperatorReference")
|
|
426
431
|
) {
|
|
427
|
-
return {
|
|
432
|
+
return { kind: "Operator", data: resolved.levels };
|
|
428
433
|
}
|
|
429
434
|
if (resolved.kind === "Declared" && resolved.arity > 0) {
|
|
430
435
|
const data = createData();
|
|
431
436
|
data.params.add(name);
|
|
432
|
-
return { data, declared: { name, arity: resolved.arity } };
|
|
437
|
+
return { kind: "Declared", data, declared: { name, arity: resolved.arity } };
|
|
433
438
|
}
|
|
434
|
-
if (expression.kind === "OperatorReference") return { data: createData() };
|
|
439
|
+
if (expression.kind === "OperatorReference") return { kind: "Value", data: createData() };
|
|
435
440
|
}
|
|
436
|
-
return { data: analyze(expression, scope) };
|
|
441
|
+
return { kind: "Value", data: analyze(expression, scope) };
|
|
437
442
|
};
|
|
438
443
|
|
|
439
444
|
const toOperands = (expressions: Expression[], scope: Scope) =>
|
|
@@ -509,14 +514,9 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
509
514
|
argConstraints: new Map(body.argConstraints),
|
|
510
515
|
argParams: new Set(body.argParams),
|
|
511
516
|
};
|
|
512
|
-
expression.definitions.forEach((definition) =>
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
levels.argConstraints.forEach((value, key) =>
|
|
516
|
-
putArgConstraint(data.argConstraints, key, value),
|
|
517
|
-
);
|
|
518
|
-
levels.argParams.forEach((key) => data.argParams.add(key));
|
|
519
|
-
});
|
|
517
|
+
expression.definitions.forEach((definition) =>
|
|
518
|
+
mergeConstraints(data, analyzeDefinition(definition, inner)),
|
|
519
|
+
);
|
|
520
520
|
return data;
|
|
521
521
|
};
|
|
522
522
|
|
|
@@ -683,14 +683,14 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
683
683
|
toOperand(expression.function, scope),
|
|
684
684
|
expression.args.length === 1
|
|
685
685
|
? toOperand(expression.args[0], scope)
|
|
686
|
-
: { data: applyBuiltin(SET_LEVELS, expression.args, scope) },
|
|
686
|
+
: { kind: "Value", data: applyBuiltin(SET_LEVELS, expression.args, scope) },
|
|
687
687
|
]);
|
|
688
688
|
case "Bracket":
|
|
689
689
|
return createData();
|
|
690
690
|
case "FieldAccess":
|
|
691
691
|
return applyDefined(SELECT_LEVELS, [
|
|
692
692
|
toOperand(expression.record, scope),
|
|
693
|
-
{ data: createData() },
|
|
693
|
+
{ kind: "Value", data: createData() },
|
|
694
694
|
]);
|
|
695
695
|
case "BoxAction":
|
|
696
696
|
case "AngleAction":
|
|
@@ -753,10 +753,9 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
753
753
|
);
|
|
754
754
|
return names;
|
|
755
755
|
default:
|
|
756
|
-
|
|
757
|
-
visit(child, isNonLeibniz, bindFormals(scope, toFormals(bound)))
|
|
758
|
-
|
|
759
|
-
});
|
|
756
|
+
forEachChild(expression, (child, bound) =>
|
|
757
|
+
visit(child, isNonLeibniz, bindFormals(scope, toFormals(bound))),
|
|
758
|
+
);
|
|
760
759
|
return names;
|
|
761
760
|
}
|
|
762
761
|
};
|
|
@@ -869,9 +868,7 @@ export const analyzeAssumeProve = (
|
|
|
869
868
|
const data = createData(Math.max(...parts.map((part) => part.level)));
|
|
870
869
|
parts.forEach((part) => {
|
|
871
870
|
part.params.forEach((param) => data.params.add(param));
|
|
872
|
-
|
|
873
|
-
part.argConstraints.forEach((value, key) => putArgConstraint(data.argConstraints, key, value));
|
|
874
|
-
part.argParams.forEach((key) => data.argParams.add(key));
|
|
871
|
+
mergeConstraints(data, part);
|
|
875
872
|
});
|
|
876
873
|
return data;
|
|
877
874
|
};
|
package/src/liveness-checker.ts
CHANGED
|
@@ -89,14 +89,14 @@ const containsAlways = (expression: LiveExpression): boolean => {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
+
const isEmptyModel = (model: Solution["models"][number]) =>
|
|
93
|
+
model.eventuallyAlways.length === 0 &&
|
|
94
|
+
model.infinitelyOftenStates.length === 0 &&
|
|
95
|
+
model.infinitelyOftenActions.length === 0;
|
|
96
|
+
|
|
92
97
|
const isCycleConstrained = (solution: Solution) =>
|
|
93
98
|
solution.promises.some((promise) => containsAlways(promise.body)) ||
|
|
94
|
-
solution.models.some(
|
|
95
|
-
(model) =>
|
|
96
|
-
model.eventuallyAlways.length > 0 ||
|
|
97
|
-
model.infinitelyOftenStates.length > 0 ||
|
|
98
|
-
model.infinitelyOftenActions.length > 0,
|
|
99
|
-
);
|
|
99
|
+
solution.models.some((model) => !isEmptyModel(model));
|
|
100
100
|
|
|
101
101
|
const isSameState = (left: Value[], right: Value[]) =>
|
|
102
102
|
left.every((value, position) => isSameValue(value, right[position]));
|
|
@@ -315,13 +315,6 @@ export const createLivenessChecker = (
|
|
|
315
315
|
tableauNode.successors[0] === node
|
|
316
316
|
);
|
|
317
317
|
};
|
|
318
|
-
const hasEmptyModel = (behavior: BehaviorGraph) =>
|
|
319
|
-
behavior.solution.models.some(
|
|
320
|
-
(model) =>
|
|
321
|
-
model.eventuallyAlways.length === 0 &&
|
|
322
|
-
model.infinitelyOftenStates.length === 0 &&
|
|
323
|
-
model.infinitelyOftenActions.length === 0,
|
|
324
|
-
);
|
|
325
318
|
|
|
326
319
|
const getNodeId = (behavior: BehaviorGraph, state: number, tableauNode: number) => {
|
|
327
320
|
if (!behavior.solution.tableau) return state;
|
|
@@ -429,7 +422,7 @@ export const createLivenessChecker = (
|
|
|
429
422
|
if (
|
|
430
423
|
isAccepting(tableau, next) &&
|
|
431
424
|
behavior.errorNode === undefined &&
|
|
432
|
-
|
|
425
|
+
behavior.solution.models.some(isEmptyModel)
|
|
433
426
|
) {
|
|
434
427
|
behavior.errorNode = node;
|
|
435
428
|
return;
|
|
@@ -493,12 +486,9 @@ export const createLivenessChecker = (
|
|
|
493
486
|
});
|
|
494
487
|
writeNode(behavior, node, successors, actions, stateResults);
|
|
495
488
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
.reverse()
|
|
500
|
-
.map((node) => behavior.nodeStates[node]),
|
|
501
|
-
);
|
|
489
|
+
return behavior.errorNode === undefined
|
|
490
|
+
? undefined
|
|
491
|
+
: getStatePath(behavior, behavior.errorNode);
|
|
502
492
|
};
|
|
503
493
|
|
|
504
494
|
const addPlainState = (
|
|
@@ -545,6 +535,13 @@ export const createLivenessChecker = (
|
|
|
545
535
|
throw new TlaEvaluationError(`Couldn't re-create liveness trace (path) starting at: ${target}`);
|
|
546
536
|
};
|
|
547
537
|
|
|
538
|
+
const getStatePath = (behavior: BehaviorGraph, target: number) =>
|
|
539
|
+
removeRepeats(
|
|
540
|
+
getPath(behavior, target)
|
|
541
|
+
.reverse()
|
|
542
|
+
.map((node) => behavior.nodeStates[node]),
|
|
543
|
+
);
|
|
544
|
+
|
|
548
545
|
const findLassoInModel = (
|
|
549
546
|
behavior: BehaviorGraph,
|
|
550
547
|
model: Solution["models"][number],
|
|
@@ -606,11 +603,7 @@ export const createLivenessChecker = (
|
|
|
606
603
|
members: Set<number>,
|
|
607
604
|
membersByState: Map<number, number[]>,
|
|
608
605
|
) => {
|
|
609
|
-
const prefix =
|
|
610
|
-
getPath(behavior, root)
|
|
611
|
-
.reverse()
|
|
612
|
-
.map((node) => behavior.nodeStates[node]),
|
|
613
|
-
);
|
|
606
|
+
const prefix = getStatePath(behavior, root);
|
|
614
607
|
const cycleStack: number[] = [];
|
|
615
608
|
const seen = new Set<number>([root]);
|
|
616
609
|
const stateDone = model.infinitelyOftenStates.map(() => false);
|
|
@@ -618,7 +611,6 @@ export const createLivenessChecker = (
|
|
|
618
611
|
const promiseDone = solution.promises.map(() => false);
|
|
619
612
|
let remainingCount = stateDone.length + actionDone.length + promiseDone.length;
|
|
620
613
|
let currentNode = root;
|
|
621
|
-
const isMember = (node: number) => members.has(node);
|
|
622
614
|
const moveTo = (next: number) => {
|
|
623
615
|
cycleStack.push(currentNode);
|
|
624
616
|
currentNode = next;
|
|
@@ -644,7 +636,7 @@ export const createLivenessChecker = (
|
|
|
644
636
|
const countBeforeActions = remainingCount;
|
|
645
637
|
const isTaken = getNodeSuccessors(behavior, currentNode).some((next, edge) => {
|
|
646
638
|
if (membersByState.has(behavior.nodeStates[next])) {
|
|
647
|
-
if (!
|
|
639
|
+
if (!members.has(next) || !isAllowed(currentNode, edge)) return false;
|
|
648
640
|
lastNext = next;
|
|
649
641
|
model.infinitelyOftenActions.forEach((position, slot) => {
|
|
650
642
|
if (!actionDone[slot] && getAction(currentNode, edge, position)) {
|
|
@@ -658,7 +650,7 @@ export const createLivenessChecker = (
|
|
|
658
650
|
seen.clear();
|
|
659
651
|
return true;
|
|
660
652
|
}
|
|
661
|
-
if (
|
|
653
|
+
if (members.has(next) && !seen.has(next)) unvisitedNext = next;
|
|
662
654
|
return false;
|
|
663
655
|
});
|
|
664
656
|
if (isTaken) break;
|
|
@@ -677,14 +669,14 @@ export const createLivenessChecker = (
|
|
|
677
669
|
currentNode = previous;
|
|
678
670
|
unvisitedNext =
|
|
679
671
|
getNodeSuccessors(behavior, previous).find(
|
|
680
|
-
(next) =>
|
|
672
|
+
(next) => members.has(next) && !seen.has(next),
|
|
681
673
|
) ?? -1;
|
|
682
674
|
}
|
|
683
675
|
moveTo(unvisitedNext);
|
|
684
676
|
seen.add(unvisitedNext);
|
|
685
677
|
}
|
|
686
678
|
}
|
|
687
|
-
const postfix = getClosingPath(root, currentNode, membersByState
|
|
679
|
+
const postfix = getClosingPath(root, currentNode, membersByState);
|
|
688
680
|
for (let position = cycleStack.length - 1; position >= 0; position--) {
|
|
689
681
|
const state = behavior.nodeStates[cycleStack[position]];
|
|
690
682
|
if (postfix[postfix.length - 1] !== state) postfix.push(state);
|
|
@@ -698,12 +690,7 @@ export const createLivenessChecker = (
|
|
|
698
690
|
};
|
|
699
691
|
};
|
|
700
692
|
|
|
701
|
-
const getClosingPath = (
|
|
702
|
-
root: number,
|
|
703
|
-
end: number,
|
|
704
|
-
membersByState: Map<number, number[]>,
|
|
705
|
-
isAllowedEdge: (node: number, edge: number) => boolean,
|
|
706
|
-
) => {
|
|
693
|
+
const getClosingPath = (root: number, end: number, membersByState: Map<number, number[]>) => {
|
|
707
694
|
if (end === root) return [];
|
|
708
695
|
const start = behavior.nodeStates[end];
|
|
709
696
|
const parents = new Map<number, number>();
|
|
@@ -712,7 +699,7 @@ export const createLivenessChecker = (
|
|
|
712
699
|
for (let state = start, parent = -1, position = 0; ; position++) {
|
|
713
700
|
for (const node of membersByState.get(state) ?? []) {
|
|
714
701
|
for (const [edge, next] of getNodeSuccessors(behavior, node).entries()) {
|
|
715
|
-
if (next === node || !
|
|
702
|
+
if (next === node || !isAllowed(node, edge)) continue;
|
|
716
703
|
if (next === root) {
|
|
717
704
|
const path: number[] = [];
|
|
718
705
|
for (let item = state, itemParent = parent; item !== start;) {
|
package/src/liveness.ts
CHANGED
|
@@ -56,6 +56,13 @@ export interface TemporalProperty extends ScopedExpression {
|
|
|
56
56
|
name: string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
interface Expansion {
|
|
60
|
+
name: string | undefined;
|
|
61
|
+
path: string[];
|
|
62
|
+
expanding: Set<Definition>;
|
|
63
|
+
isSubstituted: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
59
66
|
const MAXIMUM_EXPANSION_DEPTH = 100;
|
|
60
67
|
|
|
61
68
|
export const createTautologyError = () =>
|
|
@@ -210,31 +217,26 @@ export const expandTemporal = (
|
|
|
210
217
|
scope: Scope | undefined,
|
|
211
218
|
environment: Environment,
|
|
212
219
|
isProperty: boolean,
|
|
213
|
-
|
|
214
|
-
isSubstituted = false,
|
|
215
|
-
name?: string,
|
|
216
|
-
path: string[] = [],
|
|
220
|
+
expansion: Expansion = { name: undefined, path: [], expanding: new Set(), isSubstituted: false },
|
|
217
221
|
): ExpandedExpression[] => {
|
|
218
222
|
const expand = (
|
|
219
223
|
child: Expression,
|
|
220
224
|
childScope: Scope | undefined,
|
|
221
|
-
childName = name,
|
|
222
|
-
childExpanding = expanding,
|
|
225
|
+
childName = expansion.name,
|
|
226
|
+
childExpanding = expansion.expanding,
|
|
223
227
|
definition?: Definition,
|
|
224
228
|
): ExpandedExpression[] =>
|
|
225
|
-
expandTemporal(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
expandTemporal(child, childScope, environment, isProperty, {
|
|
230
|
+
name: childName,
|
|
231
|
+
path:
|
|
232
|
+
definition?.kind === "Operator" && definition.params.length === 0
|
|
233
|
+
? [...expansion.path, definition.name]
|
|
234
|
+
: expansion.path,
|
|
235
|
+
expanding: childExpanding,
|
|
236
|
+
isSubstituted:
|
|
237
|
+
expansion.isSubstituted ||
|
|
232
238
|
(definition !== undefined && environment.substitutedDefinitions.has(definition)),
|
|
233
|
-
|
|
234
|
-
definition?.kind === "Operator" && definition.params.length === 0
|
|
235
|
-
? [...path, definition.name]
|
|
236
|
-
: path,
|
|
237
|
-
);
|
|
239
|
+
});
|
|
238
240
|
if (expression.kind === "And") {
|
|
239
241
|
return expression.operands.flatMap((operand) => expand(operand, scope, describeRange(operand)));
|
|
240
242
|
}
|
|
@@ -248,7 +250,7 @@ export const expandTemporal = (
|
|
|
248
250
|
return expand(
|
|
249
251
|
binding.expression,
|
|
250
252
|
binding.scope,
|
|
251
|
-
definitionThunks.has(binding) ? expression.name : name,
|
|
253
|
+
definitionThunks.has(binding) ? expression.name : expansion.name,
|
|
252
254
|
);
|
|
253
255
|
}
|
|
254
256
|
const definition = environment.constants.has(expression.name)
|
|
@@ -261,14 +263,15 @@ export const expandTemporal = (
|
|
|
261
263
|
(getDefinitionLevel(definition, environment) > CONSTANT_LEVEL ||
|
|
262
264
|
getStartupValue(definition, environment) === undefined)
|
|
263
265
|
) {
|
|
264
|
-
if (expanding.has(definition)) {
|
|
266
|
+
if (expansion.expanding.has(definition)) {
|
|
265
267
|
throw createStackOverflowError();
|
|
266
268
|
}
|
|
267
269
|
return expand(
|
|
268
270
|
definition.body,
|
|
269
271
|
undefined,
|
|
270
|
-
(!isSubstituted && environment.instanceNames.get(expression.name)) ||
|
|
271
|
-
|
|
272
|
+
(!expansion.isSubstituted && environment.instanceNames.get(expression.name)) ||
|
|
273
|
+
definition.name,
|
|
274
|
+
new Set([...expansion.expanding, definition]),
|
|
272
275
|
definition,
|
|
273
276
|
);
|
|
274
277
|
}
|
|
@@ -290,13 +293,13 @@ export const expandTemporal = (
|
|
|
290
293
|
operator?.kind === "Closure" &&
|
|
291
294
|
operator.params.length === expression.args.length &&
|
|
292
295
|
!definition?.isRecursive &&
|
|
293
|
-
(!isSubstituted || isOwnArgumentFree);
|
|
296
|
+
(!expansion.isSubstituted || isOwnArgumentFree);
|
|
294
297
|
if (isExpandable) {
|
|
295
298
|
return expand(
|
|
296
299
|
operator.body,
|
|
297
300
|
bindOperatorArguments(operator, expression.args, context),
|
|
298
|
-
isSubstituted && definition ? definition.name : expression.operator,
|
|
299
|
-
expanding,
|
|
301
|
+
expansion.isSubstituted && definition ? definition.name : expression.operator,
|
|
302
|
+
expansion.expanding,
|
|
300
303
|
definition,
|
|
301
304
|
);
|
|
302
305
|
}
|
|
@@ -315,7 +318,7 @@ export const expandTemporal = (
|
|
|
315
318
|
if (expanded.length === 0) throw createTautologyError();
|
|
316
319
|
return expanded;
|
|
317
320
|
}
|
|
318
|
-
return [{ expression, scope, name, path }];
|
|
321
|
+
return [{ expression, scope, name: expansion.name, path: expansion.path }];
|
|
319
322
|
};
|
|
320
323
|
|
|
321
324
|
const bindLetDefinitions = (
|
|
@@ -483,42 +486,16 @@ export const toLiveExpression = (
|
|
|
483
486
|
return level > ACTION_LEVEL ? parts : toAtom(expression, scope, level);
|
|
484
487
|
};
|
|
485
488
|
|
|
486
|
-
|
|
487
|
-
expression.kind === "Label" ||
|
|
488
|
-
expression.kind === "Let" ||
|
|
489
|
-
expression.kind === "And" ||
|
|
490
|
-
expression.kind === "Or" ||
|
|
491
|
-
expression.kind === "Forall" ||
|
|
492
|
-
expression.kind === "Exists" ||
|
|
493
|
-
expression.kind === "If" ||
|
|
494
|
-
(expression.kind === "Apply" &&
|
|
495
|
-
((expression.operator === "~" && !isLocallyResolved(expression)) ||
|
|
496
|
-
expression.operator === "=>"));
|
|
497
|
-
|
|
489
|
+
// These forms are translated part by part at every level; any other form below the temporal level is an atom.
|
|
498
490
|
const convert = (expression: Expression, scope: Scope | undefined): LiveExpression => {
|
|
499
491
|
const level = getLevel(expression, scope, environment);
|
|
500
|
-
if (level <= ACTION_LEVEL && !isTranslatedWhole(expression)) {
|
|
501
|
-
return toAtom(expression, scope, level);
|
|
502
|
-
}
|
|
503
492
|
switch (expression.kind) {
|
|
504
493
|
case "Label":
|
|
505
494
|
return convert(expression.body, scope);
|
|
506
495
|
case "Let":
|
|
507
496
|
return convert(expression.body, bindLetDefinitions(expression, scope, environment));
|
|
508
|
-
case "Identifier":
|
|
509
|
-
return convertCall(expression, scope);
|
|
510
497
|
case "Apply": {
|
|
511
498
|
const args = expression.args;
|
|
512
|
-
if (expression.operator === "~>") {
|
|
513
|
-
return createUnary(
|
|
514
|
-
"Always",
|
|
515
|
-
createPair(
|
|
516
|
-
"Or",
|
|
517
|
-
createUnary("Not", convert(args[0], scope)),
|
|
518
|
-
createUnary("Eventually", convert(args[1], scope)),
|
|
519
|
-
),
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
499
|
if (expression.operator === "~" && !isLocallyResolved(expression)) {
|
|
523
500
|
return toWhole(expression, scope, createUnary("Not", convert(args[0], scope)));
|
|
524
501
|
}
|
|
@@ -529,7 +506,7 @@ export const toLiveExpression = (
|
|
|
529
506
|
createPair("Or", createUnary("Not", convert(args[0], scope)), convert(args[1], scope)),
|
|
530
507
|
);
|
|
531
508
|
}
|
|
532
|
-
|
|
509
|
+
break;
|
|
533
510
|
}
|
|
534
511
|
case "And":
|
|
535
512
|
case "Or":
|
|
@@ -566,6 +543,22 @@ export const toLiveExpression = (
|
|
|
566
543
|
),
|
|
567
544
|
);
|
|
568
545
|
}
|
|
546
|
+
}
|
|
547
|
+
if (level <= ACTION_LEVEL) return toAtom(expression, scope, level);
|
|
548
|
+
switch (expression.kind) {
|
|
549
|
+
case "Identifier":
|
|
550
|
+
return convertCall(expression, scope);
|
|
551
|
+
case "Apply":
|
|
552
|
+
return expression.operator === "~>"
|
|
553
|
+
? createUnary(
|
|
554
|
+
"Always",
|
|
555
|
+
createPair(
|
|
556
|
+
"Or",
|
|
557
|
+
createUnary("Not", convert(expression.args[0], scope)),
|
|
558
|
+
createUnary("Eventually", convert(expression.args[1], scope)),
|
|
559
|
+
),
|
|
560
|
+
)
|
|
561
|
+
: convertCall(expression, scope);
|
|
569
562
|
case "Always":
|
|
570
563
|
case "Eventually":
|
|
571
564
|
return createUnary(expression.kind, convert(expression.expression, scope));
|