tla-ts 0.0.10-dev.1ebc153bd → 0.0.10-dev.22f7435d3
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/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +132 -78
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +446 -167
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +168 -49
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +9 -4
- package/src/values.ts +95 -57
package/src/resolve.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type Selector,
|
|
19
19
|
type SourceLocation,
|
|
20
20
|
type SourceRange,
|
|
21
|
+
type StepBody,
|
|
21
22
|
type Theorem,
|
|
22
23
|
type UseOrHide,
|
|
23
24
|
} from "./ast";
|
|
@@ -51,6 +52,7 @@ interface Goal {
|
|
|
51
52
|
statement: Expression | AssumeProve;
|
|
52
53
|
isSuffices: boolean;
|
|
53
54
|
isInProof: boolean;
|
|
55
|
+
keyword: string | undefined;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
interface LocalName extends Binding {
|
|
@@ -95,6 +97,7 @@ export interface SelectionArguments {
|
|
|
95
97
|
|
|
96
98
|
interface SelectionError {
|
|
97
99
|
applications: SelectionArguments[];
|
|
100
|
+
nulls: NullSelection[];
|
|
98
101
|
error: SanyError;
|
|
99
102
|
}
|
|
100
103
|
|
|
@@ -108,15 +111,40 @@ type Reference = Expression & { kind: "Identifier" | "Apply" | "Subexpression" }
|
|
|
108
111
|
|
|
109
112
|
export const LOCAL_RESOLUTION = { kind: "Local" } as const;
|
|
110
113
|
|
|
114
|
+
export const SELECTION_NAME = "$subexpression";
|
|
115
|
+
|
|
111
116
|
export interface NullSelection {
|
|
112
117
|
node: Expression;
|
|
113
118
|
error: SanyError;
|
|
119
|
+
isEmpty: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface SelectionArgument {
|
|
123
|
+
operator: string;
|
|
124
|
+
index: number;
|
|
125
|
+
range: SourceRange | undefined;
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
export const selections = new WeakSet<Expression>();
|
|
117
129
|
export const selectionErrors = new WeakMap<Expression, SelectionError>();
|
|
130
|
+
export const operatorSelectionErrors = new WeakMap<Expression, SanyError>();
|
|
131
|
+
export const factReferences = new WeakMap<Fact[], Fact[]>();
|
|
132
|
+
export const selectionArguments = new WeakMap<Expression, SelectionArgument>();
|
|
118
133
|
export const nullSelections = new WeakMap<Expression, NullSelection[]>();
|
|
134
|
+
export const selectionSources = new WeakMap<Expression, Expression>();
|
|
119
135
|
const unresolvedExpressions = new WeakSet<Expression>();
|
|
136
|
+
const emptyExpressions = new WeakSet<Expression>();
|
|
137
|
+
|
|
138
|
+
// SANY's failed selection is an operator application with no operands.
|
|
139
|
+
const isEmptyExpression = (expression: Expression): boolean =>
|
|
140
|
+
emptyExpressions.has(expression) || findNullError(nullSelections.get(expression)) !== undefined;
|
|
141
|
+
|
|
142
|
+
const findNullError = (nulls: NullSelection[] | undefined) =>
|
|
143
|
+
nulls?.find((selection) =>
|
|
144
|
+
selection.isEmpty
|
|
145
|
+
? isEmptyExpression(selection.node)
|
|
146
|
+
: unresolvedExpressions.has(selection.node),
|
|
147
|
+
)?.error;
|
|
120
148
|
|
|
121
149
|
const renamedArities = new WeakMap<Expression, number>();
|
|
122
150
|
|
|
@@ -272,10 +300,13 @@ const findSymbol = (name: string, unit: Unit): ModuleSymbol | undefined => {
|
|
|
272
300
|
arity: declared?.arity ?? getArity(definition),
|
|
273
301
|
params: declared?.params ?? getParamArities(definition),
|
|
274
302
|
kind: "Definition",
|
|
303
|
+
range: definition.location.range,
|
|
275
304
|
};
|
|
276
305
|
}
|
|
277
306
|
const binding = getModuleBinding(name, unit, undefined);
|
|
278
|
-
if (binding?.isPending)
|
|
307
|
+
if (binding?.isPending) {
|
|
308
|
+
return { key: name, arity: binding.arity, params: binding.params, kind: binding.kind };
|
|
309
|
+
}
|
|
279
310
|
return binding ? unit.imported.get(name) : undefined;
|
|
280
311
|
};
|
|
281
312
|
|
|
@@ -309,7 +340,7 @@ const getFixity = (expression: Expression) => {
|
|
|
309
340
|
if (expression.kind !== "Apply" || expression.argumentsRange) return undefined;
|
|
310
341
|
if (expression.args.length === 2) return "infix";
|
|
311
342
|
if (expression.args.length !== 1) return undefined;
|
|
312
|
-
return
|
|
343
|
+
return expression.operator === "-." ? "prefix" : "postfix";
|
|
313
344
|
};
|
|
314
345
|
|
|
315
346
|
const BUILTIN_LOCATION = "In module --TLA+ BUILTINS--";
|
|
@@ -498,7 +529,6 @@ const checkSelection = (
|
|
|
498
529
|
reference: Reference,
|
|
499
530
|
selectors: Selector[],
|
|
500
531
|
goal: Goal,
|
|
501
|
-
scope: LocalName | undefined,
|
|
502
532
|
unit: Unit,
|
|
503
533
|
isFact: boolean,
|
|
504
534
|
) => {
|
|
@@ -507,6 +537,7 @@ const checkSelection = (
|
|
|
507
537
|
(index === undefined ? undefined : reference.selectorRanges?.[index]) ??
|
|
508
538
|
reference.location.range;
|
|
509
539
|
if (range) unit.errors.push({ location: formatRange(range), message });
|
|
540
|
+
return undefined;
|
|
510
541
|
};
|
|
511
542
|
const isOutOfScope = goal.isSuffices === goal.isInProof;
|
|
512
543
|
const statement = goal.statement;
|
|
@@ -515,6 +546,8 @@ const checkSelection = (
|
|
|
515
546
|
isGoal: true,
|
|
516
547
|
isSufficesOpen: goal.isSuffices,
|
|
517
548
|
};
|
|
549
|
+
let params = 0;
|
|
550
|
+
let args = 0;
|
|
518
551
|
for (const [offset, selector] of selectors.slice(1).entries()) {
|
|
519
552
|
const index = offset + 1;
|
|
520
553
|
const node = state.node;
|
|
@@ -524,9 +557,7 @@ const checkSelection = (
|
|
|
524
557
|
node.kind !== "NewSymbol" &&
|
|
525
558
|
node.kind !== "AssumeProve" &&
|
|
526
559
|
getLabelBody(node).kind === "Let";
|
|
527
|
-
return isLet
|
|
528
|
-
? undefined
|
|
529
|
-
: report(index - 1, "A name selector here must be from a LET clause.");
|
|
560
|
+
return isLet ? node : report(index - 1, "A name selector here must be from a LET clause.");
|
|
530
561
|
}
|
|
531
562
|
const clauses =
|
|
532
563
|
statement.kind === "AssumeProve"
|
|
@@ -564,7 +595,7 @@ const checkSelection = (
|
|
|
564
595
|
state.isSufficesOpen = false;
|
|
565
596
|
continue;
|
|
566
597
|
}
|
|
567
|
-
if (selector.kind === "Colon") return;
|
|
598
|
+
if (selector.kind === "Colon") return node;
|
|
568
599
|
const operand =
|
|
569
600
|
selector.kind === "Operand"
|
|
570
601
|
? getOperandName(selector.operand)
|
|
@@ -573,6 +604,7 @@ const checkSelection = (
|
|
|
573
604
|
: "!(...)";
|
|
574
605
|
const getPosition = (count: number) =>
|
|
575
606
|
selector.kind === "Operand" ? getOperandIndex(selector.operand, count) : -1;
|
|
607
|
+
const unexpectedNull = `An unexpected null node specified by '${operand}'.\nThis is probably due to a previous error.`;
|
|
576
608
|
if (state.isSufficesOpen) {
|
|
577
609
|
if (getPosition(1) !== 0) {
|
|
578
610
|
return report(
|
|
@@ -585,21 +617,37 @@ const checkSelection = (
|
|
|
585
617
|
state.isSufficesOpen = false;
|
|
586
618
|
continue;
|
|
587
619
|
}
|
|
588
|
-
if (node.kind === "NewSymbol") return;
|
|
620
|
+
if (node.kind === "NewSymbol") return node;
|
|
589
621
|
if (node.kind !== "AssumeProve") {
|
|
590
622
|
const expression = getLabelBody(node);
|
|
623
|
+
if (unresolvedExpressions.has(expression)) {
|
|
624
|
+
return report(
|
|
625
|
+
index,
|
|
626
|
+
"Subexpression selection failed, probably due to an error in the selected expression.",
|
|
627
|
+
);
|
|
628
|
+
}
|
|
591
629
|
if (["Number", "Decimal", "String"].includes(expression.kind)) {
|
|
592
630
|
return report(index, "Selecting subexpression of expression that has none.");
|
|
593
631
|
}
|
|
594
|
-
|
|
595
|
-
expression.kind === "Identifier"
|
|
596
|
-
? findBinding(expression.name, scope, unit)?.kind
|
|
597
|
-
: undefined;
|
|
598
|
-
if (kind === "Variable" || kind?.startsWith("New")) {
|
|
632
|
+
if (isEmptyExpression(expression)) {
|
|
599
633
|
return report(index, `Choosing operand \`${operand}' of subexpression with no operands.`);
|
|
600
634
|
}
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
635
|
+
const binder = getBinder(expression);
|
|
636
|
+
if (binder && selector.kind !== "Operand") {
|
|
637
|
+
const count = selector.kind === "Bound" ? selector.args.length : 0;
|
|
638
|
+
if (selector.kind === "Bound" && count !== binder.names.length) {
|
|
639
|
+
return report(
|
|
640
|
+
index,
|
|
641
|
+
`Selector with ${count} argument(s) used for quantifier with ${binder.names.length} bound identifier(s).`,
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
params += binder.names.length;
|
|
645
|
+
args += count;
|
|
646
|
+
state.node = binder.body;
|
|
647
|
+
state.isGoal = false;
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
const sets = binder?.sets;
|
|
603
651
|
const operands =
|
|
604
652
|
expression.kind === "Identifier"
|
|
605
653
|
? []
|
|
@@ -607,14 +655,17 @@ const checkSelection = (
|
|
|
607
655
|
? sets.length > 0
|
|
608
656
|
? sets
|
|
609
657
|
: undefined
|
|
610
|
-
: expression
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
const position = getPosition(operands.length);
|
|
658
|
+
: getOperands(expression);
|
|
659
|
+
if (!operands) return node;
|
|
660
|
+
const isExcept = expression.kind === "Except";
|
|
661
|
+
const position = getPosition(isExcept ? expression.updates.length + 1 : operands.length);
|
|
615
662
|
if (position === -1) return report(index, `Nonexistent operand specified by \`${operand}'.`);
|
|
663
|
+
if (isExcept && position > 0) {
|
|
664
|
+
return report(index, "Selecting subexpression of an EXCEPT not yet implemented.");
|
|
665
|
+
}
|
|
616
666
|
state.node = operands[position];
|
|
617
667
|
state.isGoal = false;
|
|
668
|
+
if (unresolvedExpressions.has(state.node)) return report(index, unexpectedNull);
|
|
618
669
|
continue;
|
|
619
670
|
}
|
|
620
671
|
const clauses = [...node.assumptions, node.conclusion];
|
|
@@ -629,14 +680,24 @@ const checkSelection = (
|
|
|
629
680
|
}
|
|
630
681
|
state.node = clause;
|
|
631
682
|
state.isGoal = false;
|
|
683
|
+
if (
|
|
684
|
+
clause.kind !== "NewSymbol" &&
|
|
685
|
+
clause.kind !== "AssumeProve" &&
|
|
686
|
+
unresolvedExpressions.has(clause)
|
|
687
|
+
) {
|
|
688
|
+
return report(index, unexpectedNull);
|
|
689
|
+
}
|
|
632
690
|
}
|
|
633
|
-
if (isFact) return;
|
|
634
691
|
if (state.node.kind === "AssumeProve") {
|
|
635
|
-
report(undefined, "Selected ASSUME/PROVE instead of expression.");
|
|
692
|
+
return isFact ? state.node : report(undefined, "Selected ASSUME/PROVE instead of expression.");
|
|
636
693
|
}
|
|
637
694
|
if (state.node.kind === "NewSymbol") {
|
|
638
|
-
|
|
695
|
+
return isFact
|
|
696
|
+
? state.node
|
|
697
|
+
: report(undefined, "Selected a NEW declaration as an expression or operator.");
|
|
639
698
|
}
|
|
699
|
+
if (params !== args) return report(undefined, `Expected ${params} arguments but found ${args}.`);
|
|
700
|
+
return state.node;
|
|
640
701
|
};
|
|
641
702
|
|
|
642
703
|
const isLabelReported = (label: LabelExpression, unit: Unit) => {
|
|
@@ -714,8 +775,7 @@ const checkReference = (
|
|
|
714
775
|
selectors.length > 1 && first.kind === "Name"
|
|
715
776
|
? (lookupLocal(scope, first.name)?.goal ?? getGoal(first.name, unit))
|
|
716
777
|
: undefined;
|
|
717
|
-
|
|
718
|
-
return goal !== undefined;
|
|
778
|
+
return goal && { node: checkSelection(expression, selectors, goal, unit, isFact) };
|
|
719
779
|
};
|
|
720
780
|
|
|
721
781
|
const getSymbolArity = (
|
|
@@ -737,6 +797,14 @@ const getSymbolArity = (
|
|
|
737
797
|
});
|
|
738
798
|
return undefined;
|
|
739
799
|
}
|
|
800
|
+
const keyword = local?.goal?.keyword;
|
|
801
|
+
if (keyword) {
|
|
802
|
+
unit.errors.push({
|
|
803
|
+
location: formatRange(getSpelledNameRange(expression, name)),
|
|
804
|
+
message: `${keyword} proof step selected instead of expression.`,
|
|
805
|
+
});
|
|
806
|
+
return undefined;
|
|
807
|
+
}
|
|
740
808
|
if (checkReference(expression, scope, unit, false) || (isStepName(name) && local)) {
|
|
741
809
|
return expression.kind === "Apply" ? expression.args.length : 0;
|
|
742
810
|
}
|
|
@@ -761,6 +829,22 @@ const getSymbolArity = (
|
|
|
761
829
|
);
|
|
762
830
|
return undefined;
|
|
763
831
|
}
|
|
832
|
+
if (
|
|
833
|
+
expression.kind !== "OperatorReference" &&
|
|
834
|
+
prefix !== "" &&
|
|
835
|
+
isPendingSelectionReported(
|
|
836
|
+
prefix,
|
|
837
|
+
expression.kind === "Apply" && expression.argumentCounts
|
|
838
|
+
? expression.args.slice(0, expression.argumentCounts[0])
|
|
839
|
+
: [],
|
|
840
|
+
expression.selectorRanges?.[0],
|
|
841
|
+
(expression.kind === "Apply" ? expression.argumentRanges?.[0] : undefined) ?? location.range,
|
|
842
|
+
scope,
|
|
843
|
+
unit,
|
|
844
|
+
)
|
|
845
|
+
) {
|
|
846
|
+
return undefined;
|
|
847
|
+
}
|
|
764
848
|
if (selected || (prefix !== "" && isFact(prefix, unit))) {
|
|
765
849
|
return expression.kind === "Apply" ? expression.args.length : 0;
|
|
766
850
|
}
|
|
@@ -993,7 +1077,9 @@ const findInstance = (name: string, scope: LocalName | undefined, unit: Unit) =>
|
|
|
993
1077
|
prefix === name
|
|
994
1078
|
? undefined
|
|
995
1079
|
: (lookupLocal(scope, prefix) ?? getModuleBinding(prefix, unit, undefined));
|
|
996
|
-
return binding?.kind === "Instance"
|
|
1080
|
+
return binding?.kind === "Instance"
|
|
1081
|
+
? { name: prefix, arity: binding.arity, range: binding.range }
|
|
1082
|
+
: undefined;
|
|
997
1083
|
};
|
|
998
1084
|
|
|
999
1085
|
const isInstanceArityReported = (
|
|
@@ -1001,16 +1087,22 @@ const isInstanceArityReported = (
|
|
|
1001
1087
|
scope: LocalName | undefined,
|
|
1002
1088
|
unit: Unit,
|
|
1003
1089
|
) => {
|
|
1004
|
-
if (expression
|
|
1090
|
+
if (!isReference(expression)) return false;
|
|
1091
|
+
const selectors = getSelectors(expression);
|
|
1092
|
+
const nameCount = selectors.findIndex((selector) => selector.kind !== "Name");
|
|
1005
1093
|
const instance = findInstance(
|
|
1006
|
-
|
|
1094
|
+
selectors
|
|
1095
|
+
.slice(0, nameCount === -1 ? selectors.length : nameCount)
|
|
1096
|
+
.flatMap((selector) => (selector.kind === "Name" ? [selector.name] : []))
|
|
1097
|
+
.join("!"),
|
|
1007
1098
|
scope,
|
|
1008
1099
|
unit,
|
|
1009
1100
|
);
|
|
1010
|
-
const
|
|
1101
|
+
const first = selectors[0];
|
|
1102
|
+
const count = first.kind === "Name" ? first.args.length : 0;
|
|
1011
1103
|
if (!instance || count === instance.arity) return false;
|
|
1012
1104
|
const range =
|
|
1013
|
-
(expression.kind === "
|
|
1105
|
+
(expression.kind === "Identifier" ? undefined : expression.argumentRanges?.[0]) ??
|
|
1014
1106
|
expression.location.range;
|
|
1015
1107
|
if (range) {
|
|
1016
1108
|
unit.errors.push({
|
|
@@ -1030,7 +1122,7 @@ const isArgumentCountReported = (
|
|
|
1030
1122
|
) => {
|
|
1031
1123
|
const params = callee?.kind === "Definition" ? callee.params : undefined;
|
|
1032
1124
|
if (!callee || !params || params.length === callee.arity) return false;
|
|
1033
|
-
if (range) {
|
|
1125
|
+
if (range && !unit.isGenerated) {
|
|
1034
1126
|
unit.errors.push({
|
|
1035
1127
|
location: formatRange(range),
|
|
1036
1128
|
message: `Wrong number of arguments (${count}) given to operator '${resolveSynonym(name)}', \nwhich requires ${params.length} arguments.`,
|
|
@@ -1039,6 +1131,28 @@ const isArgumentCountReported = (
|
|
|
1039
1131
|
return true;
|
|
1040
1132
|
};
|
|
1041
1133
|
|
|
1134
|
+
const resolveExpressionArgument = (arg: Expression, scope: LocalName | undefined, unit: Unit) => {
|
|
1135
|
+
const range = arg.location.range;
|
|
1136
|
+
const report = (message: string) => {
|
|
1137
|
+
if (range) unit.errors.push({ location: formatRange(range), message });
|
|
1138
|
+
};
|
|
1139
|
+
const selectionError = operatorSelectionErrors.get(arg);
|
|
1140
|
+
// Deviation from SANY: SANY names its internal node kind here, where tla-ts words it as for a name.
|
|
1141
|
+
if (arg.kind === "Lambda" && arg.operator !== undefined) {
|
|
1142
|
+
report(`The operator ${resolveSynonym(arg.operator)} requires 1 arguments.`);
|
|
1143
|
+
} else if (selectionError) {
|
|
1144
|
+
unit.errors.push(selectionError);
|
|
1145
|
+
} else if (arg.kind === "Lambda" && range) {
|
|
1146
|
+
unresolvedExpressions.add(arg);
|
|
1147
|
+
report("LAMBDA expression used where an expression is required.");
|
|
1148
|
+
} else if (arg.kind === "OperatorReference") {
|
|
1149
|
+
const argArity = getSymbolArity(arg, arg.operator, scope, unit);
|
|
1150
|
+
if (argArity !== undefined) {
|
|
1151
|
+
report(`The operator ${resolveSynonym(arg.operator)} requires ${argArity} arguments.`);
|
|
1152
|
+
}
|
|
1153
|
+
} else resolveExpression(arg, scope, unit);
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1042
1156
|
const matchArgument = (
|
|
1043
1157
|
arg: Expression,
|
|
1044
1158
|
expected: number,
|
|
@@ -1051,22 +1165,18 @@ const matchArgument = (
|
|
|
1051
1165
|
const report = (range: SourceRange | undefined, message: string) => {
|
|
1052
1166
|
if (range) unit.errors.push({ location: formatRange(range), message });
|
|
1053
1167
|
};
|
|
1168
|
+
const reportOperatorArity = (name: string, arity: number) => {
|
|
1169
|
+
const definition =
|
|
1170
|
+
findInstance(operator, scope, unit)?.range ?? findBinding(operator, scope, unit)?.range;
|
|
1171
|
+
if (!definition) return;
|
|
1172
|
+
report(
|
|
1173
|
+
operatorRange,
|
|
1174
|
+
`Operator with incorrect arity passed as argument. \nOperator '${resolveSynonym(name)}' of arity ${arity} is argument number ${index + 1} (counting from 1) to operator \`${formatRange(definition)}', \nbut an operator of arity ${expected} was expected.`,
|
|
1175
|
+
);
|
|
1176
|
+
};
|
|
1054
1177
|
const range = arg.location.range;
|
|
1055
1178
|
if (expected === 0) {
|
|
1056
|
-
|
|
1057
|
-
if (arg.kind === "Lambda" && arg.operator !== undefined) {
|
|
1058
|
-
report(range, `The operator ${resolveSynonym(arg.operator)} requires 1 arguments.`);
|
|
1059
|
-
} else if (arg.kind === "Lambda" && range) {
|
|
1060
|
-
report(range, "LAMBDA expression used where an expression is required.");
|
|
1061
|
-
} else if (arg.kind === "OperatorReference") {
|
|
1062
|
-
const argArity = getSymbolArity(arg, arg.operator, scope, unit);
|
|
1063
|
-
if (argArity !== undefined) {
|
|
1064
|
-
report(
|
|
1065
|
-
range,
|
|
1066
|
-
`The operator ${resolveSynonym(arg.operator)} requires ${argArity} arguments.`,
|
|
1067
|
-
);
|
|
1068
|
-
}
|
|
1069
|
-
} else resolveExpression(arg, scope, unit);
|
|
1179
|
+
resolveExpressionArgument(arg, scope, unit);
|
|
1070
1180
|
return true;
|
|
1071
1181
|
}
|
|
1072
1182
|
if (arg.kind === "Lambda") {
|
|
@@ -1080,6 +1190,8 @@ const matchArgument = (
|
|
|
1080
1190
|
operatorRange,
|
|
1081
1191
|
`Lambda expression with arity ${arg.params.length} used as argument ${index + 1} of operator \`${operator}', \nbut an operator of arity ${expected} is required.`,
|
|
1082
1192
|
);
|
|
1193
|
+
} else if (!isMatched && arg.operator !== undefined) {
|
|
1194
|
+
reportOperatorArity(arg.operator, arg.params.length);
|
|
1083
1195
|
}
|
|
1084
1196
|
return isMatched;
|
|
1085
1197
|
}
|
|
@@ -1111,6 +1223,9 @@ const matchArgument = (
|
|
|
1111
1223
|
`Expected arity ${expected} but found operator of arity ${argArity}.`,
|
|
1112
1224
|
);
|
|
1113
1225
|
}
|
|
1226
|
+
if (arg.kind === "OperatorReference" && argArity !== undefined && argArity !== expected) {
|
|
1227
|
+
reportOperatorArity(name, argArity);
|
|
1228
|
+
}
|
|
1114
1229
|
// Deviation from SANY: OpDefNode#matchingOpArgOperand reads as many parameters as a RECURSIVE declaration gives and crashes when the definition has fewer.
|
|
1115
1230
|
return argArity === expected && argParams.every((param) => param === 0);
|
|
1116
1231
|
};
|
|
@@ -1120,16 +1235,19 @@ const resolveApply = (
|
|
|
1120
1235
|
scope: LocalName | undefined,
|
|
1121
1236
|
unit: Unit,
|
|
1122
1237
|
) => {
|
|
1123
|
-
if (isInstanceArityReported(expression, scope, unit)) return;
|
|
1124
1238
|
const operator = expression.operator;
|
|
1125
1239
|
const callee = findBinding(operator, scope, unit);
|
|
1126
|
-
const arity =
|
|
1127
|
-
|
|
1128
|
-
|
|
1240
|
+
const arity = isInstanceArityReported(expression, scope, unit)
|
|
1241
|
+
? undefined
|
|
1242
|
+
: getSymbolArity(expression, operator, scope, unit);
|
|
1243
|
+
if (arity !== undefined && arity !== expression.args.length) {
|
|
1129
1244
|
unit.errors.push({
|
|
1130
1245
|
location: formatRange(expression.argumentsRange ?? getSpelledNameRange(expression, operator)),
|
|
1131
1246
|
message: `The operator ${resolveSynonym(operator)} requires ${arity - (findInstance(operator, scope, unit)?.arity ?? 0)} arguments.`,
|
|
1132
1247
|
});
|
|
1248
|
+
}
|
|
1249
|
+
if (arity !== expression.args.length) {
|
|
1250
|
+
emptyExpressions.add(expression);
|
|
1133
1251
|
return;
|
|
1134
1252
|
}
|
|
1135
1253
|
const params =
|
|
@@ -1140,11 +1258,19 @@ const resolveApply = (
|
|
|
1140
1258
|
}
|
|
1141
1259
|
const operatorRange =
|
|
1142
1260
|
expression.selectorRanges?.at(-1) ?? getSpelledNameRange(expression, operator);
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1145
|
-
.
|
|
1146
|
-
|
|
1261
|
+
const isSelection = operator === SELECTION_NAME;
|
|
1262
|
+
const matches = expression.args.slice(0, params.length).map((arg, index) => {
|
|
1263
|
+
const source = isSelection ? selectionArguments.get(arg) : undefined;
|
|
1264
|
+
return matchArgument(
|
|
1265
|
+
arg,
|
|
1266
|
+
params[index],
|
|
1267
|
+
source?.index ?? index,
|
|
1268
|
+
source?.operator ?? operator,
|
|
1269
|
+
source?.range ?? operatorRange,
|
|
1270
|
+
scope,
|
|
1271
|
+
isSelection ? { ...unit, isGenerated: false } : unit,
|
|
1147
1272
|
);
|
|
1273
|
+
});
|
|
1148
1274
|
if (
|
|
1149
1275
|
isArgumentCountReported(
|
|
1150
1276
|
callee,
|
|
@@ -1160,7 +1286,7 @@ const resolveApply = (
|
|
|
1160
1286
|
if (!isMatched && expression.location.range) {
|
|
1161
1287
|
unit.errors.push({
|
|
1162
1288
|
location: formatRange(expression.location.range),
|
|
1163
|
-
message: `Argument number ${index + 1} to operator '${operator}' \nshould be a ${params[index]}-parameter operator.`,
|
|
1289
|
+
message: `Argument number ${index + 1} to operator '${isSelection ? "LAMBDA" : operator}' \nshould be a ${params[index]}-parameter operator.`,
|
|
1164
1290
|
});
|
|
1165
1291
|
}
|
|
1166
1292
|
});
|
|
@@ -1175,19 +1301,21 @@ const isSelectionReported = (expression: Expression, scope: LocalName | undefine
|
|
|
1175
1301
|
const failed = selectionErrors.get(expression);
|
|
1176
1302
|
if (!failed) return false;
|
|
1177
1303
|
failed.applications.forEach((application) =>
|
|
1178
|
-
application.args
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1304
|
+
application.args
|
|
1305
|
+
.slice(0, application.params.length)
|
|
1306
|
+
.forEach((arg, index) =>
|
|
1307
|
+
matchArgument(
|
|
1308
|
+
arg,
|
|
1309
|
+
application.params[index],
|
|
1310
|
+
index,
|
|
1311
|
+
application.operator,
|
|
1312
|
+
application.range,
|
|
1313
|
+
scope,
|
|
1314
|
+
unit,
|
|
1315
|
+
),
|
|
1187
1316
|
),
|
|
1188
|
-
),
|
|
1189
1317
|
);
|
|
1190
|
-
unit.errors.push(failed.error);
|
|
1318
|
+
unit.errors.push(findNullError(failed.nulls) ?? failed.error);
|
|
1191
1319
|
return true;
|
|
1192
1320
|
};
|
|
1193
1321
|
|
|
@@ -1211,11 +1339,18 @@ const resolveExpression = (
|
|
|
1211
1339
|
unit: Unit,
|
|
1212
1340
|
): void => {
|
|
1213
1341
|
if (selections.has(expression) && !unit.isGenerated) {
|
|
1214
|
-
const failed = nullSelections
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1342
|
+
const failed = findNullError(nullSelections.get(expression));
|
|
1343
|
+
if (failed) {
|
|
1344
|
+
unit.errors.push(failed);
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
const source = selectionSources.get(expression);
|
|
1348
|
+
if (source) {
|
|
1349
|
+
Object.assign(expression, source);
|
|
1350
|
+
const arity = renamedArities.get(source);
|
|
1351
|
+
if (arity !== undefined) renamedArities.set(expression, arity);
|
|
1352
|
+
}
|
|
1353
|
+
resolveExpression(expression, scope, { ...unit, isGenerated: true });
|
|
1219
1354
|
return;
|
|
1220
1355
|
}
|
|
1221
1356
|
const resolveAll = (expressions: Expression[]) =>
|
|
@@ -1231,6 +1366,7 @@ const resolveExpression = (
|
|
|
1231
1366
|
return;
|
|
1232
1367
|
case "ExceptAt":
|
|
1233
1368
|
if (!unit.isInExcept && expression.location.range) {
|
|
1369
|
+
emptyExpressions.add(expression);
|
|
1234
1370
|
unit.errors.push({
|
|
1235
1371
|
location: formatRange(expression.location.range),
|
|
1236
1372
|
message: "@ used where its meaning is not defined.",
|
|
@@ -1238,23 +1374,32 @@ const resolveExpression = (
|
|
|
1238
1374
|
}
|
|
1239
1375
|
return;
|
|
1240
1376
|
case "Identifier": {
|
|
1241
|
-
if (isInstanceArityReported(expression, scope, unit)) return;
|
|
1242
1377
|
const name = expression.name;
|
|
1243
|
-
const arity =
|
|
1378
|
+
const arity = isInstanceArityReported(expression, scope, unit)
|
|
1379
|
+
? undefined
|
|
1380
|
+
: getSymbolArity(expression, name, scope, unit);
|
|
1244
1381
|
if (arity === 0) {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1382
|
+
const binding = findBinding(name, scope, unit);
|
|
1383
|
+
const kind = binding?.kind;
|
|
1384
|
+
// SANY's selector chooses no operand of a variable, theorem, step or NEW symbol, unlike of a constant or definition.
|
|
1385
|
+
if (
|
|
1386
|
+
kind === "Variable" ||
|
|
1387
|
+
kind === "Theorem" ||
|
|
1388
|
+
kind?.startsWith("New") ||
|
|
1389
|
+
isFact(name, unit)
|
|
1390
|
+
) {
|
|
1391
|
+
emptyExpressions.add(expression);
|
|
1392
|
+
}
|
|
1393
|
+
isArgumentCountReported(binding, name, 0, getSpelledNameRange(expression, name), unit);
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
if (arity !== undefined) {
|
|
1253
1397
|
unit.errors.push({
|
|
1254
1398
|
location: formatRange(getSpelledNameRange(expression, name)),
|
|
1255
1399
|
message: `The operator ${resolveSynonym(name)} requires ${arity} arguments.`,
|
|
1256
1400
|
});
|
|
1257
1401
|
}
|
|
1402
|
+
emptyExpressions.add(expression);
|
|
1258
1403
|
return;
|
|
1259
1404
|
}
|
|
1260
1405
|
case "OperatorReference":
|
|
@@ -1266,6 +1411,7 @@ const resolveExpression = (
|
|
|
1266
1411
|
case "Lambda":
|
|
1267
1412
|
if (selections.has(expression)) resolveLambda(expression, scope, unit);
|
|
1268
1413
|
else if (expression.location.range) {
|
|
1414
|
+
unresolvedExpressions.add(expression);
|
|
1269
1415
|
unit.errors.push({
|
|
1270
1416
|
location: formatRange(expression.location.range),
|
|
1271
1417
|
message: "LAMBDA expression used where an expression is required.",
|
|
@@ -1389,85 +1535,150 @@ const resolveExpression = (
|
|
|
1389
1535
|
resolveExpression(expression.body, scope, { ...unit, labelParams: [], labels: new Set() });
|
|
1390
1536
|
checkLabel(expression, scope, unit);
|
|
1391
1537
|
return;
|
|
1392
|
-
case "Subexpression":
|
|
1393
|
-
if (
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
location: formatRange({ module: range.module, start: range.start, end: lastRange.end }),
|
|
1415
|
-
message: `Unknown operator: \`${resolveSynonym(names.join("!"))}'.`,
|
|
1416
|
-
});
|
|
1417
|
-
return;
|
|
1418
|
-
}
|
|
1419
|
-
const name = names.slice(0, symbolIndex + 1).join("!");
|
|
1420
|
-
const symbol = symbolIndex > 0 ? findSymbol(name, unit) : undefined;
|
|
1421
|
-
const argumentCount = expression.selectors
|
|
1422
|
-
.slice(0, symbolIndex + 1)
|
|
1423
|
-
.flatMap((selector) => ("args" in selector ? selector.args : [])).length;
|
|
1424
|
-
const argumentRange = expression.argumentRanges?.[symbolIndex] ?? expression.location.range;
|
|
1425
|
-
if (symbol && symbol.arity !== argumentCount && argumentRange) {
|
|
1426
|
-
unit.errors.push({
|
|
1427
|
-
location: formatRange(argumentRange),
|
|
1428
|
-
message: `The operator ${resolveSynonym(name)} requires ${symbol.arity} arguments.`,
|
|
1429
|
-
});
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
if (head.kind !== "Name" || expression.selectors[1].kind === "Name" || !range) return;
|
|
1433
|
-
const binding = lookupLocal(scope, head.name) ?? findSymbol(head.name, unit);
|
|
1434
|
-
if ((binding === undefined && !isFact(head.name, unit)) || binding?.kind === "Instance") {
|
|
1435
|
-
unit.errors.push({
|
|
1436
|
-
location: formatRange(range),
|
|
1437
|
-
message: `Unknown operator: \`${resolveSynonym(head.name)}'.`,
|
|
1438
|
-
});
|
|
1439
|
-
} else if (binding && !SELECTABLE_KINDS.has(binding.kind)) {
|
|
1440
|
-
reportUnselectable(head.name, range, unit);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1538
|
+
case "Subexpression":
|
|
1539
|
+
if (isSubexpressionReported(expression, scope, unit)) emptyExpressions.add(expression);
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1544
|
+
const isPendingSelectionReported = (
|
|
1545
|
+
name: string,
|
|
1546
|
+
args: Expression[],
|
|
1547
|
+
selectorRange: SourceRange | undefined,
|
|
1548
|
+
argumentsRange: SourceRange | undefined,
|
|
1549
|
+
scope: LocalName | undefined,
|
|
1550
|
+
unit: Unit,
|
|
1551
|
+
) => {
|
|
1552
|
+
const pending = lookupLocal(scope, name) ?? getModuleBinding(name, unit, undefined);
|
|
1553
|
+
if (!pending?.isPending || !selectorRange || !argumentsRange) return false;
|
|
1554
|
+
if (args.length !== pending.arity) {
|
|
1555
|
+
unit.errors.push({
|
|
1556
|
+
location: formatRange(argumentsRange),
|
|
1557
|
+
message: `The operator ${name} requires ${pending.arity} arguments.`,
|
|
1558
|
+
});
|
|
1559
|
+
return true;
|
|
1443
1560
|
}
|
|
1561
|
+
args.forEach((arg) => resolveExpression(arg, scope, unit));
|
|
1562
|
+
unit.errors.push({
|
|
1563
|
+
location: formatRange(selectorRange),
|
|
1564
|
+
message: `Subexpression of \`${name}' used inside the operator's definition.`,
|
|
1565
|
+
});
|
|
1566
|
+
return true;
|
|
1444
1567
|
};
|
|
1445
1568
|
|
|
1446
|
-
const
|
|
1447
|
-
|
|
1448
|
-
|
|
1569
|
+
const isSubexpressionReported = (
|
|
1570
|
+
expression: Expression & { kind: "Subexpression" },
|
|
1571
|
+
scope: LocalName | undefined,
|
|
1572
|
+
unit: Unit,
|
|
1573
|
+
) => {
|
|
1574
|
+
if (
|
|
1575
|
+
isInstanceArityReported(expression, scope, unit) ||
|
|
1576
|
+
isSelectionReported(expression, scope, unit)
|
|
1577
|
+
) {
|
|
1578
|
+
return true;
|
|
1579
|
+
}
|
|
1580
|
+
const head = expression.selectors[0];
|
|
1581
|
+
const range = expression.selectorRanges?.[0];
|
|
1582
|
+
const nameCount = expression.selectors.findIndex((selector) => selector.kind !== "Name");
|
|
1583
|
+
const names = expression.selectors
|
|
1584
|
+
.slice(0, nameCount)
|
|
1585
|
+
.flatMap((selector) => (selector.kind === "Name" ? [selector.name] : []));
|
|
1586
|
+
const symbolIndex = names.findIndex(
|
|
1587
|
+
(_name, index) => index > 0 && findSymbol(names.slice(0, index + 1).join("!"), unit),
|
|
1588
|
+
);
|
|
1589
|
+
const isInstance =
|
|
1590
|
+
names.length > 1 &&
|
|
1591
|
+
(lookupLocal(scope, names[0]) ?? getModuleBinding(names[0], unit, undefined))?.kind ===
|
|
1592
|
+
"Instance";
|
|
1593
|
+
const lastRange = expression.selectorRanges?.[nameCount - 1];
|
|
1594
|
+
if (isInstance && symbolIndex === -1 && range && lastRange) {
|
|
1595
|
+
unit.errors.push({
|
|
1596
|
+
location: formatRange({ module: range.module, start: range.start, end: lastRange.end }),
|
|
1597
|
+
message: `Unknown operator: \`${resolveSynonym(names.join("!"))}'.`,
|
|
1598
|
+
});
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1601
|
+
const name = names.slice(0, symbolIndex + 1).join("!");
|
|
1602
|
+
const symbol = symbolIndex > 0 ? findSymbol(name, unit) : undefined;
|
|
1603
|
+
const argumentCount = expression.selectors
|
|
1604
|
+
.slice(0, symbolIndex + 1)
|
|
1605
|
+
.flatMap((selector) => ("args" in selector ? selector.args : [])).length;
|
|
1606
|
+
const argumentRange = expression.argumentRanges?.[symbolIndex] ?? expression.location.range;
|
|
1607
|
+
if (symbol && symbol.arity !== argumentCount && argumentRange) {
|
|
1608
|
+
unit.errors.push({
|
|
1609
|
+
location: formatRange(argumentRange),
|
|
1610
|
+
message: `The operator ${resolveSynonym(name)} requires ${symbol.arity} arguments.`,
|
|
1611
|
+
});
|
|
1612
|
+
return true;
|
|
1613
|
+
}
|
|
1614
|
+
if (head.kind === "Name" && expression.selectors[1].kind !== "Name" && range) {
|
|
1615
|
+
const local = lookupLocal(scope, head.name);
|
|
1616
|
+
const binding = local ?? findSymbol(head.name, unit);
|
|
1617
|
+
if ((binding === undefined && !isFact(head.name, unit)) || binding?.kind === "Instance") {
|
|
1449
1618
|
unit.errors.push({
|
|
1450
|
-
location: formatRange(
|
|
1451
|
-
message:
|
|
1619
|
+
location: formatRange(range),
|
|
1620
|
+
message: `Unknown operator: \`${resolveSynonym(head.name)}'.`,
|
|
1452
1621
|
});
|
|
1453
|
-
return;
|
|
1622
|
+
return true;
|
|
1454
1623
|
}
|
|
1455
|
-
if (
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
checkReference(fact, scope, unit, true)
|
|
1459
|
-
) {
|
|
1460
|
-
return;
|
|
1624
|
+
if (binding && (!SELECTABLE_KINDS.has(binding.kind) || local?.isNonFact)) {
|
|
1625
|
+
reportUnselectable(head.name, range, unit);
|
|
1626
|
+
return true;
|
|
1461
1627
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1628
|
+
}
|
|
1629
|
+
if (
|
|
1630
|
+
head.kind === "Name" &&
|
|
1631
|
+
isPendingSelectionReported(
|
|
1632
|
+
head.name,
|
|
1633
|
+
head.args,
|
|
1634
|
+
range,
|
|
1635
|
+
expression.argumentRanges?.[0] ?? expression.location.range,
|
|
1636
|
+
scope,
|
|
1637
|
+
unit,
|
|
1638
|
+
)
|
|
1639
|
+
) {
|
|
1640
|
+
return true;
|
|
1641
|
+
}
|
|
1642
|
+
expression.selectors
|
|
1643
|
+
.flatMap((selector) => ("args" in selector ? selector.args : []))
|
|
1644
|
+
.forEach((arg) => resolveArgument(arg, scope, unit));
|
|
1645
|
+
const selected = checkReference(expression, scope, unit, false);
|
|
1646
|
+
return selected ? selected.node === undefined : false;
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, unit: Unit) => {
|
|
1650
|
+
if (fact.kind === "ModuleFact") return undefined;
|
|
1651
|
+
if (fact.kind === "ExceptAt" && fact.location.range) {
|
|
1652
|
+
unit.errors.push({
|
|
1653
|
+
location: formatRange(fact.location.range),
|
|
1654
|
+
message: "Unknown operator: `@'.",
|
|
1655
|
+
});
|
|
1656
|
+
return BUILTIN_LOCATION;
|
|
1657
|
+
}
|
|
1658
|
+
const hidden = getHiddenExpressionLocation(fact, reference, scope, unit);
|
|
1659
|
+
if (isInstanceArityReported(fact, scope, unit)) return hidden;
|
|
1660
|
+
const selected = checkReference(fact, scope, unit, true);
|
|
1661
|
+
if (selected) {
|
|
1662
|
+
const kind = selected.node?.kind;
|
|
1663
|
+
if (kind === undefined) return BUILTIN_LOCATION;
|
|
1664
|
+
return kind === "AssumeProve" || kind === "NewSymbol"
|
|
1665
|
+
? undefined
|
|
1666
|
+
: fact.location.range && formatRange(fact.location.range);
|
|
1667
|
+
}
|
|
1668
|
+
if (fact.kind === "Subexpression") {
|
|
1669
|
+
return isSubexpressionReported(fact, scope, unit) ? BUILTIN_LOCATION : hidden;
|
|
1670
|
+
}
|
|
1671
|
+
const name = fact.kind === "Identifier" ? fact.name : fact.kind === "Apply" ? fact.operator : "";
|
|
1672
|
+
if (fact.kind === "Identifier" && lookupLocal(scope, name)?.isNonFact) {
|
|
1673
|
+
unit.errors.push({
|
|
1674
|
+
location: formatRange(getSpelledNameRange(fact, name)),
|
|
1675
|
+
message: "Step number of non-fact used as a fact",
|
|
1676
|
+
});
|
|
1677
|
+
return BUILTIN_LOCATION;
|
|
1678
|
+
}
|
|
1679
|
+
if (!isFact(name, unit) && !lookupLocal(scope, name)?.goal) resolveExpression(fact, scope, unit);
|
|
1680
|
+
return hidden;
|
|
1681
|
+
};
|
|
1471
1682
|
|
|
1472
1683
|
const isDefinitionEntry = (def: Fact, scope: LocalName | undefined, unit: Unit) => {
|
|
1473
1684
|
const range = def.location.range;
|
|
@@ -1491,9 +1702,16 @@ const isDefinitionEntry = (def: Fact, scope: LocalName | undefined, unit: Unit)
|
|
|
1491
1702
|
return false;
|
|
1492
1703
|
};
|
|
1493
1704
|
|
|
1494
|
-
const getHiddenExpressionLocation = (
|
|
1705
|
+
const getHiddenExpressionLocation = (
|
|
1706
|
+
fact: Expression,
|
|
1707
|
+
reference: Fact,
|
|
1708
|
+
scope: LocalName | undefined,
|
|
1709
|
+
unit: Unit,
|
|
1710
|
+
) => {
|
|
1495
1711
|
const range = fact.location.range && formatRange(fact.location.range);
|
|
1496
|
-
if (
|
|
1712
|
+
if (selections.has(fact)) {
|
|
1713
|
+
return reference.location.range && formatRange(reference.location.range);
|
|
1714
|
+
}
|
|
1497
1715
|
if (selectionErrors.has(fact) || fact.kind === "ExceptAt") return BUILTIN_LOCATION;
|
|
1498
1716
|
switch (fact.kind) {
|
|
1499
1717
|
case "Number":
|
|
@@ -1526,14 +1744,13 @@ const checkUseOrHide = (
|
|
|
1526
1744
|
scope: LocalName | undefined,
|
|
1527
1745
|
unit: Unit,
|
|
1528
1746
|
) => {
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
checkFacts(statement.facts, scope, unit);
|
|
1747
|
+
const references = factReferences.get(statement.facts) ?? statement.facts;
|
|
1748
|
+
const hidden = statement.facts.map((fact, index) =>
|
|
1749
|
+
checkFact(fact, references[index], scope, unit),
|
|
1750
|
+
);
|
|
1534
1751
|
const defCount = statement.defs.filter((def) => isDefinitionEntry(def, scope, unit)).length;
|
|
1535
1752
|
hidden.forEach((location) => {
|
|
1536
|
-
if (location) {
|
|
1753
|
+
if (location && statement.kind === "Hide") {
|
|
1537
1754
|
unit.errors.push({
|
|
1538
1755
|
location,
|
|
1539
1756
|
message:
|
|
@@ -1614,6 +1831,42 @@ const resolveLocalInstance = (instance: Instance, scope: LocalName | undefined,
|
|
|
1614
1831
|
);
|
|
1615
1832
|
};
|
|
1616
1833
|
|
|
1834
|
+
const getStepGoal = (body: StepBody, location: SourceLocation): Goal | undefined => {
|
|
1835
|
+
const createGoal = (keyword: string, statement: Expression) => ({
|
|
1836
|
+
statement,
|
|
1837
|
+
isSuffices: false,
|
|
1838
|
+
isInProof: false,
|
|
1839
|
+
keyword,
|
|
1840
|
+
});
|
|
1841
|
+
switch (body.kind) {
|
|
1842
|
+
case "Have":
|
|
1843
|
+
return createGoal("HAVE", { kind: "Tuple", elements: [body.expression], location });
|
|
1844
|
+
case "Case":
|
|
1845
|
+
return createGoal("CASE", { kind: "Tuple", elements: [body.expression], location });
|
|
1846
|
+
case "Witness":
|
|
1847
|
+
return createGoal("WITNESS", { kind: "Tuple", elements: body.expressions, location });
|
|
1848
|
+
case "Take":
|
|
1849
|
+
return createGoal("TAKE", { kind: "Tuple", elements: getBoundSets(body.bounds), location });
|
|
1850
|
+
case "Pick":
|
|
1851
|
+
return createGoal(
|
|
1852
|
+
"PICK",
|
|
1853
|
+
body.bounds.length > 0
|
|
1854
|
+
? { kind: "Exists", bounds: body.bounds, body: body.body, location }
|
|
1855
|
+
: {
|
|
1856
|
+
kind: "UnboundedQuantifier",
|
|
1857
|
+
quantifier: "Exists",
|
|
1858
|
+
names: body.names,
|
|
1859
|
+
body: body.body,
|
|
1860
|
+
location,
|
|
1861
|
+
},
|
|
1862
|
+
);
|
|
1863
|
+
case "Qed":
|
|
1864
|
+
return createGoal("QED step", { kind: "Tuple", elements: [], location });
|
|
1865
|
+
default:
|
|
1866
|
+
return undefined;
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
|
|
1617
1870
|
const resolveStep = (
|
|
1618
1871
|
step: ProofStep,
|
|
1619
1872
|
scope: LocalName | undefined,
|
|
@@ -1624,8 +1877,9 @@ const resolveStep = (
|
|
|
1624
1877
|
step.name === undefined
|
|
1625
1878
|
? unit
|
|
1626
1879
|
: { ...unit, hasLabelScope: true, labelParams: [], labels: new Set<string>() };
|
|
1880
|
+
const goal = getStepGoal(body, step.location);
|
|
1627
1881
|
const bindStep = (parent: LocalName | undefined): LocalName | undefined =>
|
|
1628
|
-
step.name === undefined ? parent : { name: step.name, arity: 0, kind: "Theorem", parent };
|
|
1882
|
+
step.name === undefined ? parent : { name: step.name, arity: 0, kind: "Theorem", parent, goal };
|
|
1629
1883
|
const bindNonFactStep = (parent: LocalName | undefined): LocalName | undefined =>
|
|
1630
1884
|
step.name === undefined
|
|
1631
1885
|
? parent
|
|
@@ -1639,10 +1893,25 @@ const resolveStep = (
|
|
|
1639
1893
|
resolveProof(step.proof, proofScope, unit);
|
|
1640
1894
|
return body.isSuffices ? assumed : scope;
|
|
1641
1895
|
}
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1896
|
+
const assertion = {
|
|
1897
|
+
statement: body.statement,
|
|
1898
|
+
isSuffices: body.isSuffices,
|
|
1899
|
+
isInProof: true,
|
|
1900
|
+
keyword: body.isSuffices && body.statement.kind !== "AssumeProve" ? "SUFFICES" : undefined,
|
|
1901
|
+
};
|
|
1902
|
+
resolveProof(
|
|
1903
|
+
step.proof,
|
|
1904
|
+
{ name, arity: 0, kind: "Theorem", parent: proofScope, goal: assertion },
|
|
1905
|
+
unit,
|
|
1906
|
+
);
|
|
1907
|
+
assertion.isInProof = false;
|
|
1908
|
+
return {
|
|
1909
|
+
name,
|
|
1910
|
+
arity: 0,
|
|
1911
|
+
kind: "Theorem",
|
|
1912
|
+
parent: body.isSuffices ? assumed : scope,
|
|
1913
|
+
goal: assertion,
|
|
1914
|
+
};
|
|
1646
1915
|
}
|
|
1647
1916
|
case "Use":
|
|
1648
1917
|
case "Hide":
|
|
@@ -1777,7 +2046,7 @@ const checkSubstitutions = (
|
|
|
1777
2046
|
const resolveSubstitute = (declaration: Declaration, expression: Expression) => {
|
|
1778
2047
|
const range = expression.location.range;
|
|
1779
2048
|
if (declaration.arity === 0) {
|
|
1780
|
-
|
|
2049
|
+
resolveExpressionArgument(expression, scope, unit);
|
|
1781
2050
|
return;
|
|
1782
2051
|
}
|
|
1783
2052
|
if (expression.kind === "Lambda") {
|
|
@@ -1973,7 +2242,17 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
|
|
|
1973
2242
|
const goals = new Map(
|
|
1974
2243
|
module.theorems.flatMap((theorem): [string, Goal][] =>
|
|
1975
2244
|
theorem.name !== undefined && theorem.statement.kind === "AssumeProve"
|
|
1976
|
-
? [
|
|
2245
|
+
? [
|
|
2246
|
+
[
|
|
2247
|
+
theorem.name,
|
|
2248
|
+
{
|
|
2249
|
+
statement: theorem.statement,
|
|
2250
|
+
isSuffices: false,
|
|
2251
|
+
isInProof: false,
|
|
2252
|
+
keyword: undefined,
|
|
2253
|
+
},
|
|
2254
|
+
],
|
|
2255
|
+
]
|
|
1977
2256
|
: [],
|
|
1978
2257
|
),
|
|
1979
2258
|
);
|