tla-ts 0.0.4-dev.0be9567 → 0.0.4-dev.2da24e1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -126
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +996 -0
- package/dist/prove.js +996 -0
- package/dist/run-cli.cjs +37 -47
- package/dist/run-cli.js +37 -47
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +38 -44
- package/dist/transfer.js +38 -44
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/check.ts +1 -0
- package/src/errors.ts +86 -0
- package/src/evaluate.ts +54 -19
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +247 -69
- package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
- package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
- package/src/{obligations.ts → obligations/index.ts} +32 -16
- package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
- package/src/{obligation-module.ts → obligations/module.ts} +113 -121
- package/src/obligations/pickle.ts +98 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/{obligation-source.ts → obligations/source.ts} +154 -99
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/ocaml-marshal.ts +166 -0
- package/src/parallel-worker.ts +2 -18
- package/src/parallel.ts +10 -43
- package/src/prove/decide-pool.ts +95 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/first-order.ts +78 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +446 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +547 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +441 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +363 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +402 -0
- package/src/prove/isabelle/pure/name.ts +110 -0
- package/src/prove/isabelle/pure/net.ts +262 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +650 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +156 -0
- package/src/prove/isabelle/pure/simplifier.ts +112 -0
- package/src/prove/isabelle/pure/table.ts +208 -0
- package/src/prove/isabelle/pure/tactic.ts +276 -0
- package/src/prove/isabelle/pure/tactical.ts +347 -0
- package/src/prove/isabelle/pure/term-ord.ts +159 -0
- package/src/prove/isabelle/pure/term.ts +808 -0
- package/src/prove/isabelle/pure/thm.ts +806 -0
- package/src/prove/isabelle/pure/type.ts +133 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +508 -0
- package/src/prove/prep/defs.ts +33 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +529 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +22 -0
- package/src/prove/prove.ts +498 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +255 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +209 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +164 -0
- package/src/prove/smt/extensionality.ts +65 -0
- package/src/prove/smt/flatten.ts +112 -0
- package/src/prove/smt/format.ts +154 -0
- package/src/prove/smt/instances.ts +181 -0
- package/src/prove/smt/rewrite.ts +772 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +147 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +18 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +379 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +181 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/run-cli.ts +283 -81
- package/src/successors.ts +24 -5
- package/src/tlapm-cache.ts +236 -0
- package/src/tlc-random.ts +55 -32
- package/src/tlc-version.ts +8 -7
- package/src/values.ts +47 -4
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// tlapm's expression IR (E_t) with de Bruijn indices, and its substitutions (E_subst) and
|
|
2
2
|
// alpha-equivalence (E_eq).
|
|
3
3
|
|
|
4
|
-
import { TlaProofError } from "
|
|
4
|
+
import { TlaProofError } from "../errors";
|
|
5
|
+
import type { OldMethod, PragmaSetting } from "./pragma";
|
|
5
6
|
|
|
6
7
|
export interface Locus {
|
|
7
8
|
file: string;
|
|
@@ -16,6 +17,8 @@ export interface ObligationWarning {
|
|
|
16
17
|
channel: "toolbox" | "toolboxOnly" | "stderr" | "stdout";
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
export type Warn = (warning: ObligationWarning) => void;
|
|
21
|
+
|
|
19
22
|
export const getLocusPosition = (locus: Locus) => {
|
|
20
23
|
const end = locus.endColumn - 1;
|
|
21
24
|
if (locus.startLine !== locus.endLine)
|
|
@@ -28,8 +31,10 @@ export const getLocusPosition = (locus: Locus) => {
|
|
|
28
31
|
export const getLocusText = (locus: Locus) =>
|
|
29
32
|
`File ${JSON.stringify(locus.file)}, ${getLocusPosition(locus)}`;
|
|
30
33
|
|
|
31
|
-
export const
|
|
32
|
-
|
|
34
|
+
export const getLocationText = (locus: Locus | undefined) =>
|
|
35
|
+
locus ? getLocusText(locus) : "<unknown location>";
|
|
36
|
+
|
|
37
|
+
export const getAtPrefix = (locus: Locus | undefined) => `${getLocationText(locus)}:\n`;
|
|
33
38
|
|
|
34
39
|
export const getErrorNote = (locus: Locus | undefined, message: string): ObligationWarning => ({
|
|
35
40
|
text: `${getAtPrefix(locus)}Error: ${message}`,
|
|
@@ -171,7 +176,7 @@ export type ExprCore =
|
|
|
171
176
|
| { kind: "Sequent"; sequent: Sequent }
|
|
172
177
|
| { kind: "Bang"; expression: Expr; selectors: Selector[] }
|
|
173
178
|
| { kind: "Apply"; operator: Expr; args: Expr[] }
|
|
174
|
-
| { kind: "With"; expression: Expr; method:
|
|
179
|
+
| { kind: "With"; expression: Expr; method: OldMethod }
|
|
175
180
|
| { kind: "If"; condition: Expr; consequent: Expr; alternative: Expr }
|
|
176
181
|
| { kind: "List"; bullet: "And" | "Or" | "Refs"; items: Expr[] }
|
|
177
182
|
| { kind: "Let"; definitions: Defn[]; body: Expr }
|
|
@@ -217,12 +222,16 @@ type DefnCore =
|
|
|
217
222
|
| { kind: "Recursive"; name: string; shape: Shape }
|
|
218
223
|
| { kind: "Operator"; name: string; body: Expr }
|
|
219
224
|
| { kind: "Instance"; name: string; instance: InstanceDefinition }
|
|
220
|
-
| { kind: "Bpragma"; name: string; body: Expr };
|
|
221
|
-
|
|
222
|
-
export type WhereDefined = "Builtin" | "Proof" | "User";
|
|
225
|
+
| { kind: "Bpragma"; name: string; body: Expr; methods: PragmaSetting[][] };
|
|
223
226
|
|
|
224
227
|
export type Visibility = "Visible" | "Hidden";
|
|
225
228
|
|
|
229
|
+
// When a fact holds: at every point of a behavior, or only at the current one.
|
|
230
|
+
export type Time = "Now" | "Always";
|
|
231
|
+
|
|
232
|
+
// A step or a DEFINE in a proof keeps the time of the scope it is made in.
|
|
233
|
+
export type WhereDefined = "Builtin" | "User" | { kind: "Proof"; time: Time };
|
|
234
|
+
|
|
226
235
|
export type Hyp = HypCore & { location?: Locus };
|
|
227
236
|
|
|
228
237
|
type HypCore =
|
|
@@ -241,8 +250,11 @@ type HypCore =
|
|
|
241
250
|
whereDefined: WhereDefined;
|
|
242
251
|
visibility: Visibility;
|
|
243
252
|
isLocal: boolean;
|
|
253
|
+
// Module.Elab judges whether each module definition is constant. One that anonymization meets
|
|
254
|
+
// in a proof, such as a step or a DEFINE, has no judgment, so tlapm never counts it constant.
|
|
255
|
+
isConstnessUnset?: boolean;
|
|
244
256
|
}
|
|
245
|
-
| { kind: "Fact"; expression: Expr; visibility: Visibility };
|
|
257
|
+
| { kind: "Fact"; expression: Expr; visibility: Visibility; time: Time; useLocation?: Locus };
|
|
246
258
|
|
|
247
259
|
export interface Sequent {
|
|
248
260
|
context: Hyp[];
|
|
@@ -290,6 +302,14 @@ export const getHypName = (hyp: Hyp) => {
|
|
|
290
302
|
}
|
|
291
303
|
};
|
|
292
304
|
|
|
305
|
+
export const isBuiltinApply = (
|
|
306
|
+
expression: Expr,
|
|
307
|
+
builtin: Builtin,
|
|
308
|
+
): expression is Extract<Expr, { kind: "Apply" }> =>
|
|
309
|
+
expression.kind === "Apply" &&
|
|
310
|
+
expression.operator.kind === "Internal" &&
|
|
311
|
+
expression.operator.builtin === builtin;
|
|
312
|
+
|
|
293
313
|
export const applyBuiltin = (builtin: Builtin, args: Expr[], from: ExprProps): Expr =>
|
|
294
314
|
at({ kind: "Apply", operator: at({ kind: "Internal", builtin }, from), args }, from);
|
|
295
315
|
|
|
@@ -333,7 +353,6 @@ export const getScopeAt = (scope: Scope | undefined, depth: number) => {
|
|
|
333
353
|
return current;
|
|
334
354
|
};
|
|
335
355
|
|
|
336
|
-
// Maps the items in order, threading a state from each item to the next.
|
|
337
356
|
export const mapAccumulate = <State, Item, Result>(
|
|
338
357
|
state: State,
|
|
339
358
|
items: Item[],
|
|
@@ -348,6 +367,44 @@ export const mapAccumulate = <State, Item, Result>(
|
|
|
348
367
|
return [final, results];
|
|
349
368
|
};
|
|
350
369
|
|
|
370
|
+
// A mapped context prefix: the hypothesis its last key maps to, if any, and the state after it.
|
|
371
|
+
interface MappedPrefix<State> {
|
|
372
|
+
state: State;
|
|
373
|
+
hyp: Hyp | undefined;
|
|
374
|
+
parent: MappedPrefix<State> | undefined;
|
|
375
|
+
next: WeakMap<Hyp, MappedPrefix<State>>;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// mapAccumulate over a context that maps each prefix of keys once, as the obligations of a module
|
|
379
|
+
// share most of their context by identity. The input at each position must depend on the keys up
|
|
380
|
+
// to it alone, and the step on the input, its key, and the state.
|
|
381
|
+
export const createContextMap = <State>(
|
|
382
|
+
initial: State,
|
|
383
|
+
step: (state: State, input: Hyp, key: Hyp) => [State, Hyp | undefined],
|
|
384
|
+
) => {
|
|
385
|
+
const empty: MappedPrefix<State> = {
|
|
386
|
+
state: initial,
|
|
387
|
+
hyp: undefined,
|
|
388
|
+
parent: undefined,
|
|
389
|
+
next: new WeakMap(),
|
|
390
|
+
};
|
|
391
|
+
return (keys: Hyp[], inputs = keys) => {
|
|
392
|
+
const last = keys.reduce((prefix, key, index) => {
|
|
393
|
+
const known = prefix.next.get(key);
|
|
394
|
+
if (known) return known;
|
|
395
|
+
const [state, hyp] = step(prefix.state, inputs[index], key);
|
|
396
|
+
const mapped: MappedPrefix<State> = { state, hyp, parent: prefix, next: new WeakMap() };
|
|
397
|
+
prefix.next.set(key, mapped);
|
|
398
|
+
return mapped;
|
|
399
|
+
}, empty);
|
|
400
|
+
const context: Hyp[] = [];
|
|
401
|
+
for (let prefix: MappedPrefix<State> | undefined = last; prefix; prefix = prefix.parent) {
|
|
402
|
+
if (prefix.hyp) context.push(prefix.hyp);
|
|
403
|
+
}
|
|
404
|
+
return { state: last.state, context: context.reverse() };
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
|
|
351
408
|
export const getFresh = (name: string, level: Level, shape = 0): Hyp => ({
|
|
352
409
|
kind: "Fresh",
|
|
353
410
|
name,
|
|
@@ -366,6 +423,28 @@ export const getBoundedFresh = (name: string, domain: Expr): Hyp => ({
|
|
|
366
423
|
domainVisibility: "Visible",
|
|
367
424
|
});
|
|
368
425
|
|
|
426
|
+
export const getFact = (
|
|
427
|
+
expression: Expr,
|
|
428
|
+
visibility: Visibility,
|
|
429
|
+
time: Time,
|
|
430
|
+
location: Locus | undefined,
|
|
431
|
+
) => ({ kind: "Fact", expression, visibility, time, location }) satisfies Hyp;
|
|
432
|
+
|
|
433
|
+
// What a quantifier binds each name as, a LAMBDA each parameter, and a LET each definition, as
|
|
434
|
+
// Visit.map does.
|
|
435
|
+
export const getBoundFresh = (bound: Bound) => getFresh(bound.name, bound.level);
|
|
436
|
+
|
|
437
|
+
export const getParamFresh = (param: Param) => getFresh(param.name, "Unknown", param.shape);
|
|
438
|
+
|
|
439
|
+
export const getLocalDefn = (definition: Defn) =>
|
|
440
|
+
({
|
|
441
|
+
kind: "Defn",
|
|
442
|
+
definition,
|
|
443
|
+
whereDefined: "User",
|
|
444
|
+
visibility: "Visible",
|
|
445
|
+
isLocal: true,
|
|
446
|
+
}) satisfies Hyp;
|
|
447
|
+
|
|
369
448
|
const applyIndex = (substitution: Substitution, index: number, from: Expr): Expr => {
|
|
370
449
|
switch (substitution.kind) {
|
|
371
450
|
case "Shift":
|
|
@@ -500,6 +579,8 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
500
579
|
case "Sequent":
|
|
501
580
|
return { ...expression, sequent: substituteSequent(substitution, expression.sequent) };
|
|
502
581
|
case "With":
|
|
582
|
+
case "Dot":
|
|
583
|
+
case "Parens":
|
|
503
584
|
return { ...expression, expression: recurse(expression.expression) };
|
|
504
585
|
case "If":
|
|
505
586
|
return {
|
|
@@ -510,7 +591,8 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
510
591
|
};
|
|
511
592
|
case "List":
|
|
512
593
|
return { ...expression, items: substituteExprs(substitution, expression.items) };
|
|
513
|
-
case "Quant":
|
|
594
|
+
case "Quant":
|
|
595
|
+
case "Fcn": {
|
|
514
596
|
const [inner, bounds] = substituteBounds(substitution, expression.bounds);
|
|
515
597
|
return { ...expression, bounds, body: substituteExpr(inner, expression.body) };
|
|
516
598
|
}
|
|
@@ -536,6 +618,7 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
536
618
|
return { ...expression, bounds, element: substituteExpr(inner, expression.element) };
|
|
537
619
|
}
|
|
538
620
|
case "SetEnum":
|
|
621
|
+
case "Tuple":
|
|
539
622
|
return { ...expression, elements: substituteExprs(substitution, expression.elements) };
|
|
540
623
|
case "Arrow":
|
|
541
624
|
return {
|
|
@@ -543,10 +626,6 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
543
626
|
domain: recurse(expression.domain),
|
|
544
627
|
range: recurse(expression.range),
|
|
545
628
|
};
|
|
546
|
-
case "Fcn": {
|
|
547
|
-
const [inner, bounds] = substituteBounds(substitution, expression.bounds);
|
|
548
|
-
return { ...expression, bounds, body: substituteExpr(inner, expression.body) };
|
|
549
|
-
}
|
|
550
629
|
case "FcnApp":
|
|
551
630
|
return {
|
|
552
631
|
...expression,
|
|
@@ -555,8 +634,6 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
555
634
|
};
|
|
556
635
|
case "Product":
|
|
557
636
|
return { ...expression, factors: substituteExprs(substitution, expression.factors) };
|
|
558
|
-
case "Tuple":
|
|
559
|
-
return { ...expression, elements: substituteExprs(substitution, expression.elements) };
|
|
560
637
|
case "Rect":
|
|
561
638
|
case "Record":
|
|
562
639
|
return {
|
|
@@ -572,20 +649,13 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
572
649
|
function: recurse(expression.function),
|
|
573
650
|
specs: mapExceptSpecs(expression.specs, recurse),
|
|
574
651
|
};
|
|
575
|
-
case "Dot":
|
|
576
|
-
return { ...expression, expression: recurse(expression.expression) };
|
|
577
652
|
case "Sub":
|
|
578
653
|
case "Tsub":
|
|
579
|
-
return {
|
|
580
|
-
...expression,
|
|
581
|
-
action: recurse(expression.action),
|
|
582
|
-
subscript: recurse(expression.subscript),
|
|
583
|
-
};
|
|
584
654
|
case "Fair":
|
|
585
655
|
return {
|
|
586
656
|
...expression,
|
|
587
|
-
subscript: recurse(expression.subscript),
|
|
588
657
|
action: recurse(expression.action),
|
|
658
|
+
subscript: recurse(expression.subscript),
|
|
589
659
|
};
|
|
590
660
|
case "Case":
|
|
591
661
|
return {
|
|
@@ -596,8 +666,6 @@ export const substituteExpr = (substitution: Substitution, expression: Expr): Ex
|
|
|
596
666
|
})),
|
|
597
667
|
other: expression.other && recurse(expression.other),
|
|
598
668
|
};
|
|
599
|
-
case "Parens":
|
|
600
|
-
return { ...expression, expression: recurse(expression.expression) };
|
|
601
669
|
}
|
|
602
670
|
};
|
|
603
671
|
|
|
@@ -610,6 +678,9 @@ const isEqualList = <Item>(
|
|
|
610
678
|
isEqual: (left: Item, right: Item) => boolean,
|
|
611
679
|
) => left.length === right.length && left.every((item, index) => isEqual(item, right[index]));
|
|
612
680
|
|
|
681
|
+
const isEqualOptional = (left: Expr | undefined, right: Expr | undefined) =>
|
|
682
|
+
left && right ? isEqualExpr(left, right) : !left && !right;
|
|
683
|
+
|
|
613
684
|
const isEqualFields = (left: Field[], right: Field[]) => {
|
|
614
685
|
const leftMap = new Map(left.map((field) => [field.name, field.value]));
|
|
615
686
|
const rightMap = new Map(right.map((field) => [field.name, field.value]));
|
|
@@ -647,9 +718,7 @@ const isEqualSelector = (left: Selector, right: Selector) => {
|
|
|
647
718
|
};
|
|
648
719
|
|
|
649
720
|
const isEqualDefn = (left: Defn, right: Defn): boolean => {
|
|
650
|
-
if (left.kind === "Operator"
|
|
651
|
-
return isEqualExpr(left.body, right.body);
|
|
652
|
-
if (left.kind === "Bpragma" && right.kind === "Bpragma")
|
|
721
|
+
if ((left.kind === "Operator" || left.kind === "Bpragma") && right.kind === left.kind)
|
|
653
722
|
return isEqualExpr(left.body, right.body);
|
|
654
723
|
if (left.kind === "Instance" && right.kind === "Instance") {
|
|
655
724
|
const leftSubstitutions = left.instance.substitutions.map((entry): Field => ({
|
|
@@ -675,9 +744,11 @@ const isEqualDefn = (left: Defn, right: Defn): boolean => {
|
|
|
675
744
|
|
|
676
745
|
export const isEqualHyp = (left: Hyp, right: Hyp): boolean => {
|
|
677
746
|
if (left.kind === "Fresh" && right.kind === "Fresh") {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
747
|
+
return (
|
|
748
|
+
left.level === right.level &&
|
|
749
|
+
left.shape === right.shape &&
|
|
750
|
+
isEqualOptional(left.domain, right.domain)
|
|
751
|
+
);
|
|
681
752
|
}
|
|
682
753
|
if (left.kind === "Flex" && right.kind === "Flex") return true;
|
|
683
754
|
if (left.kind === "Defn" && right.kind === "Defn") {
|
|
@@ -759,11 +830,11 @@ export const isEqualExpr = (left: Expr, right: Expr): boolean => {
|
|
|
759
830
|
isEqualExpr(left.body, right.body)
|
|
760
831
|
);
|
|
761
832
|
case "Choose":
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
833
|
+
return (
|
|
834
|
+
right.kind === "Choose" &&
|
|
835
|
+
isEqualOptional(left.domain, right.domain) &&
|
|
836
|
+
isEqualExpr(left.body, right.body)
|
|
837
|
+
);
|
|
767
838
|
case "SetSt":
|
|
768
839
|
return (
|
|
769
840
|
right.kind === "SetSt" &&
|
|
@@ -777,7 +848,8 @@ export const isEqualExpr = (left: Expr, right: Expr): boolean => {
|
|
|
777
848
|
isEqualList(left.bounds, right.bounds, isEqualBound)
|
|
778
849
|
);
|
|
779
850
|
case "SetEnum":
|
|
780
|
-
|
|
851
|
+
case "Tuple":
|
|
852
|
+
return right.kind === left.kind && isEqualList(left.elements, right.elements, isEqualExpr);
|
|
781
853
|
case "Arrow":
|
|
782
854
|
return (
|
|
783
855
|
right.kind === "Arrow" &&
|
|
@@ -795,14 +867,11 @@ export const isEqualExpr = (left: Expr, right: Expr): boolean => {
|
|
|
795
867
|
right.kind === "FcnApp" &&
|
|
796
868
|
isEqualList([left.function, ...left.args], [right.function, ...right.args], isEqualExpr)
|
|
797
869
|
);
|
|
798
|
-
case "Tuple":
|
|
799
|
-
return right.kind === "Tuple" && isEqualList(left.elements, right.elements, isEqualExpr);
|
|
800
870
|
case "Product":
|
|
801
871
|
return right.kind === "Product" && isEqualList(left.factors, right.factors, isEqualExpr);
|
|
802
872
|
case "Rect":
|
|
803
|
-
return right.kind === "Rect" && isEqualFields(left.fields, right.fields);
|
|
804
873
|
case "Record":
|
|
805
|
-
return right.kind ===
|
|
874
|
+
return right.kind === left.kind && isEqualFields(left.fields, right.fields);
|
|
806
875
|
case "Except":
|
|
807
876
|
return (
|
|
808
877
|
right.kind === "Except" &&
|
|
@@ -847,9 +916,7 @@ export const isEqualExpr = (left: Expr, right: Expr): boolean => {
|
|
|
847
916
|
? left.arms.length === right.arms.length
|
|
848
917
|
: isEqualExpr(left.arms[0].condition, right.arms[0].condition) &&
|
|
849
918
|
isEqualExpr(left.arms[0].body, right.arms[0].body);
|
|
850
|
-
|
|
851
|
-
if (left.other && right.other) return isEqualExpr(left.other, right.other);
|
|
852
|
-
return !left.other && !right.other;
|
|
919
|
+
return isArmsEqual && isEqualOptional(left.other, right.other);
|
|
853
920
|
}
|
|
854
921
|
case "String":
|
|
855
922
|
return right.kind === "String" && left.value === right.value;
|
|
@@ -874,7 +941,7 @@ export const mapSelectorArgs = (selector: Selector, map: (arg: Expr) => Expr): S
|
|
|
874
941
|
? { ...selector, args: selector.args.map(map) }
|
|
875
942
|
: selector;
|
|
876
943
|
|
|
877
|
-
const mapExceptSpecs = (specs: ExceptSpec[], map: (inner: Expr) => Expr): ExceptSpec[] =>
|
|
944
|
+
export const mapExceptSpecs = (specs: ExceptSpec[], map: (inner: Expr) => Expr): ExceptSpec[] =>
|
|
878
945
|
specs.map((spec) => {
|
|
879
946
|
const value = map(spec.value);
|
|
880
947
|
const trail = spec.trail.map((point): ExceptPoint =>
|
|
@@ -888,7 +955,7 @@ const mapDefnBody = (definition: Defn, map: (body: Expr) => Expr): Defn =>
|
|
|
888
955
|
? { ...definition, body: map(definition.body) }
|
|
889
956
|
: definition;
|
|
890
957
|
|
|
891
|
-
const mapHyp = (hyp: Hyp, map: (inner: Expr) => Expr, hyps: "visible" | "all"): Hyp => {
|
|
958
|
+
export const mapHyp = (hyp: Hyp, map: (inner: Expr) => Expr, hyps: "visible" | "all"): Hyp => {
|
|
892
959
|
if (hyp.kind === "Fresh") return hyp.domain ? { ...hyp, domain: map(hyp.domain) } : hyp;
|
|
893
960
|
if (hyp.kind === "Flex" || (hyps === "visible" && hyp.visibility === "Hidden")) return hyp;
|
|
894
961
|
if (hyp.kind === "Defn") return { ...hyp, definition: mapDefnBody(hyp.definition, map) };
|
|
@@ -907,7 +974,7 @@ export const mapScoped = <State>(
|
|
|
907
974
|
): Expr => {
|
|
908
975
|
const recurse = (inner: Expr) => map(state, inner);
|
|
909
976
|
const bindBounds = (bounds: Bound[]) =>
|
|
910
|
-
bounds.reduce((current, bound) => bind(current,
|
|
977
|
+
bounds.reduce((current, bound) => bind(current, getBoundFresh(bound)), state);
|
|
911
978
|
switch (expression.kind) {
|
|
912
979
|
case "Ix":
|
|
913
980
|
case "Internal":
|
|
@@ -918,7 +985,7 @@ export const mapScoped = <State>(
|
|
|
918
985
|
return expression;
|
|
919
986
|
case "Lambda": {
|
|
920
987
|
const inner = expression.params.reduce((current, param) => {
|
|
921
|
-
const fresh =
|
|
988
|
+
const fresh = getParamFresh(param);
|
|
922
989
|
return bind(current, param.location ? { ...fresh, location: param.location } : fresh);
|
|
923
990
|
}, state);
|
|
924
991
|
return { ...expression, body: map(inner, expression.body) };
|
|
@@ -936,14 +1003,7 @@ export const mapScoped = <State>(
|
|
|
936
1003
|
expression.definitions,
|
|
937
1004
|
(current, definition) => {
|
|
938
1005
|
const mapped = mapDefnBody(definition, (body) => map(current, body));
|
|
939
|
-
|
|
940
|
-
kind: "Defn",
|
|
941
|
-
definition: mapped,
|
|
942
|
-
whereDefined: "User",
|
|
943
|
-
visibility: "Visible",
|
|
944
|
-
isLocal: true,
|
|
945
|
-
};
|
|
946
|
-
return [bind(current, hyp), mapped];
|
|
1006
|
+
return [bind(current, getLocalDefn(mapped)), mapped];
|
|
947
1007
|
},
|
|
948
1008
|
);
|
|
949
1009
|
return { ...expression, definitions, body: map(inner, expression.body) };
|
|
@@ -60,7 +60,7 @@ const getSentinel = (): ScanElement => ({
|
|
|
60
60
|
element: { size: UNKNOWN, token: { kind: "Text", text: "" }, length: 0 },
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
const createFormatter = (): Formatter => {
|
|
63
|
+
const createFormatter = (maxIndent: number): Formatter => {
|
|
64
64
|
const systemBox: QueueElement = {
|
|
65
65
|
size: UNKNOWN,
|
|
66
66
|
token: { kind: "Begin", indent: 0, box: "hov" },
|
|
@@ -72,7 +72,7 @@ const createFormatter = (): Formatter => {
|
|
|
72
72
|
scanStack: [getSentinel(), { leftTotal: 1, element: systemBox }],
|
|
73
73
|
formatStack: [],
|
|
74
74
|
margin: 78,
|
|
75
|
-
maxIndent
|
|
75
|
+
maxIndent,
|
|
76
76
|
spaceLeft: 78,
|
|
77
77
|
currentIndent: 0,
|
|
78
78
|
isNewLine: true,
|
|
@@ -242,7 +242,7 @@ const flush = (formatter: Formatter) => {
|
|
|
242
242
|
const flushNewline = (formatter: Formatter) => {
|
|
243
243
|
flush(formatter);
|
|
244
244
|
const output = [...formatter.output, "\n"];
|
|
245
|
-
Object.assign(formatter, createFormatter());
|
|
245
|
+
Object.assign(formatter, createFormatter(formatter.maxIndent));
|
|
246
246
|
formatter.output = output;
|
|
247
247
|
};
|
|
248
248
|
|
|
@@ -258,8 +258,6 @@ type Command =
|
|
|
258
258
|
|
|
259
259
|
export type Doc = (Command | Doc)[];
|
|
260
260
|
|
|
261
|
-
type FormatArgument = string | Doc;
|
|
262
|
-
|
|
263
261
|
const BOX_KINDS: Record<string, BoxKind> = { h: "h", v: "v", hv: "hv", hov: "hov", b: "b" };
|
|
264
262
|
|
|
265
263
|
const getText = (value: string): Command => ({ kind: "Text", text: value, size: getLength(value) });
|
|
@@ -282,7 +280,7 @@ const parseOpen = (directive: string): Command => {
|
|
|
282
280
|
|
|
283
281
|
// Interprets the subset of OCaml format strings that tlapm's printers use, so ported printers read
|
|
284
282
|
// like the OCaml they come from. Each %s or %a consumes one argument.
|
|
285
|
-
export const format = (pattern: string, ...args:
|
|
283
|
+
export const format = (pattern: string, ...args: (string | Doc)[]): Doc => {
|
|
286
284
|
const doc: Doc = [];
|
|
287
285
|
let argumentIndex = 0;
|
|
288
286
|
let pending = "";
|
|
@@ -399,8 +397,9 @@ const renderInto = (formatter: Formatter, doc: Doc) => {
|
|
|
399
397
|
}
|
|
400
398
|
};
|
|
401
399
|
|
|
402
|
-
|
|
403
|
-
|
|
400
|
+
// 68 is Format's default maximum indent; tlapm's stderr formatter allows 35.
|
|
401
|
+
export const renderDoc = (doc: Doc, maxIndent = 68) => {
|
|
402
|
+
const formatter = createFormatter(maxIndent);
|
|
404
403
|
renderInto(formatter, doc);
|
|
405
404
|
return flush(formatter);
|
|
406
405
|
};
|