tla-ts 0.0.3-dev.b1578d0 → 0.0.3-dev.b4e335d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +150 -8
- package/dist/index.d.ts +150 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -20
- package/dist/run-cli.js +1351 -20
- package/dist/transfer.cjs +86 -28
- package/dist/transfer.js +86 -28
- package/package.json +5 -1
- package/src/ast.ts +57 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1396 -227
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -18
- package/src/config.ts +252 -179
- package/src/environment.ts +514 -130
- package/src/errors.ts +217 -3
- package/src/evaluate.ts +722 -112
- package/src/exit-codes.ts +5 -4
- package/src/index.ts +1 -0
- package/src/instances.ts +7 -5
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +183 -37
- package/src/lexer.ts +112 -29
- package/src/live-check.ts +220 -102
- package/src/liveness.ts +216 -52
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +8 -3
- package/src/parallel.ts +56 -5
- package/src/parser.ts +445 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1465 -411
- package/src/run-cli.ts +1167 -155
- package/src/runtime.ts +18 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +26 -7
- package/src/standard-modules.ts +200 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +207 -103
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +54 -25
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -15
- package/src/tlc-order.ts +56 -6
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +697 -180
|
@@ -0,0 +1,1208 @@
|
|
|
1
|
+
import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "./levels";
|
|
2
|
+
import {
|
|
3
|
+
addSanyMessage,
|
|
4
|
+
CONSTANT_DECL_KIND,
|
|
5
|
+
VARIABLE_DECL_KIND,
|
|
6
|
+
formatSanyLocation,
|
|
7
|
+
getDeclarations,
|
|
8
|
+
getOpDefs,
|
|
9
|
+
getSymbolArity,
|
|
10
|
+
getThmOrAssumpDefs,
|
|
11
|
+
type ArgLevelConstraint,
|
|
12
|
+
type ArgLevelParam,
|
|
13
|
+
type ExprOrOpArgNode,
|
|
14
|
+
type FormalParamNode,
|
|
15
|
+
type InstanceNode,
|
|
16
|
+
type LevelFields,
|
|
17
|
+
type ModuleNode,
|
|
18
|
+
type OpApplNode,
|
|
19
|
+
type OpDeclNode,
|
|
20
|
+
type OpDefNode,
|
|
21
|
+
type ProofNode,
|
|
22
|
+
type SanyLocation,
|
|
23
|
+
type SanyMessage,
|
|
24
|
+
type SemanticNode,
|
|
25
|
+
type Subst,
|
|
26
|
+
type SymbolNode,
|
|
27
|
+
type ThmOrAssumpDefNode,
|
|
28
|
+
} from "./sany-nodes";
|
|
29
|
+
|
|
30
|
+
// A port of the levelCheck methods of SANY's semantic nodes: the levels, weights and Leibniz flags
|
|
31
|
+
// its XMLExporter writes, and the level errors it reports. Each check returns what SANY's returns,
|
|
32
|
+
// which is whether the node is free of level errors, or true for the nodes that ignore that.
|
|
33
|
+
|
|
34
|
+
type AnyDefNode = OpDefNode | ThmOrAssumpDefNode;
|
|
35
|
+
|
|
36
|
+
interface LevelCheck {
|
|
37
|
+
messages: SanyMessage[];
|
|
38
|
+
isTlc174: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const addError = (check: LevelCheck, location: SanyLocation, text: string, code?: string) =>
|
|
42
|
+
addSanyMessage(check.messages, {
|
|
43
|
+
location,
|
|
44
|
+
text,
|
|
45
|
+
isWarning: false,
|
|
46
|
+
...(code !== undefined && !check.isTlc174 && { code }),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const addAll = <Item>(target: Set<Item>, source: Iterable<Item>) => {
|
|
50
|
+
for (const item of source) target.add(item);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const getArgLevelKey = (op: SymbolNode, index: number, param: SymbolNode) =>
|
|
54
|
+
`${op.id}:${index}:${param.id}`;
|
|
55
|
+
|
|
56
|
+
const addArgLevelParam = (
|
|
57
|
+
target: Map<string, ArgLevelParam>,
|
|
58
|
+
op: SymbolNode,
|
|
59
|
+
index: number,
|
|
60
|
+
param: SymbolNode,
|
|
61
|
+
) => {
|
|
62
|
+
target.set(getArgLevelKey(op, index, param), { op, index, param });
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const addArgLevelParams = (
|
|
66
|
+
target: Map<string, ArgLevelParam>,
|
|
67
|
+
source: Map<string, ArgLevelParam>,
|
|
68
|
+
isIncluded: (argLevelParam: ArgLevelParam) => boolean = () => true,
|
|
69
|
+
) => {
|
|
70
|
+
source.forEach((argLevelParam, key) => {
|
|
71
|
+
if (isIncluded(argLevelParam)) target.set(key, argLevelParam);
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// SetOfLevelConstraints.put keeps the lowest bound.
|
|
76
|
+
const putLevelConstraint = (target: Map<SymbolNode, number>, param: SymbolNode, level: number) => {
|
|
77
|
+
target.set(param, Math.min(level, target.get(param) ?? TEMPORAL_LEVEL));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const putLevelConstraints = (
|
|
81
|
+
target: Map<SymbolNode, number>,
|
|
82
|
+
source: Map<SymbolNode, number>,
|
|
83
|
+
isIncluded: (param: SymbolNode) => boolean = () => true,
|
|
84
|
+
) => {
|
|
85
|
+
source.forEach((level, param) => {
|
|
86
|
+
if (isIncluded(param)) putLevelConstraint(target, param, level);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const getArgLevelConstraintKey = (param: SymbolNode, position: number) => `${param.id}:${position}`;
|
|
91
|
+
|
|
92
|
+
// SetOfArgLevelConstraints.put keeps the highest bound.
|
|
93
|
+
const putArgLevelConstraint = (
|
|
94
|
+
target: Map<string, ArgLevelConstraint>,
|
|
95
|
+
param: SymbolNode,
|
|
96
|
+
position: number,
|
|
97
|
+
level: number,
|
|
98
|
+
) => {
|
|
99
|
+
const key = getArgLevelConstraintKey(param, position);
|
|
100
|
+
const old = target.get(key)?.level ?? CONSTANT_LEVEL;
|
|
101
|
+
target.set(key, { param, position, level: Math.max(level, old) });
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const putArgLevelConstraints = (
|
|
105
|
+
target: Map<string, ArgLevelConstraint>,
|
|
106
|
+
source: Map<string, ArgLevelConstraint>,
|
|
107
|
+
isIncluded: (constraint: ArgLevelConstraint) => boolean = () => true,
|
|
108
|
+
) => {
|
|
109
|
+
source.forEach((constraint) => {
|
|
110
|
+
if (isIncluded(constraint)) {
|
|
111
|
+
putArgLevelConstraint(target, constraint.param, constraint.position, constraint.level);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const shareLevels = (node: LevelFields, source: LevelFields) => {
|
|
117
|
+
node.levelParams = source.levelParams;
|
|
118
|
+
node.allParams = source.allParams;
|
|
119
|
+
node.levelConstraints = source.levelConstraints;
|
|
120
|
+
node.argLevelConstraints = source.argLevelConstraints;
|
|
121
|
+
node.argLevelParams = source.argLevelParams;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const mergeLevels = (node: LevelFields, part: LevelFields) => {
|
|
125
|
+
addAll(node.levelParams, part.levelParams);
|
|
126
|
+
addAll(node.allParams, part.allParams);
|
|
127
|
+
putLevelConstraints(node.levelConstraints, part.levelConstraints);
|
|
128
|
+
putArgLevelConstraints(node.argLevelConstraints, part.argLevelConstraints);
|
|
129
|
+
addArgLevelParams(node.argLevelParams, part.argLevelParams);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ArgLevelParam.occur.
|
|
133
|
+
const isOccurring = (argLevelParam: ArgLevelParam, symbols: SymbolNode[]) =>
|
|
134
|
+
symbols.includes(argLevelParam.op) || symbols.includes(argLevelParam.param);
|
|
135
|
+
|
|
136
|
+
const isParam = (symbol: SymbolNode): symbol is FormalParamNode | OpDeclNode =>
|
|
137
|
+
symbol.kind === "OpDecl" || symbol.kind === "FormalParam";
|
|
138
|
+
|
|
139
|
+
const isLevelNode = (node: SemanticNode): node is Exclude<SemanticNode, ModuleNode> =>
|
|
140
|
+
node.kind !== "Module";
|
|
141
|
+
|
|
142
|
+
const isAnyDef = (symbol: SymbolNode): symbol is AnyDefNode =>
|
|
143
|
+
symbol.kind === "OpDef" || symbol.kind === "ThmOrAssumpDef";
|
|
144
|
+
|
|
145
|
+
const getIndex = (definition: AnyDefNode, index: number) =>
|
|
146
|
+
definition.kind === "OpDef" && definition.arity < 0 ? 0 : index;
|
|
147
|
+
|
|
148
|
+
const getWeight = (definition: AnyDefNode, index: number) =>
|
|
149
|
+
definition.kind === "OpDef" ? (definition.weights[getIndex(definition, index)] ?? 0) : 0;
|
|
150
|
+
|
|
151
|
+
const getMaxLevel = (definition: AnyDefNode, index: number) =>
|
|
152
|
+
definition.maxLevels[getIndex(definition, index)] ?? TEMPORAL_LEVEL;
|
|
153
|
+
|
|
154
|
+
const getMinMaxLevel = (definition: AnyDefNode, operand: number, position: number) =>
|
|
155
|
+
definition.minMaxLevel?.[operand]?.[position] ?? CONSTANT_LEVEL;
|
|
156
|
+
|
|
157
|
+
const isLeibnizArgument = (definition: AnyDefNode, index: number) =>
|
|
158
|
+
definition.kind === "OpDef"
|
|
159
|
+
? (definition.isLeibnizArg?.[getIndex(definition, index)] ?? true)
|
|
160
|
+
: (definition.isLeibnizArg[index] ?? true);
|
|
161
|
+
|
|
162
|
+
const getOpLevelCond = (definition: AnyDefNode, operand: number, other: number, index: number) =>
|
|
163
|
+
definition.opLevelCond?.[operand]?.[other]?.[index] ?? false;
|
|
164
|
+
|
|
165
|
+
const getBoundSymbols = (node: OpApplNode) => [
|
|
166
|
+
...(node.unbounded ?? []),
|
|
167
|
+
...(node.bounded ?? []).flat(),
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
const getSubstitute = (symbol: SymbolNode, substs: Subst[]) =>
|
|
171
|
+
substs.find((subst) => subst.op === symbol)?.expr;
|
|
172
|
+
|
|
173
|
+
// Subst.paramSet and Subst.allParamSet.
|
|
174
|
+
const getSubstitutedParams = (param: SymbolNode, substs: Subst[], isAll: boolean) => {
|
|
175
|
+
const expr = getSubstitute(param, substs);
|
|
176
|
+
if (expr === undefined) return new Set([param]);
|
|
177
|
+
return isAll ? expr.allParams : expr.levelParams;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// Subst.getSubALPSet.
|
|
181
|
+
const getSubstitutedArgLevelParams = (source: Map<string, ArgLevelParam>, substs: Subst[]) => {
|
|
182
|
+
const result = new Map<string, ArgLevelParam>();
|
|
183
|
+
source.forEach((argLevelParam, key) => {
|
|
184
|
+
const expr = getSubstitute(argLevelParam.op, substs);
|
|
185
|
+
if (expr === undefined) {
|
|
186
|
+
result.set(key, argLevelParam);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (expr.kind !== "OpArg" || !isParam(expr.op)) return;
|
|
190
|
+
const operator = expr.op;
|
|
191
|
+
getSubstitutedParams(argLevelParam.param, substs, false).forEach((param) =>
|
|
192
|
+
addArgLevelParam(result, operator, argLevelParam.index, param),
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
interface ConstraintSource {
|
|
199
|
+
levelConstraints: Map<SymbolNode, number>;
|
|
200
|
+
argLevelConstraints: Map<string, ArgLevelConstraint>;
|
|
201
|
+
argLevelParams: Map<string, ArgLevelParam>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Subst.getSubLCSet.
|
|
205
|
+
const getSubstitutedLevelConstraints = (
|
|
206
|
+
body: ConstraintSource,
|
|
207
|
+
substs: Subst[],
|
|
208
|
+
isConstant: boolean,
|
|
209
|
+
iteration: number,
|
|
210
|
+
check: LevelCheck,
|
|
211
|
+
) => {
|
|
212
|
+
const result = new Map<SymbolNode, number>();
|
|
213
|
+
body.levelConstraints.forEach((bound, param) => {
|
|
214
|
+
const level =
|
|
215
|
+
isConstant || param.kind !== "OpDecl"
|
|
216
|
+
? bound
|
|
217
|
+
: param.declKind === CONSTANT_DECL_KIND
|
|
218
|
+
? CONSTANT_LEVEL
|
|
219
|
+
: param.declKind === VARIABLE_DECL_KIND
|
|
220
|
+
? VARIABLE_LEVEL
|
|
221
|
+
: bound;
|
|
222
|
+
getSubstitutedParams(param, substs, false).forEach((substituted) =>
|
|
223
|
+
putLevelConstraint(result, substituted, level),
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
body.argLevelParams.forEach((argLevelParam) => {
|
|
227
|
+
const expr = getSubstitute(argLevelParam.op, substs);
|
|
228
|
+
if (expr?.kind !== "OpArg" || expr.op.kind !== "OpDef") return;
|
|
229
|
+
checkLevel(expr.op, iteration, check);
|
|
230
|
+
const level = getMaxLevel(expr.op, argLevelParam.index);
|
|
231
|
+
getSubstitutedParams(argLevelParam.param, substs, false).forEach((substituted) =>
|
|
232
|
+
putLevelConstraint(result, substituted, level),
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
return result;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// Subst.getSubALCSet.
|
|
239
|
+
const getSubstitutedArgLevelConstraints = (
|
|
240
|
+
body: ConstraintSource,
|
|
241
|
+
substs: Subst[],
|
|
242
|
+
iteration: number,
|
|
243
|
+
check: LevelCheck,
|
|
244
|
+
) => {
|
|
245
|
+
const result = new Map<string, ArgLevelConstraint>();
|
|
246
|
+
body.argLevelConstraints.forEach((constraint) => {
|
|
247
|
+
const expr = getSubstitute(constraint.param, substs);
|
|
248
|
+
if (expr === undefined) {
|
|
249
|
+
putArgLevelConstraint(result, constraint.param, constraint.position, constraint.level);
|
|
250
|
+
} else if (expr.kind === "OpArg" && isParam(expr.op)) {
|
|
251
|
+
putArgLevelConstraint(result, expr.op, constraint.position, constraint.level);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
body.argLevelParams.forEach((argLevelParam) => {
|
|
255
|
+
const paramExpr = getSubstitute(argLevelParam.param, substs);
|
|
256
|
+
if (paramExpr === undefined) return;
|
|
257
|
+
const opExpr = getSubstitute(argLevelParam.op, substs);
|
|
258
|
+
const operator =
|
|
259
|
+
opExpr === undefined ? argLevelParam.op : opExpr.kind === "OpArg" ? opExpr.op : undefined;
|
|
260
|
+
if (operator === undefined || !isParam(operator)) return;
|
|
261
|
+
checkLevel(paramExpr, iteration, check);
|
|
262
|
+
putArgLevelConstraint(result, operator, argLevelParam.index, paramExpr.level);
|
|
263
|
+
});
|
|
264
|
+
return result;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// ModuleNode.isConstant.
|
|
268
|
+
const isConstantModule = (module: ModuleNode, check: LevelCheck) => {
|
|
269
|
+
if (getDeclarations(module, VARIABLE_DECL_KIND).length > 0) return false;
|
|
270
|
+
checkModuleLevels(module, check);
|
|
271
|
+
if (getOpDefs(module).some((definition) => (definition.body?.level ?? 0) !== CONSTANT_LEVEL)) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
return module.topLevel.every((node) => node.kind !== "Theorem" || node.level === CONSTANT_LEVEL);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// The parts of OpDefNode.levelCheck and ThmOrAssumpDefNode.levelCheck that follow the body's.
|
|
278
|
+
const checkDefinitionBody = (node: AnyDefNode, params: FormalParamNode[], body: LevelFields) => {
|
|
279
|
+
node.minMaxLevel = params.map((param) =>
|
|
280
|
+
Array.from(
|
|
281
|
+
{ length: param.arity },
|
|
282
|
+
(_, position) =>
|
|
283
|
+
body.argLevelConstraints.get(getArgLevelConstraintKey(param, position))?.level ??
|
|
284
|
+
CONSTANT_LEVEL,
|
|
285
|
+
),
|
|
286
|
+
);
|
|
287
|
+
node.opLevelCond = params.map((param) =>
|
|
288
|
+
params.map((other) =>
|
|
289
|
+
Array.from({ length: param.arity }, (_, index) =>
|
|
290
|
+
body.argLevelParams.has(getArgLevelKey(param, index, other)),
|
|
291
|
+
),
|
|
292
|
+
),
|
|
293
|
+
);
|
|
294
|
+
addAll(node.levelParams, body.levelParams);
|
|
295
|
+
addAll(node.allParams, body.allParams);
|
|
296
|
+
addAll(node.nonLeibnizParams, body.nonLeibnizParams);
|
|
297
|
+
params.forEach((param, index) => {
|
|
298
|
+
node.levelParams.delete(param);
|
|
299
|
+
node.allParams.delete(param);
|
|
300
|
+
if (!node.nonLeibnizParams.has(param)) return;
|
|
301
|
+
node.nonLeibnizParams.delete(param);
|
|
302
|
+
if (node.isLeibnizArg) node.isLeibnizArg[index] = false;
|
|
303
|
+
node.isLeibniz = false;
|
|
304
|
+
});
|
|
305
|
+
node.levelConstraints = new Map(body.levelConstraints);
|
|
306
|
+
params.forEach((param) => node.levelConstraints.delete(param));
|
|
307
|
+
node.argLevelConstraints = new Map(body.argLevelConstraints);
|
|
308
|
+
params.forEach((param) => {
|
|
309
|
+
for (let position = 0; position < param.arity; position++) {
|
|
310
|
+
node.argLevelConstraints.delete(getArgLevelConstraintKey(param, position));
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
addArgLevelParams(
|
|
314
|
+
node.argLevelParams,
|
|
315
|
+
body.argLevelParams,
|
|
316
|
+
(argLevelParam) =>
|
|
317
|
+
!params.some((param) => param === argLevelParam.op) ||
|
|
318
|
+
!params.some((param) => param === argLevelParam.param),
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// The checks of OpApplNode.levelCheck that compare the levels of the arguments of a defined
|
|
323
|
+
// operator with the levels it allows.
|
|
324
|
+
const checkArguments = (
|
|
325
|
+
node: OpApplNode,
|
|
326
|
+
operator: AnyDefNode,
|
|
327
|
+
isOperatorCorrect: boolean,
|
|
328
|
+
iteration: number,
|
|
329
|
+
check: LevelCheck,
|
|
330
|
+
) => {
|
|
331
|
+
node.operands.forEach((operand, index) => {
|
|
332
|
+
if (operand === undefined) return;
|
|
333
|
+
if (operand.level > getMaxLevel(operator, index)) {
|
|
334
|
+
if (isOperatorCorrect && checkLevel(operand, iteration, check)) {
|
|
335
|
+
addError(
|
|
336
|
+
check,
|
|
337
|
+
node.location,
|
|
338
|
+
`Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator.`,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
node.levelCorrect = false;
|
|
342
|
+
}
|
|
343
|
+
if (operand.kind !== "OpArg" || !isAnyDef(operand.op)) return;
|
|
344
|
+
const argument = operand.op;
|
|
345
|
+
checkLevel(argument, iteration, check);
|
|
346
|
+
const arity = getSymbolArity(argument);
|
|
347
|
+
for (let position = 0; position < arity; position++) {
|
|
348
|
+
const minimum = getMinMaxLevel(operator, index, position);
|
|
349
|
+
if (getMaxLevel(argument, position) >= minimum) continue;
|
|
350
|
+
if (isOperatorCorrect && checkLevel(operand, iteration, check)) {
|
|
351
|
+
addError(
|
|
352
|
+
check,
|
|
353
|
+
node.location,
|
|
354
|
+
`Level error in applying operator ${operator.name}:\nThe permitted level of argument ${position + 1} of the operator argument ${index + 1} \nmust be at least ${minimum}.`,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
node.levelCorrect = false;
|
|
358
|
+
}
|
|
359
|
+
node.operands.forEach((other, otherIndex) => {
|
|
360
|
+
for (let position = 0; position < arity; position++) {
|
|
361
|
+
if (
|
|
362
|
+
other === undefined ||
|
|
363
|
+
!getOpLevelCond(operator, index, otherIndex, position) ||
|
|
364
|
+
other.level <= getMaxLevel(argument, position)
|
|
365
|
+
) {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (checkLevel(operand, iteration, check) && checkLevel(other, iteration, check)) {
|
|
369
|
+
addError(
|
|
370
|
+
check,
|
|
371
|
+
node.location,
|
|
372
|
+
`Level error in applying operator ${operator.name}:\nThe level of argument ${otherIndex + 1} exceeds the maximum level allowed by the operator.`,
|
|
373
|
+
"HIGHER_ORDER_OPERATOR_COPARAMETER_LEVEL_CONSTRAINTS_EXCEEDED",
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
node.levelCorrect = false;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
node.ranges.forEach((range, index) => {
|
|
381
|
+
const isRangeCorrect = checkLevel(range, iteration, check);
|
|
382
|
+
if (range.level <= ACTION_LEVEL) return;
|
|
383
|
+
if (isRangeCorrect) {
|
|
384
|
+
addError(
|
|
385
|
+
check,
|
|
386
|
+
node.location,
|
|
387
|
+
`Level error in applying operator ${operator.name}:\nThe level of the range for the bounded variable ${formatSanyLocation(node.bounded?.[index]?.[0]?.location)} \nexceeds the maximum level allowed by the operator.`,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
node.levelCorrect = false;
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// The level constraints OpApplNode.levelCheck derives for an application of a defined operator.
|
|
395
|
+
const constrainArguments = (
|
|
396
|
+
node: OpApplNode,
|
|
397
|
+
operator: AnyDefNode,
|
|
398
|
+
boundSymbols: Set<SymbolNode>,
|
|
399
|
+
iteration: number,
|
|
400
|
+
check: LevelCheck,
|
|
401
|
+
) => {
|
|
402
|
+
const params = operator.params ?? [];
|
|
403
|
+
const getArgument = (symbol: SymbolNode) =>
|
|
404
|
+
node.operands.find((_, index) => params[index] === symbol);
|
|
405
|
+
putLevelConstraints(node.levelConstraints, operator.levelConstraints);
|
|
406
|
+
node.operands.forEach((operand) => {
|
|
407
|
+
if (operand === undefined) return;
|
|
408
|
+
putLevelConstraints(
|
|
409
|
+
node.levelConstraints,
|
|
410
|
+
operand.levelConstraints,
|
|
411
|
+
(param) => !boundSymbols.has(param),
|
|
412
|
+
);
|
|
413
|
+
});
|
|
414
|
+
node.ranges.forEach((range) =>
|
|
415
|
+
putLevelConstraints(node.levelConstraints, range.levelConstraints),
|
|
416
|
+
);
|
|
417
|
+
node.operands.forEach((operand, index) => {
|
|
418
|
+
const level = getMaxLevel(operator, index);
|
|
419
|
+
operand?.levelParams.forEach((param) =>
|
|
420
|
+
putLevelConstraint(node.levelConstraints, param, level),
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
node.operands.forEach((operand, index) => {
|
|
424
|
+
if (operand?.kind !== "OpArg" || !isAnyDef(operand.op)) return;
|
|
425
|
+
const argument = operand.op;
|
|
426
|
+
checkLevel(argument, iteration, check);
|
|
427
|
+
const arity = getSymbolArity(argument);
|
|
428
|
+
node.operands.forEach((other, otherIndex) => {
|
|
429
|
+
for (let position = 0; position < arity; position++) {
|
|
430
|
+
if (!getOpLevelCond(operator, index, otherIndex, position)) continue;
|
|
431
|
+
const level = getMaxLevel(argument, position);
|
|
432
|
+
other?.levelParams.forEach((param) =>
|
|
433
|
+
putLevelConstraint(node.levelConstraints, param, level),
|
|
434
|
+
);
|
|
435
|
+
if (!argument.isLeibniz && !isLeibnizArgument(argument, position) && other) {
|
|
436
|
+
addAll(node.nonLeibnizParams, other.allParams);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
operator.argLevelParams.forEach((argLevelParam) => {
|
|
442
|
+
const argument = getArgument(argLevelParam.op);
|
|
443
|
+
if (argument?.kind !== "OpArg" || !isAnyDef(argument.op)) return;
|
|
444
|
+
checkLevel(argument.op, iteration, check);
|
|
445
|
+
putLevelConstraint(
|
|
446
|
+
node.levelConstraints,
|
|
447
|
+
argLevelParam.param,
|
|
448
|
+
getMaxLevel(argument.op, argLevelParam.index),
|
|
449
|
+
);
|
|
450
|
+
});
|
|
451
|
+
putArgLevelConstraints(node.argLevelConstraints, operator.argLevelConstraints);
|
|
452
|
+
node.operands.forEach((operand) => {
|
|
453
|
+
if (operand) putArgLevelConstraints(node.argLevelConstraints, operand.argLevelConstraints);
|
|
454
|
+
});
|
|
455
|
+
node.ranges.forEach((range) =>
|
|
456
|
+
putArgLevelConstraints(node.argLevelConstraints, range.argLevelConstraints),
|
|
457
|
+
);
|
|
458
|
+
node.operands.forEach((operand, index) => {
|
|
459
|
+
if (operand?.kind !== "OpArg" || !isParam(operand.op)) return;
|
|
460
|
+
const argument = operand.op;
|
|
461
|
+
for (let position = 0; position < argument.arity; position++) {
|
|
462
|
+
putArgLevelConstraint(
|
|
463
|
+
node.argLevelConstraints,
|
|
464
|
+
argument,
|
|
465
|
+
position,
|
|
466
|
+
getMinMaxLevel(operator, index, position),
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
node.operands.forEach((other, otherIndex) => {
|
|
470
|
+
for (let position = 0; position < argument.arity; position++) {
|
|
471
|
+
if (other === undefined || !getOpLevelCond(operator, index, otherIndex, position)) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
putArgLevelConstraint(node.argLevelConstraints, argument, position, other.level);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
operator.argLevelParams.forEach((argLevelParam) => {
|
|
479
|
+
const argument = getArgument(argLevelParam.op);
|
|
480
|
+
if (argument === undefined) return;
|
|
481
|
+
checkLevel(argument, iteration, check);
|
|
482
|
+
putArgLevelConstraint(
|
|
483
|
+
node.argLevelConstraints,
|
|
484
|
+
argLevelParam.op,
|
|
485
|
+
argLevelParam.index,
|
|
486
|
+
argument.level,
|
|
487
|
+
);
|
|
488
|
+
});
|
|
489
|
+
node.operands.forEach((operand) => {
|
|
490
|
+
if (operand === undefined) return;
|
|
491
|
+
addArgLevelParams(
|
|
492
|
+
node.argLevelParams,
|
|
493
|
+
operand.argLevelParams,
|
|
494
|
+
(argLevelParam) => !boundSymbols.has(argLevelParam.param),
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
node.ranges.forEach((range) => addArgLevelParams(node.argLevelParams, range.argLevelParams));
|
|
498
|
+
operator.argLevelParams.forEach((argLevelParam, key) => {
|
|
499
|
+
const argument = getArgument(argLevelParam.op);
|
|
500
|
+
if (argument === undefined) {
|
|
501
|
+
const paramArgument = getArgument(argLevelParam.param);
|
|
502
|
+
if (paramArgument === undefined) node.argLevelParams.set(key, argLevelParam);
|
|
503
|
+
else {
|
|
504
|
+
checkLevel(paramArgument, iteration, check);
|
|
505
|
+
paramArgument.levelParams.forEach((param) =>
|
|
506
|
+
addArgLevelParam(node.argLevelParams, argLevelParam.op, argLevelParam.index, param),
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (argument.kind === "OpArg" && isParam(argument.op)) {
|
|
512
|
+
addArgLevelParam(node.argLevelParams, argument.op, argLevelParam.index, argLevelParam.param);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
node.operands.forEach((operand, index) => {
|
|
516
|
+
if (operand?.kind !== "OpArg" || !isParam(operand.op)) return;
|
|
517
|
+
const argument = operand.op;
|
|
518
|
+
node.operands.forEach((other, otherIndex) => {
|
|
519
|
+
for (let position = 0; position < argument.arity; position++) {
|
|
520
|
+
if (other === undefined || !getOpLevelCond(operator, index, otherIndex, position)) {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
other.levelParams.forEach((param) =>
|
|
524
|
+
addArgLevelParam(node.argLevelParams, argument, position, param),
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
// The operators OpApplNode.levelCheck rejects with both temporal and action arguments, and how its
|
|
532
|
+
// message names them.
|
|
533
|
+
const LOGICAL_OPERATOR_NAMES = new Map([
|
|
534
|
+
["\\land", "\\land"],
|
|
535
|
+
["\\lor", "\\lor"],
|
|
536
|
+
["=>", "=>"],
|
|
537
|
+
["\\equiv", "\\equiv"],
|
|
538
|
+
["$ConjList", "Conjunction list"],
|
|
539
|
+
["$DisjList", "Disjunction list"],
|
|
540
|
+
]);
|
|
541
|
+
|
|
542
|
+
// The checks at the end of OpApplNode.levelCheck of the temporal operators and quantifiers. TLC
|
|
543
|
+
// 1.7.4's SANY reports these errors but leaves the node level-correct, so an operator applied to it
|
|
544
|
+
// still checks its level.
|
|
545
|
+
const checkTemporalApplication = (node: OpApplNode, check: LevelCheck) => {
|
|
546
|
+
const addTemporalError = (location: SanyLocation, text: string) => {
|
|
547
|
+
addError(check, location, text);
|
|
548
|
+
if (!check.isTlc174) node.levelCorrect = false;
|
|
549
|
+
};
|
|
550
|
+
const name = node.operator.name;
|
|
551
|
+
const first = node.operands[0];
|
|
552
|
+
if (
|
|
553
|
+
(name === "[]" || name === "<>") &&
|
|
554
|
+
first?.level === ACTION_LEVEL &&
|
|
555
|
+
first.kind === "OpAppl"
|
|
556
|
+
) {
|
|
557
|
+
const isBoxed = name === "[]";
|
|
558
|
+
if (first.operator.name !== (isBoxed ? "$SquareAct" : "$AngleAct")) {
|
|
559
|
+
addTemporalError(
|
|
560
|
+
node.location,
|
|
561
|
+
isBoxed
|
|
562
|
+
? "[] followed by action not of form [A]_v."
|
|
563
|
+
: "<> followed by action not of form <<A>>_v.",
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (
|
|
568
|
+
(name === "~>" || name === "-+->") &&
|
|
569
|
+
(first?.level === ACTION_LEVEL || node.operands[1]?.level === ACTION_LEVEL)
|
|
570
|
+
) {
|
|
571
|
+
addTemporalError(
|
|
572
|
+
node.location,
|
|
573
|
+
"Action used where only temporal formula or state predicate allowed.",
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
const logicalName = LOGICAL_OPERATOR_NAMES.get(name);
|
|
577
|
+
if (
|
|
578
|
+
logicalName !== undefined &&
|
|
579
|
+
node.operands.some((operand) => operand?.level === TEMPORAL_LEVEL) &&
|
|
580
|
+
node.operands.some((operand) => operand?.level === ACTION_LEVEL)
|
|
581
|
+
) {
|
|
582
|
+
addTemporalError(
|
|
583
|
+
node.location,
|
|
584
|
+
`${logicalName} has both temporal formula and action as arguments.`,
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
if (node.level === TEMPORAL_LEVEL && (name === "$BoundedExists" || name === "$BoundedForall")) {
|
|
588
|
+
node.ranges.forEach((range) => {
|
|
589
|
+
if (range.level === ACTION_LEVEL) {
|
|
590
|
+
addTemporalError(range.location, "Action-level bound of quantified temporal formula.");
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
const checkApplication = (node: OpApplNode, iteration: number, check: LevelCheck) => {
|
|
597
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
598
|
+
node.levelChecked = iteration;
|
|
599
|
+
node.levelCorrect = true;
|
|
600
|
+
const operands = node.operands.filter(
|
|
601
|
+
(operand): operand is ExprOrOpArgNode => operand !== undefined,
|
|
602
|
+
);
|
|
603
|
+
operands.forEach((operand) => {
|
|
604
|
+
if (!checkLevel(operand, iteration, check)) node.levelCorrect = false;
|
|
605
|
+
});
|
|
606
|
+
node.ranges.forEach((range) => {
|
|
607
|
+
if (!checkLevel(range, iteration, check)) node.levelCorrect = false;
|
|
608
|
+
});
|
|
609
|
+
const operator = node.operator;
|
|
610
|
+
if (isAnyDef(operator)) {
|
|
611
|
+
const isOperatorCorrect = checkLevel(operator, iteration, check);
|
|
612
|
+
checkArguments(node, operator, isOperatorCorrect, iteration, check);
|
|
613
|
+
node.level = node.operands.reduce(
|
|
614
|
+
(level, operand, index) =>
|
|
615
|
+
operand !== undefined && getWeight(operator, index) === 1
|
|
616
|
+
? Math.max(level, operand.level)
|
|
617
|
+
: level,
|
|
618
|
+
operator.level,
|
|
619
|
+
);
|
|
620
|
+
node.ranges.forEach((range) => {
|
|
621
|
+
node.level = Math.max(node.level, range.level);
|
|
622
|
+
});
|
|
623
|
+
addAll(node.levelParams, operator.levelParams);
|
|
624
|
+
addAll(node.allParams, operator.allParams);
|
|
625
|
+
addAll(node.nonLeibnizParams, operator.nonLeibnizParams);
|
|
626
|
+
node.operands.forEach((operand, index) => {
|
|
627
|
+
if (operand === undefined) return;
|
|
628
|
+
if (getWeight(operator, index) === 1) addAll(node.levelParams, operand.levelParams);
|
|
629
|
+
addAll(node.allParams, operand.allParams);
|
|
630
|
+
addAll(node.nonLeibnizParams, operand.nonLeibnizParams);
|
|
631
|
+
if (!isLeibnizArgument(operator, index)) addAll(node.nonLeibnizParams, operand.allParams);
|
|
632
|
+
});
|
|
633
|
+
node.ranges.forEach((range) => {
|
|
634
|
+
addAll(node.levelParams, range.levelParams);
|
|
635
|
+
addAll(node.allParams, range.allParams);
|
|
636
|
+
addAll(node.nonLeibnizParams, range.nonLeibnizParams);
|
|
637
|
+
});
|
|
638
|
+
const boundSymbols = new Set<SymbolNode>(getBoundSymbols(node));
|
|
639
|
+
boundSymbols.forEach((symbol) => {
|
|
640
|
+
node.levelParams.delete(symbol);
|
|
641
|
+
node.allParams.delete(symbol);
|
|
642
|
+
node.nonLeibnizParams.delete(symbol);
|
|
643
|
+
});
|
|
644
|
+
constrainArguments(node, operator, boundSymbols, iteration, check);
|
|
645
|
+
} else {
|
|
646
|
+
checkLevel(operator, iteration, check);
|
|
647
|
+
node.level = operands.reduce(
|
|
648
|
+
(level, operand) => Math.max(level, operand.level),
|
|
649
|
+
operator.kind === "Module" ? 0 : operator.level,
|
|
650
|
+
);
|
|
651
|
+
node.levelParams = new Set([operator]);
|
|
652
|
+
node.allParams.add(operator);
|
|
653
|
+
operands.forEach((operand, index) => {
|
|
654
|
+
addAll(node.levelParams, operand.levelParams);
|
|
655
|
+
addAll(node.allParams, operand.allParams);
|
|
656
|
+
addAll(node.nonLeibnizParams, operand.nonLeibnizParams);
|
|
657
|
+
putLevelConstraints(node.levelConstraints, operand.levelConstraints);
|
|
658
|
+
putArgLevelConstraint(node.argLevelConstraints, operator, index, operand.level);
|
|
659
|
+
putArgLevelConstraints(node.argLevelConstraints, operand.argLevelConstraints);
|
|
660
|
+
operand.levelParams.forEach((param) =>
|
|
661
|
+
addArgLevelParam(node.argLevelParams, operator, index, param),
|
|
662
|
+
);
|
|
663
|
+
addArgLevelParams(node.argLevelParams, operand.argLevelParams);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
checkTemporalApplication(node, check);
|
|
667
|
+
return node.levelCorrect;
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
const checkDefinition = (node: OpDefNode, iteration: number, check: LevelCheck) => {
|
|
671
|
+
if (node.levelChecked >= iteration || (!node.inRecursiveSection && node.levelChecked > 0)) {
|
|
672
|
+
return node.levelCorrect;
|
|
673
|
+
}
|
|
674
|
+
node.levelChecked = iteration;
|
|
675
|
+
const body = node.body;
|
|
676
|
+
if (body === undefined) {
|
|
677
|
+
node.levelCorrect = node.step === undefined || checkLevel(node.step, iteration, check);
|
|
678
|
+
return node.levelCorrect;
|
|
679
|
+
}
|
|
680
|
+
node.levelCorrect = checkLevel(body, iteration, check);
|
|
681
|
+
node.level = Math.max(node.level, body.level);
|
|
682
|
+
const params = node.params ?? [];
|
|
683
|
+
params.forEach((param, index) => {
|
|
684
|
+
const bound = body.levelConstraints.get(param);
|
|
685
|
+
if (bound !== undefined) node.maxLevels[index] = Math.min(node.maxLevels[index], bound);
|
|
686
|
+
if (body.levelParams.has(param)) node.weights[index] = Math.max(node.weights[index], 1);
|
|
687
|
+
});
|
|
688
|
+
checkDefinitionBody(node, params, body);
|
|
689
|
+
return node.levelCorrect;
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
const checkTheoremDefinition = (node: ThmOrAssumpDefNode, iteration: number, check: LevelCheck) => {
|
|
693
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
694
|
+
node.levelChecked = iteration;
|
|
695
|
+
node.maxLevels = node.params.map(() => TEMPORAL_LEVEL);
|
|
696
|
+
// SANY allocates isLeibnizArg anew for each parameter, so only the last one starts out Leibniz.
|
|
697
|
+
node.isLeibnizArg = node.params.map((_, index) => index === node.params.length - 1);
|
|
698
|
+
if (node.params.length > 0) node.isLeibniz = true;
|
|
699
|
+
node.levelCorrect = checkLevel(node.body, iteration, check);
|
|
700
|
+
node.level = node.body.level;
|
|
701
|
+
node.params.forEach((param, index) => {
|
|
702
|
+
const bound = node.body.levelConstraints.get(param);
|
|
703
|
+
if (bound !== undefined) node.maxLevels[index] = bound;
|
|
704
|
+
});
|
|
705
|
+
checkDefinitionBody(node, node.params, node.body);
|
|
706
|
+
return node.levelCorrect;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
// ModuleNode.levelCheck: the definitions of each recursive section are checked twice, the second
|
|
710
|
+
// time with the highest level and the parameters of the section's recursive operators.
|
|
711
|
+
export const checkModuleLevels = (module: ModuleNode, check: LevelCheck) => {
|
|
712
|
+
if (module.isLevelChecked) return module.levelCorrect;
|
|
713
|
+
module.isLevelChecked = true;
|
|
714
|
+
const sections = module.opDefsInRecursiveSection;
|
|
715
|
+
let first = 0;
|
|
716
|
+
while (first < sections.length) {
|
|
717
|
+
const section = sections[first].recursiveSection;
|
|
718
|
+
let end = first;
|
|
719
|
+
while (end < sections.length && sections[end].recursiveSection === section) {
|
|
720
|
+
const definition = sections[end];
|
|
721
|
+
if (definition.inRecursive) {
|
|
722
|
+
definition.levelChecked = 1;
|
|
723
|
+
definition.maxLevels = definition.maxLevels.map(() => ACTION_LEVEL);
|
|
724
|
+
definition.weights = definition.weights.map(() => 1);
|
|
725
|
+
} else definition.levelChecked = 0;
|
|
726
|
+
end++;
|
|
727
|
+
}
|
|
728
|
+
const members = sections.slice(first, end);
|
|
729
|
+
const levelParams = new Set<SymbolNode>();
|
|
730
|
+
const allParams = new Set<SymbolNode>();
|
|
731
|
+
let maxLevel = 0;
|
|
732
|
+
members.forEach((definition) => {
|
|
733
|
+
if (definition.inRecursive) definition.levelChecked = 0;
|
|
734
|
+
checkDefinition(definition, 1, check);
|
|
735
|
+
if (!definition.inRecursive) return;
|
|
736
|
+
definition.maxLevels.forEach((level, index) => {
|
|
737
|
+
if (level >= ACTION_LEVEL) return;
|
|
738
|
+
addError(
|
|
739
|
+
check,
|
|
740
|
+
definition.location,
|
|
741
|
+
`Argument ${index + 1} of recursive operator ${definition.name} is primed`,
|
|
742
|
+
);
|
|
743
|
+
});
|
|
744
|
+
maxLevel = Math.max(maxLevel, definition.level);
|
|
745
|
+
addAll(levelParams, definition.levelParams);
|
|
746
|
+
addAll(allParams, definition.allParams);
|
|
747
|
+
});
|
|
748
|
+
members.forEach((definition) => {
|
|
749
|
+
if (definition.inRecursive) definition.levelChecked = 2;
|
|
750
|
+
definition.level = Math.max(definition.level, maxLevel);
|
|
751
|
+
addAll(definition.levelParams, levelParams);
|
|
752
|
+
addAll(definition.allParams, allParams);
|
|
753
|
+
});
|
|
754
|
+
members.forEach((definition) => {
|
|
755
|
+
if (definition.inRecursive) definition.levelChecked = 1;
|
|
756
|
+
checkDefinition(definition, 2, check);
|
|
757
|
+
});
|
|
758
|
+
first = end;
|
|
759
|
+
}
|
|
760
|
+
module.levelCorrect = true;
|
|
761
|
+
const recordCorrectness = (isNodeCorrect: boolean) => {
|
|
762
|
+
if (!isNodeCorrect) module.levelCorrect = false;
|
|
763
|
+
};
|
|
764
|
+
module.definitions
|
|
765
|
+
.filter((definition): definition is ModuleNode => definition.kind === "Module")
|
|
766
|
+
.forEach((inner) => recordCorrectness(checkModuleLevels(inner, check)));
|
|
767
|
+
const definitions = getOpDefs(module);
|
|
768
|
+
definitions.forEach((definition) => recordCorrectness(checkDefinition(definition, 1, check)));
|
|
769
|
+
getThmOrAssumpDefs(module).forEach((definition) =>
|
|
770
|
+
recordCorrectness(checkTheoremDefinition(definition, 1, check)),
|
|
771
|
+
);
|
|
772
|
+
module.topLevel.forEach((node) => recordCorrectness(checkLevel(node, 1, check)));
|
|
773
|
+
if (!isConstantModule(module, check)) {
|
|
774
|
+
getDeclarations(module, CONSTANT_DECL_KIND).forEach((declaration) =>
|
|
775
|
+
putLevelConstraint(module.levelConstraints, declaration, CONSTANT_LEVEL),
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
definitions.forEach((definition) => {
|
|
779
|
+
putLevelConstraints(module.levelConstraints, definition.levelConstraints);
|
|
780
|
+
putArgLevelConstraints(module.argLevelConstraints, definition.argLevelConstraints);
|
|
781
|
+
addArgLevelParams(
|
|
782
|
+
module.argLevelParams,
|
|
783
|
+
definition.argLevelParams,
|
|
784
|
+
(argLevelParam) => !isOccurring(argLevelParam, definition.params ?? []),
|
|
785
|
+
);
|
|
786
|
+
});
|
|
787
|
+
module.topLevel.forEach((node) => {
|
|
788
|
+
putLevelConstraints(module.levelConstraints, node.levelConstraints);
|
|
789
|
+
putArgLevelConstraints(module.argLevelConstraints, node.argLevelConstraints);
|
|
790
|
+
addArgLevelParams(module.argLevelParams, node.argLevelParams);
|
|
791
|
+
});
|
|
792
|
+
return module.levelCorrect;
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
// LevelNode.levelCheckSubnodes, which skips modules.
|
|
796
|
+
const checkSubnodes = (
|
|
797
|
+
node: LevelFields,
|
|
798
|
+
subnodes: SemanticNode[],
|
|
799
|
+
iteration: number,
|
|
800
|
+
check: LevelCheck,
|
|
801
|
+
) => {
|
|
802
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
803
|
+
node.levelChecked = iteration;
|
|
804
|
+
subnodes.forEach((subnode) => {
|
|
805
|
+
if (!isLevelNode(subnode)) return;
|
|
806
|
+
if (subnode.kind === "OpDef" && subnode.defKind === "ModuleInstance") return;
|
|
807
|
+
node.levelCorrect = checkLevel(subnode, iteration, check) && node.levelCorrect;
|
|
808
|
+
node.level = Math.max(node.level, subnode.level);
|
|
809
|
+
mergeLevels(node, subnode);
|
|
810
|
+
addAll(node.nonLeibnizParams, subnode.nonLeibnizParams);
|
|
811
|
+
});
|
|
812
|
+
return node.levelCorrect;
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
// TheoremNode.LevelCheckTemporal: the steps of the proof of a temporal theorem that must be
|
|
816
|
+
// constant.
|
|
817
|
+
const checkTemporalProof = (proof: ProofNode | undefined, check: LevelCheck) => {
|
|
818
|
+
if (proof?.kind !== "NonLeafProof") return;
|
|
819
|
+
proof.steps.forEach((step) => {
|
|
820
|
+
if (step.kind !== "Theorem" || step.body.kind !== "OpAppl") return;
|
|
821
|
+
const name = step.body.operator.name;
|
|
822
|
+
if (name === "$Take" || name === "$Witness" || name === "$Have") {
|
|
823
|
+
if (step.body.level !== CONSTANT_LEVEL) {
|
|
824
|
+
addError(
|
|
825
|
+
check,
|
|
826
|
+
step.body.location,
|
|
827
|
+
"Non-constant TAKE, WITNESS, or HAVE for temporal goal.",
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
} else if (name === "$Pfcase") {
|
|
831
|
+
if (step.body.level !== CONSTANT_LEVEL) {
|
|
832
|
+
addError(check, step.body.location, "Non-constant CASE for temporal goal.");
|
|
833
|
+
}
|
|
834
|
+
checkTemporalProof(step.proof, check);
|
|
835
|
+
} else if (name === "$Qed") checkTemporalProof(step.proof, check);
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// Subst.getSubLCSet, getSubALCSet and getSubALPSet for the body of an instantiation.
|
|
840
|
+
const constrainSubstitution = (
|
|
841
|
+
node: LevelFields,
|
|
842
|
+
body: ConstraintSource,
|
|
843
|
+
substs: Subst[],
|
|
844
|
+
isConstant: boolean,
|
|
845
|
+
iteration: number,
|
|
846
|
+
check: LevelCheck,
|
|
847
|
+
) => {
|
|
848
|
+
node.levelConstraints = getSubstitutedLevelConstraints(
|
|
849
|
+
body,
|
|
850
|
+
substs,
|
|
851
|
+
isConstant,
|
|
852
|
+
iteration,
|
|
853
|
+
check,
|
|
854
|
+
);
|
|
855
|
+
node.argLevelConstraints = getSubstitutedArgLevelConstraints(body, substs, iteration, check);
|
|
856
|
+
node.argLevelParams = getSubstitutedArgLevelParams(body.argLevelParams, substs);
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
// InstanceNode.levelCheck.
|
|
860
|
+
const checkInstance = (node: InstanceNode, iteration: number, check: LevelCheck) => {
|
|
861
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
862
|
+
node.levelChecked = iteration;
|
|
863
|
+
node.levelParams = new Set();
|
|
864
|
+
node.levelCorrect = true;
|
|
865
|
+
const module = node.module;
|
|
866
|
+
if (!checkModuleLevels(module, check)) node.levelCorrect = false;
|
|
867
|
+
node.substs.forEach((subst) => {
|
|
868
|
+
if (!checkLevel(subst.expr, iteration, check)) node.levelCorrect = false;
|
|
869
|
+
});
|
|
870
|
+
const isConstant = isConstantModule(module, check);
|
|
871
|
+
node.substs.forEach((subst) => {
|
|
872
|
+
if (!isConstant && subst.expr.level > subst.op.level) {
|
|
873
|
+
if (checkLevel(subst.expr, iteration, check)) {
|
|
874
|
+
addError(
|
|
875
|
+
check,
|
|
876
|
+
node.location,
|
|
877
|
+
`Level error in instantiating module '${module.name}':\nThe level of the expression or operator substituted for '${subst.op.name}' \nmust be at most ${subst.op.level}.`,
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
node.levelCorrect = false;
|
|
881
|
+
}
|
|
882
|
+
if (
|
|
883
|
+
subst.expr.kind === "OpArg" &&
|
|
884
|
+
subst.expr.op.kind === "OpDef" &&
|
|
885
|
+
(subst.expr.op.defKind === "UserDefined" || subst.expr.op.defKind === "BuiltIn") &&
|
|
886
|
+
!subst.expr.op.isLeibniz
|
|
887
|
+
) {
|
|
888
|
+
addError(
|
|
889
|
+
check,
|
|
890
|
+
node.location,
|
|
891
|
+
`Error in instantiating module '${module.name}':\n A non-Leibniz operator substituted for '${subst.op.name}'.`,
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
node.substs.forEach((subst) => {
|
|
896
|
+
const bound = module.levelConstraints.get(subst.op);
|
|
897
|
+
if (bound !== undefined && subst.expr.level > bound) {
|
|
898
|
+
if (checkLevel(subst.expr, iteration, check)) {
|
|
899
|
+
addError(
|
|
900
|
+
check,
|
|
901
|
+
node.location,
|
|
902
|
+
`Level error in instantiating module '${module.name}':\nThe level of the expression or operator substituted for '${subst.op.name}' \nmust be at most ${bound}.`,
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
node.levelCorrect = false;
|
|
906
|
+
}
|
|
907
|
+
if (subst.op.arity <= 0 || subst.expr.kind !== "OpArg" || subst.expr.op.kind !== "OpDef")
|
|
908
|
+
return;
|
|
909
|
+
const definition = subst.expr.op;
|
|
910
|
+
const isDefinitionCorrect = checkLevel(definition, iteration, check);
|
|
911
|
+
for (let position = 0; position < subst.op.arity; position++) {
|
|
912
|
+
const minimum = module.argLevelConstraints.get(
|
|
913
|
+
getArgLevelConstraintKey(subst.op, position),
|
|
914
|
+
)?.level;
|
|
915
|
+
if (minimum === undefined || getMaxLevel(definition, position) >= minimum) continue;
|
|
916
|
+
if (isDefinitionCorrect) {
|
|
917
|
+
addError(
|
|
918
|
+
check,
|
|
919
|
+
node.location,
|
|
920
|
+
`Level error in instantiating module '${module.name}':\nThe level of the argument ${position + 1} of the operator ${definition.name} \nmust be at least ${minimum}.`,
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
node.levelCorrect = false;
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
module.argLevelParams.forEach((argLevelParam) => {
|
|
927
|
+
node.substs.forEach((opSubst) => {
|
|
928
|
+
node.substs.forEach((paramSubst) => {
|
|
929
|
+
if (argLevelParam.op !== opSubst.op || argLevelParam.param !== paramSubst.op) return;
|
|
930
|
+
if (opSubst.expr.kind !== "OpArg") return;
|
|
931
|
+
const operator = opSubst.expr.op;
|
|
932
|
+
const isOperatorCorrect = checkLevel(operator, iteration, check);
|
|
933
|
+
if (operator.kind !== "OpDef") return;
|
|
934
|
+
const maximum = getMaxLevel(operator, argLevelParam.index);
|
|
935
|
+
if (paramSubst.expr.level <= maximum) return;
|
|
936
|
+
if (isOperatorCorrect && checkLevel(paramSubst.expr, iteration, check)) {
|
|
937
|
+
addError(
|
|
938
|
+
check,
|
|
939
|
+
node.location,
|
|
940
|
+
`Level error when instantiating module '${module.name}':\nThe level of the argument ${argLevelParam.index} of the operator ${opSubst.op.name}' \nmust be at most ${maximum}.`,
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
node.levelCorrect = false;
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
const isOutside = (symbol: SymbolNode) => !node.params.some((param) => param === symbol);
|
|
948
|
+
putLevelConstraints(
|
|
949
|
+
node.levelConstraints,
|
|
950
|
+
getSubstitutedLevelConstraints(module, node.substs, isConstant, iteration, check),
|
|
951
|
+
isOutside,
|
|
952
|
+
);
|
|
953
|
+
node.substs.forEach((subst) =>
|
|
954
|
+
putLevelConstraints(node.levelConstraints, subst.expr.levelConstraints, isOutside),
|
|
955
|
+
);
|
|
956
|
+
putArgLevelConstraints(
|
|
957
|
+
node.argLevelConstraints,
|
|
958
|
+
getSubstitutedArgLevelConstraints(module, node.substs, iteration, check),
|
|
959
|
+
(constraint) => isOutside(constraint.param),
|
|
960
|
+
);
|
|
961
|
+
node.substs.forEach((subst) =>
|
|
962
|
+
putArgLevelConstraints(node.argLevelConstraints, subst.expr.argLevelConstraints, (constraint) =>
|
|
963
|
+
isOutside(constraint.param),
|
|
964
|
+
),
|
|
965
|
+
);
|
|
966
|
+
addArgLevelParams(
|
|
967
|
+
node.argLevelParams,
|
|
968
|
+
getSubstitutedArgLevelParams(module.argLevelParams, node.substs),
|
|
969
|
+
(argLevelParam) => !isOccurring(argLevelParam, node.params),
|
|
970
|
+
);
|
|
971
|
+
node.substs.forEach((subst) =>
|
|
972
|
+
addArgLevelParams(
|
|
973
|
+
node.argLevelParams,
|
|
974
|
+
subst.expr.argLevelParams,
|
|
975
|
+
(argLevelParam) => !isOccurring(argLevelParam, node.params),
|
|
976
|
+
),
|
|
977
|
+
);
|
|
978
|
+
return node.levelCorrect;
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
const checkLevel = (node: SemanticNode, iteration: number, check: LevelCheck): boolean => {
|
|
982
|
+
if (!isLevelNode(node)) return checkModuleLevels(node, check);
|
|
983
|
+
switch (node.kind) {
|
|
984
|
+
case "OpAppl":
|
|
985
|
+
return checkApplication(node, iteration, check);
|
|
986
|
+
case "OpDef":
|
|
987
|
+
return checkDefinition(node, iteration, check);
|
|
988
|
+
case "ThmOrAssumpDef":
|
|
989
|
+
return checkTheoremDefinition(node, iteration, check);
|
|
990
|
+
case "FormalParam":
|
|
991
|
+
if (node.levelChecked !== 0) return true;
|
|
992
|
+
node.levelChecked = iteration;
|
|
993
|
+
node.levelParams.add(node);
|
|
994
|
+
node.allParams.add(node);
|
|
995
|
+
return true;
|
|
996
|
+
case "OpDecl":
|
|
997
|
+
return true;
|
|
998
|
+
case "Numeral":
|
|
999
|
+
case "String":
|
|
1000
|
+
case "Decimal":
|
|
1001
|
+
if (node.levelChecked < iteration) node.levelChecked = iteration;
|
|
1002
|
+
return true;
|
|
1003
|
+
case "OpArg": {
|
|
1004
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
1005
|
+
node.levelChecked = iteration;
|
|
1006
|
+
const operator = node.op;
|
|
1007
|
+
node.levelCorrect = checkLevel(operator, iteration, check);
|
|
1008
|
+
if (operator.kind === "Module") return node.levelCorrect;
|
|
1009
|
+
node.level = operator.level;
|
|
1010
|
+
shareLevels(node, operator);
|
|
1011
|
+
return node.levelCorrect;
|
|
1012
|
+
}
|
|
1013
|
+
case "LetIn": {
|
|
1014
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
1015
|
+
node.levelChecked = iteration;
|
|
1016
|
+
node.levelCorrect = true;
|
|
1017
|
+
const definitions = node.opDefs.filter(
|
|
1018
|
+
(definition) => definition.kind !== "OpDef" || definition.defKind !== "ModuleInstance",
|
|
1019
|
+
);
|
|
1020
|
+
definitions.forEach((definition) => {
|
|
1021
|
+
if (!checkLevel(definition, iteration, check)) node.levelCorrect = false;
|
|
1022
|
+
});
|
|
1023
|
+
if (!checkLevel(node.body, iteration, check)) node.levelCorrect = false;
|
|
1024
|
+
node.instances.forEach((instance) => {
|
|
1025
|
+
if (!checkLevel(instance, iteration, check)) node.levelCorrect = false;
|
|
1026
|
+
});
|
|
1027
|
+
node.level = node.body.level;
|
|
1028
|
+
node.levelParams = new Set(node.body.levelParams);
|
|
1029
|
+
node.allParams = new Set(node.body.allParams);
|
|
1030
|
+
putLevelConstraints(node.levelConstraints, node.body.levelConstraints);
|
|
1031
|
+
definitions.forEach((definition) =>
|
|
1032
|
+
putLevelConstraints(node.levelConstraints, definition.levelConstraints),
|
|
1033
|
+
);
|
|
1034
|
+
putArgLevelConstraints(node.argLevelConstraints, node.body.argLevelConstraints);
|
|
1035
|
+
definitions.forEach((definition) =>
|
|
1036
|
+
putArgLevelConstraints(node.argLevelConstraints, definition.argLevelConstraints),
|
|
1037
|
+
);
|
|
1038
|
+
addArgLevelParams(node.argLevelParams, node.body.argLevelParams);
|
|
1039
|
+
definitions.forEach((definition) => {
|
|
1040
|
+
const params = definition.kind === "OpDef" ? (definition.params ?? []) : [];
|
|
1041
|
+
addArgLevelParams(
|
|
1042
|
+
node.argLevelParams,
|
|
1043
|
+
definition.argLevelParams,
|
|
1044
|
+
(argLevelParam) => !isOccurring(argLevelParam, params),
|
|
1045
|
+
);
|
|
1046
|
+
});
|
|
1047
|
+
node.instances.forEach((instance) =>
|
|
1048
|
+
addArgLevelParams(node.argLevelParams, instance.argLevelParams),
|
|
1049
|
+
);
|
|
1050
|
+
return node.levelCorrect;
|
|
1051
|
+
}
|
|
1052
|
+
case "Label": {
|
|
1053
|
+
if (node.levelChecked >= iteration) return true;
|
|
1054
|
+
node.levelChecked = iteration;
|
|
1055
|
+
node.params.forEach((param) => checkLevel(param, iteration, check));
|
|
1056
|
+
const isCorrect = checkLevel(node.body, iteration, check);
|
|
1057
|
+
node.level = node.body.level;
|
|
1058
|
+
shareLevels(node, node.body);
|
|
1059
|
+
return isCorrect;
|
|
1060
|
+
}
|
|
1061
|
+
case "At": {
|
|
1062
|
+
if (node.levelChecked >= iteration) return true;
|
|
1063
|
+
node.levelChecked = iteration;
|
|
1064
|
+
const args = node.except.operands;
|
|
1065
|
+
const first = args[0];
|
|
1066
|
+
if (first === undefined) return true;
|
|
1067
|
+
checkLevel(first, iteration, check);
|
|
1068
|
+
node.level = first.level;
|
|
1069
|
+
const parts = [first];
|
|
1070
|
+
for (const argument of args.slice(1)) {
|
|
1071
|
+
if (argument === undefined) continue;
|
|
1072
|
+
checkLevel(argument, iteration, check);
|
|
1073
|
+
if (argument === node.component) break;
|
|
1074
|
+
node.level = Math.max(node.level, argument.level);
|
|
1075
|
+
parts.push(argument);
|
|
1076
|
+
}
|
|
1077
|
+
parts.forEach((part) => mergeLevels(node, part));
|
|
1078
|
+
return true;
|
|
1079
|
+
}
|
|
1080
|
+
case "SubstIn":
|
|
1081
|
+
case "APSubstIn": {
|
|
1082
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
1083
|
+
node.levelChecked = iteration;
|
|
1084
|
+
node.levelCorrect = true;
|
|
1085
|
+
const body = node.body;
|
|
1086
|
+
if (!checkLevel(body, iteration, check)) node.levelCorrect = false;
|
|
1087
|
+
node.substs.forEach((subst) => {
|
|
1088
|
+
if (!checkLevel(subst.expr, iteration, check)) node.levelCorrect = false;
|
|
1089
|
+
});
|
|
1090
|
+
node.level = node.substs.reduce(
|
|
1091
|
+
(level, subst) =>
|
|
1092
|
+
body.levelParams.has(subst.op) ? Math.max(level, subst.expr.level) : level,
|
|
1093
|
+
body.level,
|
|
1094
|
+
);
|
|
1095
|
+
body.levelParams.forEach((param) =>
|
|
1096
|
+
addAll(node.levelParams, getSubstitutedParams(param, node.substs, false)),
|
|
1097
|
+
);
|
|
1098
|
+
if (node.kind === "APSubstIn") {
|
|
1099
|
+
body.allParams.forEach((param) =>
|
|
1100
|
+
addAll(node.allParams, getSubstitutedParams(param, node.substs, true)),
|
|
1101
|
+
);
|
|
1102
|
+
} else {
|
|
1103
|
+
node.allParams = new Set(body.allParams);
|
|
1104
|
+
node.nonLeibnizParams = new Set(body.nonLeibnizParams);
|
|
1105
|
+
node.substs.forEach((subst) => {
|
|
1106
|
+
if (!node.allParams.has(subst.op)) return;
|
|
1107
|
+
node.allParams.delete(subst.op);
|
|
1108
|
+
addAll(node.allParams, subst.expr.allParams);
|
|
1109
|
+
addAll(node.nonLeibnizParams, subst.expr.nonLeibnizParams);
|
|
1110
|
+
if (node.nonLeibnizParams.has(subst.op)) {
|
|
1111
|
+
node.nonLeibnizParams.delete(subst.op);
|
|
1112
|
+
addAll(node.nonLeibnizParams, subst.expr.allParams);
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
const isConstant = isConstantModule(node.instantiatedModule, check);
|
|
1117
|
+
constrainSubstitution(node, body, node.substs, isConstant, iteration, check);
|
|
1118
|
+
return node.levelCorrect;
|
|
1119
|
+
}
|
|
1120
|
+
case "Instance":
|
|
1121
|
+
return checkInstance(node, iteration, check);
|
|
1122
|
+
case "Assume": {
|
|
1123
|
+
if (node.levelChecked >= iteration) return true;
|
|
1124
|
+
node.levelChecked = iteration;
|
|
1125
|
+
const isBodyCorrect = checkLevel(node.body, iteration, check);
|
|
1126
|
+
const isDefinitionCorrect = !node.definition || checkLevel(node.definition, iteration, check);
|
|
1127
|
+
// AssumeNode's getters return its expression's levels.
|
|
1128
|
+
node.level = node.body.level;
|
|
1129
|
+
shareLevels(node, node.body);
|
|
1130
|
+
if (node.level !== CONSTANT_LEVEL) {
|
|
1131
|
+
addError(
|
|
1132
|
+
check,
|
|
1133
|
+
node.location,
|
|
1134
|
+
`Level error: assumptions must be level 0 (Constant), \nbut this one has level ${node.level}.`,
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1137
|
+
return isBodyCorrect && isDefinitionCorrect;
|
|
1138
|
+
}
|
|
1139
|
+
case "Theorem": {
|
|
1140
|
+
// TheoremNode declares its own levelChecked, so levelCheckSubnodes still runs on the
|
|
1141
|
+
// theorem's definition, or its statement when it has none, and its proof.
|
|
1142
|
+
if (node.levelChecked >= iteration) return true;
|
|
1143
|
+
const isCorrect = checkSubnodes(
|
|
1144
|
+
node,
|
|
1145
|
+
[node.definition ?? node.body, ...(node.proof ? [node.proof] : [])],
|
|
1146
|
+
iteration,
|
|
1147
|
+
check,
|
|
1148
|
+
);
|
|
1149
|
+
const body = node.body;
|
|
1150
|
+
if (
|
|
1151
|
+
body.kind === "OpAppl" &&
|
|
1152
|
+
body.operator.name === "$Pick" &&
|
|
1153
|
+
body.level === TEMPORAL_LEVEL
|
|
1154
|
+
) {
|
|
1155
|
+
body.ranges.forEach((range) => {
|
|
1156
|
+
if (range.level === CONSTANT_LEVEL) return;
|
|
1157
|
+
addError(check, range.location, "Non-constant bound of temporal PICK.");
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
if (body.level === TEMPORAL_LEVEL) checkTemporalProof(node.proof, check);
|
|
1161
|
+
return isCorrect;
|
|
1162
|
+
}
|
|
1163
|
+
case "LeafProof":
|
|
1164
|
+
case "UseOrHide":
|
|
1165
|
+
return checkSubnodes(node, node.facts, iteration, check);
|
|
1166
|
+
case "NonLeafProof":
|
|
1167
|
+
return checkSubnodes(node, [...node.steps, ...node.instances], iteration, check);
|
|
1168
|
+
case "DefStep":
|
|
1169
|
+
return checkSubnodes(node, node.defs, iteration, check);
|
|
1170
|
+
case "NewSymb": {
|
|
1171
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
1172
|
+
node.levelChecked = iteration;
|
|
1173
|
+
node.level = node.declaration.level;
|
|
1174
|
+
if (node.set === undefined) return node.levelCorrect;
|
|
1175
|
+
node.levelCorrect = checkLevel(node.set, iteration, check);
|
|
1176
|
+
node.level = Math.max(node.level, node.set.level);
|
|
1177
|
+
if (node.level === TEMPORAL_LEVEL) {
|
|
1178
|
+
node.levelCorrect = false;
|
|
1179
|
+
addError(check, node.location, "Level error:\nTemporal formula used as set.");
|
|
1180
|
+
}
|
|
1181
|
+
shareLevels(node, node.set);
|
|
1182
|
+
return node.levelCorrect;
|
|
1183
|
+
}
|
|
1184
|
+
case "AssumeProve": {
|
|
1185
|
+
if (node.levelChecked >= iteration) return node.levelCorrect;
|
|
1186
|
+
node.levelChecked = iteration;
|
|
1187
|
+
node.levelCorrect = true;
|
|
1188
|
+
node.assumptions.forEach((assumption) => {
|
|
1189
|
+
if (!checkLevel(assumption, iteration, check)) node.levelCorrect = false;
|
|
1190
|
+
});
|
|
1191
|
+
checkLevel(node.goal, iteration, check);
|
|
1192
|
+
node.level = node.assumptions.reduce(
|
|
1193
|
+
(level, assumption) => Math.max(level, assumption.level),
|
|
1194
|
+
node.goal.level,
|
|
1195
|
+
);
|
|
1196
|
+
[node.goal, ...node.assumptions].forEach((part) => mergeLevels(node, part));
|
|
1197
|
+
// LevelNode.addTemporalLevelConstraintToConstants.
|
|
1198
|
+
if (node.levelCorrect) {
|
|
1199
|
+
node.levelParams.forEach((param) => {
|
|
1200
|
+
if (param.kind === "OpDecl" && param.declKind === CONSTANT_DECL_KIND) {
|
|
1201
|
+
putLevelConstraint(node.levelConstraints, param, ACTION_LEVEL);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
return node.levelCorrect;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
};
|