tla-ts 0.0.4-dev.2be6058 → 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 +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 +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/codegen.ts +26 -7
- package/src/errors.ts +86 -0
- package/src/evaluate.ts +255 -56
- 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/standard-modules.ts +5 -2
- package/src/successors.ts +25 -6
- 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 +97 -47
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
|
@@ -0,0 +1,321 @@
|
|
|
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
|
+
adjoinAll,
|
|
7
|
+
applyBuiltin,
|
|
8
|
+
at,
|
|
9
|
+
getFresh,
|
|
10
|
+
getLocalDefn,
|
|
11
|
+
getScopeAt,
|
|
12
|
+
mapChildren,
|
|
13
|
+
type Builtin,
|
|
14
|
+
type Expr,
|
|
15
|
+
type Hyp,
|
|
16
|
+
type Scope,
|
|
17
|
+
type Time,
|
|
18
|
+
} from "./expression";
|
|
19
|
+
|
|
20
|
+
const isApplied = (expression: Expr, builtins: Builtin[]) =>
|
|
21
|
+
expression.kind === "Apply" &&
|
|
22
|
+
expression.operator.kind === "Internal" &&
|
|
23
|
+
builtins.includes(expression.operator.builtin);
|
|
24
|
+
|
|
25
|
+
const unchanged = (expression: Expr) => applyBuiltin("UNCHANGED", [expression], expression);
|
|
26
|
+
|
|
27
|
+
const getEquality = (expression: Expr) =>
|
|
28
|
+
applyBuiltin("Eq", [applyBuiltin("Prime", [expression], expression), expression], expression);
|
|
29
|
+
|
|
30
|
+
// E_tla_norm.rewrite_unch: UNCHANGED <<x, <<y>>>> as x' = x /\ y' = y.
|
|
31
|
+
export const rewriteUnchanged = (expression: Expr): Expr => {
|
|
32
|
+
const flatten = (inner: Expr): Expr[] =>
|
|
33
|
+
inner.kind === "Tuple" ? inner.elements.flatMap(flatten) : [inner];
|
|
34
|
+
const items = flatten(expression);
|
|
35
|
+
if (items.length === 0) return at({ kind: "Internal", builtin: "TRUE" }, expression);
|
|
36
|
+
if (items.length === 1) return getEquality(items[0]);
|
|
37
|
+
return at({ kind: "List", bullet: "And", items: items.map(getEquality) }, expression);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Each visitor rewrites the outermost match and leaves the rest of the tree as it is.
|
|
41
|
+
const rewrite =
|
|
42
|
+
(match: (expression: Expr, recurse: (inner: Expr) => Expr) => Expr | undefined) =>
|
|
43
|
+
(expression: Expr): Expr => {
|
|
44
|
+
const recurse = rewrite(match);
|
|
45
|
+
return match(expression, recurse) ?? mapChildren(expression, recurse);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const expandLeadsto = rewrite((expression, recurse) =>
|
|
49
|
+
expression.kind === "Apply" && isApplied(expression, ["Leadsto"])
|
|
50
|
+
? applyBuiltin(
|
|
51
|
+
"BoxTrue",
|
|
52
|
+
[
|
|
53
|
+
applyBuiltin(
|
|
54
|
+
"Implies",
|
|
55
|
+
[
|
|
56
|
+
recurse(expression.args[0]),
|
|
57
|
+
applyBuiltin("Diamond", [recurse(expression.args[1])], expression),
|
|
58
|
+
],
|
|
59
|
+
expression,
|
|
60
|
+
),
|
|
61
|
+
],
|
|
62
|
+
expression,
|
|
63
|
+
)
|
|
64
|
+
: undefined,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export const expandFairness = rewrite((expression) => {
|
|
68
|
+
if (expression.kind !== "Fair") return undefined;
|
|
69
|
+
const action = expression.action;
|
|
70
|
+
const subscript = expression.subscript;
|
|
71
|
+
const enabled = applyBuiltin(
|
|
72
|
+
"ENABLED",
|
|
73
|
+
[at({ kind: "Sub", modal: "Dia", action, subscript }, action)],
|
|
74
|
+
action,
|
|
75
|
+
);
|
|
76
|
+
const outer = expression.fairness === "Weak" ? "Diamond" : "BoxTrue";
|
|
77
|
+
const inner = expression.fairness === "Weak" ? "BoxTrue" : "Diamond";
|
|
78
|
+
return applyBuiltin(
|
|
79
|
+
"Implies",
|
|
80
|
+
[
|
|
81
|
+
applyBuiltin(outer, [applyBuiltin(inner, [enabled], action)], action),
|
|
82
|
+
applyBuiltin(
|
|
83
|
+
"BoxTrue",
|
|
84
|
+
[at({ kind: "Tsub", modal: "Dia", action, subscript }, action)],
|
|
85
|
+
action,
|
|
86
|
+
),
|
|
87
|
+
],
|
|
88
|
+
action,
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const expandAction = rewrite((expression, recurse) => {
|
|
93
|
+
if (expression.kind !== "Sub" && expression.kind !== "Tsub") return undefined;
|
|
94
|
+
const action = recurse(expression.action);
|
|
95
|
+
const subscript = recurse(expression.subscript);
|
|
96
|
+
const step =
|
|
97
|
+
expression.modal === "Box"
|
|
98
|
+
? applyBuiltin("Disj", [action, unchanged(subscript)], expression)
|
|
99
|
+
: applyBuiltin(
|
|
100
|
+
"Conj",
|
|
101
|
+
[action, applyBuiltin("Neg", [unchanged(subscript)], expression)],
|
|
102
|
+
expression,
|
|
103
|
+
);
|
|
104
|
+
if (expression.kind === "Sub") return step;
|
|
105
|
+
return applyBuiltin(expression.modal === "Box" ? "BoxTrue" : "Diamond", [step], expression);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Only getTime uses this, so the locations rewriteUnchanged gives do not matter.
|
|
109
|
+
const expandUnchanged = rewrite((expression) =>
|
|
110
|
+
expression.kind === "Apply" && isApplied(expression, ["UNCHANGED"])
|
|
111
|
+
? rewriteUnchanged(expression.args[0])
|
|
112
|
+
: undefined,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const TEMPORAL_BUILTINS: Builtin[] = [
|
|
116
|
+
"Prime",
|
|
117
|
+
"StrongPrime",
|
|
118
|
+
"Leadsto",
|
|
119
|
+
"ENABLED",
|
|
120
|
+
"UNCHANGED",
|
|
121
|
+
"Cdot",
|
|
122
|
+
"Actplus",
|
|
123
|
+
"BoxTrue",
|
|
124
|
+
"BoxFalse",
|
|
125
|
+
"Diamond",
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const constantBodies = new WeakMap<Expr, boolean>();
|
|
129
|
+
|
|
130
|
+
const isConstantHyp = (scope: Scope | undefined, hyp: Hyp) => {
|
|
131
|
+
switch (hyp.kind) {
|
|
132
|
+
case "Fresh":
|
|
133
|
+
return hyp.level === "Constant";
|
|
134
|
+
case "Defn":
|
|
135
|
+
return hyp.definition.kind === "Operator" && isConstant(scope, hyp.definition.body);
|
|
136
|
+
case "Fact":
|
|
137
|
+
return isConstant(scope, hyp.expression);
|
|
138
|
+
case "Flex":
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const bindConstants = (scope: Scope | undefined, names: string[]) =>
|
|
144
|
+
adjoinAll(
|
|
145
|
+
scope,
|
|
146
|
+
names.map((name) => getFresh(name, "Constant")),
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
export const isConstant = (scope: Scope | undefined, expression: Expr): boolean => {
|
|
150
|
+
const recurse = (inner: Expr) => isConstant(scope, inner);
|
|
151
|
+
switch (expression.kind) {
|
|
152
|
+
case "Ix": {
|
|
153
|
+
const found = getScopeAt(scope, expression.index - 1);
|
|
154
|
+
const hyp = found?.hyp;
|
|
155
|
+
if (hyp?.kind === "Fresh") return hyp.level === "Constant";
|
|
156
|
+
if (hyp?.kind !== "Defn" || hyp.definition.kind !== "Operator" || hyp.isConstnessUnset)
|
|
157
|
+
return false;
|
|
158
|
+
const body = hyp.definition.body;
|
|
159
|
+
const cached = constantBodies.get(body);
|
|
160
|
+
if (cached !== undefined) return cached;
|
|
161
|
+
const result = isConstant(found?.rest, body);
|
|
162
|
+
constantBodies.set(body, result);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
case "Opaque":
|
|
166
|
+
case "String":
|
|
167
|
+
case "Num":
|
|
168
|
+
case "At":
|
|
169
|
+
return true;
|
|
170
|
+
case "Internal":
|
|
171
|
+
return !TEMPORAL_BUILTINS.includes(expression.builtin);
|
|
172
|
+
case "Tquant":
|
|
173
|
+
case "Sub":
|
|
174
|
+
case "Tsub":
|
|
175
|
+
case "Fair":
|
|
176
|
+
return false;
|
|
177
|
+
case "Lambda":
|
|
178
|
+
return isConstant(
|
|
179
|
+
bindConstants(
|
|
180
|
+
scope,
|
|
181
|
+
expression.params.map((param) => param.name),
|
|
182
|
+
),
|
|
183
|
+
expression.body,
|
|
184
|
+
);
|
|
185
|
+
case "Sequent": {
|
|
186
|
+
const inner = expression.sequent.context.reduce<{
|
|
187
|
+
scope: Scope | undefined;
|
|
188
|
+
isGood: boolean;
|
|
189
|
+
}>(
|
|
190
|
+
(state, hyp) => ({
|
|
191
|
+
scope: adjoin(state.scope, hyp),
|
|
192
|
+
isGood: state.isGood && isConstantHyp(state.scope, hyp),
|
|
193
|
+
}),
|
|
194
|
+
{ scope, isGood: true },
|
|
195
|
+
);
|
|
196
|
+
return inner.isGood && isConstant(inner.scope, expression.sequent.active);
|
|
197
|
+
}
|
|
198
|
+
case "Bang":
|
|
199
|
+
case "With":
|
|
200
|
+
case "Dot":
|
|
201
|
+
case "Parens":
|
|
202
|
+
return recurse(expression.expression);
|
|
203
|
+
case "Apply":
|
|
204
|
+
return recurse(expression.operator) && expression.args.every(recurse);
|
|
205
|
+
case "Let": {
|
|
206
|
+
const inner = expression.definitions.reduce<{ scope: Scope | undefined; isGood: boolean }>(
|
|
207
|
+
(state, definition) => ({
|
|
208
|
+
scope: adjoin(state.scope, getLocalDefn(definition)),
|
|
209
|
+
isGood:
|
|
210
|
+
state.isGood &&
|
|
211
|
+
definition.kind === "Operator" &&
|
|
212
|
+
isConstant(state.scope, definition.body),
|
|
213
|
+
}),
|
|
214
|
+
{ scope, isGood: true },
|
|
215
|
+
);
|
|
216
|
+
return inner.isGood && isConstant(inner.scope, expression.body);
|
|
217
|
+
}
|
|
218
|
+
case "Quant":
|
|
219
|
+
case "Fcn":
|
|
220
|
+
case "SetOf": {
|
|
221
|
+
const body = expression.kind === "SetOf" ? expression.element : expression.body;
|
|
222
|
+
return (
|
|
223
|
+
expression.bounds.every(
|
|
224
|
+
(bound) => bound.domain.kind !== "Domain" || recurse(bound.domain.expression),
|
|
225
|
+
) &&
|
|
226
|
+
isConstant(
|
|
227
|
+
bindConstants(
|
|
228
|
+
scope,
|
|
229
|
+
expression.bounds.map((bound) => bound.name),
|
|
230
|
+
),
|
|
231
|
+
body,
|
|
232
|
+
)
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
case "Choose":
|
|
236
|
+
case "SetSt":
|
|
237
|
+
return (
|
|
238
|
+
(expression.domain === undefined || recurse(expression.domain)) &&
|
|
239
|
+
isConstant(bindConstants(scope, [expression.name]), expression.body)
|
|
240
|
+
);
|
|
241
|
+
case "If":
|
|
242
|
+
return (
|
|
243
|
+
recurse(expression.condition) &&
|
|
244
|
+
recurse(expression.consequent) &&
|
|
245
|
+
recurse(expression.alternative)
|
|
246
|
+
);
|
|
247
|
+
case "List":
|
|
248
|
+
return expression.items.every(recurse);
|
|
249
|
+
case "Tuple":
|
|
250
|
+
case "SetEnum":
|
|
251
|
+
return expression.elements.every(recurse);
|
|
252
|
+
case "Product":
|
|
253
|
+
return expression.factors.every(recurse);
|
|
254
|
+
case "FcnApp":
|
|
255
|
+
return recurse(expression.function) && expression.args.every(recurse);
|
|
256
|
+
case "Rect":
|
|
257
|
+
case "Record":
|
|
258
|
+
return expression.fields.every((field) => recurse(field.value));
|
|
259
|
+
case "Arrow":
|
|
260
|
+
return recurse(expression.domain) && recurse(expression.range);
|
|
261
|
+
case "Except":
|
|
262
|
+
return (
|
|
263
|
+
recurse(expression.function) &&
|
|
264
|
+
expression.specs.every(
|
|
265
|
+
(spec) =>
|
|
266
|
+
spec.trail.every((point) => point.kind === "Dot" || recurse(point.expression)) &&
|
|
267
|
+
recurse(spec.value),
|
|
268
|
+
)
|
|
269
|
+
);
|
|
270
|
+
case "Case":
|
|
271
|
+
return (
|
|
272
|
+
expression.arms.every((arm) => recurse(arm.condition) && recurse(arm.body)) &&
|
|
273
|
+
(expression.other === undefined || recurse(expression.other))
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// Temporal_props.box_closure: whether the formula is equivalent to [] of itself, judged by its
|
|
279
|
+
// shape. Under a negation or on the left of =>, <> takes the place of [].
|
|
280
|
+
const isClosed = (scope: Scope | undefined, expression: Expr, isBox: boolean): boolean => {
|
|
281
|
+
if (isConstant(scope, expression)) return true;
|
|
282
|
+
if (expression.kind === "Internal")
|
|
283
|
+
return ["Eq", "Neq", "UNCHANGED", "TRUE", "FALSE"].includes(expression.builtin);
|
|
284
|
+
if (expression.kind === "List")
|
|
285
|
+
return expression.items.every((item) => isClosed(scope, item, isBox));
|
|
286
|
+
if (expression.kind === "Sequent") {
|
|
287
|
+
return isClosed(adjoinAll(scope, expression.sequent.context), expression.sequent.active, isBox);
|
|
288
|
+
}
|
|
289
|
+
if (expression.kind !== "Apply") return false;
|
|
290
|
+
const args = expression.args;
|
|
291
|
+
if (isApplied(expression, ["BoxTrue", "BoxFalse"]) && isBox) return true;
|
|
292
|
+
if (isApplied(expression, ["Diamond"]) && !isBox) return true;
|
|
293
|
+
if (args.length === 1 && isApplied(expression, ["BoxTrue", "BoxFalse", "Diamond", "Prime"]))
|
|
294
|
+
return isClosed(scope, args[0], isBox);
|
|
295
|
+
if (args.length === 1 && isApplied(expression, ["Neg"])) return isClosed(scope, args[0], !isBox);
|
|
296
|
+
if (args.length === 2 && isApplied(expression, ["Conj", "Disj"]))
|
|
297
|
+
return isClosed(scope, args[0], isBox) && isClosed(scope, args[1], isBox);
|
|
298
|
+
if (args.length === 2 && isApplied(expression, ["Implies"]))
|
|
299
|
+
return isClosed(scope, args[0], !isBox) && isClosed(scope, args[1], isBox);
|
|
300
|
+
if (args.length === 2 && isApplied(expression, ["Equiv"]))
|
|
301
|
+
return [true, false].every(
|
|
302
|
+
(isFlipped) =>
|
|
303
|
+
isClosed(scope, args[0], isBox !== isFlipped) &&
|
|
304
|
+
isClosed(scope, args[1], isBox === isFlipped),
|
|
305
|
+
);
|
|
306
|
+
return (
|
|
307
|
+
isClosed(scope, expression.operator, isBox) && args.every((arg) => isClosed(scope, arg, isBox))
|
|
308
|
+
);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export const getTime = (scope: Scope | undefined, expression: Expr): Time =>
|
|
312
|
+
isClosed(scope, expandLeadsto(expandFairness(expandAction(expandUnchanged(expression)))), true)
|
|
313
|
+
? "Always"
|
|
314
|
+
: "Now";
|
|
315
|
+
|
|
316
|
+
// Temporal_props.check_time_change: a proof stays in the always scope while no fact it assumes
|
|
317
|
+
// holds only now.
|
|
318
|
+
export const getScopeTime = (context: Hyp[], time: Time): Time =>
|
|
319
|
+
time === "Always" && context.some((hyp) => hyp.kind === "Fact" && hyp.time === "Now")
|
|
320
|
+
? "Now"
|
|
321
|
+
: 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 }
|
|
@@ -63,74 +63,58 @@ export const expandQuant = (
|
|
|
63
63
|
else groups.push([bound]);
|
|
64
64
|
});
|
|
65
65
|
return groups.reduceRight((inner: Expr, group): Expr => {
|
|
66
|
+
const quantify = (quantified: Bound[], quantifiedBody = inner): Expr => ({
|
|
67
|
+
kind: "Quant",
|
|
68
|
+
quantifier,
|
|
69
|
+
bounds: quantified,
|
|
70
|
+
body: quantifiedBody,
|
|
71
|
+
location: inner.location,
|
|
72
|
+
});
|
|
66
73
|
const first = group[0];
|
|
67
74
|
if (first.kind === "Name") {
|
|
68
|
-
return
|
|
69
|
-
kind
|
|
70
|
-
|
|
71
|
-
bounds: group.flatMap((bound) => (bound.kind === "Name" ? [getNamedBound(bound)] : [])),
|
|
72
|
-
body: inner,
|
|
73
|
-
location: inner.location,
|
|
74
|
-
};
|
|
75
|
+
return quantify(
|
|
76
|
+
group.flatMap((bound) => (bound.kind === "Name" ? [getNamedBound(bound)] : [])),
|
|
77
|
+
);
|
|
75
78
|
}
|
|
76
79
|
const factors = getFactors(first.domain, first.names);
|
|
77
|
-
if (factors)
|
|
78
|
-
return {
|
|
79
|
-
kind: "Quant",
|
|
80
|
-
quantifier,
|
|
81
|
-
bounds: getFactorBounds(first.names, factors),
|
|
82
|
-
body: inner,
|
|
83
|
-
location: inner.location,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
80
|
+
if (factors) return quantify(getFactorBounds(first.names, factors));
|
|
86
81
|
const membership: Expr = {
|
|
87
82
|
kind: "Apply",
|
|
88
83
|
operator: { kind: "Internal", builtin: quantifier === "Exists" ? "Mem" : "Notmem" },
|
|
89
84
|
args: [getNamesTuple(first.names), first.domain],
|
|
90
85
|
};
|
|
91
|
-
return {
|
|
92
|
-
kind: "
|
|
93
|
-
quantifier,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
kind: "List",
|
|
97
|
-
bullet: quantifier === "Exists" ? "And" : "Or",
|
|
98
|
-
items: [membership, inner],
|
|
99
|
-
},
|
|
100
|
-
location: inner.location,
|
|
101
|
-
};
|
|
86
|
+
return quantify(getUnbounded(first.names), {
|
|
87
|
+
kind: "List",
|
|
88
|
+
bullet: quantifier === "Exists" ? "And" : "Or",
|
|
89
|
+
items: [membership, inner],
|
|
90
|
+
});
|
|
102
91
|
}, body);
|
|
103
92
|
};
|
|
104
93
|
|
|
105
94
|
// CHOOSE <<x, y>> \in A \X B: P binds t \in A \X B with x == t[1], y == t[2], and any other
|
|
106
|
-
// domain binds t with \E x, y: t = <<x, y>> /\ P.
|
|
107
|
-
const
|
|
108
|
-
|
|
95
|
+
// domain binds t with \E x, y: t = <<x, y>> /\ P. {<<x, y>> \in S: P} binds t the same way.
|
|
96
|
+
export const expandChoose = (
|
|
97
|
+
binder: { kind: "Choose"; domain: Expr | undefined } | { kind: "SetSt"; domain: Expr },
|
|
109
98
|
names: string[],
|
|
110
|
-
domain: Expr | undefined,
|
|
111
99
|
body: Expr,
|
|
112
|
-
): Expr =>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
kind: "
|
|
121
|
-
|
|
122
|
-
|
|
100
|
+
): Expr => {
|
|
101
|
+
const name = `${binder.kind.toLowerCase()}#${names[0]}`;
|
|
102
|
+
return {
|
|
103
|
+
...binder,
|
|
104
|
+
name,
|
|
105
|
+
body: getFactors(binder.domain, names)
|
|
106
|
+
? { kind: "Let", definitions: getItemDefinitions(name, names), body }
|
|
107
|
+
: {
|
|
108
|
+
kind: "Quant",
|
|
109
|
+
quantifier: "Exists",
|
|
110
|
+
bounds: getUnbounded(names),
|
|
111
|
+
body: {
|
|
112
|
+
kind: "List",
|
|
113
|
+
bullet: "And",
|
|
114
|
+
items: [getEquality(getOpaque(name), getNamesTuple(names)), body],
|
|
115
|
+
},
|
|
123
116
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export const expandChoose = (names: string[], domain: Expr | undefined, body: Expr): Expr => {
|
|
127
|
-
const name = `choose#${names[0]}`;
|
|
128
|
-
return { kind: "Choose", name, domain, body: getChooseBody(name, names, domain, body) };
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const expandSetSt = (names: string[], domain: Expr, body: Expr): Expr => {
|
|
132
|
-
const name = `setst#${names[0]}`;
|
|
133
|
-
return { kind: "SetSt", name, domain, body: getChooseBody(name, names, domain, body) };
|
|
117
|
+
};
|
|
134
118
|
};
|
|
135
119
|
|
|
136
120
|
// A set or function constructor binds each tuple as fcn#x, with its names defined in a LET around
|
|
@@ -157,8 +141,8 @@ const expandConstructorBounds = (bounds: TuplyBound[], value: Expr, isSetOf: boo
|
|
|
157
141
|
kind: "Operator",
|
|
158
142
|
name: choice,
|
|
159
143
|
body: expandChoose(
|
|
144
|
+
{ kind: "Choose", domain: undefined },
|
|
160
145
|
bound.names,
|
|
161
|
-
undefined,
|
|
162
146
|
getEquality(getOpaque(name), getNamesTuple(bound.names)),
|
|
163
147
|
),
|
|
164
148
|
},
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// OCaml's Marshal format, ported from runtime/intern.c and runtime/extern.c, for the values in
|
|
2
|
+
// tlapm's fingerprints file. It writes no sharing, which OCaml reads the same.
|
|
3
|
+
|
|
4
|
+
import { TlaProofError } from "./errors";
|
|
5
|
+
|
|
6
|
+
interface OcamlBlock {
|
|
7
|
+
tag: number;
|
|
8
|
+
fields: OcamlValue[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface OcamlFloat {
|
|
12
|
+
float: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type OcamlValue = number | string | OcamlBlock | OcamlFloat;
|
|
16
|
+
|
|
17
|
+
const MAGIC_NUMBER_SMALL = 0x8495a6be;
|
|
18
|
+
|
|
19
|
+
const CODE = {
|
|
20
|
+
int8: 0x0,
|
|
21
|
+
int16: 0x1,
|
|
22
|
+
int32: 0x2,
|
|
23
|
+
shared8: 0x4,
|
|
24
|
+
shared16: 0x5,
|
|
25
|
+
shared32: 0x6,
|
|
26
|
+
block32: 0x8,
|
|
27
|
+
string8: 0x9,
|
|
28
|
+
string32: 0xa,
|
|
29
|
+
doubleLittle: 0xc,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const PREFIX = { smallInt: 0x40, smallString: 0x20, smallBlock: 0x80 };
|
|
33
|
+
|
|
34
|
+
const HEADER_SIZE = 20;
|
|
35
|
+
|
|
36
|
+
export const block = (tag: number, ...fields: OcamlValue[]): OcamlBlock => ({ tag, fields });
|
|
37
|
+
|
|
38
|
+
export const isBlock = (value: OcamlValue): value is OcamlBlock =>
|
|
39
|
+
typeof value === "object" && "tag" in value;
|
|
40
|
+
|
|
41
|
+
// Returns the value marshaled at offset, and where the next one starts.
|
|
42
|
+
export const readMarshaled = (bytes: Uint8Array, offset: number) => {
|
|
43
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
44
|
+
if (bytes.length < offset + HEADER_SIZE || view.getUint32(offset) !== MAGIC_NUMBER_SMALL)
|
|
45
|
+
throw new TlaProofError("corrupted fingerprint file");
|
|
46
|
+
const end = offset + HEADER_SIZE + view.getUint32(offset + 4);
|
|
47
|
+
const objects: OcamlValue[] = [];
|
|
48
|
+
const state = { position: offset + HEADER_SIZE };
|
|
49
|
+
const take = (length: number) => {
|
|
50
|
+
const start = state.position;
|
|
51
|
+
state.position += length;
|
|
52
|
+
if (state.position > end) throw new TlaProofError("corrupted fingerprint file");
|
|
53
|
+
return start;
|
|
54
|
+
};
|
|
55
|
+
const decoder = new TextDecoder();
|
|
56
|
+
const readString = (length: number) => {
|
|
57
|
+
const start = take(length);
|
|
58
|
+
const value = decoder.decode(bytes.subarray(start, start + length));
|
|
59
|
+
objects.push(value);
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
const readBlock = (tag: number, size: number): OcamlBlock => {
|
|
63
|
+
const value = block(tag);
|
|
64
|
+
if (size > 0) objects.push(value);
|
|
65
|
+
for (let index = 0; index < size; index++) value.fields.push(read());
|
|
66
|
+
return value;
|
|
67
|
+
};
|
|
68
|
+
const readShared = (distance: number) => objects[objects.length - distance];
|
|
69
|
+
const read = (): OcamlValue => {
|
|
70
|
+
const code = bytes[take(1)];
|
|
71
|
+
if (code >= PREFIX.smallBlock) return readBlock(code & 0xf, (code >> 4) & 0x7);
|
|
72
|
+
if (code >= PREFIX.smallInt) return code & 0x3f;
|
|
73
|
+
if (code >= PREFIX.smallString) return readString(code & 0x1f);
|
|
74
|
+
switch (code) {
|
|
75
|
+
case CODE.int8:
|
|
76
|
+
return view.getInt8(take(1));
|
|
77
|
+
case CODE.int16:
|
|
78
|
+
return view.getInt16(take(2));
|
|
79
|
+
case CODE.int32:
|
|
80
|
+
return view.getInt32(take(4));
|
|
81
|
+
case CODE.shared8:
|
|
82
|
+
return readShared(view.getUint8(take(1)));
|
|
83
|
+
case CODE.shared16:
|
|
84
|
+
return readShared(view.getUint16(take(2)));
|
|
85
|
+
case CODE.shared32:
|
|
86
|
+
return readShared(view.getUint32(take(4)));
|
|
87
|
+
case CODE.block32: {
|
|
88
|
+
const header = view.getUint32(take(4));
|
|
89
|
+
return readBlock(header & 0xff, header >>> 10);
|
|
90
|
+
}
|
|
91
|
+
case CODE.string8:
|
|
92
|
+
return readString(view.getUint8(take(1)));
|
|
93
|
+
case CODE.string32:
|
|
94
|
+
return readString(view.getUint32(take(4)));
|
|
95
|
+
case CODE.doubleLittle: {
|
|
96
|
+
const value = { float: view.getFloat64(take(8), true) };
|
|
97
|
+
objects.push(value);
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
throw new TlaProofError("corrupted fingerprint file");
|
|
102
|
+
};
|
|
103
|
+
return { value: read(), next: end };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const writeMarshaled = (value: OcamlValue) => {
|
|
107
|
+
const bytes: number[] = [];
|
|
108
|
+
const sizes = { objects: 0, words32: 0, words64: 0 };
|
|
109
|
+
const pushInteger = (integer: number, length: number) => {
|
|
110
|
+
for (let shift = (length - 1) * 8; shift >= 0; shift -= 8)
|
|
111
|
+
bytes.push((integer >>> shift) & 0xff);
|
|
112
|
+
};
|
|
113
|
+
const encoder = new TextEncoder();
|
|
114
|
+
const write = (inner: OcamlValue) => {
|
|
115
|
+
if (typeof inner === "number") {
|
|
116
|
+
if (inner >= 0 && inner < 0x40) return bytes.push(PREFIX.smallInt + inner);
|
|
117
|
+
if (inner >= -0x80 && inner < 0x80) return bytes.push(CODE.int8, inner & 0xff);
|
|
118
|
+
if (inner >= -0x8000 && inner < 0x8000) {
|
|
119
|
+
bytes.push(CODE.int16);
|
|
120
|
+
return pushInteger(inner, 2);
|
|
121
|
+
}
|
|
122
|
+
bytes.push(CODE.int32);
|
|
123
|
+
return pushInteger(inner, 4);
|
|
124
|
+
}
|
|
125
|
+
sizes.objects++;
|
|
126
|
+
if (typeof inner === "string") {
|
|
127
|
+
const encoded = encoder.encode(inner);
|
|
128
|
+
if (encoded.length < 0x20) bytes.push(PREFIX.smallString + encoded.length);
|
|
129
|
+
else if (encoded.length < 0x100) bytes.push(CODE.string8, encoded.length);
|
|
130
|
+
else {
|
|
131
|
+
bytes.push(CODE.string32);
|
|
132
|
+
pushInteger(encoded.length, 4);
|
|
133
|
+
}
|
|
134
|
+
bytes.push(...encoded);
|
|
135
|
+
sizes.words32 += 1 + Math.floor((encoded.length + 4) / 4);
|
|
136
|
+
sizes.words64 += 1 + Math.floor((encoded.length + 8) / 8);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!isBlock(inner)) {
|
|
140
|
+
const float = new DataView(new ArrayBuffer(8));
|
|
141
|
+
float.setFloat64(0, inner.float, true);
|
|
142
|
+
bytes.push(CODE.doubleLittle, ...new Uint8Array(float.buffer));
|
|
143
|
+
sizes.words32 += 3;
|
|
144
|
+
sizes.words64 += 2;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const size = inner.fields.length;
|
|
148
|
+
if (size === 0) sizes.objects--;
|
|
149
|
+
else {
|
|
150
|
+
sizes.words32 += 1 + size;
|
|
151
|
+
sizes.words64 += 1 + size;
|
|
152
|
+
}
|
|
153
|
+
if (inner.tag < 16 && size < 8) bytes.push(PREFIX.smallBlock + inner.tag + (size << 4));
|
|
154
|
+
else {
|
|
155
|
+
bytes.push(CODE.block32);
|
|
156
|
+
pushInteger(size * 1024 + inner.tag, 4);
|
|
157
|
+
}
|
|
158
|
+
inner.fields.forEach(write);
|
|
159
|
+
};
|
|
160
|
+
write(value);
|
|
161
|
+
const header = new DataView(new ArrayBuffer(HEADER_SIZE));
|
|
162
|
+
[MAGIC_NUMBER_SMALL, bytes.length, sizes.objects, sizes.words32, sizes.words64].forEach(
|
|
163
|
+
(field, index) => header.setUint32(index * 4, field),
|
|
164
|
+
);
|
|
165
|
+
return new Uint8Array([...new Uint8Array(header.buffer), ...bytes]);
|
|
166
|
+
};
|
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);
|