tla-ts 0.0.4-dev.81d0769 → 0.0.4-dev.8fefa42
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 +62 -70
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -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 +515 -0
- package/dist/prove.js +515 -0
- package/dist/run-cli.cjs +30 -47
- package/dist/run-cli.js +30 -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/errors.ts +86 -0
- package/src/evaluate.ts +29 -8
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +258 -37
- package/src/{obligation-anon.ts → obligations/anon.ts} +13 -7
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +2 -2
- package/src/{obligation-expression.ts → obligations/expression.ts} +54 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +134 -61
- package/src/{obligations.ts → obligations/index.ts} +26 -12
- package/src/{obligation-levels.ts → obligations/levels.ts} +12 -2
- package/src/{obligation-module.ts → obligations/module.ts} +46 -20
- package/src/obligations/pickle.ts +100 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +5 -59
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
- package/src/{obligation-source.ts → obligations/source.ts} +91 -35
- package/src/obligations/temporal.ts +319 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
- package/src/parallel-worker.ts +2 -18
- package/src/parallel.ts +10 -43
- package/src/prove/decide-pool.ts +100 -0
- package/src/prove/deciders.ts +27 -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 +477 -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 +520 -0
- package/src/prove/prep/defs.ts +27 -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 +552 -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 +29 -0
- package/src/prove/prove.ts +417 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +256 -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 +210 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +665 -0
- package/src/prove/smt/encode.ts +169 -0
- package/src/prove/smt/extensionality.ts +63 -0
- package/src/prove/smt/flatten.ts +127 -0
- package/src/prove/smt/format.ts +143 -0
- package/src/prove/smt/instances.ts +182 -0
- package/src/prove/smt/rewrite.ts +784 -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 +13 -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 +444 -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 +73 -20
- package/src/successors.ts +24 -5
- package/src/tlc-version.ts +8 -7
- package/src/values.ts +8 -3
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- /package/src/{obligation-format.ts → obligations/format.ts} +0 -0
|
@@ -14,8 +14,8 @@ import type {
|
|
|
14
14
|
SourceLocation,
|
|
15
15
|
SourceRange,
|
|
16
16
|
UseOrHide,
|
|
17
|
-
} from "
|
|
18
|
-
import { TlaProofError, TlaUnsupportedError } from "
|
|
17
|
+
} from "../ast";
|
|
18
|
+
import { TlaProofError, TlaUnsupportedError } from "../errors";
|
|
19
19
|
import {
|
|
20
20
|
at,
|
|
21
21
|
type Bound,
|
|
@@ -27,8 +27,9 @@ import {
|
|
|
27
27
|
type Locus,
|
|
28
28
|
type Selector,
|
|
29
29
|
type Sequent,
|
|
30
|
-
} from "./
|
|
31
|
-
import type { ModuleUnit, Mule } from "./
|
|
30
|
+
} from "./expression";
|
|
31
|
+
import type { ModuleUnit, Mule } from "./module";
|
|
32
|
+
import { readNewMethod, readOldMethod } from "./pragma";
|
|
32
33
|
import {
|
|
33
34
|
expandChoose,
|
|
34
35
|
expandFcn,
|
|
@@ -37,8 +38,8 @@ import {
|
|
|
37
38
|
expandSetSt,
|
|
38
39
|
getUnbounded,
|
|
39
40
|
type TuplyBound,
|
|
40
|
-
} from "./
|
|
41
|
-
import { lookupOperator, type Fixity, type Operator } from "./
|
|
41
|
+
} from "./tuples";
|
|
42
|
+
import { lookupOperator, type Fixity, type Operator } from "./printer";
|
|
42
43
|
import {
|
|
43
44
|
getUnique,
|
|
44
45
|
type Counter,
|
|
@@ -47,7 +48,7 @@ import {
|
|
|
47
48
|
type StepNumber,
|
|
48
49
|
type UseDef,
|
|
49
50
|
type Usable,
|
|
50
|
-
} from "./
|
|
51
|
+
} from "./proof";
|
|
51
52
|
|
|
52
53
|
const BUILTINS: Record<string, Builtin> = {
|
|
53
54
|
"=>": "Implies",
|
|
@@ -231,6 +232,22 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
231
232
|
return locus;
|
|
232
233
|
};
|
|
233
234
|
|
|
235
|
+
const getMethod = (range: SourceRange | undefined) =>
|
|
236
|
+
range && readOldMethod(lines, { line: range.end.line - 1, column: range.end.column });
|
|
237
|
+
|
|
238
|
+
// A method pragma belongs to the node it follows, whose locus then takes it in.
|
|
239
|
+
const withMethod = (range: SourceRange) => {
|
|
240
|
+
const method = getMethod(range);
|
|
241
|
+
const location = getRangeLocus(range);
|
|
242
|
+
return method ? { location: withPragma(location), method } : { location };
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Module.Parser's with_meth, which wraps the expression a method follows.
|
|
246
|
+
const withExpressionMethod = (expression: Expr, range: SourceRange | undefined): Expr => {
|
|
247
|
+
const method = getMethod(range);
|
|
248
|
+
return method ? at({ kind: "With", expression, method }, expression) : expression;
|
|
249
|
+
};
|
|
250
|
+
|
|
234
251
|
const getNameLocus = (name: string, location: SourceLocation): Locus => ({
|
|
235
252
|
file,
|
|
236
253
|
startLine: location.line,
|
|
@@ -376,8 +393,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
376
393
|
const [integer, fraction] = expression.text.split(".");
|
|
377
394
|
return at({ kind: "Num", integer, fraction }, { location });
|
|
378
395
|
}
|
|
379
|
-
case "String":
|
|
380
|
-
|
|
396
|
+
case "String": {
|
|
397
|
+
// tlapm's lexer keeps a string's escapes as written. The location ends at the closing
|
|
398
|
+
// quote.
|
|
399
|
+
const written = /"((?:[^"\\]|\\.)*)"$/.exec(
|
|
400
|
+
(lines[location.endLine - 1] ?? "").slice(0, location.endColumn - 1),
|
|
401
|
+
);
|
|
402
|
+
return at({ kind: "String", value: written?.[1] ?? expression.value }, { location });
|
|
403
|
+
}
|
|
381
404
|
case "Identifier":
|
|
382
405
|
return getName(expression.name, [], location);
|
|
383
406
|
case "Apply": {
|
|
@@ -768,24 +791,26 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
768
791
|
location,
|
|
769
792
|
};
|
|
770
793
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
794
|
+
const operatorBody =
|
|
795
|
+
definition.params.length === 0
|
|
796
|
+
? body
|
|
797
|
+
: at(
|
|
798
|
+
{
|
|
799
|
+
kind: "Lambda",
|
|
800
|
+
params: definition.params.map((param) => ({
|
|
801
|
+
name: getCanonicalName(param.name),
|
|
802
|
+
shape: param.arity,
|
|
803
|
+
...(param.location && { location: getNameLocus(param.name, param.location) }),
|
|
804
|
+
})),
|
|
805
|
+
body,
|
|
806
|
+
},
|
|
807
|
+
{ location },
|
|
808
|
+
);
|
|
809
|
+
const end = definition.location.range?.end;
|
|
810
|
+
const methods = end && readNewMethod(lines, { line: end.line - 1, column: end.column });
|
|
811
|
+
return methods
|
|
812
|
+
? { kind: "Bpragma", name, body: operatorBody, methods, location }
|
|
813
|
+
: { kind: "Operator", name, body: operatorBody, location };
|
|
789
814
|
};
|
|
790
815
|
|
|
791
816
|
const convertNewSymbol = (symbol: NewSymbol): Hyp => {
|
|
@@ -802,6 +827,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
802
827
|
};
|
|
803
828
|
};
|
|
804
829
|
|
|
830
|
+
// Anonymization judges the time of each assumption once it resolves the names in it.
|
|
805
831
|
const convertSequent = (statement: Expression | AssumeProve): Sequent => {
|
|
806
832
|
if (statement.kind !== "AssumeProve")
|
|
807
833
|
return { context: [], active: convertExpression(statement, false) };
|
|
@@ -814,11 +840,18 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
814
840
|
kind: "Fact",
|
|
815
841
|
expression: at({ kind: "Sequent", sequent: convertSequent(assumption) }, { location }),
|
|
816
842
|
visibility: "Visible",
|
|
843
|
+
time: "Now",
|
|
817
844
|
location,
|
|
818
845
|
};
|
|
819
846
|
}
|
|
820
847
|
const expression = convertFactLabel(assumption);
|
|
821
|
-
return {
|
|
848
|
+
return {
|
|
849
|
+
kind: "Fact",
|
|
850
|
+
expression,
|
|
851
|
+
visibility: "Visible",
|
|
852
|
+
time: "Now",
|
|
853
|
+
location: expression.location,
|
|
854
|
+
};
|
|
822
855
|
}),
|
|
823
856
|
active: convertExpression(statement.conclusion, false),
|
|
824
857
|
};
|
|
@@ -880,7 +913,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
880
913
|
if (!proof) return { kind: "Omitted", omission: "Implicit", location: enclosing };
|
|
881
914
|
switch (proof.kind) {
|
|
882
915
|
case "Obvious":
|
|
883
|
-
return { kind: "Obvious",
|
|
916
|
+
return { kind: "Obvious", ...withMethod(proof.keyword) };
|
|
884
917
|
case "Omitted":
|
|
885
918
|
return {
|
|
886
919
|
kind: "Omitted",
|
|
@@ -894,6 +927,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
894
927
|
isOnly: proof.isOnly,
|
|
895
928
|
location: getRangeLocus(proof.keyword),
|
|
896
929
|
step: { kind: "Unnamed", level, id: 0 },
|
|
930
|
+
method: getMethod(proof.location.range),
|
|
897
931
|
};
|
|
898
932
|
case "Steps": {
|
|
899
933
|
// A <*> first step takes the enclosing level only after PROOF, and the top level
|
|
@@ -937,6 +971,11 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
937
971
|
return { ...make(proof), location: mergeLoci(head, proof.location), step: number };
|
|
938
972
|
};
|
|
939
973
|
const plain = (converted: Step): Step => ({ ...converted, location: head, step: number });
|
|
974
|
+
const withStepMethod = (converted: Step): Step => ({
|
|
975
|
+
...converted,
|
|
976
|
+
...withMethod(step.head),
|
|
977
|
+
step: number,
|
|
978
|
+
});
|
|
940
979
|
switch (body.kind) {
|
|
941
980
|
case "Use":
|
|
942
981
|
case "Hide": {
|
|
@@ -946,7 +985,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
946
985
|
);
|
|
947
986
|
const usable = convertUsable(body);
|
|
948
987
|
return body.kind === "Use"
|
|
949
|
-
? {
|
|
988
|
+
? {
|
|
989
|
+
kind: "Use",
|
|
990
|
+
usable,
|
|
991
|
+
isOnly: body.isOnly,
|
|
992
|
+
location,
|
|
993
|
+
step: number,
|
|
994
|
+
method: getMethod(body.location.range),
|
|
995
|
+
}
|
|
950
996
|
: { kind: "Hide", usable, location, step: number };
|
|
951
997
|
}
|
|
952
998
|
case "Instance":
|
|
@@ -957,15 +1003,18 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
957
1003
|
definitions: body.definitions.map((definition) => convertDefinition(definition)),
|
|
958
1004
|
});
|
|
959
1005
|
case "Have":
|
|
960
|
-
return
|
|
1006
|
+
return withStepMethod({
|
|
1007
|
+
kind: "Have",
|
|
1008
|
+
expression: convertExpression(body.expression, false),
|
|
1009
|
+
});
|
|
961
1010
|
case "Take":
|
|
962
|
-
return
|
|
1011
|
+
return withStepMethod({
|
|
963
1012
|
kind: "Take",
|
|
964
1013
|
bounds:
|
|
965
1014
|
body.names.length > 0 ? getUnbounded(body.names) : convertBounds(body.bounds, false),
|
|
966
1015
|
});
|
|
967
1016
|
case "Witness":
|
|
968
|
-
return
|
|
1017
|
+
return withStepMethod({
|
|
969
1018
|
kind: "Witness",
|
|
970
1019
|
expressions: body.expressions.map((expression) => convertExpression(expression, false)),
|
|
971
1020
|
});
|
|
@@ -1048,17 +1097,24 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
1048
1097
|
return {
|
|
1049
1098
|
kind: "Axiom",
|
|
1050
1099
|
name: unit.assumption.name,
|
|
1051
|
-
expression:
|
|
1100
|
+
expression: withExpressionMethod(
|
|
1101
|
+
convertExpression(unit.assumption.expression, false),
|
|
1102
|
+
unit.assumption.location.range,
|
|
1103
|
+
),
|
|
1052
1104
|
location: getLocus(unit.assumption.location),
|
|
1053
1105
|
};
|
|
1054
1106
|
case "Theorem": {
|
|
1055
1107
|
const theorem = unit.theorem;
|
|
1056
1108
|
const location = getLocus(theorem.location);
|
|
1057
1109
|
const end = withPragma(location);
|
|
1110
|
+
const sequent = convertSequent(theorem.statement);
|
|
1058
1111
|
return {
|
|
1059
1112
|
kind: "Theorem",
|
|
1060
1113
|
name: theorem.name,
|
|
1061
|
-
sequent:
|
|
1114
|
+
sequent: {
|
|
1115
|
+
...sequent,
|
|
1116
|
+
active: withExpressionMethod(sequent.active, theorem.statement.location.range),
|
|
1117
|
+
},
|
|
1062
1118
|
axiomCount: 0,
|
|
1063
1119
|
proof: convertProof(theorem.proof, 0, {
|
|
1064
1120
|
...end,
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// tlapm's expansions of temporal operators (Expr.Tla_norm), constant detection (Expr.Constness), and
|
|
2
|
+
// the time of a fact (Expr.Temporal_props): a fact holds always when it is closed under [].
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
adjoin,
|
|
6
|
+
applyBuiltin,
|
|
7
|
+
at,
|
|
8
|
+
getFresh,
|
|
9
|
+
getScopeAt,
|
|
10
|
+
mapChildren,
|
|
11
|
+
type Builtin,
|
|
12
|
+
type Expr,
|
|
13
|
+
type Hyp,
|
|
14
|
+
type Scope,
|
|
15
|
+
type Time,
|
|
16
|
+
} from "./expression";
|
|
17
|
+
|
|
18
|
+
const isApplied = (expression: Expr, builtins: Builtin[]) =>
|
|
19
|
+
expression.kind === "Apply" &&
|
|
20
|
+
expression.operator.kind === "Internal" &&
|
|
21
|
+
builtins.includes(expression.operator.builtin);
|
|
22
|
+
|
|
23
|
+
const unchanged = (expression: Expr) => applyBuiltin("UNCHANGED", [expression], expression);
|
|
24
|
+
|
|
25
|
+
// Each visitor rewrites the outermost match and leaves the rest of the tree as it is.
|
|
26
|
+
const rewrite =
|
|
27
|
+
(match: (expression: Expr, recurse: (inner: Expr) => Expr) => Expr | undefined) =>
|
|
28
|
+
(expression: Expr): Expr => {
|
|
29
|
+
const recurse = rewrite(match);
|
|
30
|
+
return match(expression, recurse) ?? mapChildren(expression, recurse);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const expandLeadsto = rewrite((expression, recurse) =>
|
|
34
|
+
expression.kind === "Apply" && isApplied(expression, ["Leadsto"])
|
|
35
|
+
? applyBuiltin(
|
|
36
|
+
"BoxTrue",
|
|
37
|
+
[
|
|
38
|
+
applyBuiltin(
|
|
39
|
+
"Implies",
|
|
40
|
+
[
|
|
41
|
+
recurse(expression.args[0]),
|
|
42
|
+
applyBuiltin("Diamond", [recurse(expression.args[1])], expression),
|
|
43
|
+
],
|
|
44
|
+
expression,
|
|
45
|
+
),
|
|
46
|
+
],
|
|
47
|
+
expression,
|
|
48
|
+
)
|
|
49
|
+
: undefined,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export const expandFairness = rewrite((expression) => {
|
|
53
|
+
if (expression.kind !== "Fair") return undefined;
|
|
54
|
+
const action = expression.action;
|
|
55
|
+
const subscript = expression.subscript;
|
|
56
|
+
const enabled = applyBuiltin(
|
|
57
|
+
"ENABLED",
|
|
58
|
+
[at({ kind: "Sub", modal: "Dia", action, subscript }, action)],
|
|
59
|
+
action,
|
|
60
|
+
);
|
|
61
|
+
const outer = expression.fairness === "Weak" ? "Diamond" : "BoxTrue";
|
|
62
|
+
const inner = expression.fairness === "Weak" ? "BoxTrue" : "Diamond";
|
|
63
|
+
return applyBuiltin(
|
|
64
|
+
"Implies",
|
|
65
|
+
[
|
|
66
|
+
applyBuiltin(outer, [applyBuiltin(inner, [enabled], action)], action),
|
|
67
|
+
applyBuiltin(
|
|
68
|
+
"BoxTrue",
|
|
69
|
+
[at({ kind: "Tsub", modal: "Dia", action, subscript }, action)],
|
|
70
|
+
action,
|
|
71
|
+
),
|
|
72
|
+
],
|
|
73
|
+
action,
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const expandAction = rewrite((expression, recurse) => {
|
|
78
|
+
if (expression.kind !== "Sub" && expression.kind !== "Tsub") return undefined;
|
|
79
|
+
const action = recurse(expression.action);
|
|
80
|
+
const subscript = recurse(expression.subscript);
|
|
81
|
+
const step =
|
|
82
|
+
expression.modal === "Box"
|
|
83
|
+
? applyBuiltin("Disj", [action, unchanged(subscript)], expression)
|
|
84
|
+
: applyBuiltin(
|
|
85
|
+
"Conj",
|
|
86
|
+
[action, applyBuiltin("Neg", [unchanged(subscript)], expression)],
|
|
87
|
+
expression,
|
|
88
|
+
);
|
|
89
|
+
if (expression.kind === "Sub") return step;
|
|
90
|
+
return applyBuiltin(expression.modal === "Box" ? "BoxTrue" : "Diamond", [step], expression);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const flattenTuple = (expression: Expr): Expr[] =>
|
|
94
|
+
expression.kind === "Tuple" ? expression.elements.flatMap(flattenTuple) : [expression];
|
|
95
|
+
|
|
96
|
+
const expandUnchanged = rewrite((expression) => {
|
|
97
|
+
if (expression.kind !== "Apply" || !isApplied(expression, ["UNCHANGED"])) return undefined;
|
|
98
|
+
const equalities = flattenTuple(expression.args[0]).map((element) =>
|
|
99
|
+
applyBuiltin("Eq", [applyBuiltin("Prime", [element], element), element], element),
|
|
100
|
+
);
|
|
101
|
+
if (equalities.length === 0) return at({ kind: "Internal", builtin: "TRUE" }, expression);
|
|
102
|
+
if (equalities.length === 1) return equalities[0];
|
|
103
|
+
return at({ kind: "List", bullet: "And", items: equalities }, expression);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const TEMPORAL_BUILTINS: Builtin[] = [
|
|
107
|
+
"Prime",
|
|
108
|
+
"StrongPrime",
|
|
109
|
+
"Leadsto",
|
|
110
|
+
"ENABLED",
|
|
111
|
+
"UNCHANGED",
|
|
112
|
+
"Cdot",
|
|
113
|
+
"Actplus",
|
|
114
|
+
"BoxTrue",
|
|
115
|
+
"BoxFalse",
|
|
116
|
+
"Diamond",
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
const constantBodies = new WeakMap<Expr, boolean>();
|
|
120
|
+
|
|
121
|
+
const isConstantHyp = (scope: Scope | undefined, hyp: Hyp) => {
|
|
122
|
+
switch (hyp.kind) {
|
|
123
|
+
case "Fresh":
|
|
124
|
+
return hyp.level === "Constant";
|
|
125
|
+
case "Defn":
|
|
126
|
+
return hyp.definition.kind === "Operator" && isConstant(scope, hyp.definition.body);
|
|
127
|
+
case "Fact":
|
|
128
|
+
return isConstant(scope, hyp.expression);
|
|
129
|
+
case "Flex":
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const isConstantBound = (scope: Scope | undefined, names: string[]) =>
|
|
135
|
+
names.reduce<Scope | undefined>(
|
|
136
|
+
(inner, name) => adjoin(inner, getFresh(name, "Constant")),
|
|
137
|
+
scope,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
export const isConstant = (scope: Scope | undefined, expression: Expr): boolean => {
|
|
141
|
+
const recurse = (inner: Expr) => isConstant(scope, inner);
|
|
142
|
+
switch (expression.kind) {
|
|
143
|
+
case "Ix": {
|
|
144
|
+
const found = getScopeAt(scope, expression.index - 1);
|
|
145
|
+
const hyp = found?.hyp;
|
|
146
|
+
if (hyp?.kind === "Fresh") return hyp.level === "Constant";
|
|
147
|
+
if (hyp?.kind !== "Defn" || hyp.definition.kind !== "Operator" || hyp.isConstnessUnset)
|
|
148
|
+
return false;
|
|
149
|
+
const body = hyp.definition.body;
|
|
150
|
+
const cached = constantBodies.get(body);
|
|
151
|
+
if (cached !== undefined) return cached;
|
|
152
|
+
const result = isConstant(found?.rest, body);
|
|
153
|
+
constantBodies.set(body, result);
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
case "Opaque":
|
|
157
|
+
case "String":
|
|
158
|
+
case "Num":
|
|
159
|
+
case "At":
|
|
160
|
+
return true;
|
|
161
|
+
case "Internal":
|
|
162
|
+
return !TEMPORAL_BUILTINS.includes(expression.builtin);
|
|
163
|
+
case "Tquant":
|
|
164
|
+
case "Sub":
|
|
165
|
+
case "Tsub":
|
|
166
|
+
case "Fair":
|
|
167
|
+
return false;
|
|
168
|
+
case "Lambda":
|
|
169
|
+
return isConstant(
|
|
170
|
+
isConstantBound(
|
|
171
|
+
scope,
|
|
172
|
+
expression.params.map((param) => param.name),
|
|
173
|
+
),
|
|
174
|
+
expression.body,
|
|
175
|
+
);
|
|
176
|
+
case "Sequent": {
|
|
177
|
+
const inner = expression.sequent.context.reduce<{
|
|
178
|
+
scope: Scope | undefined;
|
|
179
|
+
isGood: boolean;
|
|
180
|
+
}>(
|
|
181
|
+
(state, hyp) => ({
|
|
182
|
+
scope: adjoin(state.scope, hyp),
|
|
183
|
+
isGood: state.isGood && isConstantHyp(state.scope, hyp),
|
|
184
|
+
}),
|
|
185
|
+
{ scope, isGood: true },
|
|
186
|
+
);
|
|
187
|
+
return inner.isGood && isConstant(inner.scope, expression.sequent.active);
|
|
188
|
+
}
|
|
189
|
+
case "Bang":
|
|
190
|
+
case "With":
|
|
191
|
+
case "Dot":
|
|
192
|
+
case "Parens":
|
|
193
|
+
return recurse(expression.expression);
|
|
194
|
+
case "Apply":
|
|
195
|
+
return recurse(expression.operator) && expression.args.every(recurse);
|
|
196
|
+
case "Let": {
|
|
197
|
+
const inner = expression.definitions.reduce<{ scope: Scope | undefined; isGood: boolean }>(
|
|
198
|
+
(state, definition) => ({
|
|
199
|
+
scope: adjoin(state.scope, {
|
|
200
|
+
kind: "Defn",
|
|
201
|
+
definition,
|
|
202
|
+
whereDefined: "User",
|
|
203
|
+
visibility: "Visible",
|
|
204
|
+
isLocal: true,
|
|
205
|
+
}),
|
|
206
|
+
isGood:
|
|
207
|
+
state.isGood &&
|
|
208
|
+
definition.kind === "Operator" &&
|
|
209
|
+
isConstant(state.scope, definition.body),
|
|
210
|
+
}),
|
|
211
|
+
{ scope, isGood: true },
|
|
212
|
+
);
|
|
213
|
+
return inner.isGood && isConstant(inner.scope, expression.body);
|
|
214
|
+
}
|
|
215
|
+
case "Quant":
|
|
216
|
+
case "Fcn":
|
|
217
|
+
case "SetOf": {
|
|
218
|
+
const body = expression.kind === "SetOf" ? expression.element : expression.body;
|
|
219
|
+
return (
|
|
220
|
+
expression.bounds.every(
|
|
221
|
+
(bound) => bound.domain.kind !== "Domain" || recurse(bound.domain.expression),
|
|
222
|
+
) &&
|
|
223
|
+
isConstant(
|
|
224
|
+
isConstantBound(
|
|
225
|
+
scope,
|
|
226
|
+
expression.bounds.map((bound) => bound.name),
|
|
227
|
+
),
|
|
228
|
+
body,
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
case "Choose":
|
|
233
|
+
case "SetSt":
|
|
234
|
+
return (
|
|
235
|
+
(expression.domain === undefined || recurse(expression.domain)) &&
|
|
236
|
+
isConstant(isConstantBound(scope, [expression.name]), expression.body)
|
|
237
|
+
);
|
|
238
|
+
case "If":
|
|
239
|
+
return (
|
|
240
|
+
recurse(expression.condition) &&
|
|
241
|
+
recurse(expression.consequent) &&
|
|
242
|
+
recurse(expression.alternative)
|
|
243
|
+
);
|
|
244
|
+
case "List":
|
|
245
|
+
return expression.items.every(recurse);
|
|
246
|
+
case "Tuple":
|
|
247
|
+
case "SetEnum":
|
|
248
|
+
return expression.elements.every(recurse);
|
|
249
|
+
case "Product":
|
|
250
|
+
return expression.factors.every(recurse);
|
|
251
|
+
case "FcnApp":
|
|
252
|
+
return recurse(expression.function) && expression.args.every(recurse);
|
|
253
|
+
case "Rect":
|
|
254
|
+
case "Record":
|
|
255
|
+
return expression.fields.every((field) => recurse(field.value));
|
|
256
|
+
case "Arrow":
|
|
257
|
+
return recurse(expression.domain) && recurse(expression.range);
|
|
258
|
+
case "Except":
|
|
259
|
+
return (
|
|
260
|
+
recurse(expression.function) &&
|
|
261
|
+
expression.specs.every(
|
|
262
|
+
(spec) =>
|
|
263
|
+
spec.trail.every((point) => point.kind === "Dot" || recurse(point.expression)) &&
|
|
264
|
+
recurse(spec.value),
|
|
265
|
+
)
|
|
266
|
+
);
|
|
267
|
+
case "Case":
|
|
268
|
+
return (
|
|
269
|
+
expression.arms.every((arm) => recurse(arm.condition) && recurse(arm.body)) &&
|
|
270
|
+
(expression.other === undefined || recurse(expression.other))
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// Temporal_props.box_closure: whether the formula is equivalent to [] of itself, judged by its
|
|
276
|
+
// shape. Under a negation or on the left of =>, <> takes the place of [].
|
|
277
|
+
const isClosed = (scope: Scope | undefined, expression: Expr, isBox: boolean): boolean => {
|
|
278
|
+
if (isConstant(scope, expression)) return true;
|
|
279
|
+
if (expression.kind === "Internal")
|
|
280
|
+
return ["Eq", "Neq", "UNCHANGED", "TRUE", "FALSE"].includes(expression.builtin);
|
|
281
|
+
if (expression.kind === "List")
|
|
282
|
+
return expression.items.every((item) => isClosed(scope, item, isBox));
|
|
283
|
+
if (expression.kind === "Sequent") {
|
|
284
|
+
const inner = expression.sequent.context.reduce<Scope | undefined>(adjoin, scope);
|
|
285
|
+
return isClosed(inner, expression.sequent.active, isBox);
|
|
286
|
+
}
|
|
287
|
+
if (expression.kind !== "Apply") return false;
|
|
288
|
+
const args = expression.args;
|
|
289
|
+
if (isApplied(expression, ["BoxTrue", "BoxFalse"]) && isBox) return true;
|
|
290
|
+
if (isApplied(expression, ["Diamond"]) && !isBox) return true;
|
|
291
|
+
if (args.length === 1 && isApplied(expression, ["BoxTrue", "BoxFalse", "Diamond", "Prime"]))
|
|
292
|
+
return isClosed(scope, args[0], isBox);
|
|
293
|
+
if (args.length === 1 && isApplied(expression, ["Neg"])) return isClosed(scope, args[0], !isBox);
|
|
294
|
+
if (args.length === 2 && isApplied(expression, ["Conj", "Disj"]))
|
|
295
|
+
return isClosed(scope, args[0], isBox) && isClosed(scope, args[1], isBox);
|
|
296
|
+
if (args.length === 2 && isApplied(expression, ["Implies"]))
|
|
297
|
+
return isClosed(scope, args[0], !isBox) && isClosed(scope, args[1], isBox);
|
|
298
|
+
if (args.length === 2 && isApplied(expression, ["Equiv"]))
|
|
299
|
+
return [true, false].every(
|
|
300
|
+
(isFlipped) =>
|
|
301
|
+
isClosed(scope, args[0], isBox !== isFlipped) &&
|
|
302
|
+
isClosed(scope, args[1], isBox === isFlipped),
|
|
303
|
+
);
|
|
304
|
+
return (
|
|
305
|
+
isClosed(scope, expression.operator, isBox) && args.every((arg) => isClosed(scope, arg, isBox))
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export const getTime = (scope: Scope | undefined, expression: Expr): Time =>
|
|
310
|
+
isClosed(scope, expandLeadsto(expandFairness(expandAction(expandUnchanged(expression)))), true)
|
|
311
|
+
? "Always"
|
|
312
|
+
: "Now";
|
|
313
|
+
|
|
314
|
+
// Temporal_props.check_time_change: a proof stays in the always scope while no fact it assumes
|
|
315
|
+
// holds only now.
|
|
316
|
+
export const getScopeTime = (context: Hyp[], time: Time): Time =>
|
|
317
|
+
time === "Always" && context.some((hyp) => hyp.kind === "Fact" && hyp.time === "Now")
|
|
318
|
+
? "Now"
|
|
319
|
+
: time;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// tlapm's E_tuply_declarations: declarations such as <<x, y>> \in S become declarations of names.
|
|
2
2
|
|
|
3
|
-
import type { Bound, BoundDomain, Defn, Expr } from "./
|
|
3
|
+
import type { Bound, BoundDomain, Defn, Expr } from "./expression";
|
|
4
4
|
|
|
5
5
|
export type TuplyBound =
|
|
6
6
|
| { kind: "Name"; name: string; domain: BoundDomain }
|
package/src/parallel-worker.ts
CHANGED
|
@@ -7,20 +7,14 @@ import {
|
|
|
7
7
|
isSharedFingerprintsFull,
|
|
8
8
|
writeStateFingerprint,
|
|
9
9
|
} from "./fingerprints";
|
|
10
|
-
import type {
|
|
11
|
-
CoordinatorMessage,
|
|
12
|
-
LevelMessage,
|
|
13
|
-
Port,
|
|
14
|
-
StartMessage,
|
|
15
|
-
WorkerMessage,
|
|
16
|
-
} from "./parallel";
|
|
10
|
+
import type { CoordinatorMessage, LevelMessage, StartMessage, WorkerMessage } from "./parallel";
|
|
17
11
|
import { getSuccessors, type Successor } from "./successors";
|
|
18
12
|
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
19
13
|
import { OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
20
14
|
import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
|
|
21
15
|
import { getRankedStringCount, setStringOrder, setValueVersion, type Value } from "./values";
|
|
16
|
+
import { getParentPort, type Port } from "./worker";
|
|
22
17
|
|
|
23
|
-
const WORKER_THREADS_MODULE = "node:worker_threads";
|
|
24
18
|
const LOCKED = -1;
|
|
25
19
|
|
|
26
20
|
interface Expansion {
|
|
@@ -36,16 +30,6 @@ interface Expansion {
|
|
|
36
30
|
fingerprintStates: Value[][];
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
const getParentPort = async () => {
|
|
40
|
-
if (typeof (globalThis as { postMessage?: unknown }).postMessage === "function") {
|
|
41
|
-
return globalThis as unknown as Port;
|
|
42
|
-
}
|
|
43
|
-
const threads: typeof import("node:worker_threads") = await import(
|
|
44
|
-
/* @vite-ignore */ /* webpackIgnore: true */ WORKER_THREADS_MODULE
|
|
45
|
-
);
|
|
46
|
-
return threads.parentPort as unknown as Port;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
33
|
const run = (start: StartMessage, parent: Port) => {
|
|
50
34
|
const modules = new Map(start.modules);
|
|
51
35
|
const loadModule = (name: string) => modules.get(name);
|
package/src/parallel.ts
CHANGED
|
@@ -29,15 +29,7 @@ import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
|
29
29
|
import { createStateEncoder, type EncodedStates } from "./transfer";
|
|
30
30
|
import type { TlcVersion } from "./tlc-version";
|
|
31
31
|
import { getRankedStringCount, setStringOrder, setValueVersion, type Value } from "./values";
|
|
32
|
-
|
|
33
|
-
const WORKER_THREADS_MODULE = "node:worker_threads";
|
|
34
|
-
|
|
35
|
-
export interface Port {
|
|
36
|
-
postMessage: (message: unknown, transfer?: unknown[]) => void;
|
|
37
|
-
addEventListener: (type: "message", listener: (event: { data: unknown }) => void) => void;
|
|
38
|
-
removeEventListener?: (type: "message", listener: (event: { data: unknown }) => void) => void;
|
|
39
|
-
start?: () => void;
|
|
40
|
-
}
|
|
32
|
+
import { spawnWorker, type Port } from "./worker";
|
|
41
33
|
|
|
42
34
|
export interface StartMessage {
|
|
43
35
|
type: "start";
|
|
@@ -76,39 +68,6 @@ export type CoordinatorMessage =
|
|
|
76
68
|
| { type: "level"; level: number }
|
|
77
69
|
| { type: "resize"; fingerprints: SharedFingerprints };
|
|
78
70
|
|
|
79
|
-
interface WorkerHandle {
|
|
80
|
-
postMessage: (message: unknown, transfer?: unknown[]) => void;
|
|
81
|
-
terminate: () => void;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
interface WebWorker {
|
|
85
|
-
postMessage: (message: unknown, transfer?: unknown[]) => void;
|
|
86
|
-
addEventListener: (type: string, listener: (event: { data: unknown }) => void) => void;
|
|
87
|
-
terminate: () => void;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
declare const Worker: new (url: URL, options: { type: "module" }) => WebWorker;
|
|
91
|
-
|
|
92
|
-
const spawnWorker = async (onMessage: (message: WorkerMessage) => void): Promise<WorkerHandle> => {
|
|
93
|
-
if (typeof Worker === "function") {
|
|
94
|
-
const worker = new Worker(new URL("./parallel-worker.js", import.meta.url), { type: "module" });
|
|
95
|
-
worker.addEventListener("message", (event) => onMessage(event.data as WorkerMessage));
|
|
96
|
-
worker.addEventListener("error", () => onMessage({ type: "abort" }));
|
|
97
|
-
return worker;
|
|
98
|
-
}
|
|
99
|
-
const threads: typeof import("node:worker_threads") = await import(
|
|
100
|
-
/* @vite-ignore */ /* webpackIgnore: true */ WORKER_THREADS_MODULE
|
|
101
|
-
);
|
|
102
|
-
const worker = new threads.Worker(new URL("./parallel-worker.js", import.meta.url));
|
|
103
|
-
worker.on("message", onMessage);
|
|
104
|
-
worker.on("error", () => onMessage({ type: "abort" }));
|
|
105
|
-
return {
|
|
106
|
-
postMessage: (message, transfer) =>
|
|
107
|
-
worker.postMessage(message, transfer as Parameters<typeof worker.postMessage>[1]),
|
|
108
|
-
terminate: () => void worker.terminate(),
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
|
|
112
71
|
export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
113
72
|
const config =
|
|
114
73
|
typeof options.config === "string"
|
|
@@ -290,7 +249,15 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
290
249
|
const ready = waitForReports(count);
|
|
291
250
|
const requests = new Int32Array(new SharedArrayBuffer(count * 4));
|
|
292
251
|
const remaining = new Int32Array(new SharedArrayBuffer(count * 4));
|
|
293
|
-
const workers = await Promise.all(
|
|
252
|
+
const workers = await Promise.all(
|
|
253
|
+
Array.from({ length: count }, () =>
|
|
254
|
+
spawnWorker(
|
|
255
|
+
new URL("./parallel-worker.js", import.meta.url),
|
|
256
|
+
(message) => onMessage(message as WorkerMessage),
|
|
257
|
+
() => onMessage({ type: "abort" }),
|
|
258
|
+
),
|
|
259
|
+
),
|
|
260
|
+
);
|
|
294
261
|
const terminate = () => workers.forEach((worker) => worker.terminate());
|
|
295
262
|
const channels = new Map<string, MessageChannel>();
|
|
296
263
|
const getPort = (from: number, to: number) => {
|