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
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// What Backend.Prep does to an obligation before a backend's frontend: normalize_expand, which
|
|
2
|
+
// expands definitions, runs Expr.Elab.normalize and the frontend methods the obligation cites, then
|
|
3
|
+
// trivial and flatten.
|
|
4
|
+
|
|
5
|
+
import { TlapmBugError, TlaProofError } from "../../errors";
|
|
6
|
+
import { expandActionOperators, lambdify } from "../../obligations/action";
|
|
7
|
+
import { createAnonymizer } from "../../obligations/anonymize";
|
|
8
|
+
import { isEqualExpr } from "../../obligations/equality";
|
|
9
|
+
import {
|
|
10
|
+
applyBuiltin,
|
|
11
|
+
at,
|
|
12
|
+
createContextMap,
|
|
13
|
+
getChildren,
|
|
14
|
+
mapChildren,
|
|
15
|
+
mapExceptSpecs,
|
|
16
|
+
mapHyp,
|
|
17
|
+
type Bound,
|
|
18
|
+
type ExceptPoint,
|
|
19
|
+
type Expr,
|
|
20
|
+
type Hyp,
|
|
21
|
+
type Sequent,
|
|
22
|
+
} from "../../obligations/expression";
|
|
23
|
+
import {
|
|
24
|
+
bumpBy,
|
|
25
|
+
consSubstitution,
|
|
26
|
+
shift,
|
|
27
|
+
shiftExpr,
|
|
28
|
+
substituteExpr,
|
|
29
|
+
substituteHyp,
|
|
30
|
+
type Substitution,
|
|
31
|
+
} from "../../obligations/substitution";
|
|
32
|
+
import type { OldMethod } from "../../obligations/pragma";
|
|
33
|
+
import { implicationToEnabled } from "./enabled-axioms";
|
|
34
|
+
import { checkLevelChange } from "./level-comparison";
|
|
35
|
+
import { findMethods } from "./methods";
|
|
36
|
+
|
|
37
|
+
const createDefinitionExpander = (isPragmaExpanded: boolean) =>
|
|
38
|
+
createContextMap(shift(0), (current, hyp) => {
|
|
39
|
+
if (
|
|
40
|
+
hyp.kind === "Defn" &&
|
|
41
|
+
((isPragmaExpanded && hyp.definition.kind === "Bpragma") ||
|
|
42
|
+
(hyp.definition.kind === "Operator" && hyp.visibility === "Visible"))
|
|
43
|
+
) {
|
|
44
|
+
return [consSubstitution(substituteExpr(current, hyp.definition.body), current), undefined];
|
|
45
|
+
}
|
|
46
|
+
return [bumpBy(1, current), substituteHyp(current, hyp)];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const expandDefinitionsAndPragmas = createDefinitionExpander(true);
|
|
50
|
+
|
|
51
|
+
const expandDefinitions = createDefinitionExpander(false);
|
|
52
|
+
|
|
53
|
+
// expand_defs: each visible operator definition and each pragma, whatever its visibility,
|
|
54
|
+
// substitutes into the rest of the obligation and leaves the context. Toolbox.expand_defs leaves
|
|
55
|
+
// the pragmas.
|
|
56
|
+
export const expandDefs = (sequent: Sequent, isPragmaExpanded = true): Sequent => {
|
|
57
|
+
const expanded = (isPragmaExpanded ? expandDefinitionsAndPragmas : expandDefinitions)(
|
|
58
|
+
sequent.context,
|
|
59
|
+
);
|
|
60
|
+
return { context: expanded.context, active: substituteExpr(expanded.state, sequent.active) };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type ExceptSpec = Extract<Expr, { kind: "Except" }>["specs"][number];
|
|
64
|
+
|
|
65
|
+
const TEMPORAL_BUILTINS = new Set(["BoxTrue", "BoxFalse", "Diamond", "Actplus", "Leadsto", "Cdot"]);
|
|
66
|
+
|
|
67
|
+
// The expressions of a hypothesis that Visit.iter visits, none for a hidden one.
|
|
68
|
+
const getVisitedExprs = (hyp: Hyp): Expr[] => {
|
|
69
|
+
switch (hyp.kind) {
|
|
70
|
+
case "Fresh":
|
|
71
|
+
return hyp.domain ? [hyp.domain] : [];
|
|
72
|
+
case "Flex":
|
|
73
|
+
return [];
|
|
74
|
+
case "Defn":
|
|
75
|
+
return hyp.visibility === "Hidden" ||
|
|
76
|
+
(hyp.definition.kind !== "Operator" && hyp.definition.kind !== "Bpragma")
|
|
77
|
+
? []
|
|
78
|
+
: [hyp.definition.body];
|
|
79
|
+
case "Fact":
|
|
80
|
+
return hyp.visibility === "Hidden" ? [] : [hyp.expression];
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Elab.non_temporal: no temporal operator, but in hidden hypotheses.
|
|
85
|
+
const isNonTemporal = (expression: Expr): boolean => {
|
|
86
|
+
if (expression.kind === "Tsub" || expression.kind === "Fair") return false;
|
|
87
|
+
if (
|
|
88
|
+
expression.kind === "Apply" &&
|
|
89
|
+
expression.operator.kind === "Internal" &&
|
|
90
|
+
TEMPORAL_BUILTINS.has(expression.operator.builtin)
|
|
91
|
+
)
|
|
92
|
+
return false;
|
|
93
|
+
if (expression.kind === "Sequent") {
|
|
94
|
+
const sequent = expression.sequent;
|
|
95
|
+
return [...sequent.context.flatMap(getVisitedExprs), sequent.active].every(isNonTemporal);
|
|
96
|
+
}
|
|
97
|
+
return getChildren(expression).every(isNonTemporal);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Elab.let_normalize: each LET definition is substituted into the rest of the LET.
|
|
101
|
+
const normalizeLet = (expression: Expr): Expr => {
|
|
102
|
+
if (expression.kind !== "Let") return mapChildren(expression, normalizeLet);
|
|
103
|
+
const [definition, ...definitions] = expression.definitions;
|
|
104
|
+
if (!definition) return normalizeLet(expression.body);
|
|
105
|
+
if (definition.kind !== "Operator" && definition.kind !== "Bpragma") {
|
|
106
|
+
throw new TlaProofError(
|
|
107
|
+
definition.kind === "Instance"
|
|
108
|
+
? "Found INSTANCE in Expr.Elab.let_normalize, all INSTANCE statements have been replaced with definitions in Module.Elab "
|
|
109
|
+
: "Expr.Elab.let_normalize",
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const operator = normalizeLet(definition.body);
|
|
113
|
+
const rest: Expr = { ...expression, definitions };
|
|
114
|
+
return normalizeLet(substituteExpr(consSubstitution(operator, shift(0)), rest));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const getAccess = (base: Expr, point: ExceptPoint): Expr =>
|
|
118
|
+
point.kind === "Dot"
|
|
119
|
+
? at({ kind: "Dot", expression: base, field: point.field }, base)
|
|
120
|
+
: at({ kind: "FcnApp", function: base, args: [point.expression] }, base);
|
|
121
|
+
|
|
122
|
+
const isSameHead = (left: ExceptPoint, right: ExceptPoint) =>
|
|
123
|
+
left.kind === "Dot"
|
|
124
|
+
? right.kind === "Dot" && left.field === right.field
|
|
125
|
+
: right.kind === "Apply" && isEqualExpr(left.expression, right.expression);
|
|
126
|
+
|
|
127
|
+
// The field of a record constructor that a point names, as a field or as a string argument.
|
|
128
|
+
const getRecordField = (record: Expr, point: ExceptPoint) => {
|
|
129
|
+
const name =
|
|
130
|
+
point.kind === "Dot"
|
|
131
|
+
? point.field
|
|
132
|
+
: point.expression.kind === "String"
|
|
133
|
+
? point.expression.value
|
|
134
|
+
: undefined;
|
|
135
|
+
return record.kind === "Record" && name !== undefined
|
|
136
|
+
? record.fields.find((field) => field.name === name)
|
|
137
|
+
: undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// Elab.except_normalize: [f EXCEPT p1 = b1, ...] folds left to right into f, sharing each prefix of
|
|
141
|
+
// adjacent updates and updating a record constructor in place on a field it has.
|
|
142
|
+
const normalizeExcept = (expression: Expr): Expr => {
|
|
143
|
+
if (expression.kind !== "Except") return mapChildren(expression, normalizeExcept);
|
|
144
|
+
const except = expression;
|
|
145
|
+
const select = (base: Expr, point: ExceptPoint) =>
|
|
146
|
+
getRecordField(base, point)?.value ?? getAccess(base, point);
|
|
147
|
+
const update = (base: Expr, point: ExceptPoint, value: Expr): Expr => {
|
|
148
|
+
const field = getRecordField(base, point);
|
|
149
|
+
if (base.kind !== "Record" || !field)
|
|
150
|
+
return at({ kind: "Except", function: base, specs: [{ trail: [point], value }] }, except);
|
|
151
|
+
const fields = base.fields.map((entry) =>
|
|
152
|
+
entry.name === field.name ? { name: entry.name, value } : entry,
|
|
153
|
+
);
|
|
154
|
+
return at({ kind: "Record", fields }, base);
|
|
155
|
+
};
|
|
156
|
+
const apply = (base: Expr, specs: ExceptSpec[]): Expr => {
|
|
157
|
+
const [first, ...others] = specs;
|
|
158
|
+
if (!first) return base;
|
|
159
|
+
if (first.trail.length === 0) return apply(first.value, others);
|
|
160
|
+
const head = first.trail[0];
|
|
161
|
+
const end = specs.findIndex(
|
|
162
|
+
(spec) => spec.trail.length === 0 || !isSameHead(spec.trail[0], head),
|
|
163
|
+
);
|
|
164
|
+
const count = end === -1 ? specs.length : end;
|
|
165
|
+
const tails = specs
|
|
166
|
+
.slice(0, count)
|
|
167
|
+
.map((spec) => ({ trail: spec.trail.slice(1), value: spec.value }));
|
|
168
|
+
return apply(update(base, head, apply(select(base, head), tails)), specs.slice(count));
|
|
169
|
+
};
|
|
170
|
+
return apply(normalizeExcept(except.function), mapExceptSpecs(except.specs, normalizeExcept));
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// let_normalize on each hypothesis, and whether the context so far is non_temporal.
|
|
174
|
+
const normalizeLetContext = createContextMap(true, (isContextNonTemporal, hyp) => [
|
|
175
|
+
isContextNonTemporal && getVisitedExprs(hyp).every(isNonTemporal),
|
|
176
|
+
mapHyp(hyp, normalizeLet, "all"),
|
|
177
|
+
]);
|
|
178
|
+
|
|
179
|
+
const normalizeExceptContext = createContextMap(undefined, (_state, hyp) => [
|
|
180
|
+
undefined,
|
|
181
|
+
mapHyp(hyp, normalizeExcept, "all"),
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
// Elab.normalize, on an obligation as a sequent expression, as Prep.normalize_expr calls it: LET
|
|
185
|
+
// definitions inline, and the updates of an EXCEPT fold into the function they update.
|
|
186
|
+
export const normalizeSequent = (sequent: Sequent): Sequent => {
|
|
187
|
+
const inlined = normalizeLetContext(sequent.context);
|
|
188
|
+
const active = normalizeLet(sequent.active);
|
|
189
|
+
return inlined.state && isNonTemporal(sequent.active)
|
|
190
|
+
? {
|
|
191
|
+
context: normalizeExceptContext(sequent.context, inlined.context).context,
|
|
192
|
+
active: normalizeExcept(active),
|
|
193
|
+
}
|
|
194
|
+
: { context: inlined.context, active };
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// expand_enabled_cdot: the first frontend the methods cite, in tlapm's order, transforms the
|
|
198
|
+
// obligation. Its soundness checks throw a TlaProverError, as tlapm then runs no backend.
|
|
199
|
+
const expandEnabledCdot = (sequent: Sequent, frontends: Set<string>): Sequent => {
|
|
200
|
+
const isEnabled = frontends.has("expandenabled");
|
|
201
|
+
const isCdot = frontends.has("expandcdot");
|
|
202
|
+
const isAutoUse = frontends.has("autouse");
|
|
203
|
+
const isLambdify = frontends.has("lambdify");
|
|
204
|
+
if (!isEnabled && !isCdot && !isLambdify) {
|
|
205
|
+
if (frontends.has("levelcomparison")) return checkLevelChange(sequent);
|
|
206
|
+
if (frontends.has("enabledaxioms")) return implicationToEnabled(sequent);
|
|
207
|
+
return sequent;
|
|
208
|
+
}
|
|
209
|
+
// Expr.Anon's anon, which only meets the names that lambdification binds.
|
|
210
|
+
const anonymizer = createAnonymizer(
|
|
211
|
+
{ value: 0 },
|
|
212
|
+
() => {
|
|
213
|
+
throw new TlapmBugError();
|
|
214
|
+
},
|
|
215
|
+
() => {},
|
|
216
|
+
);
|
|
217
|
+
const expression: Expr = { kind: "Sequent", sequent };
|
|
218
|
+
const result =
|
|
219
|
+
isEnabled || isCdot
|
|
220
|
+
? expandActionOperators(anonymizer, () => {}, undefined, expression, {
|
|
221
|
+
isEnabled,
|
|
222
|
+
isCdot,
|
|
223
|
+
isAutoUse,
|
|
224
|
+
})
|
|
225
|
+
: lambdify(anonymizer, () => {}, undefined, expression, {
|
|
226
|
+
isEnabled: true,
|
|
227
|
+
isCdot: true,
|
|
228
|
+
isAutoUse,
|
|
229
|
+
});
|
|
230
|
+
if (result.kind !== "Sequent") throw new TlapmBugError();
|
|
231
|
+
return result.sequent;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// normalize_expand: expand_defs, Elab.normalize, then the frontends the obligation cites.
|
|
235
|
+
export const normalizeExpand = (
|
|
236
|
+
obligation: { sequent: Sequent; method?: OldMethod },
|
|
237
|
+
methods = findMethods(obligation),
|
|
238
|
+
) => expandEnabledCdot(normalizeSequent(expandDefs(obligation.sequent)), methods.frontends);
|
|
239
|
+
|
|
240
|
+
// trivial: the goal is TRUE, or find_fact finds it as a hypothesis, visible or not: a fact
|
|
241
|
+
// alpha-equivalent to it, or the x \in S of a declaration NEW x \in S.
|
|
242
|
+
export const isTrivial = (sequent: Sequent) =>
|
|
243
|
+
(sequent.active.kind === "Internal" && sequent.active.builtin === "TRUE") ||
|
|
244
|
+
sequent.context.some((hyp, index) => {
|
|
245
|
+
if (hyp.kind === "Fact")
|
|
246
|
+
return isEqualExpr(hyp.expression, shiftExpr(index - sequent.context.length, sequent.active));
|
|
247
|
+
if (hyp.kind !== "Fresh" || !hyp.domain) return false;
|
|
248
|
+
return isEqualExpr(
|
|
249
|
+
applyBuiltin("Mem", [{ kind: "Ix", index: 1 }, shiftExpr(1, hyp.domain)], {}),
|
|
250
|
+
shiftExpr(index + 1 - sequent.context.length, sequent.active),
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const isUnbounded = (bound: Bound) => bound.domain.kind === "NoDomain";
|
|
255
|
+
|
|
256
|
+
// extract_equalities: the equalities in a conjunction, apart from the rest of it.
|
|
257
|
+
const extractEqualities = (expression: Expr): [Expr[], Expr | undefined] => {
|
|
258
|
+
if (expression.kind === "List" && (expression.bullet === "And" || expression.bullet === "Refs")) {
|
|
259
|
+
const parts = expression.items.map(extractEqualities);
|
|
260
|
+
const equalities = parts.flatMap((part) => part[0]);
|
|
261
|
+
const rest = parts.flatMap((part) => (part[1] ? [part[1]] : []));
|
|
262
|
+
if (rest.length <= 1) return [equalities, rest[0]];
|
|
263
|
+
return [equalities, { ...expression, bullet: "And", items: rest }];
|
|
264
|
+
}
|
|
265
|
+
if (expression.kind === "Apply" && expression.operator.kind === "Internal") {
|
|
266
|
+
const builtin = expression.operator.builtin;
|
|
267
|
+
if (builtin === "Conj" && expression.args.length === 2) {
|
|
268
|
+
const left = extractEqualities(expression.args[0]);
|
|
269
|
+
const right = extractEqualities(expression.args[1]);
|
|
270
|
+
const equalities = [...left[0], ...right[0]];
|
|
271
|
+
if (left[1] && right[1]) return [equalities, { ...expression, args: [left[1], right[1]] }];
|
|
272
|
+
return [equalities, left[1] ?? right[1]];
|
|
273
|
+
}
|
|
274
|
+
if (builtin === "Eq") return [[expression], undefined];
|
|
275
|
+
}
|
|
276
|
+
if (expression.kind === "Internal" && expression.builtin === "TRUE") return [[], undefined];
|
|
277
|
+
if (
|
|
278
|
+
expression.kind === "Quant" &&
|
|
279
|
+
expression.quantifier === "Forall" &&
|
|
280
|
+
expression.bounds.every(isUnbounded)
|
|
281
|
+
) {
|
|
282
|
+
const extracted = extractEqualities(expression.body);
|
|
283
|
+
const quantify = (inner: Expr, from: Expr) =>
|
|
284
|
+
at({ kind: "Quant", quantifier: "Forall", bounds: expression.bounds, body: inner }, from);
|
|
285
|
+
return [
|
|
286
|
+
extracted[0].map((equality) => quantify(equality, equality)),
|
|
287
|
+
extracted[1] && quantify(extracted[1], expression),
|
|
288
|
+
];
|
|
289
|
+
}
|
|
290
|
+
return [[], expression];
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// flatten: each visible fact becomes the rest of it, then its equalities.
|
|
294
|
+
export const flatten = (sequent: Sequent): Sequent => {
|
|
295
|
+
const context: Hyp[] = [];
|
|
296
|
+
const substitution = sequent.context.reduce<Substitution>((current, hyp) => {
|
|
297
|
+
if (hyp.kind !== "Fact" || hyp.visibility !== "Visible") {
|
|
298
|
+
context.push(substituteHyp(current, hyp));
|
|
299
|
+
return bumpBy(1, current);
|
|
300
|
+
}
|
|
301
|
+
const extracted = extractEqualities(hyp.expression);
|
|
302
|
+
const facts = [...(extracted[1] ? [extracted[1]] : []), ...extracted[0]];
|
|
303
|
+
facts.forEach((fact, index) =>
|
|
304
|
+
context.push({ ...hyp, expression: shiftExpr(index, substituteExpr(current, fact)) }),
|
|
305
|
+
);
|
|
306
|
+
return { kind: "Compose", outer: shift(facts.length - 1), inner: bumpBy(1, current) };
|
|
307
|
+
}, shift(0));
|
|
308
|
+
return { context, active: substituteExpr(substitution, sequent.active) };
|
|
309
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// A worker of the decide pool: it decides each request with the backend its prover selects.
|
|
2
2
|
|
|
3
|
-
import { TlaProverError
|
|
3
|
+
import { TlaProverError } from "../errors";
|
|
4
4
|
import { getParentPort } from "../worker";
|
|
5
5
|
import { decide } from "./deciders";
|
|
6
6
|
import type { DecideRequest, DecideResponse } from "./decide-pool";
|
|
@@ -9,10 +9,7 @@ const getResponse = (request: DecideRequest): DecideResponse => {
|
|
|
9
9
|
try {
|
|
10
10
|
return decide(request.prover, request.text, { timeLimitMs: request.timeLimitMs });
|
|
11
11
|
} catch (error) {
|
|
12
|
-
if (error instanceof TlaProverError)
|
|
13
|
-
return { error: { name: "TlaProverError", message: error.message } };
|
|
14
|
-
if (error instanceof TlaUnsupportedError)
|
|
15
|
-
return { error: { name: "TlaUnsupportedError", message: error.message } };
|
|
12
|
+
if (error instanceof TlaProverError) return { error: error.message };
|
|
16
13
|
throw error;
|
|
17
14
|
}
|
|
18
15
|
};
|