tla-ts 0.0.4-dev.b254db0 → 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 -10
- 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
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
import { TlaProofError, TlaUnsupportedError } from "../errors";
|
|
19
19
|
import {
|
|
20
20
|
at,
|
|
21
|
+
getFact,
|
|
21
22
|
type Bound,
|
|
22
23
|
type Builtin,
|
|
23
24
|
type Defn,
|
|
@@ -29,17 +30,17 @@ import {
|
|
|
29
30
|
type Sequent,
|
|
30
31
|
} from "./expression";
|
|
31
32
|
import type { ModuleUnit, Mule } from "./module";
|
|
32
|
-
import { readNewMethod, readOldMethod } from "./pragma";
|
|
33
|
+
import { findPragma, readNewMethod, readOldMethod } from "./pragma";
|
|
33
34
|
import {
|
|
34
35
|
expandChoose,
|
|
35
36
|
expandFcn,
|
|
36
37
|
expandQuant,
|
|
37
38
|
expandSetOf,
|
|
38
|
-
expandSetSt,
|
|
39
39
|
getUnbounded,
|
|
40
40
|
type TuplyBound,
|
|
41
41
|
} from "./tuples";
|
|
42
|
-
import { lookupOperator, type Fixity
|
|
42
|
+
import { lookupOperator, type Fixity } from "./operators";
|
|
43
|
+
import { regroup } from "./regroup";
|
|
43
44
|
import {
|
|
44
45
|
getUnique,
|
|
45
46
|
type Counter,
|
|
@@ -102,109 +103,17 @@ const mergeLoci = (left: Locus | undefined, right: Locus | undefined): Locus | u
|
|
|
102
103
|
};
|
|
103
104
|
};
|
|
104
105
|
|
|
105
|
-
type Grouping =
|
|
106
|
-
| { kind: "Attached"; expression: Expression }
|
|
107
|
-
| { kind: "Reduced"; isFinal: boolean };
|
|
108
|
-
|
|
109
|
-
const PREFIX_KEYWORDS: Partial<Record<Expression["kind"], string>> = {
|
|
110
|
-
Always: "[]",
|
|
111
|
-
Eventually: "<>",
|
|
112
|
-
Enabled: "ENABLED",
|
|
113
|
-
Unchanged: "UNCHANGED",
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const isSamePosition = (left: SourceLocation | undefined, right: SourceLocation | undefined) =>
|
|
117
|
-
left !== undefined &&
|
|
118
|
-
right !== undefined &&
|
|
119
|
-
left.line === right.line &&
|
|
120
|
-
left.column === right.column;
|
|
121
|
-
|
|
122
|
-
const getStart = (expression: Expression) => expression.location.range?.start;
|
|
123
|
-
|
|
124
|
-
const getEnd = (expression: Expression) => expression.location.range?.end;
|
|
125
|
-
|
|
126
|
-
const withEnd = (expression: Expression, end: SourceLocation | undefined): Expression => {
|
|
127
|
-
const range = expression.location.range;
|
|
128
|
-
return range && end
|
|
129
|
-
? { ...expression, location: { ...expression.location, range: { ...range, end } } }
|
|
130
|
-
: expression;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// The operator an expression leaves open on tlapm's parse stack, with the operand after it.
|
|
134
|
-
const getOpenOperator = (expression: Expression) => {
|
|
135
|
-
if (expression.kind === "Apply") {
|
|
136
|
-
const operator = lookupOperator(expression.operator);
|
|
137
|
-
const isInfix = expression.args.length === 2 && operator.fixity.startsWith("Infix");
|
|
138
|
-
const isPrefix = expression.args.length === 1 && operator.fixity === "Prefix";
|
|
139
|
-
if (!isInfix && !isPrefix) return undefined;
|
|
140
|
-
const last = expression.args.length - 1;
|
|
141
|
-
return {
|
|
142
|
-
operator,
|
|
143
|
-
isInfix,
|
|
144
|
-
operand: expression.args[last],
|
|
145
|
-
replace: (operand: Expression): Expression => ({
|
|
146
|
-
...expression,
|
|
147
|
-
args: [...expression.args.slice(0, last), operand],
|
|
148
|
-
}),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
const keyword = PREFIX_KEYWORDS[expression.kind];
|
|
152
|
-
if (keyword === undefined || !("expression" in expression)) return undefined;
|
|
153
|
-
return {
|
|
154
|
-
operator: lookupOperator(keyword),
|
|
155
|
-
isInfix: false,
|
|
156
|
-
operand: expression.expression,
|
|
157
|
-
replace: (operand: Expression): Expression => ({ ...expression, expression: operand }),
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const isBelow = (left: Operator, right: Operator) => left.high < right.low;
|
|
162
|
-
|
|
163
|
-
// Pco.resolve: tlapm's parser lets an operator take in every later infix operator that is not
|
|
164
|
-
// entirely below it, so SUBSET S \ T is SUBSET (S \ T) to tlapm though SANY reads (SUBSET S) \ T.
|
|
165
|
-
// This regroups an infix application the way tlapm does.
|
|
166
|
-
const regroup = (expression: Extract<Expression, { kind: "Apply" }>): Expression => {
|
|
167
|
-
const operator = lookupOperator(expression.operator);
|
|
168
|
-
const [left, right] = expression.args;
|
|
169
|
-
const end = getEnd(expression);
|
|
170
|
-
const getInfix = (operand: Expression): Expression => {
|
|
171
|
-
const range = expression.location.range;
|
|
172
|
-
const start = getStart(operand);
|
|
173
|
-
return {
|
|
174
|
-
...expression,
|
|
175
|
-
args: [operand, right],
|
|
176
|
-
location:
|
|
177
|
-
range && start
|
|
178
|
-
? { ...expression.location, range: { ...range, start } }
|
|
179
|
-
: expression.location,
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
const attach = (node: Expression, isOpen: boolean): Grouping => {
|
|
183
|
-
const open = isOpen ? getOpenOperator(node) : undefined;
|
|
184
|
-
if (!open) return { kind: "Reduced", isFinal: false };
|
|
185
|
-
const inner = attach(open.operand, isSamePosition(getEnd(open.operand), getEnd(node)));
|
|
186
|
-
if (inner.kind === "Attached")
|
|
187
|
-
return { kind: "Attached", expression: withEnd(open.replace(inner.expression), end) };
|
|
188
|
-
const isReduced =
|
|
189
|
-
!inner.isFinal &&
|
|
190
|
-
(isBelow(operator, open.operator) ||
|
|
191
|
-
(open.isInfix &&
|
|
192
|
-
operator.fixity === "InfixLeft" &&
|
|
193
|
-
open.operator.fixity === "InfixLeft" &&
|
|
194
|
-
!isBelow(open.operator, operator)));
|
|
195
|
-
if (isReduced) return { kind: "Reduced", isFinal: !isBelow(operator, open.operator) };
|
|
196
|
-
return { kind: "Attached", expression: withEnd(open.replace(getInfix(open.operand)), end) };
|
|
197
|
-
};
|
|
198
|
-
const grouping = attach(left, isSamePosition(getStart(left), getStart(expression)));
|
|
199
|
-
return grouping.kind === "Attached" ? grouping.expression : expression;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
106
|
const TUPLY_FAILURE = "use instead the class`E_visit.iter_concrete`";
|
|
203
107
|
|
|
204
108
|
const isDitto = (bounds: QuantifierExpression["bounds"], index: number) =>
|
|
205
109
|
index > 0 && bounds[index - 1].set === bounds[index].set;
|
|
206
110
|
|
|
207
|
-
export const createSource = (
|
|
111
|
+
export const createSource = (
|
|
112
|
+
file: string,
|
|
113
|
+
text: string,
|
|
114
|
+
counter: Counter,
|
|
115
|
+
isExpandingTuples: boolean,
|
|
116
|
+
) => {
|
|
208
117
|
const lines = text.split("\n");
|
|
209
118
|
|
|
210
119
|
const getRangeLocus = (range: SourceRange): Locus => ({
|
|
@@ -216,18 +125,10 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
216
125
|
});
|
|
217
126
|
|
|
218
127
|
const withPragma = (locus: Locus) => {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
while (isBlank(line[position.column])) position.column++;
|
|
224
|
-
if (position.column < line.length) break;
|
|
225
|
-
position.line++;
|
|
226
|
-
position.column = 0;
|
|
227
|
-
}
|
|
228
|
-
if (!(lines[position.line] ?? "").startsWith("(*{", position.column)) return locus;
|
|
229
|
-
for (let index = position.line; index < lines.length; index++) {
|
|
230
|
-
const close = lines[index].indexOf("}*)", index === position.line ? position.column : 0);
|
|
128
|
+
const open = findPragma(lines, { line: locus.endLine - 1, column: locus.endColumn - 1 });
|
|
129
|
+
if (!open) return locus;
|
|
130
|
+
for (let index = open.line; index < lines.length; index++) {
|
|
131
|
+
const close = lines[index].indexOf("}*)", index === open.line ? open.column : 0);
|
|
231
132
|
if (close !== -1) return { ...locus, endLine: index + 1, endColumn: close + 4 };
|
|
232
133
|
}
|
|
233
134
|
return locus;
|
|
@@ -260,7 +161,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
260
161
|
const getLocus = (location: SourceLocation): Locus =>
|
|
261
162
|
location.range ? getRangeLocus(location.range) : getPointLocus(location, 1);
|
|
262
163
|
|
|
263
|
-
const
|
|
164
|
+
const convertOperator = (name: string, location: Locus | undefined): Expr => {
|
|
264
165
|
const canonical = getCanonicalName(name);
|
|
265
166
|
const builtin = BUILTINS[canonical];
|
|
266
167
|
return at(builtin ? { kind: "Internal", builtin } : { kind: "Opaque", name: canonical }, {
|
|
@@ -269,7 +170,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
269
170
|
};
|
|
270
171
|
|
|
271
172
|
// A name with ! selects through instances, which anonymization resolves by joining the names.
|
|
272
|
-
const
|
|
173
|
+
const convertName = (
|
|
273
174
|
name: string,
|
|
274
175
|
args: Expr[],
|
|
275
176
|
location: Locus,
|
|
@@ -339,7 +240,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
339
240
|
});
|
|
340
241
|
|
|
341
242
|
const expandTuples = (expanded: Expr, location: Locus) => {
|
|
342
|
-
if (!
|
|
243
|
+
if (!isExpandingTuples)
|
|
343
244
|
throw new TlaProofError("Unexpected tuple declaration", { failure: TUPLY_FAILURE });
|
|
344
245
|
return at(expanded, { location });
|
|
345
246
|
};
|
|
@@ -393,7 +294,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
393
294
|
return at({ kind: "String", value: written?.[1] ?? expression.value }, { location });
|
|
394
295
|
}
|
|
395
296
|
case "Identifier":
|
|
396
|
-
return
|
|
297
|
+
return convertName(expression.name, [], location);
|
|
397
298
|
case "Apply": {
|
|
398
299
|
if (expression.args.length === 2) {
|
|
399
300
|
const regrouped = regroup(expression);
|
|
@@ -403,14 +304,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
403
304
|
const operator = lookupOperator(expression.operator);
|
|
404
305
|
if (operator.fixity !== "Nonfix") {
|
|
405
306
|
return at(
|
|
406
|
-
{ kind: "Apply", operator:
|
|
307
|
+
{ kind: "Apply", operator: convertOperator(expression.operator, undefined), args },
|
|
407
308
|
{ location: getOperatorLocus(args, operator.fixity) },
|
|
408
309
|
);
|
|
409
310
|
}
|
|
410
|
-
return
|
|
311
|
+
return convertName(expression.operator, args, location, expression.argumentCounts);
|
|
411
312
|
}
|
|
412
313
|
case "OperatorReference":
|
|
413
|
-
return
|
|
314
|
+
return convertOperator(expression.operator, location);
|
|
414
315
|
case "Lambda":
|
|
415
316
|
return at(
|
|
416
317
|
{
|
|
@@ -516,8 +417,8 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
516
417
|
if (expression.pattern.kind === "Tuple") {
|
|
517
418
|
return expandTuples(
|
|
518
419
|
expandChoose(
|
|
420
|
+
{ kind: "Choose", domain: expression.set && recurse(expression.set) },
|
|
519
421
|
expression.pattern.names,
|
|
520
|
-
expression.set && recurse(expression.set),
|
|
521
422
|
recurse(expression.body),
|
|
522
423
|
),
|
|
523
424
|
location,
|
|
@@ -537,9 +438,9 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
537
438
|
case "SetFilter":
|
|
538
439
|
if (expression.bound.pattern.kind === "Tuple") {
|
|
539
440
|
return expandTuples(
|
|
540
|
-
|
|
441
|
+
expandChoose(
|
|
442
|
+
{ kind: "SetSt", domain: recurse(expression.bound.set) },
|
|
541
443
|
expression.bound.pattern.names,
|
|
542
|
-
recurse(expression.bound.set),
|
|
543
444
|
recurse(expression.predicate),
|
|
544
445
|
),
|
|
545
446
|
location,
|
|
@@ -852,13 +753,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
852
753
|
{ location: getLocus(assumption.location) },
|
|
853
754
|
)
|
|
854
755
|
: convertFactLabel(assumption);
|
|
855
|
-
return
|
|
856
|
-
kind: "Fact",
|
|
857
|
-
expression,
|
|
858
|
-
visibility: "Visible",
|
|
859
|
-
time: "Now",
|
|
860
|
-
location: expression.location,
|
|
861
|
-
};
|
|
756
|
+
return getFact(expression, "Visible", "Now", expression.location);
|
|
862
757
|
}),
|
|
863
758
|
active: convertExpression(statement.conclusion, false),
|
|
864
759
|
};
|
|
@@ -1134,7 +1029,6 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
1134
1029
|
return {
|
|
1135
1030
|
kind: "Mutate",
|
|
1136
1031
|
mode: unit.use.kind,
|
|
1137
|
-
isSuppressed: false,
|
|
1138
1032
|
usable: convertUsable(unit.use),
|
|
1139
1033
|
location: getUseLocus(unit.use),
|
|
1140
1034
|
};
|
|
@@ -2,60 +2,62 @@
|
|
|
2
2
|
// subexpression it names, abstracted over the bound names it uses.
|
|
3
3
|
|
|
4
4
|
import { TlaProofError, TlapmBugError } from "../errors";
|
|
5
|
+
import { consAll, consSubstitution, shift, substituteExpr } from "./substitution";
|
|
5
6
|
import {
|
|
6
7
|
at,
|
|
7
|
-
consAll,
|
|
8
|
-
consSubstitution,
|
|
9
8
|
getErrorNote,
|
|
9
|
+
getBoundFresh,
|
|
10
10
|
getChildren,
|
|
11
11
|
getFresh,
|
|
12
|
+
getParamFresh,
|
|
12
13
|
mapChildren,
|
|
13
14
|
mapSelectorArgs,
|
|
14
|
-
shift,
|
|
15
|
-
substituteExpr,
|
|
16
15
|
type Bound,
|
|
17
16
|
type Defn,
|
|
18
17
|
type Expr,
|
|
19
18
|
type Hyp,
|
|
20
|
-
type
|
|
19
|
+
type Warn,
|
|
21
20
|
type Param,
|
|
22
21
|
type Selector,
|
|
23
22
|
} from "./expression";
|
|
24
23
|
|
|
25
|
-
interface
|
|
24
|
+
interface Resolution {
|
|
26
25
|
params: Param[];
|
|
27
26
|
definitions: Defn[];
|
|
28
27
|
expression: Expr;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
interface
|
|
30
|
+
interface LabelMatch {
|
|
32
31
|
context: Hyp[];
|
|
33
32
|
expression: Expr;
|
|
34
33
|
indices: { name: string; index: number }[];
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
const
|
|
36
|
+
const UNRESOLVED = { kind: "Opaque", name: "$Bad" } satisfies Expr;
|
|
38
37
|
|
|
39
|
-
const
|
|
38
|
+
const isUnresolved = (expression: Expr) =>
|
|
39
|
+
expression.kind === "Opaque" && expression.name === UNRESOLVED.name;
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const stripParensAndAtomic = (expression: Expr): Expr => {
|
|
42
42
|
const mapped =
|
|
43
|
-
expression.kind === "Parens"
|
|
43
|
+
expression.kind === "Parens"
|
|
44
|
+
? stripParensAndAtomic(expression.expression)
|
|
45
|
+
: mapChildren(expression, stripParensAndAtomic);
|
|
44
46
|
if (!mapped.isAtomic) return mapped;
|
|
45
47
|
const { isAtomic: _isAtomic, ...rest } = mapped;
|
|
46
48
|
return rest;
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
// Parentheses go everywhere but in the definitions of a LET.
|
|
50
|
-
const
|
|
52
|
+
const stripParens = (expression: Expr): Expr => {
|
|
51
53
|
if (expression.kind === "Let") {
|
|
52
54
|
return at(
|
|
53
|
-
{ kind: "Let", definitions: expression.definitions, body:
|
|
55
|
+
{ kind: "Let", definitions: expression.definitions, body: stripParens(expression.body) },
|
|
54
56
|
expression.body,
|
|
55
57
|
);
|
|
56
58
|
}
|
|
57
|
-
if (expression.kind === "Parens") return
|
|
58
|
-
return mapChildren(expression,
|
|
59
|
+
if (expression.kind === "Parens") return stripParens(expression.expression);
|
|
60
|
+
return mapChildren(expression, stripParens);
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
const hasNegativeIndex = (expression: Expr): boolean =>
|
|
@@ -63,14 +65,14 @@ const hasNegativeIndex = (expression: Expr): boolean =>
|
|
|
63
65
|
|
|
64
66
|
// Visit.iter's context for each binder, stopping at labels with other names and at declarations
|
|
65
67
|
// in an ASSUME.
|
|
66
|
-
const findLabel = (expression: Expr, label: string, context: Hyp[]):
|
|
68
|
+
const findLabel = (expression: Expr, label: string, context: Hyp[]): LabelMatch | undefined => {
|
|
67
69
|
const search = (inner: Expr, innerContext = context) => findLabel(inner, label, innerContext);
|
|
68
70
|
const searchBounds = (bounds: Bound[], body: Expr) =>
|
|
69
|
-
bounds.reduce<
|
|
71
|
+
bounds.reduce<LabelMatch | undefined>(
|
|
70
72
|
(found, bound) =>
|
|
71
73
|
found ?? (bound.domain.kind === "Domain" ? search(bound.domain.expression) : undefined),
|
|
72
74
|
undefined,
|
|
73
|
-
) ?? search(body, [...context, ...bounds.map(
|
|
75
|
+
) ?? search(body, [...context, ...bounds.map(getBoundFresh)]);
|
|
74
76
|
switch (expression.kind) {
|
|
75
77
|
case "Parens":
|
|
76
78
|
if (expression.form.kind !== "Xlabel") return search(expression.expression);
|
|
@@ -78,10 +80,7 @@ const findLabel = (expression: Expr, label: string, context: Hyp[]): Label | und
|
|
|
78
80
|
? { context, expression: expression.expression, indices: expression.form.indices }
|
|
79
81
|
: undefined;
|
|
80
82
|
case "Lambda":
|
|
81
|
-
return search(expression.body, [
|
|
82
|
-
...context,
|
|
83
|
-
...expression.params.map((param) => getFresh(param.name, "Unknown", param.shape)),
|
|
84
|
-
]);
|
|
83
|
+
return search(expression.body, [...context, ...expression.params.map(getParamFresh)]);
|
|
85
84
|
case "Let": {
|
|
86
85
|
const inner = [...context];
|
|
87
86
|
for (const definition of expression.definitions) {
|
|
@@ -144,11 +143,7 @@ const getReversal = (count: number, paramCount: number) =>
|
|
|
144
143
|
const getIndices = (count: number) =>
|
|
145
144
|
Array.from({ length: count }, (_item, index): Expr => ({ kind: "Ix", index: count - index }));
|
|
146
145
|
|
|
147
|
-
const instantiate = (
|
|
148
|
-
onWarning: (warning: ObligationWarning) => void,
|
|
149
|
-
expression: Expr,
|
|
150
|
-
args: Expr[],
|
|
151
|
-
): Expr => {
|
|
146
|
+
const instantiate = (onWarning: Warn, expression: Expr, args: Expr[]): Expr => {
|
|
152
147
|
switch (expression.kind) {
|
|
153
148
|
case "Quant":
|
|
154
149
|
case "Fcn":
|
|
@@ -214,11 +209,7 @@ const instantiate = (
|
|
|
214
209
|
}
|
|
215
210
|
};
|
|
216
211
|
|
|
217
|
-
const abstract = (
|
|
218
|
-
onWarning: (warning: ObligationWarning) => void,
|
|
219
|
-
definitionCount: number,
|
|
220
|
-
expression: Expr,
|
|
221
|
-
): [Param[], Expr] => {
|
|
212
|
+
const abstract = (onWarning: Warn, definitionCount: number, expression: Expr): [Param[], Expr] => {
|
|
222
213
|
const params = ((): Param[] => {
|
|
223
214
|
switch (expression.kind) {
|
|
224
215
|
case "Quant":
|
|
@@ -244,7 +235,7 @@ const abstract = (
|
|
|
244
235
|
};
|
|
245
236
|
|
|
246
237
|
const getNumbered = (
|
|
247
|
-
onWarning:
|
|
238
|
+
onWarning: Warn,
|
|
248
239
|
expression: Expr,
|
|
249
240
|
position: number,
|
|
250
241
|
origin: Expr,
|
|
@@ -347,7 +338,7 @@ const getNumbered = (
|
|
|
347
338
|
at({ kind: "Tuple", elements: [arm.condition, arm.body] }, arm.body),
|
|
348
339
|
),
|
|
349
340
|
...(expression.other
|
|
350
|
-
? [at({ kind: "Tuple", elements: [
|
|
341
|
+
? [at({ kind: "Tuple", elements: [UNRESOLVED, expression.other] }, expression.other)]
|
|
351
342
|
: []),
|
|
352
343
|
]);
|
|
353
344
|
}
|
|
@@ -355,7 +346,7 @@ const getNumbered = (
|
|
|
355
346
|
onWarning(getErrorNote(expression.location, emptyMessage));
|
|
356
347
|
throw new TlaProofError(emptyMessage, { failure: "Expr.Deref.deref_num" });
|
|
357
348
|
})();
|
|
358
|
-
if (
|
|
349
|
+
if (isUnresolved(result)) {
|
|
359
350
|
const badMessage = `Cannot resolve subexpression reference !${position}`;
|
|
360
351
|
onWarning(getErrorNote(expression.location, badMessage));
|
|
361
352
|
throw new TlaProofError(badMessage, { failure: "Expr.Deref.deref_num" });
|
|
@@ -375,16 +366,16 @@ const permute = (indices: number[], args: Expr[]) => {
|
|
|
375
366
|
};
|
|
376
367
|
|
|
377
368
|
const resolveLabel = (
|
|
378
|
-
onWarning:
|
|
369
|
+
onWarning: Warn,
|
|
379
370
|
definitionCount: number,
|
|
380
371
|
expression: Expr,
|
|
381
372
|
label: string,
|
|
382
373
|
labelArgs: Expr[],
|
|
383
|
-
):
|
|
374
|
+
): Resolution => {
|
|
384
375
|
const found = findLabel(expression, label, []);
|
|
385
376
|
if (!found) {
|
|
386
377
|
onWarning(getErrorNote(expression.location, `Could not find label ${label}`));
|
|
387
|
-
return { params: [], definitions: [], expression:
|
|
378
|
+
return { params: [], definitions: [], expression: UNRESOLVED };
|
|
388
379
|
}
|
|
389
380
|
const indices = found.indices;
|
|
390
381
|
if (indices.length !== labelArgs.length && labelArgs.length > 0) {
|
|
@@ -438,12 +429,12 @@ const resolveLabel = (
|
|
|
438
429
|
};
|
|
439
430
|
|
|
440
431
|
const resolveLetOperator = (
|
|
441
|
-
onWarning:
|
|
432
|
+
onWarning: Warn,
|
|
442
433
|
definitionCount: number,
|
|
443
434
|
expression: Expr,
|
|
444
435
|
label: string,
|
|
445
436
|
args: Expr[],
|
|
446
|
-
):
|
|
437
|
+
): Resolution => {
|
|
447
438
|
if (expression.kind !== "Let") {
|
|
448
439
|
onWarning(getErrorNote(expression.location, `not a LET expression`));
|
|
449
440
|
throw new TlaProofError("not a LET expression", { failure: "Expr.Deref.deref_letop" });
|
|
@@ -494,10 +485,10 @@ const resolveLetOperator = (
|
|
|
494
485
|
);
|
|
495
486
|
};
|
|
496
487
|
|
|
497
|
-
const
|
|
498
|
-
onWarning:
|
|
488
|
+
const resolveSelectors = (
|
|
489
|
+
onWarning: Warn,
|
|
499
490
|
isLabel: boolean,
|
|
500
|
-
state:
|
|
491
|
+
state: Resolution,
|
|
501
492
|
selectors: Selector[],
|
|
502
493
|
): Expr => {
|
|
503
494
|
const [selector, ...rest] = selectors;
|
|
@@ -513,15 +504,15 @@ const deref = (
|
|
|
513
504
|
state.params.length === 0
|
|
514
505
|
? withDefinitions
|
|
515
506
|
: at({ kind: "Lambda", params: state.params, body: withDefinitions }, withDefinitions);
|
|
516
|
-
return { ...
|
|
507
|
+
return { ...stripParensAndAtomic(abstracted), isAtomic: true };
|
|
517
508
|
}
|
|
518
509
|
if (state.expression.isAtomic) {
|
|
519
510
|
onWarning(getErrorNote(state.expression.location, `Expression has no subexpressions`));
|
|
520
|
-
return
|
|
511
|
+
return UNRESOLVED;
|
|
521
512
|
}
|
|
522
|
-
const expression = isLabel ? state.expression :
|
|
513
|
+
const expression = isLabel ? state.expression : stripParens(state.expression);
|
|
523
514
|
const count = state.definitions.length;
|
|
524
|
-
const next = (():
|
|
515
|
+
const next = ((): Resolution & { rest: Selector[]; isLabel: boolean } => {
|
|
525
516
|
const numbered = (position: number, message: string) => {
|
|
526
517
|
const [definitions, inner] = getNumbered(
|
|
527
518
|
onWarning,
|
|
@@ -571,7 +562,7 @@ const deref = (
|
|
|
571
562
|
}
|
|
572
563
|
}
|
|
573
564
|
})();
|
|
574
|
-
return
|
|
565
|
+
return resolveSelectors(
|
|
575
566
|
onWarning,
|
|
576
567
|
next.isLabel,
|
|
577
568
|
{
|
|
@@ -585,11 +576,7 @@ const deref = (
|
|
|
585
576
|
);
|
|
586
577
|
};
|
|
587
578
|
|
|
588
|
-
const
|
|
589
|
-
onWarning: (warning: ObligationWarning) => void,
|
|
590
|
-
operator: Expr,
|
|
591
|
-
args: Expr[],
|
|
592
|
-
): Deref => {
|
|
579
|
+
const getInitialResolution = (onWarning: Warn, operator: Expr, args: Expr[]): Resolution => {
|
|
593
580
|
if (args.length > 0) {
|
|
594
581
|
return { params: [], definitions: [], expression: instantiate(onWarning, operator, args) };
|
|
595
582
|
}
|
|
@@ -599,13 +586,18 @@ const getInitialDeref = (
|
|
|
599
586
|
};
|
|
600
587
|
|
|
601
588
|
export const resolveSubexpression = (
|
|
602
|
-
onWarning:
|
|
589
|
+
onWarning: Warn,
|
|
603
590
|
operator: Expr,
|
|
604
591
|
args: Expr[],
|
|
605
592
|
selectors: Selector[],
|
|
606
593
|
) => {
|
|
607
|
-
const result =
|
|
608
|
-
|
|
594
|
+
const result = resolveSelectors(
|
|
595
|
+
onWarning,
|
|
596
|
+
true,
|
|
597
|
+
getInitialResolution(onWarning, operator, args),
|
|
598
|
+
selectors,
|
|
599
|
+
);
|
|
600
|
+
if (isUnresolved(result)) {
|
|
609
601
|
const message = "Could not resolve subexpression reference";
|
|
610
602
|
onWarning(getErrorNote(operator.location, message));
|
|
611
603
|
throw new TlaProofError(message, { failure: "Expr.Anon: 2" });
|