tla-ts 0.0.4-dev.c4929d7 → 0.0.4-dev.ca40dfe
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/README.md +31 -6
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +27 -27
- package/dist/deciders.js +34 -34
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -14
- package/dist/index.d.ts +12 -14
- 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 +37 -27
- package/dist/prove.js +39 -29
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +76 -86
- package/dist/transfer.js +73 -83
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1154
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/cli/tlc.ts +941 -0
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +12 -36
- package/src/evaluate.ts +81 -101
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/obligations/action.ts +9 -45
- package/src/obligations/{anon.ts → anonymize.ts} +13 -25
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +42 -517
- package/src/obligations/generate.ts +88 -778
- package/src/obligations/index.ts +20 -22
- package/src/obligations/levels.ts +36 -41
- package/src/obligations/module.ts +88 -708
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +21 -15
- package/src/obligations/printer.ts +81 -188
- package/src/obligations/proof.ts +0 -1
- package/src/obligations/regroup.ts +100 -0
- package/src/obligations/simplify.ts +668 -0
- package/src/obligations/source.ts +25 -131
- package/src/obligations/{deref.ts → subexpression.ts} +48 -56
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +28 -26
- package/src/obligations/tuples.ts +37 -53
- package/src/parallel-worker.ts +37 -33
- package/src/parallel.ts +30 -24
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prove/decide-pool.ts +7 -12
- package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
- package/src/prove/isabelle/decide.ts +3 -6
- package/src/prove/isabelle/encode.ts +35 -93
- package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
- package/src/prove/isabelle/isar/method.ts +3 -3
- package/src/prove/isabelle/isar/type-check.ts +1 -1
- package/src/prove/isabelle/provers/blast/blast.ts +1 -1
- package/src/prove/isabelle/provers/blast/branch.ts +1 -1
- package/src/prove/isabelle/provers/blast/term.ts +3 -4
- package/src/prove/isabelle/provers/clasimp.ts +1 -1
- package/src/prove/isabelle/provers/classical.ts +3 -3
- package/src/prove/isabelle/provers/hypsubst.ts +1 -9
- package/src/prove/isabelle/pure/conv.ts +1 -1
- package/src/prove/isabelle/pure/drule.ts +2 -2
- package/src/prove/isabelle/pure/envir.ts +3 -35
- package/src/prove/isabelle/pure/logic.ts +4 -76
- package/src/prove/isabelle/pure/name.ts +1 -13
- package/src/prove/isabelle/pure/net.ts +2 -49
- package/src/prove/isabelle/pure/pattern.ts +3 -22
- package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
- package/src/prove/isabelle/pure/seq.ts +0 -23
- package/src/prove/isabelle/pure/simplifier.ts +2 -8
- package/src/prove/isabelle/pure/table.ts +1 -8
- package/src/prove/isabelle/pure/tactic.ts +5 -113
- package/src/prove/isabelle/pure/tactical.ts +1 -84
- package/src/prove/isabelle/pure/term-ord.ts +1 -55
- package/src/prove/isabelle/pure/term.ts +8 -128
- package/src/prove/isabelle/pure/thm.ts +4 -27
- package/src/prove/isabelle/pure/type.ts +0 -12
- package/src/prove/isabelle/pure/unify.ts +1 -1
- package/src/prove/isabelle/tla/classical-setup.ts +1 -1
- package/src/prove/ocaml.ts +1 -1
- package/src/prove/prep/action.ts +23 -36
- package/src/prove/prep/enabled-axioms.ts +2 -2
- package/src/prove/prep/fingerprint.ts +3 -3
- package/src/prove/prep/level-comparison.ts +9 -37
- package/src/prove/prep/md5.ts +2 -9
- package/src/prove/prep/normalize.ts +309 -0
- package/src/prove/prove-worker.ts +2 -5
- package/src/prove/prove.ts +98 -111
- package/src/prove/ptl/encode.ts +19 -31
- package/src/prove/smt/axioms.ts +45 -58
- package/src/prove/smt/encode.ts +124 -15
- package/src/prove/smt/instances.ts +2 -3
- package/src/prove/smt/rewrite.ts +24 -31
- package/src/prove/smt/solver/ast-util.ts +0 -56
- package/src/prove/smt/solver/case-split-queue.ts +1 -1
- package/src/prove/smt/solver/enode.ts +1 -1
- package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
- package/src/prove/smt/solver/model-macro-solver.ts +1 -1
- package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
- package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
- package/src/prove/smt/solver/nlsat/explain.ts +1 -1
- package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
- package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
- package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
- package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
- package/src/prove/smt/solver/pattern-inference.ts +1 -1
- package/src/prove/smt/solver/relevancy.ts +2 -2
- package/src/prove/smt/solver/rewriter.ts +1 -1
- package/src/prove/smt/solver/solver.ts +2 -2
- package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
- package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
- package/src/prove/verdict.ts +0 -5
- package/src/prove/zenon/decide.ts +5 -11
- package/src/prove/zenon/encode.ts +21 -80
- package/src/prove/zenon/eqrel.ts +1 -1
- package/src/prove/zenon/equality-rules.ts +1 -1
- package/src/prove/zenon/expr.ts +2 -2
- package/src/prove/zenon/index-table.ts +1 -1
- package/src/prove/zenon/isar.ts +1 -1
- package/src/prove/zenon/llproof.ts +1 -1
- package/src/prove/zenon/mltoll.ts +1 -1
- package/src/prove/zenon/node.ts +1 -1
- package/src/prove/zenon/search.ts +1 -1
- package/src/prove/zenon/tla/terms.ts +1 -20
- package/src/prove/zenon/tla/tla.ts +1 -1
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +16 -19
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -213
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/transfer.ts +32 -32
- package/src/values.ts +72 -67
- package/src/worker.ts +1 -4
- package/dist/run-cli.cjs +0 -45
- package/dist/run-cli.js +0 -45
- package/src/canonical.ts +0 -40
- package/src/obligations/ctx.ts +0 -64
- package/src/prove/prep/defs.ts +0 -33
- package/src/prove/prep/elab.ts +0 -156
- package/src/prove/prep/enabled.ts +0 -43
- package/src/prove/prep/flatten.ts +0 -70
- package/src/prove/prep/trivial.ts +0 -22
- package/src/prove/smt/axiomatize.ts +0 -69
- package/src/prove/smt/simplify.ts +0 -57
- package/src/run-cli.ts +0 -1806
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
- /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
package/src/obligations/ctx.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// tlapm's Ctx, which names each binder apart from the names in scope by adding a salt, as a
|
|
2
|
-
// mutable stack: printers bind and unbind names in strict nesting order.
|
|
3
|
-
|
|
4
|
-
interface Ident {
|
|
5
|
-
rep: string;
|
|
6
|
-
salt: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface Context {
|
|
10
|
-
stack: Ident[];
|
|
11
|
-
idents: Map<string, Ident[]>;
|
|
12
|
-
defined: Map<string, number>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const getIdentName = (ident: Ident) =>
|
|
16
|
-
ident.salt === 0 ? ident.rep : `${ident.rep}_${ident.salt}`;
|
|
17
|
-
|
|
18
|
-
export const createContext = (): Context => ({
|
|
19
|
-
stack: [],
|
|
20
|
-
idents: new Map(),
|
|
21
|
-
defined: new Map(),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// The name of the binder index places in, counting from 1 for the innermost.
|
|
25
|
-
export const getBoundName = (context: Context, index: number) => {
|
|
26
|
-
const ident = context.stack[context.stack.length - index];
|
|
27
|
-
return ident && getIdentName(ident);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const pushName = (context: Context, rep: string) => {
|
|
31
|
-
const previous = context.idents.get(rep)?.at(-1);
|
|
32
|
-
let ident: Ident = previous ? { rep, salt: previous.salt + 1 } : { rep, salt: 0 };
|
|
33
|
-
while (context.defined.has(getIdentName(ident))) ident = { rep, salt: ident.salt + 1 };
|
|
34
|
-
context.stack.push(ident);
|
|
35
|
-
const idents = context.idents.get(rep);
|
|
36
|
-
if (idents) idents.push(ident);
|
|
37
|
-
else context.idents.set(rep, [ident]);
|
|
38
|
-
const key = getIdentName(ident);
|
|
39
|
-
context.defined.set(key, (context.defined.get(key) ?? 0) + 1);
|
|
40
|
-
return key;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const popNames = (context: Context, count: number) => {
|
|
44
|
-
for (let index = 0; index < count; index++) {
|
|
45
|
-
const ident = context.stack.pop();
|
|
46
|
-
if (!ident) return;
|
|
47
|
-
context.idents.get(ident.rep)?.pop();
|
|
48
|
-
const key = getIdentName(ident);
|
|
49
|
-
const remaining = (context.defined.get(key) ?? 1) - 1;
|
|
50
|
-
if (remaining === 0) context.defined.delete(key);
|
|
51
|
-
else context.defined.set(key, remaining);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const withNames = <Result>(
|
|
56
|
-
context: Context,
|
|
57
|
-
names: string[],
|
|
58
|
-
body: (idents: string[]) => Result,
|
|
59
|
-
) => {
|
|
60
|
-
const idents = names.map((name) => pushName(context, name));
|
|
61
|
-
const result = body(idents);
|
|
62
|
-
popNames(context, names.length);
|
|
63
|
-
return result;
|
|
64
|
-
};
|
package/src/prove/prep/defs.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
bumpBy,
|
|
3
|
-
consSubstitution,
|
|
4
|
-
createContextMap,
|
|
5
|
-
shift,
|
|
6
|
-
substituteExpr,
|
|
7
|
-
substituteHyp,
|
|
8
|
-
type Sequent,
|
|
9
|
-
} from "../../obligations/expression";
|
|
10
|
-
|
|
11
|
-
const createExpander = (isPragmaExpanded: boolean) =>
|
|
12
|
-
createContextMap(shift(0), (current, hyp) => {
|
|
13
|
-
if (
|
|
14
|
-
hyp.kind === "Defn" &&
|
|
15
|
-
((isPragmaExpanded && hyp.definition.kind === "Bpragma") ||
|
|
16
|
-
(hyp.definition.kind === "Operator" && hyp.visibility === "Visible"))
|
|
17
|
-
) {
|
|
18
|
-
return [consSubstitution(substituteExpr(current, hyp.definition.body), current), undefined];
|
|
19
|
-
}
|
|
20
|
-
return [bumpBy(1, current), substituteHyp(current, hyp)];
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const expandWithPragmas = createExpander(true);
|
|
24
|
-
|
|
25
|
-
const expandOperators = createExpander(false);
|
|
26
|
-
|
|
27
|
-
// expand_defs: each visible operator definition and each pragma, whatever its visibility,
|
|
28
|
-
// substitutes into the rest of the obligation and leaves the context. Toolbox.expand_defs leaves
|
|
29
|
-
// the pragmas.
|
|
30
|
-
export const expandDefs = (sequent: Sequent, isPragmaExpanded = true): Sequent => {
|
|
31
|
-
const expanded = (isPragmaExpanded ? expandWithPragmas : expandOperators)(sequent.context);
|
|
32
|
-
return { context: expanded.context, active: substituteExpr(expanded.state, sequent.active) };
|
|
33
|
-
};
|
package/src/prove/prep/elab.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// A port of tlapm's Expr.Elab.normalize, which the backends run on each obligation after expanding
|
|
2
|
-
// its definitions: LET definitions are inlined, and the updates of an EXCEPT fold into the
|
|
3
|
-
// function they update.
|
|
4
|
-
|
|
5
|
-
import { TlaProofError } from "../../errors";
|
|
6
|
-
import {
|
|
7
|
-
at,
|
|
8
|
-
consSubstitution,
|
|
9
|
-
createContextMap,
|
|
10
|
-
getChildren,
|
|
11
|
-
isEqualExpr,
|
|
12
|
-
mapChildren,
|
|
13
|
-
mapExceptSpecs,
|
|
14
|
-
mapHyp,
|
|
15
|
-
shift,
|
|
16
|
-
substituteExpr,
|
|
17
|
-
type Expr,
|
|
18
|
-
type ExceptPoint,
|
|
19
|
-
type Hyp,
|
|
20
|
-
type Sequent,
|
|
21
|
-
} from "../../obligations/expression";
|
|
22
|
-
|
|
23
|
-
type ExceptExpr = Extract<Expr, { kind: "Except" }>;
|
|
24
|
-
|
|
25
|
-
type ExceptSpec = ExceptExpr["specs"][number];
|
|
26
|
-
|
|
27
|
-
const TEMPORAL_BUILTINS = new Set(["BoxTrue", "BoxFalse", "Diamond", "Actplus", "Leadsto", "Cdot"]);
|
|
28
|
-
|
|
29
|
-
// The expressions of a hypothesis that Visit.iter visits, none for a hidden one.
|
|
30
|
-
const getVisitedExprs = (hyp: Hyp): Expr[] => {
|
|
31
|
-
switch (hyp.kind) {
|
|
32
|
-
case "Fresh":
|
|
33
|
-
return hyp.domain ? [hyp.domain] : [];
|
|
34
|
-
case "Flex":
|
|
35
|
-
return [];
|
|
36
|
-
case "Defn":
|
|
37
|
-
return hyp.visibility === "Hidden" ||
|
|
38
|
-
(hyp.definition.kind !== "Operator" && hyp.definition.kind !== "Bpragma")
|
|
39
|
-
? []
|
|
40
|
-
: [hyp.definition.body];
|
|
41
|
-
case "Fact":
|
|
42
|
-
return hyp.visibility === "Hidden" ? [] : [hyp.expression];
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// non_temporal: no temporal operator, but in hidden hypotheses.
|
|
47
|
-
const isNonTemporal = (expression: Expr): boolean => {
|
|
48
|
-
if (expression.kind === "Tsub" || expression.kind === "Fair") return false;
|
|
49
|
-
if (
|
|
50
|
-
expression.kind === "Apply" &&
|
|
51
|
-
expression.operator.kind === "Internal" &&
|
|
52
|
-
TEMPORAL_BUILTINS.has(expression.operator.builtin)
|
|
53
|
-
)
|
|
54
|
-
return false;
|
|
55
|
-
if (expression.kind === "Sequent") {
|
|
56
|
-
const sequent = expression.sequent;
|
|
57
|
-
return [...sequent.context.flatMap(getVisitedExprs), sequent.active].every(isNonTemporal);
|
|
58
|
-
}
|
|
59
|
-
return getChildren(expression).every(isNonTemporal);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// let_normalize: each LET definition is substituted into the rest of the LET.
|
|
63
|
-
const normalizeLet = (expression: Expr): Expr => {
|
|
64
|
-
if (expression.kind !== "Let") return mapChildren(expression, normalizeLet);
|
|
65
|
-
const [definition, ...definitions] = expression.definitions;
|
|
66
|
-
if (!definition) return normalizeLet(expression.body);
|
|
67
|
-
if (definition.kind !== "Operator" && definition.kind !== "Bpragma") {
|
|
68
|
-
throw new TlaProofError(
|
|
69
|
-
definition.kind === "Instance"
|
|
70
|
-
? "Found INSTANCE in Expr.Elab.let_normalize, all INSTANCE statements have been replaced with definitions in Module.Elab "
|
|
71
|
-
: "Expr.Elab.let_normalize",
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
const operator = normalizeLet(definition.body);
|
|
75
|
-
const rest: Expr = { ...expression, definitions };
|
|
76
|
-
return normalizeLet(substituteExpr(consSubstitution(operator, shift(0)), rest));
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const getAccess = (base: Expr, point: ExceptPoint): Expr =>
|
|
80
|
-
point.kind === "Dot"
|
|
81
|
-
? at({ kind: "Dot", expression: base, field: point.field }, base)
|
|
82
|
-
: at({ kind: "FcnApp", function: base, args: [point.expression] }, base);
|
|
83
|
-
|
|
84
|
-
const isSameHead = (left: ExceptPoint, right: ExceptPoint) =>
|
|
85
|
-
left.kind === "Dot"
|
|
86
|
-
? right.kind === "Dot" && left.field === right.field
|
|
87
|
-
: right.kind === "Apply" && isEqualExpr(left.expression, right.expression);
|
|
88
|
-
|
|
89
|
-
// The field of a record constructor that a point names, as a field or as a string argument.
|
|
90
|
-
const getRecordField = (record: Expr, point: ExceptPoint) => {
|
|
91
|
-
const name =
|
|
92
|
-
point.kind === "Dot"
|
|
93
|
-
? point.field
|
|
94
|
-
: point.expression.kind === "String"
|
|
95
|
-
? point.expression.value
|
|
96
|
-
: undefined;
|
|
97
|
-
return record.kind === "Record" && name !== undefined
|
|
98
|
-
? record.fields.find((field) => field.name === name)
|
|
99
|
-
: undefined;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// except_normalize: [f EXCEPT p1 = b1, ...] folds left to right into f, sharing each prefix of
|
|
103
|
-
// adjacent updates and updating a record constructor in place on a field it has.
|
|
104
|
-
const normalizeExcept = (expression: Expr): Expr => {
|
|
105
|
-
if (expression.kind !== "Except") return mapChildren(expression, normalizeExcept);
|
|
106
|
-
const except = expression;
|
|
107
|
-
const select = (base: Expr, point: ExceptPoint) =>
|
|
108
|
-
getRecordField(base, point)?.value ?? getAccess(base, point);
|
|
109
|
-
const update = (base: Expr, point: ExceptPoint, value: Expr): Expr => {
|
|
110
|
-
const field = getRecordField(base, point);
|
|
111
|
-
if (base.kind !== "Record" || !field)
|
|
112
|
-
return at({ kind: "Except", function: base, specs: [{ trail: [point], value }] }, except);
|
|
113
|
-
const fields = base.fields.map((entry) =>
|
|
114
|
-
entry.name === field.name ? { name: entry.name, value } : entry,
|
|
115
|
-
);
|
|
116
|
-
return at({ kind: "Record", fields }, base);
|
|
117
|
-
};
|
|
118
|
-
const apply = (base: Expr, specs: ExceptSpec[]): Expr => {
|
|
119
|
-
const [first, ...others] = specs;
|
|
120
|
-
if (!first) return base;
|
|
121
|
-
if (first.trail.length === 0) return apply(first.value, others);
|
|
122
|
-
const head = first.trail[0];
|
|
123
|
-
const end = specs.findIndex(
|
|
124
|
-
(spec) => spec.trail.length === 0 || !isSameHead(spec.trail[0], head),
|
|
125
|
-
);
|
|
126
|
-
const count = end === -1 ? specs.length : end;
|
|
127
|
-
const tails = specs
|
|
128
|
-
.slice(0, count)
|
|
129
|
-
.map((spec) => ({ trail: spec.trail.slice(1), value: spec.value }));
|
|
130
|
-
return apply(update(base, head, apply(select(base, head), tails)), specs.slice(count));
|
|
131
|
-
};
|
|
132
|
-
return apply(normalizeExcept(except.function), mapExceptSpecs(except.specs, normalizeExcept));
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// let_normalize on each hypothesis, and whether the context so far is non_temporal.
|
|
136
|
-
const normalizeLetContext = createContextMap(true, (isContextNonTemporal, hyp) => [
|
|
137
|
-
isContextNonTemporal && getVisitedExprs(hyp).every(isNonTemporal),
|
|
138
|
-
mapHyp(hyp, normalizeLet, "all"),
|
|
139
|
-
]);
|
|
140
|
-
|
|
141
|
-
const normalizeExceptContext = createContextMap(undefined, (_state, hyp) => [
|
|
142
|
-
undefined,
|
|
143
|
-
mapHyp(hyp, normalizeExcept, "all"),
|
|
144
|
-
]);
|
|
145
|
-
|
|
146
|
-
// normalize, on an obligation as a sequent expression, as Backend.Prep.normalize_expr calls it.
|
|
147
|
-
export const normalizeSequent = (sequent: Sequent): Sequent => {
|
|
148
|
-
const inlined = normalizeLetContext(sequent.context);
|
|
149
|
-
const active = normalizeLet(sequent.active);
|
|
150
|
-
return inlined.state && isNonTemporal(sequent.active)
|
|
151
|
-
? {
|
|
152
|
-
context: normalizeExceptContext(sequent.context, inlined.context).context,
|
|
153
|
-
active: normalizeExcept(active),
|
|
154
|
-
}
|
|
155
|
-
: { context: inlined.context, active };
|
|
156
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { TlapmBugError } from "../../errors";
|
|
2
|
-
import { expandActionOperators, lambdify } from "../../obligations/action";
|
|
3
|
-
import { createAnonymizer } from "../../obligations/anon";
|
|
4
|
-
import type { Expr, Sequent } from "../../obligations/expression";
|
|
5
|
-
import { implicationToEnabled } from "./enabled-axioms";
|
|
6
|
-
import { checkLevelChange } from "./level-comparison";
|
|
7
|
-
|
|
8
|
-
// expand_enabled_cdot: the first frontend the methods cite, in tlapm's order, transforms the
|
|
9
|
-
// obligation. Its soundness checks throw a TlaProverError, as tlapm then runs no backend.
|
|
10
|
-
export const expandEnabledCdot = (sequent: Sequent, frontends: Set<string>): Sequent => {
|
|
11
|
-
const isEnabled = frontends.has("expandenabled");
|
|
12
|
-
const isCdot = frontends.has("expandcdot");
|
|
13
|
-
const isAutoUse = frontends.has("autouse");
|
|
14
|
-
const isLambdify = frontends.has("lambdify");
|
|
15
|
-
if (!isEnabled && !isCdot && !isLambdify) {
|
|
16
|
-
if (frontends.has("levelcomparison")) return checkLevelChange(sequent);
|
|
17
|
-
if (frontends.has("enabledaxioms")) return implicationToEnabled(sequent);
|
|
18
|
-
return sequent;
|
|
19
|
-
}
|
|
20
|
-
// Expr.Anon's anon, which only meets the names that lambdification binds.
|
|
21
|
-
const anonymizer = createAnonymizer(
|
|
22
|
-
{ value: 0 },
|
|
23
|
-
() => {
|
|
24
|
-
throw new TlapmBugError();
|
|
25
|
-
},
|
|
26
|
-
() => {},
|
|
27
|
-
);
|
|
28
|
-
const expression: Expr = { kind: "Sequent", sequent };
|
|
29
|
-
const result =
|
|
30
|
-
isEnabled || isCdot
|
|
31
|
-
? expandActionOperators(anonymizer, () => {}, undefined, expression, {
|
|
32
|
-
isEnabled,
|
|
33
|
-
isCdot,
|
|
34
|
-
isAutoUse,
|
|
35
|
-
})
|
|
36
|
-
: lambdify(anonymizer, () => {}, undefined, expression, {
|
|
37
|
-
isEnabled: true,
|
|
38
|
-
isCdot: true,
|
|
39
|
-
isAutoUse,
|
|
40
|
-
});
|
|
41
|
-
if (result.kind !== "Sequent") throw new TlapmBugError();
|
|
42
|
-
return result.sequent;
|
|
43
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
at,
|
|
3
|
-
bumpBy,
|
|
4
|
-
shift,
|
|
5
|
-
shiftExpr,
|
|
6
|
-
substituteExpr,
|
|
7
|
-
substituteHyp,
|
|
8
|
-
type Bound,
|
|
9
|
-
type Expr,
|
|
10
|
-
type Hyp,
|
|
11
|
-
type Sequent,
|
|
12
|
-
type Substitution,
|
|
13
|
-
} from "../../obligations/expression";
|
|
14
|
-
|
|
15
|
-
const isUnbounded = (bound: Bound) => bound.domain.kind === "NoDomain";
|
|
16
|
-
|
|
17
|
-
// extract_equalities: the equalities in a conjunction, apart from the rest of it.
|
|
18
|
-
const extractEqualities = (expression: Expr): [Expr[], Expr | undefined] => {
|
|
19
|
-
if (expression.kind === "List" && (expression.bullet === "And" || expression.bullet === "Refs")) {
|
|
20
|
-
const parts = expression.items.map(extractEqualities);
|
|
21
|
-
const equalities = parts.flatMap((part) => part[0]);
|
|
22
|
-
const rest = parts.flatMap((part) => (part[1] ? [part[1]] : []));
|
|
23
|
-
if (rest.length <= 1) return [equalities, rest[0]];
|
|
24
|
-
return [equalities, { ...expression, bullet: "And", items: rest }];
|
|
25
|
-
}
|
|
26
|
-
if (expression.kind === "Apply" && expression.operator.kind === "Internal") {
|
|
27
|
-
const builtin = expression.operator.builtin;
|
|
28
|
-
if (builtin === "Conj" && expression.args.length === 2) {
|
|
29
|
-
const left = extractEqualities(expression.args[0]);
|
|
30
|
-
const right = extractEqualities(expression.args[1]);
|
|
31
|
-
const equalities = [...left[0], ...right[0]];
|
|
32
|
-
if (left[1] && right[1]) return [equalities, { ...expression, args: [left[1], right[1]] }];
|
|
33
|
-
return [equalities, left[1] ?? right[1]];
|
|
34
|
-
}
|
|
35
|
-
if (builtin === "Eq") return [[expression], undefined];
|
|
36
|
-
}
|
|
37
|
-
if (expression.kind === "Internal" && expression.builtin === "TRUE") return [[], undefined];
|
|
38
|
-
if (
|
|
39
|
-
expression.kind === "Quant" &&
|
|
40
|
-
expression.quantifier === "Forall" &&
|
|
41
|
-
expression.bounds.every(isUnbounded)
|
|
42
|
-
) {
|
|
43
|
-
const extracted = extractEqualities(expression.body);
|
|
44
|
-
const quantify = (inner: Expr, from: Expr) =>
|
|
45
|
-
at({ kind: "Quant", quantifier: "Forall", bounds: expression.bounds, body: inner }, from);
|
|
46
|
-
return [
|
|
47
|
-
extracted[0].map((equality) => quantify(equality, equality)),
|
|
48
|
-
extracted[1] && quantify(extracted[1], expression),
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
return [[], expression];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// flatten: each visible fact becomes the rest of it, then its equalities.
|
|
55
|
-
export const flatten = (sequent: Sequent): Sequent => {
|
|
56
|
-
const context: Hyp[] = [];
|
|
57
|
-
const substitution = sequent.context.reduce<Substitution>((current, hyp) => {
|
|
58
|
-
if (hyp.kind !== "Fact" || hyp.visibility !== "Visible") {
|
|
59
|
-
context.push(substituteHyp(current, hyp));
|
|
60
|
-
return bumpBy(1, current);
|
|
61
|
-
}
|
|
62
|
-
const extracted = extractEqualities(hyp.expression);
|
|
63
|
-
const facts = [...(extracted[1] ? [extracted[1]] : []), ...extracted[0]];
|
|
64
|
-
facts.forEach((fact, index) =>
|
|
65
|
-
context.push({ ...hyp, expression: shiftExpr(index, substituteExpr(current, fact)) }),
|
|
66
|
-
);
|
|
67
|
-
return { kind: "Compose", outer: shift(facts.length - 1), inner: bumpBy(1, current) };
|
|
68
|
-
}, shift(0));
|
|
69
|
-
return { context, active: substituteExpr(substitution, sequent.active) };
|
|
70
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
applyBuiltin,
|
|
3
|
-
isEqualExpr,
|
|
4
|
-
shiftExpr,
|
|
5
|
-
type Expr,
|
|
6
|
-
type Sequent,
|
|
7
|
-
} from "../../obligations/expression";
|
|
8
|
-
|
|
9
|
-
// Prep.trivial: the goal is TRUE, or find_fact finds it as a hypothesis, visible or not: a fact
|
|
10
|
-
// alpha-equivalent to it, or the x \in S of a declaration NEW x \in S.
|
|
11
|
-
export const isTrivial = (sequent: Sequent) =>
|
|
12
|
-
(sequent.active.kind === "Internal" && sequent.active.builtin === "TRUE") ||
|
|
13
|
-
sequent.context.some((hyp, index) => {
|
|
14
|
-
if (hyp.kind === "Fact")
|
|
15
|
-
return isEqualExpr(hyp.expression, shiftExpr(index - sequent.context.length, sequent.active));
|
|
16
|
-
if (hyp.kind !== "Fresh" || !hyp.domain) return false;
|
|
17
|
-
const variable: Expr = { kind: "Ix", index: 1 };
|
|
18
|
-
return isEqualExpr(
|
|
19
|
-
applyBuiltin("Mem", [variable, shiftExpr(1, hyp.domain)], {}),
|
|
20
|
-
shiftExpr(index + 1 - sequent.context.length, sequent.active),
|
|
21
|
-
);
|
|
22
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// encode/n_axiomatize.ml: the symbols and axioms an encoding needs.
|
|
2
|
-
|
|
3
|
-
import { compareStrings } from "../ocaml";
|
|
4
|
-
import { getSymbolSpec, type CollectState, type SymbolSpec } from "./data";
|
|
5
|
-
import type { Entry, Flattened } from "./flatten";
|
|
6
|
-
import { getTlaName } from "./format";
|
|
7
|
-
import { getAxiomKey, type Axiom } from "./table";
|
|
8
|
-
|
|
9
|
-
// N_axiomatize.collect: each symbol the obligation uses, in the order tlapm visits them, brings
|
|
10
|
-
// the symbols and axioms it depends on, smallest name first.
|
|
11
|
-
export const collectSymbols = (
|
|
12
|
-
entries: Entry[],
|
|
13
|
-
flattened: Map<string, Flattened>,
|
|
14
|
-
anonymous: Map<string, number>,
|
|
15
|
-
recordFields: Map<string, string[]>,
|
|
16
|
-
) => {
|
|
17
|
-
const state: CollectState = {
|
|
18
|
-
recordFields,
|
|
19
|
-
strings: [],
|
|
20
|
-
isFunConstr: false,
|
|
21
|
-
isFunSet: false,
|
|
22
|
-
isExcept: false,
|
|
23
|
-
tuples: [],
|
|
24
|
-
records: [],
|
|
25
|
-
anonymous,
|
|
26
|
-
};
|
|
27
|
-
const symbols = new Map<string, SymbolSpec>();
|
|
28
|
-
const axioms = new Map<string, Axiom>();
|
|
29
|
-
const add = (name: string) => {
|
|
30
|
-
const work = new Set([name]);
|
|
31
|
-
while (work.size > 0) {
|
|
32
|
-
const next = [...work].toSorted(compareStrings)[0];
|
|
33
|
-
work.delete(next);
|
|
34
|
-
if (symbols.has(next)) continue;
|
|
35
|
-
const spec = getSymbolSpec(next, state);
|
|
36
|
-
symbols.set(next, spec);
|
|
37
|
-
spec.deps.forEach((dep) => work.add(dep));
|
|
38
|
-
spec.axioms.forEach((entry) => axioms.set(getAxiomKey(entry), entry));
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
// A flattened symbol stands for a builtin applied to its first-order arguments and then its
|
|
42
|
-
// higher-order ones, so its higher-order text is visited after its arguments.
|
|
43
|
-
const visit = (text: string) => {
|
|
44
|
-
const tokens = text.match(/[()]|[^\s()]+/g) ?? [];
|
|
45
|
-
const pending: { depth: number; text: string }[] = [];
|
|
46
|
-
tokens.reduce((depth, token, index) => {
|
|
47
|
-
if (token === "(") return depth + 1;
|
|
48
|
-
if (token === ")") {
|
|
49
|
-
if (pending.at(-1)?.depth === depth) visit(pending.pop()?.text ?? "");
|
|
50
|
-
return depth - 1;
|
|
51
|
-
}
|
|
52
|
-
const flat = flattened.get(token);
|
|
53
|
-
if (!flat) {
|
|
54
|
-
const builtin = getTlaName(token);
|
|
55
|
-
if (builtin !== undefined) add(builtin);
|
|
56
|
-
return depth;
|
|
57
|
-
}
|
|
58
|
-
if (flat.kind !== "") add(flat.kind);
|
|
59
|
-
if (tokens[index - 1] === "(") pending.push({ depth, text: flat.visit });
|
|
60
|
-
else visit(flat.visit);
|
|
61
|
-
return depth;
|
|
62
|
-
}, 0);
|
|
63
|
-
};
|
|
64
|
-
entries.forEach((entry) => {
|
|
65
|
-
if (typeof entry === "string") visit(entry);
|
|
66
|
-
else if ("omitted" in entry) visit(entry.omitted);
|
|
67
|
-
});
|
|
68
|
-
return { symbols, axioms };
|
|
69
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// The rewrites of encode/n_rewrite.ml that run on the sequent before Type.Synthesize.
|
|
2
|
-
|
|
3
|
-
import { applyBuiltin, at, mapChildren, type Expr } from "../../obligations/expression";
|
|
4
|
-
import { compareStrings } from "../ocaml";
|
|
5
|
-
|
|
6
|
-
type RecordExpr = Extract<Expr, { kind: "Record" }>;
|
|
7
|
-
|
|
8
|
-
const isSameFieldSet = (left: RecordExpr, right: RecordExpr) =>
|
|
9
|
-
left.fields.length === right.fields.length &&
|
|
10
|
-
left.fields.every((field) => right.fields.some((other) => other.name === field.name)) &&
|
|
11
|
-
right.fields.every((field) => left.fields.some((other) => other.name === field.name));
|
|
12
|
-
|
|
13
|
-
// mk_conj: e1 /\ (e2 /\ ...).
|
|
14
|
-
const conjoinRight = (items: Expr[]): Expr =>
|
|
15
|
-
items.length === 1
|
|
16
|
-
? items[0]
|
|
17
|
-
: applyBuiltin("Conj", [items[0], conjoinRight(items.slice(1))], items[0]);
|
|
18
|
-
|
|
19
|
-
const decompose = (left: Expr, right: Expr, from: Expr): Expr => {
|
|
20
|
-
if (left.kind !== "Record" || right.kind !== "Record" || !isSameFieldSet(left, right))
|
|
21
|
-
return applyBuiltin("Eq", [left, right], from);
|
|
22
|
-
return conjoinRight(
|
|
23
|
-
left.fields.map((field) =>
|
|
24
|
-
decompose(
|
|
25
|
-
field.value,
|
|
26
|
-
right.fields.find((other) => other.name === field.name)?.value ?? field.value,
|
|
27
|
-
from,
|
|
28
|
-
),
|
|
29
|
-
),
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// simpl_receq: an equality of two record constructors with the same fields is the conjunction of
|
|
34
|
-
// the equalities of their fields, paired by name.
|
|
35
|
-
export const simplifyRecordEqualities = (expression: Expr): Expr => {
|
|
36
|
-
const inner = mapChildren(expression, simplifyRecordEqualities);
|
|
37
|
-
const isRecordEquality =
|
|
38
|
-
inner.kind === "Apply" &&
|
|
39
|
-
inner.operator.kind === "Internal" &&
|
|
40
|
-
inner.operator.builtin === "Eq" &&
|
|
41
|
-
inner.args.length === 2 &&
|
|
42
|
-
inner.args[0].kind === "Record" &&
|
|
43
|
-
inner.args[1].kind === "Record";
|
|
44
|
-
return isRecordEquality && inner.kind === "Apply"
|
|
45
|
-
? at(decompose(inner.args[0], inner.args[1], inner), inner)
|
|
46
|
-
: inner;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// sort_recfields: a record's or a record set's fields in order. Like tlapm, it doesn't visit the
|
|
50
|
-
// field values, so a record inside a record keeps the order it's written in.
|
|
51
|
-
export const sortRecordFields = (expression: Expr): Expr =>
|
|
52
|
-
expression.kind === "Record" || expression.kind === "Rect"
|
|
53
|
-
? {
|
|
54
|
-
...expression,
|
|
55
|
-
fields: expression.fields.toSorted((left, right) => compareStrings(left.name, right.name)),
|
|
56
|
-
}
|
|
57
|
-
: mapChildren(expression, sortRecordFields);
|