tla-ts 0.0.9 → 0.0.10-dev.63a6693bd
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 +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +29 -29
- package/dist/deciders.js +42 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +117 -37
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +48 -62
- package/src/bags.ts +99 -102
- package/src/builtins.ts +28 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +599 -754
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +19 -12
- package/src/cli/tlapm.ts +14 -25
- package/src/cli/tlc-arguments.ts +652 -0
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +309 -658
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +196 -74
- package/src/config.ts +140 -109
- package/src/coverage.ts +830 -0
- package/src/dependencies.ts +14 -53
- package/src/dfid.ts +618 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +169 -335
- package/src/errors.ts +71 -55
- package/src/evaluate.ts +598 -340
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +126 -21
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +46 -58
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +103 -153
- package/src/liveness.ts +150 -109
- package/src/obligations/action.ts +8 -39
- package/src/obligations/anonymize.ts +88 -82
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +20 -21
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +46 -49
- package/src/obligations/index.ts +2 -13
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +28 -53
- package/src/obligations/normalize.ts +7 -25
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +42 -58
- package/src/obligations/source.ts +48 -78
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +13 -19
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +30 -60
- package/src/parallel.ts +57 -71
- package/src/parser.ts +584 -316
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +8 -13
- package/src/prover/deciders.ts +3 -7
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +114 -115
- package/src/prover/isabelle/isar/method.ts +29 -53
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +26 -36
- package/src/prover/isabelle/isar/type-check.ts +17 -31
- package/src/prover/isabelle/provers/blast/blast.ts +17 -104
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +28 -51
- package/src/prover/isabelle/pure/bicompose.ts +25 -38
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +3 -17
- package/src/prover/isabelle/pure/drule.ts +33 -42
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +2 -15
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +17 -62
- package/src/prover/isabelle/pure/rewriter.ts +31 -67
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +3 -32
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +48 -47
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +27 -47
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +17 -24
- package/src/prover/isabelle/tla/context.ts +15 -18
- package/src/prover/isabelle/tla/logic.ts +14 -32
- package/src/prover/isabelle/tla/simpdata.ts +46 -43
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +14 -54
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +2 -21
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +33 -39
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +87 -100
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +20 -28
- package/src/prover/smt/data.ts +433 -424
- package/src/prover/smt/encode.ts +43 -52
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +663 -667
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -165
- package/src/prover/smt/solver/auf-solver.ts +8 -44
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +7 -64
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +4 -35
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +1 -6
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +7 -100
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +9 -102
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +36 -135
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +18 -58
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +3 -37
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +15 -32
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +23 -88
- package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
- package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +10 -69
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
- package/src/prover/smt/solver/nlsat/solver.ts +18 -90
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -52
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +27 -47
- package/src/prover/smt/solver/quantifier-manager.ts +2 -13
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +80 -131
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +1 -7
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +45 -40
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +21 -20
- package/src/prover/verdict.ts +7 -2
- package/src/prover/zenon/check/check.ts +1 -11
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +1 -6
- package/src/prover/zenon/check/relations.ts +2 -14
- package/src/prover/zenon/check/rewrites.ts +2 -21
- package/src/prover/zenon/check/sets.ts +40 -61
- package/src/prover/zenon/check/terms.ts +1 -19
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +2 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +8 -26
- package/src/prover/zenon/index-table.ts +26 -57
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +36 -64
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +2 -20
- package/src/prover/zenon/mltoll.ts +66 -104
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +4 -12
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +5 -31
- package/src/prover/zenon/tla/functions.ts +59 -31
- package/src/prover/zenon/tla/llproof.ts +67 -76
- package/src/prover/zenon/tla/records.ts +57 -33
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +83 -53
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +66 -64
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +67 -184
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +191 -2764
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +58 -77
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +5 -43
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +49 -76
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +35 -117
- package/src/search.ts +541 -163
- package/src/simulate.ts +709 -0
- package/src/spec-description.ts +192 -100
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +264 -95
- package/src/state-graph.ts +52 -31
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +266 -99
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +125 -54
- package/src/tlc/order.ts +39 -69
- package/src/tlc/random.ts +37 -49
- package/src/tlc/replay.ts +553 -228
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +78 -44
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +249 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +479 -0
- package/src/typescript/collections.ts +614 -0
- package/src/typescript/compile.ts +63 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +154 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +162 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +167 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -484
- package/src/worker.ts +7 -8
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/mam.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
|
|
3
|
-
// code trees, new relevant terms become candidates of the tree for their label, and the inverted
|
|
4
|
-
// path index with approximate label sets finds the candidates that a merge creates.
|
|
5
|
-
import { AstManager, KIND_VAR } from "./ast";
|
|
1
|
+
// Ported from Z3 (src/smt/mam.cpp), MIT license, see z3-license.txt.
|
|
2
|
+
import { type AstManager, KIND_VAR } from "./ast";
|
|
6
3
|
import type { Context } from "./context";
|
|
7
4
|
import type { Enode } from "./enode";
|
|
8
5
|
import { hashU, mkMix } from "./hash";
|
|
@@ -10,8 +7,6 @@ import { type CodeTree, Compiler, hasHash, type LabelHasher } from "./mam-compil
|
|
|
10
7
|
import { Interpreter, type OnMatch } from "./mam-interpreter";
|
|
11
8
|
import { setAt, shrink } from "./array";
|
|
12
9
|
|
|
13
|
-
// A step from a term to its parent: the parent's label, the position of the term in it, and an
|
|
14
|
-
// optional ground argument the parent must also have.
|
|
15
10
|
interface Path {
|
|
16
11
|
label: number;
|
|
17
12
|
argIndex: number;
|
|
@@ -21,8 +16,6 @@ interface Path {
|
|
|
21
16
|
child: Path | null;
|
|
22
17
|
}
|
|
23
18
|
|
|
24
|
-
// The inverted path index shares the prefixes of paths. Siblings are alternatives for the same step,
|
|
25
|
-
// the first child is the next step, and a code receives the terms where a path ends.
|
|
26
19
|
interface PathTree {
|
|
27
20
|
label: number;
|
|
28
21
|
argIndex: number;
|
|
@@ -33,7 +26,6 @@ interface PathTree {
|
|
|
33
26
|
code: CodeTree | null;
|
|
34
27
|
firstChild: PathTree | null;
|
|
35
28
|
sibling: PathTree | null;
|
|
36
|
-
// The roots that collect_parents visits at this node, while it walks the tree.
|
|
37
29
|
todo: Enode[] | null;
|
|
38
30
|
}
|
|
39
31
|
|
|
@@ -54,7 +46,6 @@ const isEqualPath = (first: Path, second: Path): boolean => {
|
|
|
54
46
|
}
|
|
55
47
|
};
|
|
56
48
|
|
|
57
|
-
// A multi-pattern of a quantifier: the terms of one of its patterns.
|
|
58
49
|
interface MultiPattern {
|
|
59
50
|
quantifier: number;
|
|
60
51
|
patterns: number[];
|
|
@@ -62,7 +53,6 @@ interface MultiPattern {
|
|
|
62
53
|
|
|
63
54
|
export class Mam implements LabelHasher {
|
|
64
55
|
private trees = new Map<number, CodeTree>();
|
|
65
|
-
// m_shared_enodes: the ground terms of the patterns.
|
|
66
56
|
private sharedEnodes = new Set<Enode>();
|
|
67
57
|
private toMatch: CodeTree[] = [];
|
|
68
58
|
private newPatterns: MultiPattern[] = [];
|
|
@@ -72,12 +62,9 @@ export class Mam implements LabelHasher {
|
|
|
72
62
|
private clbls = new Set<number>();
|
|
73
63
|
private r1: Enode | null = null;
|
|
74
64
|
private r2: Enode | null = null;
|
|
75
|
-
// The nodes that collect_parents marks, to unmark at the end of each level.
|
|
76
65
|
private visitedParents: Enode[] = [];
|
|
77
66
|
private queuedRoots: Enode[] = [];
|
|
78
67
|
private labelHashes: (number | undefined)[] = [];
|
|
79
|
-
// m_trail_stack: the matcher undoes its changes with a trail of its own, which the quantifier
|
|
80
|
-
// manager pops before the context pops its trail.
|
|
81
68
|
private trail: (() => void)[] = [];
|
|
82
69
|
private trailScopes: number[] = [];
|
|
83
70
|
private compiler: Compiler;
|
|
@@ -87,7 +74,7 @@ export class Mam implements LabelHasher {
|
|
|
87
74
|
private context: Context,
|
|
88
75
|
onMatch: OnMatch,
|
|
89
76
|
) {
|
|
90
|
-
this.compiler = new Compiler(context
|
|
77
|
+
this.compiler = new Compiler(context, this);
|
|
91
78
|
this.interpreter = new Interpreter(context, onMatch);
|
|
92
79
|
}
|
|
93
80
|
|
|
@@ -95,7 +82,6 @@ export class Mam implements LabelHasher {
|
|
|
95
82
|
return this.context.manager;
|
|
96
83
|
}
|
|
97
84
|
|
|
98
|
-
// label_hasher: Bob Jenkins' mix of the small id of a declaration, in [0, 64).
|
|
99
85
|
getLabelHash(decl: number) {
|
|
100
86
|
const cached = this.labelHashes[decl];
|
|
101
87
|
if (cached !== undefined) return cached;
|
|
@@ -104,9 +90,7 @@ export class Mam implements LabelHasher {
|
|
|
104
90
|
return hash;
|
|
105
91
|
}
|
|
106
92
|
|
|
107
|
-
//
|
|
108
|
-
// The context's trail undoes both. Z3 pops it after the matcher's trail, so the labels of a root
|
|
109
|
-
// can keep a hash that a merge undone by the matcher's trail added.
|
|
93
|
+
// Z3 undoes this on the context's trail, popped after the matcher's, so a root can keep a hash that an undone merge added.
|
|
110
94
|
private setLblHash(node: Enode) {
|
|
111
95
|
const hash = hashU(this.manager.ids[node.owner]) & 63;
|
|
112
96
|
node.lblHash = hash;
|
|
@@ -184,12 +168,10 @@ export class Mam implements LabelHasher {
|
|
|
184
168
|
if (this.context.isRelevant(node.owner)) this.updateLbls(node, hash);
|
|
185
169
|
}
|
|
186
170
|
|
|
187
|
-
// mk_code: the code tree of a path, which runs each candidate once.
|
|
188
171
|
private mkCode(mp: MultiPattern, patternIndex: number) {
|
|
189
172
|
return this.compiler.mkTree(mp.quantifier, mp.patterns, patternIndex, true);
|
|
190
173
|
}
|
|
191
174
|
|
|
192
|
-
// mk_path_tree: a chain of path tree nodes whose last one has a code for the path's pattern.
|
|
193
175
|
private mkPathTree(path: Path, mp: MultiPattern): PathTree {
|
|
194
176
|
const tree: PathTree = {
|
|
195
177
|
label: path.label,
|
|
@@ -211,7 +193,6 @@ export class Mam implements LabelHasher {
|
|
|
211
193
|
return tree;
|
|
212
194
|
}
|
|
213
195
|
|
|
214
|
-
// compiler::insert for path trees.
|
|
215
196
|
private insertPath(head: PathTree, path: Path, mp: MultiPattern) {
|
|
216
197
|
let isLabelFound = false;
|
|
217
198
|
let last = head;
|
|
@@ -388,7 +369,6 @@ export class Mam implements LabelHasher {
|
|
|
388
369
|
patterns.forEach((pattern, index) => this.updateFilters(pattern, null, index, varPaths, mp));
|
|
389
370
|
this.collectGroundExprs(quantifier, patterns);
|
|
390
371
|
this.newPatterns.push(mp);
|
|
391
|
-
// code_tree_map::add_pattern for each pattern as the first one.
|
|
392
372
|
patterns.forEach((pattern, firstIndex) => {
|
|
393
373
|
if (manager.isGround(pattern)) return;
|
|
394
374
|
const label = manager.decls[pattern];
|
|
@@ -403,8 +383,6 @@ export class Mam implements LabelHasher {
|
|
|
403
383
|
});
|
|
404
384
|
}
|
|
405
385
|
|
|
406
|
-
// collect_ground_exprs: the ground patterns become relevant enodes, and the ground subterms of the
|
|
407
|
-
// other patterns become enodes that theory combination treats as shared.
|
|
408
386
|
private collectGroundExprs(quantifier: number, patterns: number[]) {
|
|
409
387
|
const manager = this.manager;
|
|
410
388
|
const todo: number[] = [];
|
|
@@ -440,8 +418,6 @@ export class Mam implements LabelHasher {
|
|
|
440
418
|
return this.sharedEnodes.has(node);
|
|
441
419
|
}
|
|
442
420
|
|
|
443
|
-
// add_candidate, with compress_candidates, which keeps the first of each candidate once there are
|
|
444
|
-
// many, as match does.
|
|
445
421
|
private addCandidateTo(tree: CodeTree, node: Enode) {
|
|
446
422
|
if (tree.candidates.length === 0) this.toMatch.push(tree);
|
|
447
423
|
tree.candidates.push(node);
|
|
@@ -470,9 +446,6 @@ export class Mam implements LabelHasher {
|
|
|
470
446
|
);
|
|
471
447
|
}
|
|
472
448
|
|
|
473
|
-
// collect_parents: walks the path tree level by level from the merged class, visiting each parent
|
|
474
|
-
// once per level, and hands the terms where a path ends to that path's code. The mark of a parent
|
|
475
|
-
// says it was visited at this level, and the second mark of a root says it is queued for the next.
|
|
476
449
|
private collectParents(start: Enode, head: PathTree | null | undefined) {
|
|
477
450
|
if (head === null || head === undefined) return;
|
|
478
451
|
const context = this.context;
|
|
@@ -569,7 +542,6 @@ export class Mam implements LabelHasher {
|
|
|
569
542
|
}
|
|
570
543
|
}
|
|
571
544
|
|
|
572
|
-
// add_eq_eh: r2's labels take r1's after the paths are followed.
|
|
573
545
|
addEqEh(r1: Enode, r2: Enode) {
|
|
574
546
|
this.r1 = r1;
|
|
575
547
|
this.r2 = r2;
|
|
@@ -603,8 +575,6 @@ export class Mam implements LabelHasher {
|
|
|
603
575
|
if (this.newPatterns.length > 0) this.matchNewPatterns();
|
|
604
576
|
}
|
|
605
577
|
|
|
606
|
-
// match_new_patterns: one temporary tree per label, in the order the labels first appear, run
|
|
607
|
-
// against the relevant terms with the label.
|
|
608
578
|
private matchNewPatterns() {
|
|
609
579
|
const context = this.context;
|
|
610
580
|
const manager = this.manager;
|
|
@@ -627,7 +597,6 @@ export class Mam implements LabelHasher {
|
|
|
627
597
|
this.newPatterns = [];
|
|
628
598
|
}
|
|
629
599
|
|
|
630
|
-
// rematch: every code tree, in the order of their labels' small ids, against every relevant term.
|
|
631
600
|
rematch() {
|
|
632
601
|
const context = this.context;
|
|
633
602
|
const funcDecls = this.manager.funcDecls;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/smt_enode.h, src/smt/smt_eq_justification.h, src/smt/smt_justification.h),
|
|
2
|
-
// MIT license, see z3-license.txt. E-graph nodes and the justifications for their equalities.
|
|
1
|
+
// Ported from Z3 (src/smt/smt_enode.h, src/smt/smt_eq_justification.h, src/smt/smt_justification.h), MIT license, see z3-license.txt.
|
|
3
2
|
import type { Literal } from "./literal";
|
|
4
3
|
|
|
5
4
|
interface Antecedents {
|
|
@@ -14,7 +13,6 @@ export abstract class Justification {
|
|
|
14
13
|
abstract getAntecedents(antecedents: Antecedents): void;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
// eq_justification: why two nodes on a transitivity branch are equal.
|
|
18
16
|
export type EqJustification =
|
|
19
17
|
| { kind: "axiom" }
|
|
20
18
|
| { kind: "congruence"; isCommutative: boolean }
|
|
@@ -23,15 +21,11 @@ export type EqJustification =
|
|
|
23
21
|
|
|
24
22
|
export const AXIOM_EQ_JUSTIFICATION: EqJustification = { kind: "axiom" };
|
|
25
23
|
|
|
26
|
-
// The congruence justifications, which carry no data of their own and so are shared.
|
|
27
24
|
export const CONGRUENCE_JUSTIFICATIONS: readonly EqJustification[] = [
|
|
28
25
|
{ kind: "congruence", isCommutative: false },
|
|
29
26
|
{ kind: "congruence", isCommutative: true },
|
|
30
27
|
];
|
|
31
28
|
|
|
32
|
-
// The parents of a node without any, and the arguments past the second of a node with at most two.
|
|
33
|
-
// Nothing adds to it: addParent gives a node its own list, so that a node with one parent holds one
|
|
34
|
-
// entry instead of V8's sixteen.
|
|
35
29
|
export const NO_ENODES: Enode[] = [];
|
|
36
30
|
|
|
37
31
|
const IS_EQ = 1;
|
|
@@ -41,7 +35,6 @@ const IS_CGC_ENABLED = 8;
|
|
|
41
35
|
const IS_MARKED = 16;
|
|
42
36
|
const IS_MARKED2 = 32;
|
|
43
37
|
const IS_INTERPRETED = 64;
|
|
44
|
-
// The number of arguments, in the bits of flags above the Boolean fields.
|
|
45
38
|
const NUM_ARGS_SHIFT = 7;
|
|
46
39
|
|
|
47
40
|
export class Enode {
|
|
@@ -50,26 +43,19 @@ export class Enode {
|
|
|
50
43
|
cg: Enode = this;
|
|
51
44
|
classSize = 1;
|
|
52
45
|
parents: Enode[] = NO_ENODES;
|
|
53
|
-
// m_trans: the next node on the transitivity branch toward the root of the proof tree, and why the
|
|
54
|
-
// two are equal.
|
|
55
46
|
transTarget: Enode | null = null;
|
|
56
47
|
transJustification: EqJustification = AXIOM_EQ_JUSTIFICATION;
|
|
57
48
|
thVar = -1;
|
|
58
|
-
// The approximate label sets of the class, 64 bits in two words: the low 32 bits, then the high.
|
|
59
49
|
lbls = 0;
|
|
60
50
|
lblsHigh = 0;
|
|
61
51
|
plbls = 0;
|
|
62
52
|
plblsHigh = 0;
|
|
63
53
|
lblHash = -1;
|
|
64
|
-
// The Boolean fields, one bit each, so a node takes 48 bytes less, and the number of arguments.
|
|
65
54
|
private flags: number;
|
|
66
|
-
// m_args: the first two arguments inline, like Z3's arguments after the node, and the rest in an
|
|
67
|
-
// array. A missing argument is the node itself.
|
|
68
55
|
private readonly arg0: Enode;
|
|
69
56
|
private readonly arg1: Enode;
|
|
70
57
|
private readonly moreArgs: Enode[];
|
|
71
58
|
|
|
72
|
-
// moreArgs are the arguments past the second, and arg0 and arg1 are null when there are fewer.
|
|
73
59
|
constructor(
|
|
74
60
|
readonly owner: number,
|
|
75
61
|
readonly decl: number,
|
|
@@ -169,7 +155,6 @@ export class Enode {
|
|
|
169
155
|
}
|
|
170
156
|
}
|
|
171
157
|
|
|
172
|
-
// eq_propagation_justification: the equality atom is true because its sides are in one class.
|
|
173
158
|
export class EqPropagationJustification extends Justification {
|
|
174
159
|
constructor(
|
|
175
160
|
private first: Enode,
|
|
@@ -183,7 +168,6 @@ export class EqPropagationJustification extends Justification {
|
|
|
183
168
|
}
|
|
184
169
|
}
|
|
185
170
|
|
|
186
|
-
// eq_root_propagation_justification: a Boolean node merged with true or false.
|
|
187
171
|
export class EqRootPropagationJustification extends Justification {
|
|
188
172
|
constructor(private node: Enode) {
|
|
189
173
|
super();
|
|
@@ -194,7 +178,6 @@ export class EqRootPropagationJustification extends Justification {
|
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
180
|
|
|
197
|
-
// eq_conflict_justification: two interpreted roots, such as two numerals, were merged.
|
|
198
181
|
export class EqConflictJustification extends Justification {
|
|
199
182
|
constructor(
|
|
200
183
|
private first: Enode,
|
|
@@ -211,7 +194,6 @@ export class EqConflictJustification extends Justification {
|
|
|
211
194
|
}
|
|
212
195
|
}
|
|
213
196
|
|
|
214
|
-
// mp_iff_justification: a Boolean node takes the value of an equal node.
|
|
215
197
|
export class MpIffJustification extends Justification {
|
|
216
198
|
constructor(
|
|
217
199
|
private first: Enode,
|
|
@@ -227,7 +209,6 @@ export class MpIffJustification extends Justification {
|
|
|
227
209
|
}
|
|
228
210
|
}
|
|
229
211
|
|
|
230
|
-
// unit_resolution_justification: a clause simplified with literals that were false.
|
|
231
212
|
export class UnitResolutionJustification extends Justification {
|
|
232
213
|
constructor(
|
|
233
214
|
private justification: Justification | null,
|
|
@@ -242,7 +223,6 @@ export class UnitResolutionJustification extends Justification {
|
|
|
242
223
|
}
|
|
243
224
|
}
|
|
244
225
|
|
|
245
|
-
// ext_theory_propagation_justification: theory reasoning from literals and equalities.
|
|
246
226
|
export class TheoryJustification extends Justification {
|
|
247
227
|
constructor(
|
|
248
228
|
private literals: Literal[],
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
// Ported from Z3 (src/ast/ast.h), MIT license, see z3-license.txt.
|
|
2
|
-
// code that keeps Z3's reference counts by hand so that expressions are created and deleted in Z3's
|
|
3
|
-
// order. -1 stands for a null expression.
|
|
1
|
+
// Ported from Z3 (src/ast/ast.h), MIT license, see z3-license.txt.
|
|
4
2
|
import type { AstManager } from "./ast";
|
|
5
3
|
|
|
6
|
-
// expr_ref's assignment: the new value gains a reference before the old one loses its own.
|
|
7
4
|
export const assign = (manager: AstManager, old: number, value: number) => {
|
|
8
5
|
if (value !== -1) manager.incRef(value);
|
|
9
6
|
if (old !== -1) manager.decRef(old);
|
|
10
7
|
return value;
|
|
11
8
|
};
|
|
12
9
|
|
|
13
|
-
// expr_ref's move assignment of a value the caller owns.
|
|
14
10
|
export const assignOwned = (manager: AstManager, old: number, value: number) => {
|
|
15
11
|
if (old !== -1) manager.decRef(old);
|
|
16
12
|
return value;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
// Ported from Z3 (src/ast/rewriter/expr_safe_replace.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// Replaces subterms by terms, under quantifiers too, without rewriting. Like Z3, it visits the
|
|
3
|
-
// arguments of an application from the last one, and holds the expressions it creates.
|
|
4
2
|
import { SmtInvariantError } from "../../../errors";
|
|
5
3
|
import { KIND_APP, KIND_VAR, type AstManager } from "./ast";
|
|
6
4
|
import { RefVector } from "./ref-vector";
|
|
@@ -25,7 +23,6 @@ export class ExprSafeReplace {
|
|
|
25
23
|
this.cache.clear();
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
// operator(): the result comes with a reference, which the caller releases.
|
|
29
26
|
apply(expr: number) {
|
|
30
27
|
const manager = this.manager;
|
|
31
28
|
if (this.sources.size === 0) {
|
|
@@ -79,7 +76,6 @@ export class ExprSafeReplace {
|
|
|
79
76
|
return result;
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
// Replaces the quantifier, or pushes the children it still needs.
|
|
83
79
|
private applyQuantifier(quantifier: number, todo: number[]) {
|
|
84
80
|
const manager = this.manager;
|
|
85
81
|
const data = manager.getQuantifier(quantifier);
|
|
@@ -154,7 +150,7 @@ export class ExprSafeReplace {
|
|
|
154
150
|
shifter.release();
|
|
155
151
|
replace.release();
|
|
156
152
|
}
|
|
157
|
-
const result = manager.mkQuantifier({ ...data, body, patterns:
|
|
153
|
+
const result = manager.mkQuantifier({ ...data, body, patterns: patterns.items });
|
|
158
154
|
this.refs.push(result);
|
|
159
155
|
this.cache.set(quantifier, result);
|
|
160
156
|
todo.pop();
|
|
@@ -162,7 +158,6 @@ export class ExprSafeReplace {
|
|
|
162
158
|
manager.decRef(body);
|
|
163
159
|
}
|
|
164
160
|
|
|
165
|
-
// ~expr_safe_replace.
|
|
166
161
|
release() {
|
|
167
162
|
this.cache.clear();
|
|
168
163
|
this.refs.reset();
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/fingerprints.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// quantifier instances already found, so a match on equal terms is not instantiated twice. Scopes
|
|
3
|
-
// undo the insertions.
|
|
1
|
+
// Ported from Z3 (src/smt/fingerprints.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import type { AstManager } from "./ast";
|
|
5
3
|
import type { Enode } from "./enode";
|
|
6
4
|
import { getCompositeHash } from "./hash";
|
|
7
5
|
import { shrink } from "./array";
|
|
8
6
|
|
|
9
7
|
export class FingerprintSet {
|
|
10
|
-
// The quantifier, hash and roots of each fingerprint, in the order of insertion.
|
|
11
8
|
private quantifiers: number[] = [];
|
|
12
9
|
private hashes: number[] = [];
|
|
13
10
|
private roots: Enode[][] = [];
|
|
14
|
-
// Open addressing with linear probing over the indices of the fingerprints, -1 for an empty slot.
|
|
15
|
-
// Scopes remove the newest fingerprints first, and the table grows by inserting them in order, so
|
|
16
|
-
// emptying the slot of a removed fingerprint never cuts the probe of one that remains.
|
|
17
11
|
private slots = new Int32Array(1024).fill(-1);
|
|
18
12
|
private scopes: number[] = [];
|
|
19
|
-
// The hashes and the roots of the bindings of the instance being inserted.
|
|
20
13
|
private bindingHashes: number[] = [];
|
|
21
14
|
private bindingRoots: Enode[] = [];
|
|
22
15
|
|
|
23
16
|
constructor(private manager: AstManager) {}
|
|
24
17
|
|
|
25
|
-
// fingerprint_set::insert: the roots of the bindings, which a new fingerprint keeps, or null when
|
|
26
|
-
// the instance is already in the set. The hash comes from the bindings themselves, and the set is
|
|
27
|
-
// searched with the bindings and then with their roots.
|
|
28
18
|
insert(quantifier: number, bindings: Enode[]) {
|
|
29
19
|
const manager = this.manager;
|
|
30
20
|
const bindingHashes = this.bindingHashes;
|
|
@@ -50,7 +40,6 @@ export class FingerprintSet {
|
|
|
50
40
|
return roots;
|
|
51
41
|
}
|
|
52
42
|
|
|
53
|
-
// The empty slot that ends the probe for the fingerprint, or -1 when the set has it.
|
|
54
43
|
private find(quantifier: number, hash: number, args: Enode[]) {
|
|
55
44
|
const mask = this.slots.length - 1;
|
|
56
45
|
let slot = hash & mask;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/ast/rewriter/bool_rewriter.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// literals of a flattened conjunction or disjunction, without duplicates. Like the expr_fast_mark1
|
|
3
|
-
// and expr_fast_mark2 of mk_nflat_and_core, it marks the literals and the negated atoms it holds,
|
|
4
|
-
// here with a stamp for each use, so it finds a complementary pair without creating each negation.
|
|
5
|
-
// Its manager owns the one instance that its rewriters share: a list is filled and read before any
|
|
6
|
-
// other starts, so like Z3's ptr_buffer it reuses one array.
|
|
1
|
+
// Ported from Z3 (src/ast/rewriter/bool_rewriter.cpp), MIT license, see z3-license.txt.
|
|
7
2
|
import { shrink } from "./array";
|
|
8
3
|
import type { AstManager } from "./ast";
|
|
9
4
|
|
|
@@ -15,14 +10,11 @@ export class FlatLiterals {
|
|
|
15
10
|
|
|
16
11
|
constructor(private manager: AstManager) {}
|
|
17
12
|
|
|
18
|
-
// Starts a new, empty list.
|
|
19
13
|
clear() {
|
|
20
14
|
shrink(this.list, 0);
|
|
21
15
|
this.stamp++;
|
|
22
16
|
}
|
|
23
17
|
|
|
24
|
-
// Adds a literal, and returns whether its complement is already there. An expression's arguments
|
|
25
|
-
// are older than it, so their ids are smaller.
|
|
26
18
|
add(literal: number) {
|
|
27
19
|
const manager = this.manager;
|
|
28
20
|
if (literal >= this.literalStamps.length) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/tactic/goal.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// transforms, kept split into conjuncts. Like Z3's goal, it holds a reference to each formula.
|
|
1
|
+
// Ported from Z3 (src/tactic/goal.cpp), MIT license, see z3-license.txt.
|
|
3
2
|
import { OP_AND, OP_NOT, OP_OR, SORT_BOOL, type AstManager } from "./ast";
|
|
4
3
|
import { RefVector } from "./ref-vector";
|
|
5
4
|
|
|
@@ -16,7 +15,6 @@ export class Goal {
|
|
|
16
15
|
this.forms = new RefVector(manager);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
// push_back: a false formula replaces the whole goal.
|
|
20
18
|
private pushBack(form: number) {
|
|
21
19
|
const manager = this.manager;
|
|
22
20
|
if (manager.isTrue(form)) return;
|
|
@@ -27,9 +25,6 @@ export class Goal {
|
|
|
27
25
|
this.forms.push(form);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
// quick_process: splits conjunctions and negated disjunctions in order. With isSavingFirst, the
|
|
31
|
-
// first conjunct is returned instead of added. The formula comes with a reference, and so does
|
|
32
|
-
// the result. The negations it creates are held until it returns.
|
|
33
28
|
private quickProcess(form: number, isSavingFirst: boolean) {
|
|
34
29
|
const manager = this.manager;
|
|
35
30
|
const op = manager.getOp(form);
|
|
@@ -66,7 +61,6 @@ export class Goal {
|
|
|
66
61
|
return first;
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
// assert_expr.
|
|
70
64
|
assert(form: number) {
|
|
71
65
|
const manager = this.manager;
|
|
72
66
|
manager.incRef(form);
|
|
@@ -77,9 +71,7 @@ export class Goal {
|
|
|
77
71
|
manager.decRef(form);
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
//
|
|
81
|
-
// first conjunct is false, Z3 adds the whole formula (goal.cpp:312), and this adds false, so the
|
|
82
|
-
// goal becomes inconsistent.
|
|
74
|
+
// When the first conjunct is false, Z3 adds the whole formula (goal.cpp:312), where this adds false.
|
|
83
75
|
update(index: number, form: number) {
|
|
84
76
|
const manager = this.manager;
|
|
85
77
|
if (this.isInconsistent) return;
|
|
@@ -92,12 +84,10 @@ export class Goal {
|
|
|
92
84
|
manager.decRef(first);
|
|
93
85
|
}
|
|
94
86
|
|
|
95
|
-
// shrink: drops the formulas from size on, the last one first.
|
|
96
87
|
private shrink(size: number) {
|
|
97
88
|
while (this.forms.size > size) this.forms.pop();
|
|
98
89
|
}
|
|
99
90
|
|
|
100
|
-
// elim_true.
|
|
101
91
|
elimTrue() {
|
|
102
92
|
const manager = this.manager;
|
|
103
93
|
let kept = 0;
|
|
@@ -109,8 +99,6 @@ export class Goal {
|
|
|
109
99
|
this.shrink(kept);
|
|
110
100
|
}
|
|
111
101
|
|
|
112
|
-
// elim_redundancies: drops true and repeated literals, and finds a complementary pair. The marks
|
|
113
|
-
// hold the literals until it returns.
|
|
114
102
|
elimRedundancies() {
|
|
115
103
|
const manager = this.manager;
|
|
116
104
|
if (this.isInconsistent) return;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
// Ported from Z3 (src/util/hash.h, src/util/hash.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// Bob Jenkins' hash functions, on unsigned 32-bit integers. Z3 hashes every AST with them, and its
|
|
3
|
-
// hash tables iterate in hash order, so matching the hashes matches Z3's iteration order.
|
|
4
2
|
const GOLDEN_RATIO = 0x9e3779b9;
|
|
5
3
|
|
|
6
4
|
const mix = (state: Uint32Array) => {
|
|
@@ -30,8 +28,6 @@ const mix = (state: Uint32Array) => {
|
|
|
30
28
|
state[2] = c;
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
// The a, b and c of Z3's mix, which wrap like its unsigned integers. No hash function calls another
|
|
34
|
-
// while it uses the state, so they share one rather than allocating one per hash.
|
|
35
31
|
const sharedState = new Uint32Array(3);
|
|
36
32
|
|
|
37
33
|
const mkState = (a: number, b: number, c: number) => {
|
|
@@ -63,7 +59,6 @@ export const combineHash = (first: number, second: number) =>
|
|
|
63
59
|
|
|
64
60
|
const encoder = new TextEncoder();
|
|
65
61
|
|
|
66
|
-
// string_hash, over the bytes of a string or of a number's digits.
|
|
67
62
|
export const bytesHash = (data: Uint8Array, initValue: number) => {
|
|
68
63
|
const readUnsigned = (offset: number) =>
|
|
69
64
|
(data[offset] |
|
|
@@ -94,7 +89,6 @@ export const bytesHash = (data: Uint8Array, initValue: number) => {
|
|
|
94
89
|
export const stringHash = (text: string, initValue: number) =>
|
|
95
90
|
bytesHash(encoder.encode(text), initValue);
|
|
96
91
|
|
|
97
|
-
// get_composite_hash over child hashes, with the default kind hash of 17.
|
|
98
92
|
export const getCompositeHash = (childHashes: number[], kindHash = 17) => {
|
|
99
93
|
const count = childHashes.length;
|
|
100
94
|
const state = mkState(GOLDEN_RATIO, GOLDEN_RATIO, 11);
|
|
@@ -137,8 +131,6 @@ export const getCompositeHash = (childHashes: number[], kindHash = 17) => {
|
|
|
137
131
|
}
|
|
138
132
|
};
|
|
139
133
|
|
|
140
|
-
// ast_array_hash: the hash of an AST from the hashes of its children, each looked up in hashes like
|
|
141
|
-
// Z3's get_hash.
|
|
142
134
|
export const astArrayHash = (items: number[], hashes: ArrayLike<number>, initValue: number) => {
|
|
143
135
|
const count = items.length;
|
|
144
136
|
switch (count) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/util/hashtable.h, src/util/obj_hashtable.h), MIT license, see
|
|
2
|
-
// z3-license.txt. Z3's open-addressing table with linear probing. Its iteration order is the slot
|
|
3
|
-
// order, which the model finder depends on, so the AST maps that Z3 iterates use this table.
|
|
1
|
+
// Ported from Z3 (src/util/hashtable.h, src/util/obj_hashtable.h), MIT license, see z3-license.txt.
|
|
4
2
|
import { SmtInvariantError } from "../../../errors";
|
|
5
3
|
|
|
6
4
|
const INITIAL_CAPACITY = 8;
|
|
@@ -9,7 +7,6 @@ const FREE = 0;
|
|
|
9
7
|
const DELETED = 1;
|
|
10
8
|
const USED = 2;
|
|
11
9
|
|
|
12
|
-
// u_hash: an unsigned key is its own hash.
|
|
13
10
|
export const getIdentityHash = (key: number) => key;
|
|
14
11
|
|
|
15
12
|
export class ObjMap<V> {
|
|
@@ -33,7 +30,6 @@ export class ObjMap<V> {
|
|
|
33
30
|
return -1;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
// move_table: reinserts the used slots, in slot order, into a table of the new capacity.
|
|
37
33
|
private moveTable(capacity: number) {
|
|
38
34
|
const states = this.states;
|
|
39
35
|
const keys = this.slotKeys;
|
|
@@ -63,7 +59,6 @@ export class ObjMap<V> {
|
|
|
63
59
|
return slot === -1 ? undefined : this.values[slot];
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
// find_core and an assignment to the entry: unlike insert, never grows the table.
|
|
67
62
|
replace(key: number, value: V) {
|
|
68
63
|
const slot = this.findSlot(key);
|
|
69
64
|
if (slot !== -1) this.values[slot] = value;
|
|
@@ -108,7 +103,6 @@ export class ObjMap<V> {
|
|
|
108
103
|
this.moveTable(this.capacity);
|
|
109
104
|
}
|
|
110
105
|
|
|
111
|
-
// reset: empties the table, halving it when most slots were in use.
|
|
112
106
|
clear() {
|
|
113
107
|
if (this.size === 0 && this.numDeleted === 0) return;
|
|
114
108
|
let overhead = 0;
|
|
@@ -136,7 +130,6 @@ export class ObjMap<V> {
|
|
|
136
130
|
}
|
|
137
131
|
}
|
|
138
132
|
|
|
139
|
-
// obj_hashtable: a set of ASTs in Z3's slot order.
|
|
140
133
|
export class ObjHashtable {
|
|
141
134
|
private map: ObjMap<true>;
|
|
142
135
|
|
|
@@ -156,10 +149,6 @@ export class ObjHashtable {
|
|
|
156
149
|
this.map.set(key, true);
|
|
157
150
|
}
|
|
158
151
|
|
|
159
|
-
delete(key: number) {
|
|
160
|
-
this.map.delete(key);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
152
|
[Symbol.iterator]() {
|
|
164
153
|
return this.map.keys();
|
|
165
154
|
}
|