tla-ts 0.0.10-dev.d618a2d79 → 0.0.10-dev.e5c8dc315
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compile.cjs +3 -3
- package/dist/compile.js +1 -1
- package/dist/deciders.cjs +36 -36
- package/dist/deciders.js +53 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- 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 +56 -56
- package/dist/prove.js +78 -78
- package/dist/run.cjs +40 -44
- package/dist/run.js +42 -46
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +97 -92
- package/dist/transfer.js +97 -92
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +31 -3
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +146 -93
- package/src/check.ts +518 -281
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +18 -4
- package/src/cli/tlc.ts +18 -12
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +23 -10
- package/src/coverage.ts +255 -18
- package/src/dependencies.ts +68 -15
- package/src/dfid.ts +101 -36
- package/src/environment.ts +155 -66
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +424 -135
- package/src/exit-codes.ts +28 -14
- package/src/instances.ts +152 -25
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +675 -236
- package/src/lexer.ts +12 -2
- package/src/liveness-checker.ts +179 -60
- package/src/liveness.ts +55 -10
- package/src/obligations/index.ts +1 -1
- package/src/obligations/normalize.ts +1 -4
- package/src/obligations/printer.ts +5 -5
- package/src/obligations/source.ts +2 -0
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/parser.ts +180 -149
- package/src/prover/isabelle/isar/attrib.ts +4 -4
- package/src/prover/isabelle/isar/rule-cases.ts +8 -6
- package/src/prover/isabelle/provers/clasimp.ts +1 -1
- package/src/prover/isabelle/provers/hypsubst.ts +2 -2
- package/src/prover/isabelle/pure/rewriter.ts +3 -3
- package/src/prover/isabelle/pure/term.ts +3 -3
- package/src/prover/prep/md5.ts +26 -29
- package/src/prover/smt/rewrite.ts +2 -7
- package/src/prover/smt/simplify.ts +1 -1
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +3 -2
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +171 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +66 -14
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +28 -2
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-simplifier.ts +11 -13
- package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
- package/src/prover/smt/solver/bv-rewriter.ts +1 -1
- package/src/prover/smt/solver/bv1-blast.ts +1 -1
- package/src/prover/smt/solver/card2bv.ts +35 -18
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
- package/src/prover/smt/solver/context.ts +84 -15
- package/src/prover/smt/solver/ctx-simplify.ts +9 -4
- package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +28 -16
- package/src/prover/smt/solver/diff-neq.ts +9 -8
- package/src/prover/smt/solver/dt2bv-tactic.ts +66 -28
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +31 -28
- package/src/prover/smt/solver/eq2bv-tactic.ts +15 -6
- package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/egraph.ts +4 -11
- package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
- package/src/prover/smt/solver/euf/mam.ts +1 -5
- package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
- package/src/prover/smt/solver/euf/th-solver.ts +0 -7
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fd-solver.ts +608 -139
- package/src/prover/smt/solver/fix-dl-var.ts +2 -3
- package/src/prover/smt/solver/fm-tactic.ts +9 -7
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +1 -1
- package/src/prover/smt/solver/goal.ts +6 -3
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/hashtable.ts +4 -0
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lia2pb.ts +1 -1
- package/src/prover/smt/solver/logic-tactics.ts +15 -5
- package/src/prover/smt/solver/lp/core-solver.ts +12 -8
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +6 -2
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +158 -80
- package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -290
- package/src/prover/smt/solver/lp/union-find.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +1 -1
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-based-opt.ts +1 -1
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +85 -43
- package/src/prover/smt/solver/mpf.ts +2 -4
- package/src/prover/smt/solver/mus.ts +2 -3
- package/src/prover/smt/solver/muz/dl-context.ts +22 -44
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
- package/src/prover/smt/solver/muz/dl-rule.ts +8 -9
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
- package/src/prover/smt/solver/muz/horn-tactic.ts +15 -2
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/nlqsat.ts +2 -1
- package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
- package/src/prover/smt/solver/nlsat/solver.ts +74 -64
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
- package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
- package/src/prover/smt/solver/nnf.ts +6 -2
- package/src/prover/smt/solver/normalize-bounds.ts +2 -2
- package/src/prover/smt/solver/occf.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +21 -7
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-preprocess.ts +1 -1
- package/src/prover/smt/solver/opt-solver.ts +10 -6
- package/src/prover/smt/solver/optsmt.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/pb-rewriter.ts +1 -4
- package/src/prover/smt/solver/pb2bv-tactic.ts +9 -3
- package/src/prover/smt/solver/poly-rewriter.ts +75 -18
- package/src/prover/smt/solver/probes.ts +88 -23
- package/src/prover/smt/solver/proto-model.ts +8 -8
- package/src/prover/smt/solver/purify-arith.ts +51 -49
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
- package/src/prover/smt/solver/qe-lite.ts +2 -2
- package/src/prover/smt/solver/qe.ts +3 -2
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/quantifier-manager.ts +14 -9
- package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
- package/src/prover/smt/solver/reduce-args.ts +2 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/rlimit.ts +7 -3
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +75 -12
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +149 -47
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-constraint.ts +7 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +26 -7
- package/src/prover/smt/solver/sat/sat-tactic.ts +54 -25
- package/src/prover/smt/solver/sat/sat2goal.ts +75 -50
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +27 -47
- package/src/prover/smt/solver/seq-axioms.ts +20 -35
- package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
- package/src/prover/smt/solver/seq-derive.ts +2 -2
- package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
- package/src/prover/smt/solver/seq-monadic.ts +7 -5
- package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
- package/src/prover/smt/solver/seq-re-util.ts +1 -1
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +2 -2
- package/src/prover/smt/solver/seq-rewriter.ts +31 -29
- package/src/prover/smt/solver/seq-skolem.ts +0 -23
- package/src/prover/smt/solver/seq-view-witness.ts +4 -4
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +48 -7
- package/src/prover/smt/solver/smt-setup.ts +106 -13
- package/src/prover/smt/solver/smtlib-parser.ts +589 -224
- package/src/prover/smt/solver/smtlib-script.ts +718 -213
- package/src/prover/smt/solver/solve-eqs.ts +36 -37
- package/src/prover/smt/solver/solver.ts +18 -4
- package/src/prover/smt/solver/tactic.ts +389 -199
- package/src/prover/smt/solver/theory-bv.ts +13 -3
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +12 -3
- package/src/prover/smt/solver/theory-lra-state.ts +1 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -1
- package/src/prover/smt/solver/theory-pb.ts +24 -7
- package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
- package/src/prover/smt/solver/theory-seq-state.ts +2 -21
- package/src/prover/smt/solver/theory-without-terms.ts +24 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +15 -5
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/index-table.ts +5 -2
- package/src/prover/zenon/isar-case.ts +1 -1
- package/src/prover/zenon/isar.ts +2 -2
- package/src/prover/zenon/phrase.ts +1 -1
- package/src/resolve.ts +1311 -268
- package/src/runtime.ts +21 -2
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +5 -15
- package/src/sany/generator-def-entries.ts +123 -36
- package/src/sany/generator-definitions.ts +5 -3
- package/src/sany/generator-expressions.ts +60 -37
- package/src/sany/generator-proofs.ts +19 -12
- package/src/sany/generator.ts +12 -6
- package/src/sany/lexer.ts +15 -7
- package/src/sany/modules.ts +4 -2
- package/src/sany/nodes.ts +1 -1
- package/src/sany/selectors.ts +12 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +321 -135
- package/src/simulate.ts +247 -185
- package/src/spec-description.ts +15 -7
- package/src/standard-definitions.ts +1 -0
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +666 -147
- package/src/successors.ts +50 -20
- package/src/symmetry.ts +2 -1
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/order.ts +14 -3
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +147 -46
- package/src/tlc/tlc-operators.ts +10 -8
- package/src/tlc/tlcext-operators.ts +44 -15
- package/src/tlc/trace-spec.ts +9 -22
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +52 -31
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +150 -79
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
isStackOverflow,
|
|
4
4
|
SmtCanceledError,
|
|
5
5
|
SmtParseError,
|
|
6
|
+
SmtDefaultError,
|
|
6
7
|
SmtTacticError,
|
|
7
8
|
SmtUnsupportedError,
|
|
8
9
|
} from "../../../errors";
|
|
@@ -38,19 +39,23 @@ import {
|
|
|
38
39
|
createCommandReader,
|
|
39
40
|
createSmtlibReader,
|
|
40
41
|
DECLARATIONS,
|
|
42
|
+
expectClosed,
|
|
41
43
|
isSymbol,
|
|
44
|
+
isUnsigned,
|
|
42
45
|
type SExpr,
|
|
43
46
|
type SmtList,
|
|
44
47
|
type SmtlibReader,
|
|
48
|
+
type SmtToken,
|
|
45
49
|
} from "./smtlib-parser";
|
|
46
50
|
import { O_MAXIMIZE, O_MAXSMT, O_MINIMIZE, OptContext, type OptObjective } from "./opt-context";
|
|
47
51
|
import { getLogicStrategy } from "./logic-tactics";
|
|
48
52
|
import { isMbqiByFeatures, isMbqiByLogic } from "./smt-setup";
|
|
49
|
-
import { isSupportedLogic } from "./smt-logics";
|
|
53
|
+
import { isSupportedLogic, logicHasSeq } from "./smt-logics";
|
|
50
54
|
import { getVerdict, solveAssertions, solveAssuming } from "./solver";
|
|
51
55
|
import { getConsequences } from "./smt-consequences";
|
|
52
|
-
import {
|
|
56
|
+
import { FdSolver } from "./fd-solver";
|
|
53
57
|
import { SmtKernel } from "./smt-kernel";
|
|
58
|
+
import { RefVector } from "./ref-vector";
|
|
54
59
|
import { IncSatSolver } from "./sat/inc-sat-solver";
|
|
55
60
|
import { mkThSolver } from "./euf/th-solvers";
|
|
56
61
|
import { isAstLess } from "./ast-lt";
|
|
@@ -61,6 +66,7 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
|
61
66
|
import type { DatalogContext } from "./muz/dl-context";
|
|
62
67
|
import { createDatalogContext } from "./muz/horn-tactic";
|
|
63
68
|
import { printModel } from "./model-printer";
|
|
69
|
+
import { ModelEvaluator } from "./model-evaluator";
|
|
64
70
|
import { FuncInterp, getManagerSomeValue, ProtoModel } from "./proto-model";
|
|
65
71
|
import {
|
|
66
72
|
applyTactic,
|
|
@@ -69,9 +75,60 @@ import {
|
|
|
69
75
|
compileTactic,
|
|
70
76
|
getRewriterOptions,
|
|
71
77
|
getSatParams,
|
|
78
|
+
getSmtTacticFailure,
|
|
72
79
|
type TacticParam,
|
|
73
80
|
} from "./tactic";
|
|
74
81
|
|
|
82
|
+
const UNPORTED_COMMANDS = new Set([
|
|
83
|
+
"assert-not",
|
|
84
|
+
"assume",
|
|
85
|
+
"dbg-bool-rewriter",
|
|
86
|
+
"dbg-elim-and",
|
|
87
|
+
"dbg-get-qbody",
|
|
88
|
+
"dbg-params",
|
|
89
|
+
"dbg-pp-var",
|
|
90
|
+
"dbg-set",
|
|
91
|
+
"dbg-set-next-id",
|
|
92
|
+
"dbg-sexpr",
|
|
93
|
+
"dbg-shift-vars",
|
|
94
|
+
"dbg-size",
|
|
95
|
+
"dbg-subst",
|
|
96
|
+
"dbg-th-rewriter",
|
|
97
|
+
"dbg-translator",
|
|
98
|
+
"declare-map",
|
|
99
|
+
"declare-tactic",
|
|
100
|
+
"declare-type-var",
|
|
101
|
+
"del",
|
|
102
|
+
"display-dimacs",
|
|
103
|
+
"euf-project",
|
|
104
|
+
"eufi",
|
|
105
|
+
"ff-boolean-certify",
|
|
106
|
+
"ff-certify",
|
|
107
|
+
"ff-check-native-proof",
|
|
108
|
+
"ff-integrated-certify",
|
|
109
|
+
"get-interpolant",
|
|
110
|
+
"get-proof",
|
|
111
|
+
"get-proof-graph",
|
|
112
|
+
"get-user-tactics",
|
|
113
|
+
"help",
|
|
114
|
+
"help-simplifier",
|
|
115
|
+
"help-tactic",
|
|
116
|
+
"include",
|
|
117
|
+
"infer",
|
|
118
|
+
"labels",
|
|
119
|
+
"mbi",
|
|
120
|
+
"mbp",
|
|
121
|
+
"mbp-qel",
|
|
122
|
+
"model-add",
|
|
123
|
+
"model-del",
|
|
124
|
+
"prefer",
|
|
125
|
+
"qe-lite",
|
|
126
|
+
"qel",
|
|
127
|
+
"reset-preferences",
|
|
128
|
+
"set-initial-value",
|
|
129
|
+
"set-simplifier",
|
|
130
|
+
]);
|
|
131
|
+
|
|
75
132
|
const SILENT_COMMANDS = new Set([
|
|
76
133
|
...DECLARATIONS,
|
|
77
134
|
"assert",
|
|
@@ -81,8 +138,6 @@ const SILENT_COMMANDS = new Set([
|
|
|
81
138
|
"reset-assertions",
|
|
82
139
|
"set-option",
|
|
83
140
|
"set-info",
|
|
84
|
-
"minimize",
|
|
85
|
-
"maximize",
|
|
86
141
|
"assert-soft",
|
|
87
142
|
"declare-rel",
|
|
88
143
|
"declare-var",
|
|
@@ -121,6 +176,7 @@ const SIMPLIFY_PARAMETERS = new Set([
|
|
|
121
176
|
"som",
|
|
122
177
|
"sort_sums",
|
|
123
178
|
"arith_lhs",
|
|
179
|
+
"arith_ineq_lhs",
|
|
124
180
|
"gcd_rounding",
|
|
125
181
|
"hi_div0",
|
|
126
182
|
"mul2concat",
|
|
@@ -175,7 +231,9 @@ const getSoftParameters = (items: SExpr[]) => {
|
|
|
175
231
|
const parameters = { weight: Rational.one, id: null as string | null };
|
|
176
232
|
for (let index = 0; index < items.length; index += 2) {
|
|
177
233
|
const keyword = items[index];
|
|
178
|
-
|
|
234
|
+
if (keyword.kind !== "keyword")
|
|
235
|
+
throw new SmtParseError("invalid command argument, keyword expected", keyword);
|
|
236
|
+
const name = getParameterName(keyword.text);
|
|
179
237
|
const value = items[index + 1];
|
|
180
238
|
if (name === "weight" && (value?.kind === "numeral" || value?.kind === "decimal")) {
|
|
181
239
|
const [whole, fraction = ""] = value.text.split(".");
|
|
@@ -193,7 +251,9 @@ const getSimplifyParams = (items: SExpr[]) => {
|
|
|
193
251
|
const params = new Map<string, TacticParam>();
|
|
194
252
|
for (let index = 0; index < items.length; index += 2) {
|
|
195
253
|
const keyword = items[index];
|
|
196
|
-
|
|
254
|
+
if (keyword.kind !== "keyword")
|
|
255
|
+
throw new SmtParseError("invalid command argument, keyword expected", keyword);
|
|
256
|
+
const name = getParameterName(keyword.text);
|
|
197
257
|
const value = items[index + 1];
|
|
198
258
|
if (SIMPLIFY_UINT_PARAMETERS.has(name) && value?.kind === "numeral") {
|
|
199
259
|
params.set(name, Number(value.text));
|
|
@@ -206,6 +266,17 @@ const getSimplifyParams = (items: SExpr[]) => {
|
|
|
206
266
|
return params;
|
|
207
267
|
};
|
|
208
268
|
|
|
269
|
+
const GET_INFO_KEYWORDS = [
|
|
270
|
+
":reason-unknown",
|
|
271
|
+
":status",
|
|
272
|
+
":version",
|
|
273
|
+
":authors",
|
|
274
|
+
":error-behavior",
|
|
275
|
+
":parameters",
|
|
276
|
+
":rlimit",
|
|
277
|
+
":assertion-stack-levels",
|
|
278
|
+
];
|
|
279
|
+
|
|
209
280
|
const APPLY_PARAMETERS = new Map([
|
|
210
281
|
["print", true],
|
|
211
282
|
["print_model_converter", true],
|
|
@@ -245,12 +316,29 @@ const getCommandParams = (items: SExpr[], isBooleans: ReadonlyMap<string, boolea
|
|
|
245
316
|
"invalid command argument, unsigned integer expected",
|
|
246
317
|
value ?? keyword,
|
|
247
318
|
);
|
|
319
|
+
if (!isUnsigned(value.text))
|
|
320
|
+
throw new SmtParseError(
|
|
321
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
322
|
+
value,
|
|
323
|
+
);
|
|
248
324
|
params.set(name, Number(value.text));
|
|
249
325
|
}
|
|
250
326
|
}
|
|
251
327
|
return params;
|
|
252
328
|
};
|
|
253
329
|
|
|
330
|
+
const getFirstArgument = (list: SmtList) => {
|
|
331
|
+
const argument = list.items[1];
|
|
332
|
+
if (argument === undefined)
|
|
333
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
334
|
+
return argument;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const checkArgumentCount = (list: SmtList, count: number) => {
|
|
338
|
+
const extra = list.items[count + 1];
|
|
339
|
+
if (extra !== undefined) throw new SmtParseError("invalid command, too many arguments", extra);
|
|
340
|
+
};
|
|
341
|
+
|
|
254
342
|
// Z3's parse_opt_unsigned names the push command for pop as well.
|
|
255
343
|
const getScopeCount = (list: SmtList) => {
|
|
256
344
|
const argument = list.items[1];
|
|
@@ -266,18 +354,27 @@ interface Scope {
|
|
|
266
354
|
assertions: number;
|
|
267
355
|
objectives: number;
|
|
268
356
|
softTrail: number;
|
|
357
|
+
rlimit: number;
|
|
269
358
|
}
|
|
270
359
|
|
|
271
360
|
interface CheckResult {
|
|
272
361
|
status: number;
|
|
273
362
|
context: Context | undefined;
|
|
274
363
|
isOptimizing: boolean;
|
|
364
|
+
isFromTactic: boolean;
|
|
275
365
|
model: ProtoModel | undefined;
|
|
366
|
+
fdSolver: FdSolver | undefined;
|
|
276
367
|
core: number[] | undefined;
|
|
277
368
|
// check_sat_result::reason_unknown, where the port tracks it.
|
|
278
369
|
reasonUnknown?: string;
|
|
279
370
|
}
|
|
280
371
|
|
|
372
|
+
interface SolverAnswer {
|
|
373
|
+
result: number;
|
|
374
|
+
context: Context | undefined;
|
|
375
|
+
reasonUnknown: string | undefined;
|
|
376
|
+
}
|
|
377
|
+
|
|
281
378
|
interface ScriptState {
|
|
282
379
|
manager: AstManager;
|
|
283
380
|
logic: string | undefined;
|
|
@@ -299,9 +396,8 @@ interface ScriptState {
|
|
|
299
396
|
// combined_solver's incremental smt kernel, which keeps one context across the checks, or
|
|
300
397
|
// undefined while Z3 has made no such kernel.
|
|
301
398
|
kernel: SmtKernel | undefined;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
eufSolver: IncSatSolver | undefined;
|
|
399
|
+
satSolver: IncSatSolver | undefined;
|
|
400
|
+
fdSolver: FdSolver | undefined;
|
|
305
401
|
}
|
|
306
402
|
|
|
307
403
|
// Z3 fixes the proof mode at the first command that needs terms.
|
|
@@ -311,6 +407,7 @@ const MANAGERLESS_COMMANDS = new Set([
|
|
|
311
407
|
"set-logic",
|
|
312
408
|
"get-option",
|
|
313
409
|
"get-info",
|
|
410
|
+
"get-assertions",
|
|
314
411
|
"echo",
|
|
315
412
|
]);
|
|
316
413
|
|
|
@@ -330,6 +427,7 @@ export const runSmtlibScript = (
|
|
|
330
427
|
isPrintingSuccess: false,
|
|
331
428
|
isProducingModels: true,
|
|
332
429
|
isProducingUnsatCores: false,
|
|
430
|
+
isProducingUnsatAssumptions: false,
|
|
333
431
|
isProducingProofs: false,
|
|
334
432
|
isExitingOnError: false,
|
|
335
433
|
isInteractive: false,
|
|
@@ -343,11 +441,11 @@ export const runSmtlibScript = (
|
|
|
343
441
|
rlimit: 0,
|
|
344
442
|
printOptions: { ...DEFAULT_PRINT_OPTIONS },
|
|
345
443
|
parserOptions: { isIgnoringBadPatterns: true },
|
|
444
|
+
// Z3 keeps set-info's :status across reset.
|
|
445
|
+
status: L_UNDEF,
|
|
346
446
|
};
|
|
347
447
|
const createState = (): ScriptState => {
|
|
348
|
-
const manager = new AstManager(
|
|
349
|
-
new ResourceLimit(Date.now() + options.timeLimitMs, options.signal),
|
|
350
|
-
);
|
|
448
|
+
const manager = new AstManager(new ResourceLimit(Infinity, options.signal));
|
|
351
449
|
manager.isHiDiv0 = settings.isHiDiv0;
|
|
352
450
|
manager.maxChar = settings.encoding.maxChar;
|
|
353
451
|
manager.charBits = settings.encoding.charBits;
|
|
@@ -368,7 +466,8 @@ export const runSmtlibScript = (
|
|
|
368
466
|
hasChecked: false,
|
|
369
467
|
datalog: undefined,
|
|
370
468
|
kernel: undefined,
|
|
371
|
-
|
|
469
|
+
satSolver: undefined,
|
|
470
|
+
fdSolver: undefined,
|
|
372
471
|
};
|
|
373
472
|
};
|
|
374
473
|
let state = createState();
|
|
@@ -409,7 +508,7 @@ export const runSmtlibScript = (
|
|
|
409
508
|
paretoMaxLemmas: Number(parameters.get("opt.pareto_nlsat_max_lemmas") ?? 128),
|
|
410
509
|
};
|
|
411
510
|
};
|
|
412
|
-
const optimize = (extra: number[]) => {
|
|
511
|
+
const optimize = (extra: number[], end: SmtToken) => {
|
|
413
512
|
const manager = state.manager;
|
|
414
513
|
const objectives = state.objectives;
|
|
415
514
|
const hard = [...getNamedAssertions(), ...state.names.filter((name) => name !== -1), ...extra];
|
|
@@ -452,7 +551,11 @@ export const runSmtlibScript = (
|
|
|
452
551
|
!hasAssumptions &&
|
|
453
552
|
settings.parameters.get("opt.incremental") !== "true",
|
|
454
553
|
});
|
|
455
|
-
setCheck(status, {
|
|
554
|
+
setCheck(status, {
|
|
555
|
+
isOptimizing: true,
|
|
556
|
+
model: optimizer.model ?? undefined,
|
|
557
|
+
reasonUnknown: optimizer.getReasonUnknown(),
|
|
558
|
+
});
|
|
456
559
|
print(getVerdict(status));
|
|
457
560
|
return true;
|
|
458
561
|
} catch (error) {
|
|
@@ -461,9 +564,16 @@ export const runSmtlibScript = (
|
|
|
461
564
|
resetOptimizer();
|
|
462
565
|
return false;
|
|
463
566
|
}
|
|
567
|
+
if (error instanceof SmtDefaultError) {
|
|
568
|
+
setCheck(L_UNDEF, { isFromTactic: true, reasonUnknown: optimizer.getReasonUnknown() });
|
|
569
|
+
throw new SmtParseError(error.message, end);
|
|
570
|
+
}
|
|
464
571
|
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
572
|
+
const reasonUnknown = optimizer.getReasonUnknown();
|
|
465
573
|
optimizer.release();
|
|
466
|
-
setCheck(L_UNDEF, { isOptimizing: true });
|
|
574
|
+
setCheck(L_UNDEF, { isOptimizing: true, reasonUnknown });
|
|
575
|
+
if (error instanceof SmtCanceledError)
|
|
576
|
+
throw new SmtParseError(manager.limit.getCancelMessage(), end);
|
|
467
577
|
print("unknown");
|
|
468
578
|
return true;
|
|
469
579
|
} finally {
|
|
@@ -477,79 +587,136 @@ export const runSmtlibScript = (
|
|
|
477
587
|
};
|
|
478
588
|
// The port keeps answering with the smt kernel where it lacks a piece of the logic's strategy.
|
|
479
589
|
const solveWithStrategy = () => {
|
|
480
|
-
const goal = getGoal();
|
|
481
|
-
const strategy =
|
|
482
|
-
settings.parameters.get("tactic.default_tactic") ??
|
|
483
|
-
getLogicStrategy(state.logic, goal.isProofsEnabled);
|
|
484
590
|
try {
|
|
591
|
+
const goal = getGoal();
|
|
592
|
+
const strategy =
|
|
593
|
+
settings.parameters.get("tactic.default_tactic") ??
|
|
594
|
+
getLogicStrategy(state.logic, goal.isProofsEnabled);
|
|
485
595
|
const checked = checkSatUsing(compileInternalTactic(getTacticEnvironment(), strategy), goal);
|
|
486
|
-
return {
|
|
596
|
+
return {
|
|
597
|
+
result: checked.status,
|
|
598
|
+
context: undefined,
|
|
599
|
+
model: checked.model,
|
|
600
|
+
reasonUnknown: checked.reasonUnknown,
|
|
601
|
+
};
|
|
487
602
|
} catch (error) {
|
|
488
603
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
489
604
|
const hasQuantifiers = state.assertions.some(
|
|
490
605
|
(assertion) => state.manager.hasQuantifierFlags[assertion],
|
|
491
606
|
);
|
|
607
|
+
const solved = solveAssertions(state.manager, state.assertions, {
|
|
608
|
+
isMbqi: settings.isMbqi || isMbqiByFeatures(getSetup(), hasQuantifiers),
|
|
609
|
+
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
610
|
+
isFindingMacros: settings.isFindingMacros,
|
|
611
|
+
setup: getSetup(),
|
|
612
|
+
});
|
|
492
613
|
return {
|
|
493
|
-
...
|
|
494
|
-
isMbqi: settings.isMbqi || isMbqiByFeatures(getSetup(), hasQuantifiers),
|
|
495
|
-
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
496
|
-
isFindingMacros: settings.isFindingMacros,
|
|
497
|
-
setup: getSetup(),
|
|
498
|
-
}),
|
|
614
|
+
...solved,
|
|
499
615
|
model: undefined,
|
|
616
|
+
reasonUnknown:
|
|
617
|
+
solved.result === L_UNDEF && solved.context !== undefined
|
|
618
|
+
? getSmtTacticFailure(solved.context)
|
|
619
|
+
: "",
|
|
500
620
|
};
|
|
501
621
|
}
|
|
502
622
|
};
|
|
503
|
-
|
|
504
|
-
|
|
623
|
+
// Deviation from Z3: the heap guard and a stack overflow, which Z3 lacks, read as an exhausted rlimit.
|
|
624
|
+
const getCancelMessage = (deadline: number) =>
|
|
625
|
+
Date.now() > deadline || options.signal?.aborted === true
|
|
626
|
+
? "canceled"
|
|
627
|
+
: "max. resource limit exceeded";
|
|
628
|
+
// As in Z3, a timeout leaves "timeout" in the kernel, which reports it while its last search hasn't failed.
|
|
629
|
+
const getReasonUnknown = (solved: SolverAnswer, deadline: number) => {
|
|
630
|
+
const isTimedOut = solved.result === L_UNDEF && Date.now() > deadline;
|
|
631
|
+
const context = state.kernel?.context;
|
|
632
|
+
if (isTimedOut && context !== undefined) context.reasonUnknown = "timeout";
|
|
633
|
+
if (context !== undefined && solved.context === context) return context.getLastFailureMessage();
|
|
634
|
+
return isTimedOut ? "timeout" : (solved.reasonUnknown ?? getCancelMessage(deadline));
|
|
635
|
+
};
|
|
636
|
+
// As in Z3, a kernel loses the mbqi its logic turned on once it reads the parameters again.
|
|
637
|
+
const getKernelParams = (isSetUp = false) => ({
|
|
638
|
+
isMbqi: settings.isMbqi || (!isSetUp && isMbqiByLogic(getSetup())),
|
|
505
639
|
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
506
640
|
isFindingMacros: settings.isFindingMacros,
|
|
641
|
+
isCoreMinimizing: settings.parameters.get("smt.core.minimize") === "true",
|
|
507
642
|
setup: getSetup(),
|
|
508
643
|
});
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
644
|
+
const checkFdSolver = (fdSolver: FdSolver, extra: number[]) => {
|
|
645
|
+
const result = fdSolver.check(extra);
|
|
646
|
+
// cmd_context::check_sat counts a step to see whether the limit stopped a search that gave up.
|
|
647
|
+
if (result === L_UNDEF) state.manager.limit.inc();
|
|
648
|
+
return {
|
|
649
|
+
result,
|
|
650
|
+
context: undefined,
|
|
651
|
+
model: undefined,
|
|
652
|
+
core: result === L_FALSE ? [...fdSolver.getUnsatCore()] : undefined,
|
|
653
|
+
reasonUnknown: fdSolver.reasonUnknown,
|
|
654
|
+
};
|
|
655
|
+
};
|
|
656
|
+
const checkSat = (extra: number[], end: SmtToken) => {
|
|
657
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
658
|
+
state.manager.limit.restart(deadline);
|
|
516
659
|
// opt::context::optimize answers as the search of the hard constraints does: once they are
|
|
517
660
|
// satisfiable, optsmt and maxsmt only improve the model. The unported parts of optimization
|
|
518
661
|
// only get that answer.
|
|
519
|
-
if (state.objectives.length > 0 && optimize(extra)) return;
|
|
662
|
+
if (state.objectives.length > 0 && optimize(extra, end)) return;
|
|
520
663
|
state.manager.limit.push(settings.rlimit);
|
|
521
664
|
const isOptimizing = state.objectives.length > 0;
|
|
665
|
+
const manager = state.manager;
|
|
666
|
+
const names = state.names.filter((name) => name !== -1);
|
|
667
|
+
const isNamed = names.length > 0;
|
|
668
|
+
const isAssuming = isNamed || extra.length > 0;
|
|
669
|
+
if (isAssuming) state.isIncremental = true;
|
|
670
|
+
if (!isOptimizing) state.hasChecked = true;
|
|
671
|
+
const fdSolver = state.fdSolver;
|
|
672
|
+
const isKernelChecking =
|
|
673
|
+
fdSolver === undefined && (isAssuming || (state.isIncremental && !isOptimizing));
|
|
522
674
|
try {
|
|
523
|
-
const
|
|
524
|
-
const names = state.names.filter((name) => name !== -1);
|
|
525
|
-
const isNamed = names.length > 0;
|
|
526
|
-
const isAssuming = isNamed || extra.length > 0;
|
|
527
|
-
if (isAssuming) state.isIncremental = true;
|
|
528
|
-
if (!isOptimizing) state.hasChecked = true;
|
|
529
|
-
const assumptions = isNamed ? [...names, ...extra] : extra;
|
|
530
|
-
const kernel =
|
|
531
|
-
isAssuming || (state.isIncremental && !isOptimizing && !isUsingFdSolver())
|
|
532
|
-
? checkKernel(assumptions)
|
|
533
|
-
: undefined;
|
|
675
|
+
const kernel = isKernelChecking ? checkKernel(names, extra) : undefined;
|
|
534
676
|
// Z3 retries a quantifier-free problem with its tactic when the incremental kernel gives up.
|
|
535
|
-
const
|
|
677
|
+
const isFromTactic =
|
|
536
678
|
kernel === undefined ||
|
|
537
679
|
(!isAssuming &&
|
|
538
680
|
kernel.result === L_UNDEF &&
|
|
539
681
|
!state.assertions.some((assertion) => manager.hasQuantifierFlags[assertion]) &&
|
|
540
|
-
manager.limit.inc())
|
|
541
|
-
|
|
542
|
-
|
|
682
|
+
manager.limit.inc());
|
|
683
|
+
const solved =
|
|
684
|
+
fdSolver !== undefined
|
|
685
|
+
? checkFdSolver(fdSolver, extra)
|
|
686
|
+
: isFromTactic
|
|
687
|
+
? { ...solveWithStrategy(), core: undefined }
|
|
688
|
+
: kernel;
|
|
543
689
|
setCheck(solved.result, {
|
|
544
690
|
context: solved.context,
|
|
545
691
|
isOptimizing,
|
|
692
|
+
isFromTactic,
|
|
546
693
|
model: solved.model,
|
|
694
|
+
fdSolver,
|
|
547
695
|
core: solved.core ?? solved.context?.unsatCore ?? [],
|
|
696
|
+
reasonUnknown: getReasonUnknown(solved, deadline),
|
|
548
697
|
});
|
|
549
698
|
print(getVerdict(solved.result));
|
|
550
699
|
} catch (error) {
|
|
551
|
-
if (
|
|
552
|
-
|
|
700
|
+
if (
|
|
701
|
+
!(
|
|
702
|
+
error instanceof SmtCanceledError ||
|
|
703
|
+
error instanceof SmtDefaultError ||
|
|
704
|
+
isStackOverflow(error)
|
|
705
|
+
)
|
|
706
|
+
)
|
|
707
|
+
throw error;
|
|
708
|
+
const context = isKernelChecking ? state.kernel?.context : undefined;
|
|
709
|
+
const reasonUnknown = isKernelChecking
|
|
710
|
+
? state.satSolver?.reasonUnknown
|
|
711
|
+
: state.fdSolver?.reasonUnknown;
|
|
712
|
+
setCheck(L_UNDEF, {
|
|
713
|
+
isOptimizing,
|
|
714
|
+
isFromTactic: !isKernelChecking,
|
|
715
|
+
reasonUnknown:
|
|
716
|
+
error instanceof SmtDefaultError
|
|
717
|
+
? ((isKernelChecking ? undefined : reasonUnknown) ?? error.message)
|
|
718
|
+
: getReasonUnknown({ result: L_UNDEF, context, reasonUnknown }, deadline),
|
|
719
|
+
});
|
|
553
720
|
print("unknown");
|
|
554
721
|
} finally {
|
|
555
722
|
state.manager.limit.release();
|
|
@@ -563,8 +730,18 @@ export const runSmtlibScript = (
|
|
|
563
730
|
if (check.model !== undefined) return check.model;
|
|
564
731
|
if (check.isOptimizing) throw new SmtUnsupportedError("the models of optimization");
|
|
565
732
|
if (check.context === undefined && check.status !== L_TRUE)
|
|
566
|
-
throw
|
|
567
|
-
|
|
733
|
+
throw check.isFromTactic
|
|
734
|
+
? new SmtParseError("model is not available", list.end)
|
|
735
|
+
: new SmtUnsupportedError("the model of a canceled search");
|
|
736
|
+
const context = check.context;
|
|
737
|
+
const model =
|
|
738
|
+
check.fdSolver !== undefined
|
|
739
|
+
? check.fdSolver.getModel()
|
|
740
|
+
: context === undefined
|
|
741
|
+
? new ProtoModel(state.manager)
|
|
742
|
+
: context.getModel();
|
|
743
|
+
if (model === undefined) throw new SmtParseError("model is not available", list.end);
|
|
744
|
+
if (check.fdSolver !== undefined) return model;
|
|
568
745
|
model.incRef();
|
|
569
746
|
check.model = model;
|
|
570
747
|
return model;
|
|
@@ -573,6 +750,12 @@ export const runSmtlibScript = (
|
|
|
573
750
|
state.check?.model?.decRef();
|
|
574
751
|
state.check = undefined;
|
|
575
752
|
};
|
|
753
|
+
// cmd_context::validate_check_sat_result runs after the answer is printed.
|
|
754
|
+
const validateCheck = (end: SmtToken) => {
|
|
755
|
+
const status = state.check?.status ?? L_UNDEF;
|
|
756
|
+
if (status !== L_UNDEF && settings.status !== L_UNDEF && status !== settings.status)
|
|
757
|
+
throw new SmtParseError(`check annotation that says ${getVerdict(settings.status)}`, end);
|
|
758
|
+
};
|
|
576
759
|
// The check holds a reference to its model until clearCheck.
|
|
577
760
|
const setCheck = (status: number, result: Partial<Omit<CheckResult, "status">> = {}) => {
|
|
578
761
|
result.model?.incRef();
|
|
@@ -580,14 +763,13 @@ export const runSmtlibScript = (
|
|
|
580
763
|
status,
|
|
581
764
|
context: undefined,
|
|
582
765
|
isOptimizing: false,
|
|
766
|
+
isFromTactic: false,
|
|
583
767
|
model: undefined,
|
|
768
|
+
fdSolver: undefined,
|
|
584
769
|
core: undefined,
|
|
585
770
|
...result,
|
|
586
771
|
};
|
|
587
772
|
};
|
|
588
|
-
// cmd_context::mk_solver: mk_solver_for_logic makes the incremental solver the smt kernel unless
|
|
589
|
-
// the logic, the default tactic or the sat parameters pick a sat solver. Under sat.euf that
|
|
590
|
-
// solver is inc_sat_solver in euf mode; the other sat solvers only store their assertions.
|
|
591
773
|
const resetKernel = () => {
|
|
592
774
|
const logic = state.logic;
|
|
593
775
|
const parameters = settings.parameters;
|
|
@@ -601,48 +783,70 @@ export const runSmtlibScript = (
|
|
|
601
783
|
parameters.get("tactic.default_tactic") === "sat" ||
|
|
602
784
|
parameters.get("sat.smt") === "true" ||
|
|
603
785
|
isEuf;
|
|
604
|
-
state.
|
|
786
|
+
state.satSolver?.release();
|
|
605
787
|
state.kernel = isSatSolver ? undefined : new SmtKernel(state.manager, getKernelParams());
|
|
606
|
-
state.
|
|
607
|
-
|
|
608
|
-
? new IncSatSolver(state.manager, getSatParams(parameters), true, mkThSolver)
|
|
788
|
+
state.satSolver =
|
|
789
|
+
isSatSolver && !isFdSolver && parameters.get("sat.smt") !== "true"
|
|
790
|
+
? new IncSatSolver(state.manager, getSatParams(parameters), true, isEuf ? mkThSolver : null)
|
|
791
|
+
: undefined;
|
|
792
|
+
state.fdSolver?.release();
|
|
793
|
+
state.fdSolver =
|
|
794
|
+
(logic === "QF_FD" || logic === "SAT") &&
|
|
795
|
+
!isProofsEnabled &&
|
|
796
|
+
!parameters.has("tactic.default_tactic")
|
|
797
|
+
? new FdSolver(state.manager, getSatParams(parameters))
|
|
609
798
|
: undefined;
|
|
610
799
|
for (let index = 0; index < state.scopes.length; index++) {
|
|
611
800
|
state.kernel?.push();
|
|
612
|
-
|
|
801
|
+
useSatSolver((solver) => solver.push());
|
|
802
|
+
state.fdSolver?.push();
|
|
613
803
|
}
|
|
614
804
|
};
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
805
|
+
const initManager = () => {
|
|
806
|
+
if (state.isProofsEnabled !== undefined) return;
|
|
807
|
+
state.isProofsEnabled = settings.parameters.get("proof") === "true";
|
|
808
|
+
if (state.logic === undefined || logicHasSeq(state.logic)) state.manager.initSeqPlugin();
|
|
809
|
+
if (state.logic === undefined) state.reader.registerList();
|
|
810
|
+
resetKernel();
|
|
811
|
+
};
|
|
812
|
+
// The parts of inc_sat_solver that are not ported leave its answers to the smt kernel.
|
|
813
|
+
const useSatSolver = <Result>(action: (solver: IncSatSolver) => Result) => {
|
|
814
|
+
const solver = state.satSolver;
|
|
618
815
|
if (solver === undefined) return undefined;
|
|
619
816
|
try {
|
|
620
817
|
return action(solver);
|
|
621
818
|
} catch (error) {
|
|
622
819
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
623
820
|
solver.release();
|
|
624
|
-
state.
|
|
821
|
+
state.satSolver = undefined;
|
|
625
822
|
return undefined;
|
|
626
823
|
}
|
|
627
824
|
};
|
|
628
825
|
// solver_na2as asserts a named assertion as an implication from its name.
|
|
629
826
|
const assertInKernel = (formula: number, name: number) => {
|
|
630
827
|
const manager = state.manager;
|
|
828
|
+
useSatSolver((solver) =>
|
|
829
|
+
name === -1 ? solver.assertExpr(formula) : solver.assertNamed(formula, name),
|
|
830
|
+
);
|
|
831
|
+
state.fdSolver?.assertExpr(formula, name);
|
|
832
|
+
const kernel = state.kernel;
|
|
833
|
+
if (kernel === undefined) return;
|
|
631
834
|
const asserted = name === -1 ? formula : manager.mkApp(OP_IMPLIES, [name, formula], SORT_BOOL);
|
|
632
835
|
manager.incRef(asserted);
|
|
633
|
-
|
|
634
|
-
useEufSolver((solver) => solver.assertExpr(asserted));
|
|
836
|
+
kernel.assertExpr(asserted);
|
|
635
837
|
manager.decRef(asserted);
|
|
636
838
|
};
|
|
637
|
-
const checkKernel = (
|
|
839
|
+
const checkKernel = (names: number[], extra: number[]) => {
|
|
638
840
|
const kernel = state.kernel;
|
|
639
|
-
const
|
|
640
|
-
|
|
841
|
+
const assumptions = [...names, ...extra];
|
|
842
|
+
const found = useSatSolver((solver) => {
|
|
843
|
+
const result = solver.check(extra);
|
|
641
844
|
return {
|
|
642
845
|
result,
|
|
643
846
|
context: undefined,
|
|
644
847
|
model: result === L_TRUE ? (solver.getModel() ?? undefined) : undefined,
|
|
645
848
|
core: result === L_FALSE ? [...solver.getUnsatCore()] : undefined,
|
|
849
|
+
reasonUnknown: solver.reasonUnknown,
|
|
646
850
|
};
|
|
647
851
|
});
|
|
648
852
|
if (found !== undefined) return found;
|
|
@@ -652,11 +856,21 @@ export const runSmtlibScript = (
|
|
|
652
856
|
context: kernel.context,
|
|
653
857
|
model: undefined,
|
|
654
858
|
core: undefined,
|
|
859
|
+
reasonUnknown: undefined,
|
|
655
860
|
};
|
|
861
|
+
const solved = solveAssuming(
|
|
862
|
+
state.manager,
|
|
863
|
+
getNamedAssertions(),
|
|
864
|
+
assumptions,
|
|
865
|
+
getKernelParams(),
|
|
866
|
+
);
|
|
656
867
|
return {
|
|
657
|
-
...
|
|
868
|
+
...solved,
|
|
658
869
|
model: undefined,
|
|
659
870
|
core: undefined,
|
|
871
|
+
// inc_sat_solver, which these logics use, keeps "no reason given" after an answer.
|
|
872
|
+
reasonUnknown:
|
|
873
|
+
solved.result === L_UNDEF ? solved.context.getLastFailureMessage() : "no reason given",
|
|
660
874
|
};
|
|
661
875
|
};
|
|
662
876
|
const printDiagnostic = (line: string) => print(line, !settings.isDiagnosticOnStdout);
|
|
@@ -690,11 +904,10 @@ export const runSmtlibScript = (
|
|
|
690
904
|
);
|
|
691
905
|
return state.datalog;
|
|
692
906
|
};
|
|
693
|
-
const getTactic = (sexpr: SExpr, end: SmtList["end"]) =>
|
|
694
|
-
compileTactic(getTacticEnvironment(), sexpr, end);
|
|
695
907
|
const getGoal = (isTrackingDependencies = false) => {
|
|
696
908
|
const goal = new Goal(state.manager);
|
|
697
909
|
goal.isProofsEnabled = settings.isProducingProofs || state.isProofsEnabled === true;
|
|
910
|
+
goal.isModelsEnabled = settings.isProducingModels;
|
|
698
911
|
goal.isCoresEnabled = settings.isProducingUnsatCores;
|
|
699
912
|
for (const [index, assertion] of state.assertions.entries())
|
|
700
913
|
goal.assert(
|
|
@@ -705,22 +918,43 @@ export const runSmtlibScript = (
|
|
|
705
918
|
);
|
|
706
919
|
return goal;
|
|
707
920
|
};
|
|
921
|
+
const getCommandGoal = (isTrackingDependencies: boolean, end: SmtToken) => {
|
|
922
|
+
if (
|
|
923
|
+
settings.isProducingUnsatCores &&
|
|
924
|
+
(settings.isProducingProofs || state.isProofsEnabled === true)
|
|
925
|
+
)
|
|
926
|
+
throw new SmtParseError(
|
|
927
|
+
"Frontend does not support simultaneous generation of proofs and unsat cores",
|
|
928
|
+
end,
|
|
929
|
+
);
|
|
930
|
+
return getGoal(isTrackingDependencies);
|
|
931
|
+
};
|
|
708
932
|
const hasNames = () => state.names.some((name) => name !== -1);
|
|
709
933
|
// parse_check_sat shrinks the expression stack once the check has run.
|
|
710
|
-
const checkSatAssuming = (items: SmtList["items"]) => {
|
|
934
|
+
const checkSatAssuming = (items: SmtList["items"], itemsEnd: SmtToken, end: SmtToken) => {
|
|
711
935
|
const literals: number[] = [];
|
|
712
936
|
try {
|
|
713
|
-
for (const item of items
|
|
714
|
-
|
|
937
|
+
for (const [index, item] of items.entries())
|
|
938
|
+
literals.push(
|
|
939
|
+
state.reader.parseFormula(
|
|
940
|
+
item,
|
|
941
|
+
items[index + 1] ?? itemsEnd,
|
|
942
|
+
"invalid check-sat command, argument must be a Boolean literal",
|
|
943
|
+
),
|
|
944
|
+
);
|
|
945
|
+
checkSat(literals, end);
|
|
715
946
|
} finally {
|
|
716
947
|
for (const literal of literals) state.manager.decRef(literal);
|
|
717
948
|
}
|
|
718
949
|
};
|
|
719
950
|
const addObjective = (list: SmtList, isMax: boolean) => {
|
|
720
|
-
const term = state.reader.parseTerm(list
|
|
951
|
+
const term = state.reader.parseTerm(getFirstArgument(list));
|
|
721
952
|
const sort = state.manager.sorts[term];
|
|
722
953
|
if (sort !== SORT_INT && sort !== SORT_REAL && !state.manager.isBvSort(sort))
|
|
723
|
-
throw new SmtParseError(
|
|
954
|
+
throw new SmtParseError(
|
|
955
|
+
"Objective must be bit-vector, integer or real",
|
|
956
|
+
list.items[2] ?? list.end,
|
|
957
|
+
);
|
|
724
958
|
resetOptimizer();
|
|
725
959
|
state.manager.incRef(term);
|
|
726
960
|
state.objectives.push({
|
|
@@ -730,6 +964,8 @@ export const runSmtlibScript = (
|
|
|
730
964
|
weights: [],
|
|
731
965
|
id: null,
|
|
732
966
|
});
|
|
967
|
+
if (settings.isPrintingSuccess) print("success");
|
|
968
|
+
checkArgumentCount(list, 1);
|
|
733
969
|
};
|
|
734
970
|
const releaseObjectives = (size: number, softSize: number) => {
|
|
735
971
|
for (const index of state.softTrail.splice(softSize).reverse()) {
|
|
@@ -798,20 +1034,25 @@ export const runSmtlibScript = (
|
|
|
798
1034
|
if (name.kind === "list")
|
|
799
1035
|
throw new SmtUnsupportedError("an indexed function declaration reference");
|
|
800
1036
|
throw new SmtParseError(
|
|
801
|
-
|
|
1037
|
+
`invalid function declaration reference, symbol or '(' expected got ${name.lastId}`,
|
|
802
1038
|
name,
|
|
803
1039
|
);
|
|
804
1040
|
}
|
|
805
1041
|
const domain = reference.items[1] ?? reference.end;
|
|
806
1042
|
if (domain.kind !== "list")
|
|
807
1043
|
throw new SmtParseError(
|
|
808
|
-
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.
|
|
1044
|
+
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.lastId}`,
|
|
809
1045
|
domain,
|
|
810
1046
|
);
|
|
811
|
-
const sorts = domain.items.map((sort) =>
|
|
1047
|
+
const sorts = domain.items.map((sort) =>
|
|
1048
|
+
state.reader.parseSort(
|
|
1049
|
+
sort,
|
|
1050
|
+
"Invalid function name. Expecting sort list starting with '(' to disambiguate function name",
|
|
1051
|
+
),
|
|
1052
|
+
);
|
|
812
1053
|
if (reference.items[2] === undefined)
|
|
813
1054
|
throw new SmtParseError("Invalid function name invalid sort, unexpected ')'", reference.end);
|
|
814
|
-
const range = state.reader.parseSort(reference.items[2]);
|
|
1055
|
+
const range = state.reader.parseSort(reference.items[2], "Invalid function name");
|
|
815
1056
|
const follower = reference.items[3] ?? reference.end;
|
|
816
1057
|
const found = state.reader.getFuncs(name.text).find((decl) => {
|
|
817
1058
|
const funcDecl = state.manager.funcDecls[decl];
|
|
@@ -830,16 +1071,87 @@ export const runSmtlibScript = (
|
|
|
830
1071
|
throw new SmtUnsupportedError("a function declaration reference with trailing terms");
|
|
831
1072
|
return found;
|
|
832
1073
|
};
|
|
1074
|
+
// get_info_cmd prints in set_next_arg, before the parser checks the rest of the command.
|
|
1075
|
+
const printInfo = (list: SmtList, keyword: string) => {
|
|
1076
|
+
if (keyword === ":reason-unknown") {
|
|
1077
|
+
const check = state.check;
|
|
1078
|
+
const reasonUnknown =
|
|
1079
|
+
check === undefined
|
|
1080
|
+
? "state of the most recent check-sat command is not known"
|
|
1081
|
+
: check.reasonUnknown;
|
|
1082
|
+
if (reasonUnknown === undefined)
|
|
1083
|
+
throw new SmtUnsupportedError("the information :reason-unknown");
|
|
1084
|
+
print(`(:reason-unknown "${reasonUnknown.replaceAll('"', '\\"')}")`);
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
if (keyword === ":rlimit") {
|
|
1088
|
+
initManager();
|
|
1089
|
+
print(`(:rlimit ${state.manager.limit.count})`);
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
if (keyword === ":error-behavior") {
|
|
1093
|
+
print(
|
|
1094
|
+
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1095
|
+
);
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (keyword === ":name") {
|
|
1099
|
+
print('(:name "Z3")');
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
if (keyword === ":authors") {
|
|
1103
|
+
print(
|
|
1104
|
+
'(:authors "Leonardo de Moura, Nikolaj Bjorner, Lev Nachmanson and Christoph Wintersteiger")',
|
|
1105
|
+
);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
if (keyword === ":version") {
|
|
1109
|
+
print('(:version "5.3.2")');
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
if (keyword === ":status") {
|
|
1113
|
+
print(`(:status ${getVerdict(settings.status)})`);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
if (keyword === ":assertion-stack-levels") {
|
|
1117
|
+
print(`(:assertion-stack-levels ${state.scopes.length})`);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
if (keyword === ":all-statistics" || keyword === ":parameters")
|
|
1121
|
+
throw new SmtUnsupportedError(`the information ${keyword}`);
|
|
1122
|
+
if (keyword !== ":?") {
|
|
1123
|
+
print("unsupported");
|
|
1124
|
+
printDiagnostic(`; ${keyword} line: ${list.line} position: ${list.column}`);
|
|
1125
|
+
}
|
|
1126
|
+
print("; Suppported get-info parameters:");
|
|
1127
|
+
for (const supported of GET_INFO_KEYWORDS) print(`; (get-info ${supported})`);
|
|
1128
|
+
};
|
|
1129
|
+
const printCore = () => {
|
|
1130
|
+
const check = state.check;
|
|
1131
|
+
if (check?.core === undefined)
|
|
1132
|
+
throw new SmtUnsupportedError("the unsat core of a tactic that drops dependencies");
|
|
1133
|
+
const kernel = state.kernel;
|
|
1134
|
+
if (kernel === undefined || check.context !== kernel.context) {
|
|
1135
|
+
print(`(${check.core.map(format).join(" ")})`);
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1139
|
+
const core = new RefVector(state.manager);
|
|
1140
|
+
kernel.getUnsatCore(core);
|
|
1141
|
+
print(`(${core.items.map(format).join(" ")})`);
|
|
1142
|
+
core.reset();
|
|
1143
|
+
};
|
|
833
1144
|
const runCommand = new Map<string, (list: SmtList) => void>([
|
|
834
1145
|
[
|
|
835
1146
|
"assert",
|
|
836
1147
|
(list) => {
|
|
837
1148
|
const term = list.items[1] ?? list.end;
|
|
838
|
-
const
|
|
1149
|
+
const follower = list.items[2] ?? list.end;
|
|
1150
|
+
const assertion = state.reader.parseAssertion(term, follower);
|
|
839
1151
|
const logicError = state.reader.getLogicError(assertion.formula);
|
|
840
1152
|
if (logicError !== undefined) {
|
|
841
1153
|
state.manager.decRef(assertion.formula);
|
|
842
|
-
throw new SmtParseError(logicError,
|
|
1154
|
+
throw new SmtParseError(logicError, follower);
|
|
843
1155
|
}
|
|
844
1156
|
state.assertions.push(assertion.formula);
|
|
845
1157
|
state.assertionTexts.push(
|
|
@@ -860,9 +1172,17 @@ export const runSmtlibScript = (
|
|
|
860
1172
|
}
|
|
861
1173
|
assertInKernel(assertion.formula, state.names[state.names.length - 1]);
|
|
862
1174
|
clearCheck();
|
|
1175
|
+
if (follower !== list.end)
|
|
1176
|
+
throw new SmtParseError("invalid assert command, ')' expected", follower);
|
|
1177
|
+
},
|
|
1178
|
+
],
|
|
1179
|
+
[
|
|
1180
|
+
"check-sat",
|
|
1181
|
+
(list) => {
|
|
1182
|
+
checkSatAssuming(list.items.slice(1), list.end, list.end);
|
|
1183
|
+
validateCheck(list.end);
|
|
863
1184
|
},
|
|
864
1185
|
],
|
|
865
|
-
["check-sat", (list) => checkSatAssuming(list.items.slice(1))],
|
|
866
1186
|
[
|
|
867
1187
|
"declare-rel",
|
|
868
1188
|
(list) => {
|
|
@@ -872,7 +1192,9 @@ export const runSmtlibScript = (
|
|
|
872
1192
|
throw new SmtParseError("at least 2 arguments expected", list.end);
|
|
873
1193
|
const decl = state.manager.mkFuncDecl(
|
|
874
1194
|
name.text,
|
|
875
|
-
domain.items.map((sort) =>
|
|
1195
|
+
domain.items.map((sort) =>
|
|
1196
|
+
state.reader.parseSort(sort, "expecting sort list starting with '('"),
|
|
1197
|
+
),
|
|
876
1198
|
SORT_BOOL,
|
|
877
1199
|
);
|
|
878
1200
|
state.reader.insertFunc(decl, list.end);
|
|
@@ -890,7 +1212,7 @@ export const runSmtlibScript = (
|
|
|
890
1212
|
list.end,
|
|
891
1213
|
);
|
|
892
1214
|
const manager = state.manager;
|
|
893
|
-
const range = state.reader.parseSort(sort);
|
|
1215
|
+
const range = state.reader.parseSort(sort, "invalid command argument, sort expected");
|
|
894
1216
|
const decl = manager.mkFuncDecl(name.text, [], range);
|
|
895
1217
|
state.reader.insertFunc(decl, list.end);
|
|
896
1218
|
getDatalog().registerVariable(manager.mkApp(decl, [], range));
|
|
@@ -902,7 +1224,10 @@ export const runSmtlibScript = (
|
|
|
902
1224
|
const rule = list.items[1];
|
|
903
1225
|
if (rule === undefined) throw new SmtParseError("invalid rule, expected formula", list.end);
|
|
904
1226
|
const name = list.items[2];
|
|
905
|
-
getDatalog().addRule(
|
|
1227
|
+
getDatalog().addRule(
|
|
1228
|
+
state.reader.parseFormula(rule, rule),
|
|
1229
|
+
isSymbol(name) ? name.text : undefined,
|
|
1230
|
+
);
|
|
906
1231
|
},
|
|
907
1232
|
],
|
|
908
1233
|
[
|
|
@@ -924,15 +1249,17 @@ export const runSmtlibScript = (
|
|
|
924
1249
|
for (const assertion of state.assertions) datalog.assertExpr(assertion);
|
|
925
1250
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
926
1251
|
state.manager.limit.push(settings.rlimit);
|
|
1252
|
+
let status = L_UNDEF;
|
|
927
1253
|
try {
|
|
928
|
-
|
|
1254
|
+
status = datalog.relQuery(relation);
|
|
929
1255
|
} catch (error) {
|
|
930
1256
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
931
1257
|
print(`(error "query failed: ${error.message}")`);
|
|
932
|
-
print("unknown");
|
|
933
1258
|
} finally {
|
|
934
1259
|
state.manager.limit.pop();
|
|
935
1260
|
}
|
|
1261
|
+
print(status === L_UNDEF && datalog.isBounded ? "bounded" : getVerdict(status));
|
|
1262
|
+
datalog.isBounded = false;
|
|
936
1263
|
},
|
|
937
1264
|
],
|
|
938
1265
|
[
|
|
@@ -941,37 +1268,48 @@ export const runSmtlibScript = (
|
|
|
941
1268
|
const params = getCommandParams(list.items, CHECK_SAT_USING_PARAMETERS);
|
|
942
1269
|
if (list.items[1] === undefined)
|
|
943
1270
|
throw new SmtParseError("check-sat-using needs a tactic argument", list.end);
|
|
944
|
-
|
|
1271
|
+
expectClosed(list.items[1]);
|
|
1272
|
+
const builder = compileTactic(getTacticEnvironment(), list.items[1]);
|
|
945
1273
|
const tactic = builder.build(params);
|
|
1274
|
+
const goal = getCommandGoal(builder.isTrackingDependencies, list.end);
|
|
946
1275
|
clearCheck();
|
|
947
|
-
|
|
1276
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
1277
|
+
state.manager.limit.restart(deadline);
|
|
948
1278
|
state.manager.limit.push(settings.rlimit);
|
|
949
1279
|
try {
|
|
950
|
-
const checked = checkSatUsing(tactic,
|
|
1280
|
+
const checked = checkSatUsing(tactic, goal);
|
|
1281
|
+
const reasonUnknown = checked.reasonUnknown ?? getCancelMessage(deadline);
|
|
951
1282
|
setCheck(checked.status, {
|
|
1283
|
+
isFromTactic: true,
|
|
952
1284
|
model: checked.model,
|
|
953
1285
|
core:
|
|
954
1286
|
builder.isTrackingDependencies || !hasNames()
|
|
955
1287
|
? getDependencyValues(checked.core)
|
|
956
1288
|
: undefined,
|
|
957
|
-
reasonUnknown
|
|
1289
|
+
reasonUnknown,
|
|
958
1290
|
});
|
|
959
|
-
print(
|
|
1291
|
+
print(
|
|
1292
|
+
checked.isConversionCanceled
|
|
1293
|
+
? `(error "tactic failed: ${reasonUnknown}")`
|
|
1294
|
+
: getVerdict(checked.status),
|
|
1295
|
+
);
|
|
960
1296
|
} finally {
|
|
961
1297
|
state.manager.limit.pop();
|
|
962
1298
|
}
|
|
1299
|
+
validateCheck(list.end);
|
|
963
1300
|
},
|
|
964
1301
|
],
|
|
965
1302
|
[
|
|
966
1303
|
"check-sat-assuming",
|
|
967
1304
|
(list) => {
|
|
968
|
-
const literals = list.items[1];
|
|
969
|
-
if (literals
|
|
1305
|
+
const literals = list.items[1] ?? list.end;
|
|
1306
|
+
if (literals.kind !== "list")
|
|
970
1307
|
throw new SmtParseError(
|
|
971
|
-
|
|
972
|
-
literals
|
|
1308
|
+
`invalid check-sat-assuming command, '(', expected got ${literals.lastId}`,
|
|
1309
|
+
literals,
|
|
973
1310
|
);
|
|
974
|
-
checkSatAssuming(literals.items);
|
|
1311
|
+
checkSatAssuming(literals.items, literals.end, list.end);
|
|
1312
|
+
validateCheck(list.end);
|
|
975
1313
|
},
|
|
976
1314
|
],
|
|
977
1315
|
[
|
|
@@ -982,27 +1320,29 @@ export const runSmtlibScript = (
|
|
|
982
1320
|
if (terms === undefined)
|
|
983
1321
|
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
984
1322
|
if (terms.kind !== "list")
|
|
985
|
-
throw new SmtParseError(
|
|
1323
|
+
throw new SmtParseError(
|
|
1324
|
+
`invalid list of terms, '(' expected got ${terms.lastId}`,
|
|
1325
|
+
terms,
|
|
1326
|
+
);
|
|
986
1327
|
return terms.items.map((item) => state.reader.parseTerm(item));
|
|
987
1328
|
});
|
|
988
1329
|
if (list.items.length > 3)
|
|
989
1330
|
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
990
1331
|
clearCheck();
|
|
991
|
-
|
|
1332
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
1333
|
+
manager.limit.restart(deadline);
|
|
992
1334
|
manager.limit.push(settings.rlimit);
|
|
993
1335
|
const names = state.names.filter((name) => name !== -1);
|
|
994
1336
|
try {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
);
|
|
1005
|
-
setCheck(found.result, { model: found.model });
|
|
1337
|
+
const fdSolver = state.fdSolver;
|
|
1338
|
+
if (fdSolver !== undefined) {
|
|
1339
|
+
const found = fdSolver.getConsequences(assumptions, vars);
|
|
1340
|
+
setCheck(found.result, {
|
|
1341
|
+
isFromTactic: true,
|
|
1342
|
+
fdSolver,
|
|
1343
|
+
core: [...fdSolver.getUnsatCore()],
|
|
1344
|
+
reasonUnknown: fdSolver.reasonUnknown,
|
|
1345
|
+
});
|
|
1006
1346
|
print(getVerdict(found.result));
|
|
1007
1347
|
print("");
|
|
1008
1348
|
for (const consequence of found.consequences.items) display(consequence);
|
|
@@ -1013,11 +1353,22 @@ export const runSmtlibScript = (
|
|
|
1013
1353
|
if (state.kernel === undefined)
|
|
1014
1354
|
for (const assertion of getNamedAssertions()) kernel.assertExpr(assertion);
|
|
1015
1355
|
const found = getConsequences(kernel, [...names, ...assumptions], vars);
|
|
1016
|
-
setCheck(found.result, {
|
|
1356
|
+
setCheck(found.result, {
|
|
1357
|
+
context: kernel.context,
|
|
1358
|
+
core: kernel.context.unsatCore,
|
|
1359
|
+
reasonUnknown: kernel.context.getLastFailureMessage(),
|
|
1360
|
+
});
|
|
1017
1361
|
print(getVerdict(found.result));
|
|
1018
1362
|
print("");
|
|
1019
1363
|
for (const consequence of found.consequences.items) display(consequence);
|
|
1020
1364
|
found.consequences.reset();
|
|
1365
|
+
} catch (error) {
|
|
1366
|
+
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
1367
|
+
const reasonUnknown = getCancelMessage(deadline);
|
|
1368
|
+
if (state.kernel !== undefined) state.kernel.context.reasonUnknown = reasonUnknown;
|
|
1369
|
+
setCheck(L_UNDEF, { reasonUnknown });
|
|
1370
|
+
print("unknown");
|
|
1371
|
+
print("");
|
|
1021
1372
|
} finally {
|
|
1022
1373
|
manager.limit.pop();
|
|
1023
1374
|
}
|
|
@@ -1061,39 +1412,60 @@ export const runSmtlibScript = (
|
|
|
1061
1412
|
assertions: state.assertions.length,
|
|
1062
1413
|
objectives: state.objectives.length,
|
|
1063
1414
|
softTrail: state.softTrail.length,
|
|
1415
|
+
rlimit: settings.rlimit,
|
|
1064
1416
|
});
|
|
1065
1417
|
state.reader.push();
|
|
1066
1418
|
state.isIncremental = true;
|
|
1067
|
-
state.
|
|
1068
|
-
|
|
1419
|
+
const limit = state.manager.limit;
|
|
1420
|
+
limit.push(settings.rlimit);
|
|
1421
|
+
try {
|
|
1422
|
+
state.kernel?.push();
|
|
1423
|
+
useSatSolver((solver) => solver.push());
|
|
1424
|
+
state.fdSolver?.push();
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
1427
|
+
throw new SmtParseError(limit.getCancelMessage(), list.end);
|
|
1428
|
+
} finally {
|
|
1429
|
+
limit.pop();
|
|
1430
|
+
}
|
|
1069
1431
|
}
|
|
1432
|
+
if (list.items[2] !== undefined)
|
|
1433
|
+
throw new SmtParseError("invalid push command, ')' expected", list.items[2]);
|
|
1070
1434
|
},
|
|
1071
1435
|
],
|
|
1072
1436
|
[
|
|
1073
1437
|
"pop",
|
|
1074
1438
|
(list) => {
|
|
1075
1439
|
const count = getScopeCount(list);
|
|
1440
|
+
const follower = list.items[2] ?? list.end;
|
|
1441
|
+
clearCheck();
|
|
1076
1442
|
if (count > state.scopes.length)
|
|
1077
1443
|
throw new SmtParseError(
|
|
1078
1444
|
"invalid pop command, argument is greater than the current stack depth",
|
|
1079
|
-
|
|
1445
|
+
follower,
|
|
1080
1446
|
);
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1447
|
+
if (count > 0) {
|
|
1448
|
+
state.isIncremental = true;
|
|
1449
|
+
const scope = state.scopes[state.scopes.length - count];
|
|
1450
|
+
state.kernel?.pop(count);
|
|
1451
|
+
useSatSolver((solver) => solver.pop(count));
|
|
1452
|
+
state.fdSolver?.pop(count);
|
|
1453
|
+
state.reader.pop(count);
|
|
1454
|
+
restoreAssertions(scope.assertions);
|
|
1455
|
+
settings.rlimit = scope.rlimit;
|
|
1456
|
+
resetOptimizer();
|
|
1457
|
+
releaseObjectives(scope.objectives, scope.softTrail);
|
|
1458
|
+
state.scopes.length -= count;
|
|
1459
|
+
}
|
|
1460
|
+
if (follower !== list.end)
|
|
1461
|
+
throw new SmtParseError("invalid pop command, ')' expected", follower);
|
|
1092
1462
|
},
|
|
1093
1463
|
],
|
|
1094
1464
|
[
|
|
1095
1465
|
"reset",
|
|
1096
|
-
() => {
|
|
1466
|
+
(list) => {
|
|
1467
|
+
if (list.items[1] !== undefined)
|
|
1468
|
+
throw new SmtParseError("invalid reset command, ')' expected", list.items[1]);
|
|
1097
1469
|
clearCheck();
|
|
1098
1470
|
resetOptimizer();
|
|
1099
1471
|
state = createState();
|
|
@@ -1101,12 +1473,17 @@ export const runSmtlibScript = (
|
|
|
1101
1473
|
],
|
|
1102
1474
|
[
|
|
1103
1475
|
"reset-assertions",
|
|
1104
|
-
() => {
|
|
1105
|
-
|
|
1476
|
+
(list) => {
|
|
1477
|
+
checkArgumentCount(list, 0);
|
|
1106
1478
|
restoreAssertions(0);
|
|
1107
1479
|
resetOptimizer();
|
|
1108
1480
|
releaseObjectives(0, 0);
|
|
1109
|
-
state.scopes = state.scopes.map(() => ({
|
|
1481
|
+
state.scopes = state.scopes.map((scope) => ({
|
|
1482
|
+
...scope,
|
|
1483
|
+
assertions: 0,
|
|
1484
|
+
objectives: 0,
|
|
1485
|
+
softTrail: 0,
|
|
1486
|
+
}));
|
|
1110
1487
|
if (state.isProofsEnabled !== undefined) resetKernel();
|
|
1111
1488
|
state.isIncremental = state.scopes.length > 0;
|
|
1112
1489
|
state.hasChecked = false;
|
|
@@ -1124,7 +1501,17 @@ export const runSmtlibScript = (
|
|
|
1124
1501
|
manager,
|
|
1125
1502
|
getRewriterOptions(manager, getSimplifyParams(list.items.slice(2))),
|
|
1126
1503
|
);
|
|
1127
|
-
|
|
1504
|
+
// simplify_cmd prints a failure of the rewriter and then the term as it was.
|
|
1505
|
+
const simplified = (() => {
|
|
1506
|
+
try {
|
|
1507
|
+
return rewriter.rewrite(term);
|
|
1508
|
+
} catch (error) {
|
|
1509
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
1510
|
+
print(`(error "simplifier failed: ${error.message}")`);
|
|
1511
|
+
manager.incRef(term);
|
|
1512
|
+
return term;
|
|
1513
|
+
}
|
|
1514
|
+
})();
|
|
1128
1515
|
rewriter.cleanup();
|
|
1129
1516
|
display(simplified);
|
|
1130
1517
|
rewriter.release();
|
|
@@ -1143,8 +1530,7 @@ export const runSmtlibScript = (
|
|
|
1143
1530
|
manager.incRef(term);
|
|
1144
1531
|
const visited = new Set<number>();
|
|
1145
1532
|
const todo = [term];
|
|
1146
|
-
|
|
1147
|
-
const expr = todo.pop() as number;
|
|
1533
|
+
for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
|
|
1148
1534
|
if (visited.has(expr)) continue;
|
|
1149
1535
|
visited.add(expr);
|
|
1150
1536
|
const family = manager.kinds[expr] === KIND_APP ? manager.getFamily(expr) : -1;
|
|
@@ -1168,13 +1554,19 @@ export const runSmtlibScript = (
|
|
|
1168
1554
|
const params = getCommandParams(list.items, APPLY_PARAMETERS);
|
|
1169
1555
|
if (list.items[1] === undefined)
|
|
1170
1556
|
throw new SmtParseError("apply needs a tactic argument", list.end);
|
|
1171
|
-
|
|
1557
|
+
expectClosed(list.items[1]);
|
|
1558
|
+
// apply_tactic_cmd, unlike check-sat-using, gives the tactic no logic.
|
|
1559
|
+
const builder = compileTactic(
|
|
1560
|
+
{ ...getTacticEnvironment(), setup: { ...getSetup(), logic: undefined } },
|
|
1561
|
+
list.items[1],
|
|
1562
|
+
);
|
|
1172
1563
|
const tactic = builder.build(params);
|
|
1564
|
+
const input = getCommandGoal(builder.isTrackingDependencies, list.end);
|
|
1173
1565
|
const isPrintingDependencies = params.get("print_dependencies") === true;
|
|
1174
1566
|
if (isPrintingDependencies && !builder.isTrackingDependencies && hasNames())
|
|
1175
1567
|
throw new SmtUnsupportedError("the dependencies of a tactic that drops dependencies");
|
|
1176
1568
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1177
|
-
|
|
1569
|
+
state.manager.limit.push(settings.rlimit);
|
|
1178
1570
|
const goals = (() => {
|
|
1179
1571
|
try {
|
|
1180
1572
|
return applyTactic(tactic, input);
|
|
@@ -1182,6 +1574,8 @@ export const runSmtlibScript = (
|
|
|
1182
1574
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
1183
1575
|
print(`(error "tactic failed: ${error.message}")`);
|
|
1184
1576
|
return undefined;
|
|
1577
|
+
} finally {
|
|
1578
|
+
state.manager.limit.pop();
|
|
1185
1579
|
}
|
|
1186
1580
|
})();
|
|
1187
1581
|
// apply_tactic_cmd releases the result goals and then the input goal.
|
|
@@ -1239,8 +1633,7 @@ export const runSmtlibScript = (
|
|
|
1239
1633
|
const decls = new Set<number>();
|
|
1240
1634
|
for (const assertion of assertions) {
|
|
1241
1635
|
const todo = [assertion];
|
|
1242
|
-
|
|
1243
|
-
const expr = todo.pop() as number;
|
|
1636
|
+
for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
|
|
1244
1637
|
if (visited.has(expr)) continue;
|
|
1245
1638
|
visited.add(expr);
|
|
1246
1639
|
if (manager.kinds[expr] === KIND_QUANTIFIER) {
|
|
@@ -1281,6 +1674,7 @@ export const runSmtlibScript = (
|
|
|
1281
1674
|
[
|
|
1282
1675
|
"get-assertions",
|
|
1283
1676
|
(list) => {
|
|
1677
|
+
checkArgumentCount(list, 0);
|
|
1284
1678
|
if (!settings.isInteractive)
|
|
1285
1679
|
throw new SmtParseError(
|
|
1286
1680
|
"command is only available in interactive mode, use command (set-option :interactive-mode true)",
|
|
@@ -1292,17 +1686,29 @@ export const runSmtlibScript = (
|
|
|
1292
1686
|
[
|
|
1293
1687
|
"get-unsat-core",
|
|
1294
1688
|
(list) => {
|
|
1689
|
+
checkArgumentCount(list, 0);
|
|
1295
1690
|
if (!settings.isProducingUnsatCores)
|
|
1296
1691
|
throw new SmtParseError(
|
|
1297
1692
|
"unsat core construction is not enabled, use command (set-option :produce-unsat-cores true)",
|
|
1298
1693
|
list.end,
|
|
1299
1694
|
);
|
|
1300
|
-
|
|
1301
|
-
if (check === undefined || check.status !== L_FALSE)
|
|
1695
|
+
if (state.check?.status !== L_FALSE)
|
|
1302
1696
|
throw new SmtParseError("unsat core is not available", list.end);
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1697
|
+
printCore();
|
|
1698
|
+
},
|
|
1699
|
+
],
|
|
1700
|
+
[
|
|
1701
|
+
"get-unsat-assumptions",
|
|
1702
|
+
(list) => {
|
|
1703
|
+
checkArgumentCount(list, 0);
|
|
1704
|
+
if (!settings.isProducingUnsatAssumptions)
|
|
1705
|
+
throw new SmtParseError(
|
|
1706
|
+
"unsat assumptions construction is not enabled, use command (set-option :produce-unsat-assumptions true)",
|
|
1707
|
+
list.end,
|
|
1708
|
+
);
|
|
1709
|
+
if (state.check?.status !== L_FALSE)
|
|
1710
|
+
throw new SmtParseError("unsat assumptions is not available", list.end);
|
|
1711
|
+
printCore();
|
|
1306
1712
|
},
|
|
1307
1713
|
],
|
|
1308
1714
|
[
|
|
@@ -1310,13 +1716,19 @@ export const runSmtlibScript = (
|
|
|
1310
1716
|
(list) => {
|
|
1311
1717
|
const target = list.items[1];
|
|
1312
1718
|
const term = target === undefined ? -1 : state.reader.parseTerm(target);
|
|
1313
|
-
|
|
1719
|
+
const parameter = list.items[2];
|
|
1720
|
+
if (parameter !== undefined && parameter.kind !== "keyword")
|
|
1721
|
+
throw new SmtParseError("invalid command argument, keyword expected", parameter);
|
|
1722
|
+
if (parameter !== undefined) throw new SmtUnsupportedError("the parameters of eval");
|
|
1314
1723
|
const model = getModel(list);
|
|
1315
1724
|
if (term === -1) throw new SmtParseError("no arguments passed to eval", list.end);
|
|
1316
1725
|
const manager = state.manager;
|
|
1317
1726
|
manager.incRef(term);
|
|
1318
|
-
const
|
|
1727
|
+
const evaluator = new ModelEvaluator(manager, model);
|
|
1728
|
+
const value = evaluator.rewrite(term);
|
|
1319
1729
|
display(value);
|
|
1730
|
+
// eval_cmd frees its model_evaluator before the value, and the parser frees the term last.
|
|
1731
|
+
evaluator.release();
|
|
1320
1732
|
manager.decRef(value);
|
|
1321
1733
|
manager.decRef(term);
|
|
1322
1734
|
},
|
|
@@ -1324,30 +1736,57 @@ export const runSmtlibScript = (
|
|
|
1324
1736
|
[
|
|
1325
1737
|
"get-value",
|
|
1326
1738
|
(list) => {
|
|
1327
|
-
const terms = list.items[1];
|
|
1328
|
-
if (terms
|
|
1329
|
-
throw new SmtParseError(
|
|
1739
|
+
const terms = list.items[1] ?? list.end;
|
|
1740
|
+
if (terms.kind !== "list")
|
|
1741
|
+
throw new SmtParseError(
|
|
1742
|
+
`invalid get-value command, '(' expected got ${terms.lastId}`,
|
|
1743
|
+
terms,
|
|
1744
|
+
);
|
|
1330
1745
|
const manager = state.manager;
|
|
1331
1746
|
const exprs = terms.items.map((item) => state.reader.parseTerm(item));
|
|
1332
1747
|
if (exprs.length === 0)
|
|
1333
1748
|
throw new SmtParseError("invalid get-value command, empty list of terms", terms.end);
|
|
1334
|
-
|
|
1749
|
+
const extra = list.items[2];
|
|
1750
|
+
if (
|
|
1751
|
+
extra?.kind === "keyword" &&
|
|
1752
|
+
(extra.text === ":model-index" || extra.text === ":model_index")
|
|
1753
|
+
)
|
|
1754
|
+
throw new SmtUnsupportedError("the model index of get-value");
|
|
1755
|
+
if (extra !== undefined)
|
|
1756
|
+
throw new SmtParseError("invalid get-value command, ')' expected", extra);
|
|
1335
1757
|
const model = getModel(list);
|
|
1758
|
+
pendingText += "(";
|
|
1336
1759
|
model.compact();
|
|
1337
1760
|
// Z3 prints each term as the script spells it, from the end of the term before.
|
|
1338
1761
|
const offsets = [
|
|
1339
1762
|
terms.offset + 1,
|
|
1340
1763
|
...terms.items.map((item) => (item.kind === "list" ? item.end : item).endOffset),
|
|
1341
1764
|
];
|
|
1342
|
-
|
|
1765
|
+
exprs.forEach((expr, index) => {
|
|
1343
1766
|
manager.incRef(expr);
|
|
1344
1767
|
const value = model.eval(expr, true);
|
|
1345
|
-
|
|
1768
|
+
pendingText += `${index > 0 ? "\n " : ""}(${text.slice(offsets[index], offsets[index + 1]).trim()} ${format(value)})`;
|
|
1346
1769
|
manager.decRef(value);
|
|
1347
1770
|
manager.decRef(expr);
|
|
1348
|
-
return line;
|
|
1349
1771
|
});
|
|
1350
|
-
print(
|
|
1772
|
+
print(")");
|
|
1773
|
+
},
|
|
1774
|
+
],
|
|
1775
|
+
[
|
|
1776
|
+
"get-assignment",
|
|
1777
|
+
(list) => {
|
|
1778
|
+
checkArgumentCount(list, 0);
|
|
1779
|
+
const manager = state.manager;
|
|
1780
|
+
const model = getModel(list);
|
|
1781
|
+
const assignments = state.reader.getConstantMacros().flatMap((macro) => {
|
|
1782
|
+
if (manager.sorts[macro.body] !== SORT_BOOL) return [];
|
|
1783
|
+
const value = model.eval(macro.body, true);
|
|
1784
|
+
const assignment = `(${getQuotedName(macro.name)} ${manager.isTrue(value)})`;
|
|
1785
|
+
const isDecided = manager.isTrue(value) || manager.isFalse(value);
|
|
1786
|
+
manager.decRef(value);
|
|
1787
|
+
return isDecided ? [assignment] : [];
|
|
1788
|
+
});
|
|
1789
|
+
print(`(${assignments.join(" ")})`);
|
|
1351
1790
|
},
|
|
1352
1791
|
],
|
|
1353
1792
|
[
|
|
@@ -1362,14 +1801,27 @@ export const runSmtlibScript = (
|
|
|
1362
1801
|
[
|
|
1363
1802
|
"get-model",
|
|
1364
1803
|
(list) => {
|
|
1365
|
-
|
|
1804
|
+
for (const index of list.items.slice(1)) {
|
|
1805
|
+
if (index.kind !== "numeral")
|
|
1806
|
+
throw new SmtParseError("invalid command argument, unsigned integer expected", index);
|
|
1807
|
+
if (!isUnsigned(index.text))
|
|
1808
|
+
throw new SmtParseError(
|
|
1809
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
1810
|
+
index,
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1366
1813
|
const manager = state.manager;
|
|
1367
1814
|
const model = getModel(list);
|
|
1815
|
+
const last = list.items[list.items.length - 1];
|
|
1816
|
+
// get_model_cmd takes any number of indices and keeps the last.
|
|
1817
|
+
if (last.kind === "numeral" && BigInt(last.text) > 0n)
|
|
1818
|
+
throw new SmtUnsupportedError("the index of get-model");
|
|
1368
1819
|
model.compact();
|
|
1369
1820
|
for (const decl of state.reader.getDeclaredFuncs()) {
|
|
1370
1821
|
const funcDecl = manager.funcDecls[decl];
|
|
1371
1822
|
if (
|
|
1372
1823
|
funcDecl.family !== FAMILY_USER ||
|
|
1824
|
+
manager.macros.has(decl) ||
|
|
1373
1825
|
model.constInterps.has(decl) ||
|
|
1374
1826
|
model.funcInterps.has(decl)
|
|
1375
1827
|
)
|
|
@@ -1387,7 +1839,13 @@ export const runSmtlibScript = (
|
|
|
1387
1839
|
print(`(\n${printModel(manager, getPrintEnvironment(), model, 2)})`);
|
|
1388
1840
|
},
|
|
1389
1841
|
],
|
|
1390
|
-
[
|
|
1842
|
+
[
|
|
1843
|
+
"display",
|
|
1844
|
+
(list) => {
|
|
1845
|
+
display(state.reader.parseTerm(getFirstArgument(list)));
|
|
1846
|
+
checkArgumentCount(list, 1);
|
|
1847
|
+
},
|
|
1848
|
+
],
|
|
1391
1849
|
[
|
|
1392
1850
|
"dbg-lt",
|
|
1393
1851
|
(list) => {
|
|
@@ -1400,7 +1858,13 @@ export const runSmtlibScript = (
|
|
|
1400
1858
|
"dbg-some-value",
|
|
1401
1859
|
(list) => {
|
|
1402
1860
|
display(
|
|
1403
|
-
getManagerSomeValue(
|
|
1861
|
+
getManagerSomeValue(
|
|
1862
|
+
state.manager,
|
|
1863
|
+
state.reader.parseSort(
|
|
1864
|
+
list.items[1] ?? list.end,
|
|
1865
|
+
"invalid command argument, sort expected",
|
|
1866
|
+
),
|
|
1867
|
+
),
|
|
1404
1868
|
);
|
|
1405
1869
|
},
|
|
1406
1870
|
],
|
|
@@ -1436,10 +1900,11 @@ export const runSmtlibScript = (
|
|
|
1436
1900
|
[
|
|
1437
1901
|
"echo",
|
|
1438
1902
|
(list) => {
|
|
1439
|
-
const message = list
|
|
1440
|
-
if (message
|
|
1441
|
-
throw new SmtParseError("invalid
|
|
1903
|
+
const message = getFirstArgument(list);
|
|
1904
|
+
if (message.kind !== "string")
|
|
1905
|
+
throw new SmtParseError("invalid command argument, string expected", message);
|
|
1442
1906
|
print(message.text);
|
|
1907
|
+
checkArgumentCount(list, 1);
|
|
1443
1908
|
},
|
|
1444
1909
|
],
|
|
1445
1910
|
[
|
|
@@ -1450,10 +1915,28 @@ export const runSmtlibScript = (
|
|
|
1450
1915
|
const optionName = `:${getParameterName(keyword)}`;
|
|
1451
1916
|
const value = list.items[2];
|
|
1452
1917
|
const isTrue = isSymbol(value, "true");
|
|
1918
|
+
if (
|
|
1919
|
+
(keyword === ":produce-proofs" ||
|
|
1920
|
+
keyword === ":produce-unsat-cores" ||
|
|
1921
|
+
keyword === ":produce-unsat-assumptions") &&
|
|
1922
|
+
state.assertions.length > 0
|
|
1923
|
+
)
|
|
1924
|
+
throw new SmtParseError(
|
|
1925
|
+
`error setting '${keyword}', option value cannot be modified after assertions have been added`,
|
|
1926
|
+
value ?? list.end,
|
|
1927
|
+
);
|
|
1453
1928
|
if (keyword === ":produce-models") settings.isProducingModels = isTrue;
|
|
1454
1929
|
if (keyword === ":produce-unsat-cores") settings.isProducingUnsatCores = isTrue;
|
|
1930
|
+
if (keyword === ":produce-unsat-assumptions") settings.isProducingUnsatAssumptions = isTrue;
|
|
1455
1931
|
if (keyword === ":produce-proofs") settings.isProducingProofs = isTrue;
|
|
1456
|
-
if (keyword === ":interactive-mode"
|
|
1932
|
+
if (keyword === ":interactive-mode" || keyword === ":produce-assertions") {
|
|
1933
|
+
if (state.isProofsEnabled !== undefined)
|
|
1934
|
+
throw new SmtParseError(
|
|
1935
|
+
"error setting ':produce-assertions', option value cannot be modified after initialization",
|
|
1936
|
+
value ?? list.end,
|
|
1937
|
+
);
|
|
1938
|
+
settings.isInteractive = isTrue;
|
|
1939
|
+
}
|
|
1457
1940
|
if (keyword === ":diagnostic-output-channel")
|
|
1458
1941
|
settings.isDiagnosticOnStdout = value?.kind === "string" && value.text === "stdout";
|
|
1459
1942
|
if (keyword === ":int-real-coercions" && !isTrue)
|
|
@@ -1466,13 +1949,12 @@ export const runSmtlibScript = (
|
|
|
1466
1949
|
);
|
|
1467
1950
|
settings.isExitingOnError = isSymbol(value, "immediate-exit");
|
|
1468
1951
|
}
|
|
1469
|
-
|
|
1952
|
+
const isParameter =
|
|
1470
1953
|
keyword !== "" &&
|
|
1471
1954
|
!BUILTIN_OPTIONS.has(keyword) &&
|
|
1472
1955
|
value !== undefined &&
|
|
1473
|
-
value.kind !== "list"
|
|
1474
|
-
)
|
|
1475
|
-
settings.parameters.set(getParameterName(keyword), value.text);
|
|
1956
|
+
value.kind !== "list";
|
|
1957
|
+
if (isParameter) settings.parameters.set(getParameterName(keyword), value.text);
|
|
1476
1958
|
if (optionName === ":print_success") settings.isPrintingSuccess = isTrue;
|
|
1477
1959
|
if (
|
|
1478
1960
|
!BUILTIN_OPTIONS.has(keyword) &&
|
|
@@ -1485,6 +1967,9 @@ export const runSmtlibScript = (
|
|
|
1485
1967
|
settings.mbqiMaxIterations = Number(value.text);
|
|
1486
1968
|
if (optionName === ":rlimit" && value?.kind === "numeral")
|
|
1487
1969
|
settings.rlimit = Number(value.text);
|
|
1970
|
+
const kernel = state.kernel;
|
|
1971
|
+
if (isParameter && kernel !== undefined)
|
|
1972
|
+
kernel.updateParams(getKernelParams(kernel.isSetUp));
|
|
1488
1973
|
if (optionName === ":rewriter.hi_div0") {
|
|
1489
1974
|
settings.isHiDiv0 = isTrue;
|
|
1490
1975
|
state.manager.isHiDiv0 = isTrue;
|
|
@@ -1502,9 +1987,10 @@ export const runSmtlibScript = (
|
|
|
1502
1987
|
const booleanOption = BOOLEAN_PRINT_OPTIONS.get(optionName);
|
|
1503
1988
|
if (booleanOption !== undefined) settings.printOptions[booleanOption] = isTrue;
|
|
1504
1989
|
if (
|
|
1505
|
-
optionName.startsWith(":pp.") &&
|
|
1506
|
-
|
|
1507
|
-
|
|
1990
|
+
(optionName.startsWith(":pp.") &&
|
|
1991
|
+
numericOption === undefined &&
|
|
1992
|
+
booleanOption === undefined) ||
|
|
1993
|
+
optionName.startsWith(":lp.")
|
|
1508
1994
|
)
|
|
1509
1995
|
throw new SmtUnsupportedError(`the option ${optionName}`);
|
|
1510
1996
|
},
|
|
@@ -1519,6 +2005,9 @@ export const runSmtlibScript = (
|
|
|
1519
2005
|
[":print-success", settings.isPrintingSuccess],
|
|
1520
2006
|
[":produce-models", settings.isProducingModels],
|
|
1521
2007
|
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
2008
|
+
[":produce-unsat-assumptions", settings.isProducingUnsatAssumptions],
|
|
2009
|
+
[":interactive-mode", settings.isInteractive],
|
|
2010
|
+
[":produce-assertions", settings.isInteractive],
|
|
1522
2011
|
[":int-real-coercions", true],
|
|
1523
2012
|
[":error-behavior", settings.isExitingOnError ? "immediate-exit" : "continued-execution"],
|
|
1524
2013
|
]);
|
|
@@ -1536,44 +2025,20 @@ export const runSmtlibScript = (
|
|
|
1536
2025
|
"get-info",
|
|
1537
2026
|
(list) => {
|
|
1538
2027
|
const info = list.items[1];
|
|
1539
|
-
if (info
|
|
1540
|
-
throw new SmtParseError("invalid command argument
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
check?.status === L_UNDEF &&
|
|
1546
|
-
optimizer !== undefined &&
|
|
1547
|
-
optimizer.reasonUnknown !== ""
|
|
1548
|
-
) {
|
|
1549
|
-
print(`(:reason-unknown "${optimizer.reasonUnknown}")`);
|
|
1550
|
-
return;
|
|
1551
|
-
}
|
|
1552
|
-
const reasonUnknown =
|
|
1553
|
-
check === undefined
|
|
1554
|
-
? "state of the most recent check-sat command is not known"
|
|
1555
|
-
: check.reasonUnknown;
|
|
1556
|
-
if (info.text === ":reason-unknown" && reasonUnknown !== undefined) {
|
|
1557
|
-
print(`(:reason-unknown "${reasonUnknown.replaceAll('"', '\\"')}")`);
|
|
1558
|
-
return;
|
|
1559
|
-
}
|
|
1560
|
-
if (info.text === ":rlimit") {
|
|
1561
|
-
print(`(:rlimit ${state.manager.limit.count})`);
|
|
1562
|
-
return;
|
|
1563
|
-
}
|
|
1564
|
-
if (info.text !== ":error-behavior")
|
|
1565
|
-
throw new SmtUnsupportedError(`the information ${info.text}`);
|
|
1566
|
-
print(
|
|
1567
|
-
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1568
|
-
);
|
|
2028
|
+
if (info === undefined)
|
|
2029
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2030
|
+
if (info.kind !== "keyword")
|
|
2031
|
+
throw new SmtParseError("invalid command argument, keyword expected", info);
|
|
2032
|
+
printInfo(list, info.text);
|
|
2033
|
+
checkArgumentCount(list, 1);
|
|
1569
2034
|
},
|
|
1570
2035
|
],
|
|
1571
2036
|
[
|
|
1572
2037
|
"set-logic",
|
|
1573
2038
|
(list) => {
|
|
1574
|
-
const logic = list
|
|
2039
|
+
const logic = getFirstArgument(list);
|
|
1575
2040
|
if (!isSymbol(logic))
|
|
1576
|
-
throw new SmtParseError("invalid
|
|
2041
|
+
throw new SmtParseError("invalid command argument, symbol expected", logic);
|
|
1577
2042
|
if (state.logic !== undefined)
|
|
1578
2043
|
throw new SmtParseError("the logic has already been set", logic);
|
|
1579
2044
|
if (state.assertions.length > 0)
|
|
@@ -1583,6 +2048,7 @@ export const runSmtlibScript = (
|
|
|
1583
2048
|
printDiagnostic(
|
|
1584
2049
|
`; ignoring unsupported logic ${logic.text} line: ${list.line} position: ${list.column}`,
|
|
1585
2050
|
);
|
|
2051
|
+
checkArgumentCount(list, 1);
|
|
1586
2052
|
return;
|
|
1587
2053
|
}
|
|
1588
2054
|
state.logic = logic.text;
|
|
@@ -1590,14 +2056,37 @@ export const runSmtlibScript = (
|
|
|
1590
2056
|
state.reader = createSmtlibReader(state.manager, logic.text, settings.parserOptions);
|
|
1591
2057
|
else {
|
|
1592
2058
|
state.reader.restrictSorts(logic.text);
|
|
1593
|
-
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop
|
|
1594
|
-
// and keeps what they asserted.
|
|
2059
|
+
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop and keeps what they asserted.
|
|
1595
2060
|
resetKernel();
|
|
1596
2061
|
}
|
|
1597
2062
|
if (settings.isPrintingSuccess) print("success");
|
|
2063
|
+
checkArgumentCount(list, 1);
|
|
2064
|
+
},
|
|
2065
|
+
],
|
|
2066
|
+
[
|
|
2067
|
+
"set-info",
|
|
2068
|
+
(list) => {
|
|
2069
|
+
const info = list.items[1];
|
|
2070
|
+
if (info === undefined)
|
|
2071
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2072
|
+
if (info.kind !== "keyword")
|
|
2073
|
+
throw new SmtParseError("invalid command argument, keyword expected", info);
|
|
2074
|
+
const value = list.items[2];
|
|
2075
|
+
if (value === undefined)
|
|
2076
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2077
|
+
if (value.kind === "list" || value.kind === "keyword" || value.kind === "eof")
|
|
2078
|
+
throw new SmtParseError("invalid option value", value);
|
|
2079
|
+
if (info.text === ":status" && value.kind === "symbol") {
|
|
2080
|
+
const status = [L_TRUE, L_FALSE, L_UNDEF].find(
|
|
2081
|
+
(innerStatus) => getVerdict(innerStatus) === value.text,
|
|
2082
|
+
);
|
|
2083
|
+
if (status === undefined) throw new SmtParseError("invalid ':status' attribute", value);
|
|
2084
|
+
settings.status = status;
|
|
2085
|
+
}
|
|
2086
|
+
if (list.items[3] !== undefined)
|
|
2087
|
+
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
1598
2088
|
},
|
|
1599
2089
|
],
|
|
1600
|
-
["set-info", () => {}],
|
|
1601
2090
|
]);
|
|
1602
2091
|
const run = (list: SmtList) => {
|
|
1603
2092
|
const head = list.items[0];
|
|
@@ -1606,18 +2095,34 @@ export const runSmtlibScript = (
|
|
|
1606
2095
|
const command = DECLARATIONS.has(head.text)
|
|
1607
2096
|
? (declaration: SmtList) => state.reader.declareCommand(declaration)
|
|
1608
2097
|
: runCommand.get(head.text);
|
|
1609
|
-
if (command === undefined
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
2098
|
+
if (command === undefined && UNPORTED_COMMANDS.has(head.text))
|
|
2099
|
+
throw new SmtUnsupportedError(`the command ${head.text}`);
|
|
2100
|
+
if (command === undefined) {
|
|
2101
|
+
expectClosed(list);
|
|
2102
|
+
print("unsupported");
|
|
2103
|
+
printDiagnostic(`; ${head.text} line: ${list.end.line} position: ${list.end.column}`);
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
// Z3's scoped_timer ends with the command that set it, so a command starts without one.
|
|
2107
|
+
state.manager.limit.restart(Infinity);
|
|
2108
|
+
if (!MANAGERLESS_COMMANDS.has(head.text)) initManager();
|
|
2109
|
+
try {
|
|
2110
|
+
command(list);
|
|
2111
|
+
} catch (error) {
|
|
2112
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
2113
|
+
throw new SmtParseError(error.message, list.end);
|
|
1613
2114
|
}
|
|
1614
|
-
command(list);
|
|
1615
2115
|
if (settings.isPrintingSuccess && SILENT_COMMANDS.has(head.text)) print("success");
|
|
1616
2116
|
};
|
|
1617
2117
|
for (;;) {
|
|
1618
2118
|
try {
|
|
1619
|
-
const list = commands.
|
|
1620
|
-
if (list === undefined
|
|
2119
|
+
const list = commands.readCommand();
|
|
2120
|
+
if (list === undefined) break;
|
|
2121
|
+
if (isSymbol(list.items[0], "exit")) {
|
|
2122
|
+
checkArgumentCount(list, 0);
|
|
2123
|
+
if (settings.isPrintingSuccess) print("success");
|
|
2124
|
+
break;
|
|
2125
|
+
}
|
|
1621
2126
|
run(list);
|
|
1622
2127
|
} catch (error) {
|
|
1623
2128
|
if (!(error instanceof SmtParseError)) throw error;
|