tla-ts 0.0.10-dev.d618a2d79 → 0.0.10-dev.e3e5dd576
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 +49 -44
- package/dist/transfer.js +48 -43
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +14 -2
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +116 -64
- package/src/check.ts +516 -280
- 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 +190 -1
- package/src/dependencies.ts +68 -15
- package/src/dfid.ts +101 -36
- package/src/environment.ts +123 -38
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +370 -99
- package/src/exit-codes.ts +28 -14
- package/src/instances.ts +135 -11
- 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 +51 -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/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 +27 -1
- 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/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 +1 -2
- 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 +1 -2
- package/src/prover/smt/solver/dt2bv-tactic.ts +57 -21
- 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 +5 -8
- 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 +1 -2
- 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/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/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 +1 -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/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/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/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/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 +65 -12
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +129 -43
- 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 +17 -7
- package/src/prover/smt/solver/sat/sat2goal.ts +72 -48
- 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 +713 -210
- package/src/prover/smt/solver/solve-eqs.ts +36 -37
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +350 -195
- 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 +11 -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 +1 -0
- 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 +1274 -257
- package/src/runtime.ts +7 -1
- 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 +18 -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 +11 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +319 -135
- package/src/simulate.ts +235 -182
- package/src/spec-description.ts +8 -6
- package/src/standard-definitions.ts +1 -0
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +564 -138
- package/src/successors.ts +37 -13
- 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 +67 -43
- 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
|
+
? 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,17 @@ 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);
|
|
568
744
|
model.incRef();
|
|
569
745
|
check.model = model;
|
|
570
746
|
return model;
|
|
@@ -573,6 +749,12 @@ export const runSmtlibScript = (
|
|
|
573
749
|
state.check?.model?.decRef();
|
|
574
750
|
state.check = undefined;
|
|
575
751
|
};
|
|
752
|
+
// cmd_context::validate_check_sat_result runs after the answer is printed.
|
|
753
|
+
const validateCheck = (end: SmtToken) => {
|
|
754
|
+
const status = state.check?.status ?? L_UNDEF;
|
|
755
|
+
if (status !== L_UNDEF && settings.status !== L_UNDEF && status !== settings.status)
|
|
756
|
+
throw new SmtParseError(`check annotation that says ${getVerdict(settings.status)}`, end);
|
|
757
|
+
};
|
|
576
758
|
// The check holds a reference to its model until clearCheck.
|
|
577
759
|
const setCheck = (status: number, result: Partial<Omit<CheckResult, "status">> = {}) => {
|
|
578
760
|
result.model?.incRef();
|
|
@@ -580,14 +762,13 @@ export const runSmtlibScript = (
|
|
|
580
762
|
status,
|
|
581
763
|
context: undefined,
|
|
582
764
|
isOptimizing: false,
|
|
765
|
+
isFromTactic: false,
|
|
583
766
|
model: undefined,
|
|
767
|
+
fdSolver: undefined,
|
|
584
768
|
core: undefined,
|
|
585
769
|
...result,
|
|
586
770
|
};
|
|
587
771
|
};
|
|
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
772
|
const resetKernel = () => {
|
|
592
773
|
const logic = state.logic;
|
|
593
774
|
const parameters = settings.parameters;
|
|
@@ -601,48 +782,70 @@ export const runSmtlibScript = (
|
|
|
601
782
|
parameters.get("tactic.default_tactic") === "sat" ||
|
|
602
783
|
parameters.get("sat.smt") === "true" ||
|
|
603
784
|
isEuf;
|
|
604
|
-
state.
|
|
785
|
+
state.satSolver?.release();
|
|
605
786
|
state.kernel = isSatSolver ? undefined : new SmtKernel(state.manager, getKernelParams());
|
|
606
|
-
state.
|
|
607
|
-
|
|
608
|
-
? new IncSatSolver(state.manager, getSatParams(parameters), true, mkThSolver)
|
|
787
|
+
state.satSolver =
|
|
788
|
+
isSatSolver && !isFdSolver && parameters.get("sat.smt") !== "true"
|
|
789
|
+
? new IncSatSolver(state.manager, getSatParams(parameters), true, isEuf ? mkThSolver : null)
|
|
790
|
+
: undefined;
|
|
791
|
+
state.fdSolver?.release();
|
|
792
|
+
state.fdSolver =
|
|
793
|
+
(logic === "QF_FD" || logic === "SAT") &&
|
|
794
|
+
!isProofsEnabled &&
|
|
795
|
+
!parameters.has("tactic.default_tactic")
|
|
796
|
+
? new FdSolver(state.manager, getSatParams(parameters))
|
|
609
797
|
: undefined;
|
|
610
798
|
for (let index = 0; index < state.scopes.length; index++) {
|
|
611
799
|
state.kernel?.push();
|
|
612
|
-
|
|
800
|
+
useSatSolver((solver) => solver.push());
|
|
801
|
+
state.fdSolver?.push();
|
|
613
802
|
}
|
|
614
803
|
};
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
804
|
+
const initManager = () => {
|
|
805
|
+
if (state.isProofsEnabled !== undefined) return;
|
|
806
|
+
state.isProofsEnabled = settings.parameters.get("proof") === "true";
|
|
807
|
+
if (state.logic === undefined || logicHasSeq(state.logic)) state.manager.initSeqPlugin();
|
|
808
|
+
if (state.logic === undefined) state.reader.registerList();
|
|
809
|
+
resetKernel();
|
|
810
|
+
};
|
|
811
|
+
// The parts of inc_sat_solver that are not ported leave its answers to the smt kernel.
|
|
812
|
+
const useSatSolver = <Result>(action: (solver: IncSatSolver) => Result) => {
|
|
813
|
+
const solver = state.satSolver;
|
|
618
814
|
if (solver === undefined) return undefined;
|
|
619
815
|
try {
|
|
620
816
|
return action(solver);
|
|
621
817
|
} catch (error) {
|
|
622
818
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
623
819
|
solver.release();
|
|
624
|
-
state.
|
|
820
|
+
state.satSolver = undefined;
|
|
625
821
|
return undefined;
|
|
626
822
|
}
|
|
627
823
|
};
|
|
628
824
|
// solver_na2as asserts a named assertion as an implication from its name.
|
|
629
825
|
const assertInKernel = (formula: number, name: number) => {
|
|
630
826
|
const manager = state.manager;
|
|
827
|
+
useSatSolver((solver) =>
|
|
828
|
+
name === -1 ? solver.assertExpr(formula) : solver.assertNamed(formula, name),
|
|
829
|
+
);
|
|
830
|
+
state.fdSolver?.assertExpr(formula, name);
|
|
831
|
+
const kernel = state.kernel;
|
|
832
|
+
if (kernel === undefined) return;
|
|
631
833
|
const asserted = name === -1 ? formula : manager.mkApp(OP_IMPLIES, [name, formula], SORT_BOOL);
|
|
632
834
|
manager.incRef(asserted);
|
|
633
|
-
|
|
634
|
-
useEufSolver((solver) => solver.assertExpr(asserted));
|
|
835
|
+
kernel.assertExpr(asserted);
|
|
635
836
|
manager.decRef(asserted);
|
|
636
837
|
};
|
|
637
|
-
const checkKernel = (
|
|
838
|
+
const checkKernel = (names: number[], extra: number[]) => {
|
|
638
839
|
const kernel = state.kernel;
|
|
639
|
-
const
|
|
640
|
-
|
|
840
|
+
const assumptions = [...names, ...extra];
|
|
841
|
+
const found = useSatSolver((solver) => {
|
|
842
|
+
const result = solver.check(extra);
|
|
641
843
|
return {
|
|
642
844
|
result,
|
|
643
845
|
context: undefined,
|
|
644
846
|
model: result === L_TRUE ? (solver.getModel() ?? undefined) : undefined,
|
|
645
847
|
core: result === L_FALSE ? [...solver.getUnsatCore()] : undefined,
|
|
848
|
+
reasonUnknown: solver.reasonUnknown,
|
|
646
849
|
};
|
|
647
850
|
});
|
|
648
851
|
if (found !== undefined) return found;
|
|
@@ -652,11 +855,21 @@ export const runSmtlibScript = (
|
|
|
652
855
|
context: kernel.context,
|
|
653
856
|
model: undefined,
|
|
654
857
|
core: undefined,
|
|
858
|
+
reasonUnknown: undefined,
|
|
655
859
|
};
|
|
860
|
+
const solved = solveAssuming(
|
|
861
|
+
state.manager,
|
|
862
|
+
getNamedAssertions(),
|
|
863
|
+
assumptions,
|
|
864
|
+
getKernelParams(),
|
|
865
|
+
);
|
|
656
866
|
return {
|
|
657
|
-
...
|
|
867
|
+
...solved,
|
|
658
868
|
model: undefined,
|
|
659
869
|
core: undefined,
|
|
870
|
+
// inc_sat_solver, which these logics use, keeps "no reason given" after an answer.
|
|
871
|
+
reasonUnknown:
|
|
872
|
+
solved.result === L_UNDEF ? solved.context.getLastFailureMessage() : "no reason given",
|
|
660
873
|
};
|
|
661
874
|
};
|
|
662
875
|
const printDiagnostic = (line: string) => print(line, !settings.isDiagnosticOnStdout);
|
|
@@ -690,11 +903,10 @@ export const runSmtlibScript = (
|
|
|
690
903
|
);
|
|
691
904
|
return state.datalog;
|
|
692
905
|
};
|
|
693
|
-
const getTactic = (sexpr: SExpr, end: SmtList["end"]) =>
|
|
694
|
-
compileTactic(getTacticEnvironment(), sexpr, end);
|
|
695
906
|
const getGoal = (isTrackingDependencies = false) => {
|
|
696
907
|
const goal = new Goal(state.manager);
|
|
697
908
|
goal.isProofsEnabled = settings.isProducingProofs || state.isProofsEnabled === true;
|
|
909
|
+
goal.isModelsEnabled = settings.isProducingModels;
|
|
698
910
|
goal.isCoresEnabled = settings.isProducingUnsatCores;
|
|
699
911
|
for (const [index, assertion] of state.assertions.entries())
|
|
700
912
|
goal.assert(
|
|
@@ -705,22 +917,43 @@ export const runSmtlibScript = (
|
|
|
705
917
|
);
|
|
706
918
|
return goal;
|
|
707
919
|
};
|
|
920
|
+
const getCommandGoal = (isTrackingDependencies: boolean, end: SmtToken) => {
|
|
921
|
+
if (
|
|
922
|
+
settings.isProducingUnsatCores &&
|
|
923
|
+
(settings.isProducingProofs || state.isProofsEnabled === true)
|
|
924
|
+
)
|
|
925
|
+
throw new SmtParseError(
|
|
926
|
+
"Frontend does not support simultaneous generation of proofs and unsat cores",
|
|
927
|
+
end,
|
|
928
|
+
);
|
|
929
|
+
return getGoal(isTrackingDependencies);
|
|
930
|
+
};
|
|
708
931
|
const hasNames = () => state.names.some((name) => name !== -1);
|
|
709
932
|
// parse_check_sat shrinks the expression stack once the check has run.
|
|
710
|
-
const checkSatAssuming = (items: SmtList["items"]) => {
|
|
933
|
+
const checkSatAssuming = (items: SmtList["items"], itemsEnd: SmtToken, end: SmtToken) => {
|
|
711
934
|
const literals: number[] = [];
|
|
712
935
|
try {
|
|
713
|
-
for (const item of items
|
|
714
|
-
|
|
936
|
+
for (const [index, item] of items.entries())
|
|
937
|
+
literals.push(
|
|
938
|
+
state.reader.parseFormula(
|
|
939
|
+
item,
|
|
940
|
+
items[index + 1] ?? itemsEnd,
|
|
941
|
+
"invalid check-sat command, argument must be a Boolean literal",
|
|
942
|
+
),
|
|
943
|
+
);
|
|
944
|
+
checkSat(literals, end);
|
|
715
945
|
} finally {
|
|
716
946
|
for (const literal of literals) state.manager.decRef(literal);
|
|
717
947
|
}
|
|
718
948
|
};
|
|
719
949
|
const addObjective = (list: SmtList, isMax: boolean) => {
|
|
720
|
-
const term = state.reader.parseTerm(list
|
|
950
|
+
const term = state.reader.parseTerm(getFirstArgument(list));
|
|
721
951
|
const sort = state.manager.sorts[term];
|
|
722
952
|
if (sort !== SORT_INT && sort !== SORT_REAL && !state.manager.isBvSort(sort))
|
|
723
|
-
throw new SmtParseError(
|
|
953
|
+
throw new SmtParseError(
|
|
954
|
+
"Objective must be bit-vector, integer or real",
|
|
955
|
+
list.items[2] ?? list.end,
|
|
956
|
+
);
|
|
724
957
|
resetOptimizer();
|
|
725
958
|
state.manager.incRef(term);
|
|
726
959
|
state.objectives.push({
|
|
@@ -730,6 +963,8 @@ export const runSmtlibScript = (
|
|
|
730
963
|
weights: [],
|
|
731
964
|
id: null,
|
|
732
965
|
});
|
|
966
|
+
if (settings.isPrintingSuccess) print("success");
|
|
967
|
+
checkArgumentCount(list, 1);
|
|
733
968
|
};
|
|
734
969
|
const releaseObjectives = (size: number, softSize: number) => {
|
|
735
970
|
for (const index of state.softTrail.splice(softSize).reverse()) {
|
|
@@ -798,20 +1033,25 @@ export const runSmtlibScript = (
|
|
|
798
1033
|
if (name.kind === "list")
|
|
799
1034
|
throw new SmtUnsupportedError("an indexed function declaration reference");
|
|
800
1035
|
throw new SmtParseError(
|
|
801
|
-
|
|
1036
|
+
`invalid function declaration reference, symbol or '(' expected got ${name.lastId}`,
|
|
802
1037
|
name,
|
|
803
1038
|
);
|
|
804
1039
|
}
|
|
805
1040
|
const domain = reference.items[1] ?? reference.end;
|
|
806
1041
|
if (domain.kind !== "list")
|
|
807
1042
|
throw new SmtParseError(
|
|
808
|
-
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.
|
|
1043
|
+
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.lastId}`,
|
|
809
1044
|
domain,
|
|
810
1045
|
);
|
|
811
|
-
const sorts = domain.items.map((sort) =>
|
|
1046
|
+
const sorts = domain.items.map((sort) =>
|
|
1047
|
+
state.reader.parseSort(
|
|
1048
|
+
sort,
|
|
1049
|
+
"Invalid function name. Expecting sort list starting with '(' to disambiguate function name",
|
|
1050
|
+
),
|
|
1051
|
+
);
|
|
812
1052
|
if (reference.items[2] === undefined)
|
|
813
1053
|
throw new SmtParseError("Invalid function name invalid sort, unexpected ')'", reference.end);
|
|
814
|
-
const range = state.reader.parseSort(reference.items[2]);
|
|
1054
|
+
const range = state.reader.parseSort(reference.items[2], "Invalid function name");
|
|
815
1055
|
const follower = reference.items[3] ?? reference.end;
|
|
816
1056
|
const found = state.reader.getFuncs(name.text).find((decl) => {
|
|
817
1057
|
const funcDecl = state.manager.funcDecls[decl];
|
|
@@ -830,16 +1070,87 @@ export const runSmtlibScript = (
|
|
|
830
1070
|
throw new SmtUnsupportedError("a function declaration reference with trailing terms");
|
|
831
1071
|
return found;
|
|
832
1072
|
};
|
|
1073
|
+
// get_info_cmd prints in set_next_arg, before the parser checks the rest of the command.
|
|
1074
|
+
const printInfo = (list: SmtList, keyword: string) => {
|
|
1075
|
+
if (keyword === ":reason-unknown") {
|
|
1076
|
+
const check = state.check;
|
|
1077
|
+
const reasonUnknown =
|
|
1078
|
+
check === undefined
|
|
1079
|
+
? "state of the most recent check-sat command is not known"
|
|
1080
|
+
: check.reasonUnknown;
|
|
1081
|
+
if (reasonUnknown === undefined)
|
|
1082
|
+
throw new SmtUnsupportedError("the information :reason-unknown");
|
|
1083
|
+
print(`(:reason-unknown "${reasonUnknown.replaceAll('"', '\\"')}")`);
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
if (keyword === ":rlimit") {
|
|
1087
|
+
initManager();
|
|
1088
|
+
print(`(:rlimit ${state.manager.limit.count})`);
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
if (keyword === ":error-behavior") {
|
|
1092
|
+
print(
|
|
1093
|
+
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1094
|
+
);
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (keyword === ":name") {
|
|
1098
|
+
print('(:name "Z3")');
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
if (keyword === ":authors") {
|
|
1102
|
+
print(
|
|
1103
|
+
'(:authors "Leonardo de Moura, Nikolaj Bjorner, Lev Nachmanson and Christoph Wintersteiger")',
|
|
1104
|
+
);
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
if (keyword === ":version") {
|
|
1108
|
+
print('(:version "5.3.2")');
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
if (keyword === ":status") {
|
|
1112
|
+
print(`(:status ${getVerdict(settings.status)})`);
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (keyword === ":assertion-stack-levels") {
|
|
1116
|
+
print(`(:assertion-stack-levels ${state.scopes.length})`);
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (keyword === ":all-statistics" || keyword === ":parameters")
|
|
1120
|
+
throw new SmtUnsupportedError(`the information ${keyword}`);
|
|
1121
|
+
if (keyword !== ":?") {
|
|
1122
|
+
print("unsupported");
|
|
1123
|
+
printDiagnostic(`; ${keyword} line: ${list.line} position: ${list.column}`);
|
|
1124
|
+
}
|
|
1125
|
+
print("; Suppported get-info parameters:");
|
|
1126
|
+
for (const supported of GET_INFO_KEYWORDS) print(`; (get-info ${supported})`);
|
|
1127
|
+
};
|
|
1128
|
+
const printCore = () => {
|
|
1129
|
+
const check = state.check;
|
|
1130
|
+
if (check?.core === undefined)
|
|
1131
|
+
throw new SmtUnsupportedError("the unsat core of a tactic that drops dependencies");
|
|
1132
|
+
const kernel = state.kernel;
|
|
1133
|
+
if (kernel === undefined || check.context !== kernel.context) {
|
|
1134
|
+
print(`(${check.core.map(format).join(" ")})`);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1138
|
+
const core = new RefVector(state.manager);
|
|
1139
|
+
kernel.getUnsatCore(core);
|
|
1140
|
+
print(`(${core.items.map(format).join(" ")})`);
|
|
1141
|
+
core.reset();
|
|
1142
|
+
};
|
|
833
1143
|
const runCommand = new Map<string, (list: SmtList) => void>([
|
|
834
1144
|
[
|
|
835
1145
|
"assert",
|
|
836
1146
|
(list) => {
|
|
837
1147
|
const term = list.items[1] ?? list.end;
|
|
838
|
-
const
|
|
1148
|
+
const follower = list.items[2] ?? list.end;
|
|
1149
|
+
const assertion = state.reader.parseAssertion(term, follower);
|
|
839
1150
|
const logicError = state.reader.getLogicError(assertion.formula);
|
|
840
1151
|
if (logicError !== undefined) {
|
|
841
1152
|
state.manager.decRef(assertion.formula);
|
|
842
|
-
throw new SmtParseError(logicError,
|
|
1153
|
+
throw new SmtParseError(logicError, follower);
|
|
843
1154
|
}
|
|
844
1155
|
state.assertions.push(assertion.formula);
|
|
845
1156
|
state.assertionTexts.push(
|
|
@@ -860,9 +1171,17 @@ export const runSmtlibScript = (
|
|
|
860
1171
|
}
|
|
861
1172
|
assertInKernel(assertion.formula, state.names[state.names.length - 1]);
|
|
862
1173
|
clearCheck();
|
|
1174
|
+
if (follower !== list.end)
|
|
1175
|
+
throw new SmtParseError("invalid assert command, ')' expected", follower);
|
|
1176
|
+
},
|
|
1177
|
+
],
|
|
1178
|
+
[
|
|
1179
|
+
"check-sat",
|
|
1180
|
+
(list) => {
|
|
1181
|
+
checkSatAssuming(list.items.slice(1), list.end, list.end);
|
|
1182
|
+
validateCheck(list.end);
|
|
863
1183
|
},
|
|
864
1184
|
],
|
|
865
|
-
["check-sat", (list) => checkSatAssuming(list.items.slice(1))],
|
|
866
1185
|
[
|
|
867
1186
|
"declare-rel",
|
|
868
1187
|
(list) => {
|
|
@@ -872,7 +1191,9 @@ export const runSmtlibScript = (
|
|
|
872
1191
|
throw new SmtParseError("at least 2 arguments expected", list.end);
|
|
873
1192
|
const decl = state.manager.mkFuncDecl(
|
|
874
1193
|
name.text,
|
|
875
|
-
domain.items.map((sort) =>
|
|
1194
|
+
domain.items.map((sort) =>
|
|
1195
|
+
state.reader.parseSort(sort, "expecting sort list starting with '('"),
|
|
1196
|
+
),
|
|
876
1197
|
SORT_BOOL,
|
|
877
1198
|
);
|
|
878
1199
|
state.reader.insertFunc(decl, list.end);
|
|
@@ -890,7 +1211,7 @@ export const runSmtlibScript = (
|
|
|
890
1211
|
list.end,
|
|
891
1212
|
);
|
|
892
1213
|
const manager = state.manager;
|
|
893
|
-
const range = state.reader.parseSort(sort);
|
|
1214
|
+
const range = state.reader.parseSort(sort, "invalid command argument, sort expected");
|
|
894
1215
|
const decl = manager.mkFuncDecl(name.text, [], range);
|
|
895
1216
|
state.reader.insertFunc(decl, list.end);
|
|
896
1217
|
getDatalog().registerVariable(manager.mkApp(decl, [], range));
|
|
@@ -902,7 +1223,10 @@ export const runSmtlibScript = (
|
|
|
902
1223
|
const rule = list.items[1];
|
|
903
1224
|
if (rule === undefined) throw new SmtParseError("invalid rule, expected formula", list.end);
|
|
904
1225
|
const name = list.items[2];
|
|
905
|
-
getDatalog().addRule(
|
|
1226
|
+
getDatalog().addRule(
|
|
1227
|
+
state.reader.parseFormula(rule, rule),
|
|
1228
|
+
isSymbol(name) ? name.text : undefined,
|
|
1229
|
+
);
|
|
906
1230
|
},
|
|
907
1231
|
],
|
|
908
1232
|
[
|
|
@@ -924,15 +1248,17 @@ export const runSmtlibScript = (
|
|
|
924
1248
|
for (const assertion of state.assertions) datalog.assertExpr(assertion);
|
|
925
1249
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
926
1250
|
state.manager.limit.push(settings.rlimit);
|
|
1251
|
+
let status = L_UNDEF;
|
|
927
1252
|
try {
|
|
928
|
-
|
|
1253
|
+
status = datalog.relQuery(relation);
|
|
929
1254
|
} catch (error) {
|
|
930
1255
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
931
1256
|
print(`(error "query failed: ${error.message}")`);
|
|
932
|
-
print("unknown");
|
|
933
1257
|
} finally {
|
|
934
1258
|
state.manager.limit.pop();
|
|
935
1259
|
}
|
|
1260
|
+
print(status === L_UNDEF && datalog.isBounded ? "bounded" : getVerdict(status));
|
|
1261
|
+
datalog.isBounded = false;
|
|
936
1262
|
},
|
|
937
1263
|
],
|
|
938
1264
|
[
|
|
@@ -941,37 +1267,48 @@ export const runSmtlibScript = (
|
|
|
941
1267
|
const params = getCommandParams(list.items, CHECK_SAT_USING_PARAMETERS);
|
|
942
1268
|
if (list.items[1] === undefined)
|
|
943
1269
|
throw new SmtParseError("check-sat-using needs a tactic argument", list.end);
|
|
944
|
-
|
|
1270
|
+
expectClosed(list.items[1]);
|
|
1271
|
+
const builder = compileTactic(getTacticEnvironment(), list.items[1]);
|
|
945
1272
|
const tactic = builder.build(params);
|
|
1273
|
+
const goal = getCommandGoal(builder.isTrackingDependencies, list.end);
|
|
946
1274
|
clearCheck();
|
|
947
|
-
|
|
1275
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
1276
|
+
state.manager.limit.restart(deadline);
|
|
948
1277
|
state.manager.limit.push(settings.rlimit);
|
|
949
1278
|
try {
|
|
950
|
-
const checked = checkSatUsing(tactic,
|
|
1279
|
+
const checked = checkSatUsing(tactic, goal);
|
|
1280
|
+
const reasonUnknown = checked.reasonUnknown ?? getCancelMessage(deadline);
|
|
951
1281
|
setCheck(checked.status, {
|
|
1282
|
+
isFromTactic: true,
|
|
952
1283
|
model: checked.model,
|
|
953
1284
|
core:
|
|
954
1285
|
builder.isTrackingDependencies || !hasNames()
|
|
955
1286
|
? getDependencyValues(checked.core)
|
|
956
1287
|
: undefined,
|
|
957
|
-
reasonUnknown
|
|
1288
|
+
reasonUnknown,
|
|
958
1289
|
});
|
|
959
|
-
print(
|
|
1290
|
+
print(
|
|
1291
|
+
checked.isConversionCanceled
|
|
1292
|
+
? `(error "tactic failed: ${reasonUnknown}")`
|
|
1293
|
+
: getVerdict(checked.status),
|
|
1294
|
+
);
|
|
960
1295
|
} finally {
|
|
961
1296
|
state.manager.limit.pop();
|
|
962
1297
|
}
|
|
1298
|
+
validateCheck(list.end);
|
|
963
1299
|
},
|
|
964
1300
|
],
|
|
965
1301
|
[
|
|
966
1302
|
"check-sat-assuming",
|
|
967
1303
|
(list) => {
|
|
968
|
-
const literals = list.items[1];
|
|
969
|
-
if (literals
|
|
1304
|
+
const literals = list.items[1] ?? list.end;
|
|
1305
|
+
if (literals.kind !== "list")
|
|
970
1306
|
throw new SmtParseError(
|
|
971
|
-
|
|
972
|
-
literals
|
|
1307
|
+
`invalid check-sat-assuming command, '(', expected got ${literals.lastId}`,
|
|
1308
|
+
literals,
|
|
973
1309
|
);
|
|
974
|
-
checkSatAssuming(literals.items);
|
|
1310
|
+
checkSatAssuming(literals.items, literals.end, list.end);
|
|
1311
|
+
validateCheck(list.end);
|
|
975
1312
|
},
|
|
976
1313
|
],
|
|
977
1314
|
[
|
|
@@ -982,27 +1319,29 @@ export const runSmtlibScript = (
|
|
|
982
1319
|
if (terms === undefined)
|
|
983
1320
|
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
984
1321
|
if (terms.kind !== "list")
|
|
985
|
-
throw new SmtParseError(
|
|
1322
|
+
throw new SmtParseError(
|
|
1323
|
+
`invalid list of terms, '(' expected got ${terms.lastId}`,
|
|
1324
|
+
terms,
|
|
1325
|
+
);
|
|
986
1326
|
return terms.items.map((item) => state.reader.parseTerm(item));
|
|
987
1327
|
});
|
|
988
1328
|
if (list.items.length > 3)
|
|
989
1329
|
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
990
1330
|
clearCheck();
|
|
991
|
-
|
|
1331
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
1332
|
+
manager.limit.restart(deadline);
|
|
992
1333
|
manager.limit.push(settings.rlimit);
|
|
993
1334
|
const names = state.names.filter((name) => name !== -1);
|
|
994
1335
|
try {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
);
|
|
1005
|
-
setCheck(found.result, { model: found.model });
|
|
1336
|
+
const fdSolver = state.fdSolver;
|
|
1337
|
+
if (fdSolver !== undefined) {
|
|
1338
|
+
const found = fdSolver.getConsequences(assumptions, vars);
|
|
1339
|
+
setCheck(found.result, {
|
|
1340
|
+
isFromTactic: true,
|
|
1341
|
+
fdSolver,
|
|
1342
|
+
core: [...fdSolver.getUnsatCore()],
|
|
1343
|
+
reasonUnknown: fdSolver.reasonUnknown,
|
|
1344
|
+
});
|
|
1006
1345
|
print(getVerdict(found.result));
|
|
1007
1346
|
print("");
|
|
1008
1347
|
for (const consequence of found.consequences.items) display(consequence);
|
|
@@ -1013,11 +1352,22 @@ export const runSmtlibScript = (
|
|
|
1013
1352
|
if (state.kernel === undefined)
|
|
1014
1353
|
for (const assertion of getNamedAssertions()) kernel.assertExpr(assertion);
|
|
1015
1354
|
const found = getConsequences(kernel, [...names, ...assumptions], vars);
|
|
1016
|
-
setCheck(found.result, {
|
|
1355
|
+
setCheck(found.result, {
|
|
1356
|
+
context: kernel.context,
|
|
1357
|
+
core: kernel.context.unsatCore,
|
|
1358
|
+
reasonUnknown: kernel.context.getLastFailureMessage(),
|
|
1359
|
+
});
|
|
1017
1360
|
print(getVerdict(found.result));
|
|
1018
1361
|
print("");
|
|
1019
1362
|
for (const consequence of found.consequences.items) display(consequence);
|
|
1020
1363
|
found.consequences.reset();
|
|
1364
|
+
} catch (error) {
|
|
1365
|
+
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
1366
|
+
const reasonUnknown = getCancelMessage(deadline);
|
|
1367
|
+
if (state.kernel !== undefined) state.kernel.context.reasonUnknown = reasonUnknown;
|
|
1368
|
+
setCheck(L_UNDEF, { reasonUnknown });
|
|
1369
|
+
print("unknown");
|
|
1370
|
+
print("");
|
|
1021
1371
|
} finally {
|
|
1022
1372
|
manager.limit.pop();
|
|
1023
1373
|
}
|
|
@@ -1061,39 +1411,60 @@ export const runSmtlibScript = (
|
|
|
1061
1411
|
assertions: state.assertions.length,
|
|
1062
1412
|
objectives: state.objectives.length,
|
|
1063
1413
|
softTrail: state.softTrail.length,
|
|
1414
|
+
rlimit: settings.rlimit,
|
|
1064
1415
|
});
|
|
1065
1416
|
state.reader.push();
|
|
1066
1417
|
state.isIncremental = true;
|
|
1067
|
-
state.
|
|
1068
|
-
|
|
1418
|
+
const limit = state.manager.limit;
|
|
1419
|
+
limit.push(settings.rlimit);
|
|
1420
|
+
try {
|
|
1421
|
+
state.kernel?.push();
|
|
1422
|
+
useSatSolver((solver) => solver.push());
|
|
1423
|
+
state.fdSolver?.push();
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
1426
|
+
throw new SmtParseError(limit.getCancelMessage(), list.end);
|
|
1427
|
+
} finally {
|
|
1428
|
+
limit.pop();
|
|
1429
|
+
}
|
|
1069
1430
|
}
|
|
1431
|
+
if (list.items[2] !== undefined)
|
|
1432
|
+
throw new SmtParseError("invalid push command, ')' expected", list.items[2]);
|
|
1070
1433
|
},
|
|
1071
1434
|
],
|
|
1072
1435
|
[
|
|
1073
1436
|
"pop",
|
|
1074
1437
|
(list) => {
|
|
1075
1438
|
const count = getScopeCount(list);
|
|
1439
|
+
const follower = list.items[2] ?? list.end;
|
|
1440
|
+
clearCheck();
|
|
1076
1441
|
if (count > state.scopes.length)
|
|
1077
1442
|
throw new SmtParseError(
|
|
1078
1443
|
"invalid pop command, argument is greater than the current stack depth",
|
|
1079
|
-
|
|
1444
|
+
follower,
|
|
1080
1445
|
);
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1446
|
+
if (count > 0) {
|
|
1447
|
+
state.isIncremental = true;
|
|
1448
|
+
const scope = state.scopes[state.scopes.length - count];
|
|
1449
|
+
state.kernel?.pop(count);
|
|
1450
|
+
useSatSolver((solver) => solver.pop(count));
|
|
1451
|
+
state.fdSolver?.pop(count);
|
|
1452
|
+
state.reader.pop(count);
|
|
1453
|
+
restoreAssertions(scope.assertions);
|
|
1454
|
+
settings.rlimit = scope.rlimit;
|
|
1455
|
+
resetOptimizer();
|
|
1456
|
+
releaseObjectives(scope.objectives, scope.softTrail);
|
|
1457
|
+
state.scopes.length -= count;
|
|
1458
|
+
}
|
|
1459
|
+
if (follower !== list.end)
|
|
1460
|
+
throw new SmtParseError("invalid pop command, ')' expected", follower);
|
|
1092
1461
|
},
|
|
1093
1462
|
],
|
|
1094
1463
|
[
|
|
1095
1464
|
"reset",
|
|
1096
|
-
() => {
|
|
1465
|
+
(list) => {
|
|
1466
|
+
if (list.items[1] !== undefined)
|
|
1467
|
+
throw new SmtParseError("invalid reset command, ')' expected", list.items[1]);
|
|
1097
1468
|
clearCheck();
|
|
1098
1469
|
resetOptimizer();
|
|
1099
1470
|
state = createState();
|
|
@@ -1101,12 +1472,17 @@ export const runSmtlibScript = (
|
|
|
1101
1472
|
],
|
|
1102
1473
|
[
|
|
1103
1474
|
"reset-assertions",
|
|
1104
|
-
() => {
|
|
1105
|
-
|
|
1475
|
+
(list) => {
|
|
1476
|
+
checkArgumentCount(list, 0);
|
|
1106
1477
|
restoreAssertions(0);
|
|
1107
1478
|
resetOptimizer();
|
|
1108
1479
|
releaseObjectives(0, 0);
|
|
1109
|
-
state.scopes = state.scopes.map(() => ({
|
|
1480
|
+
state.scopes = state.scopes.map((scope) => ({
|
|
1481
|
+
...scope,
|
|
1482
|
+
assertions: 0,
|
|
1483
|
+
objectives: 0,
|
|
1484
|
+
softTrail: 0,
|
|
1485
|
+
}));
|
|
1110
1486
|
if (state.isProofsEnabled !== undefined) resetKernel();
|
|
1111
1487
|
state.isIncremental = state.scopes.length > 0;
|
|
1112
1488
|
state.hasChecked = false;
|
|
@@ -1124,7 +1500,17 @@ export const runSmtlibScript = (
|
|
|
1124
1500
|
manager,
|
|
1125
1501
|
getRewriterOptions(manager, getSimplifyParams(list.items.slice(2))),
|
|
1126
1502
|
);
|
|
1127
|
-
|
|
1503
|
+
// simplify_cmd prints a failure of the rewriter and then the term as it was.
|
|
1504
|
+
const simplified = (() => {
|
|
1505
|
+
try {
|
|
1506
|
+
return rewriter.rewrite(term);
|
|
1507
|
+
} catch (error) {
|
|
1508
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
1509
|
+
print(`(error "simplifier failed: ${error.message}")`);
|
|
1510
|
+
manager.incRef(term);
|
|
1511
|
+
return term;
|
|
1512
|
+
}
|
|
1513
|
+
})();
|
|
1128
1514
|
rewriter.cleanup();
|
|
1129
1515
|
display(simplified);
|
|
1130
1516
|
rewriter.release();
|
|
@@ -1143,8 +1529,7 @@ export const runSmtlibScript = (
|
|
|
1143
1529
|
manager.incRef(term);
|
|
1144
1530
|
const visited = new Set<number>();
|
|
1145
1531
|
const todo = [term];
|
|
1146
|
-
|
|
1147
|
-
const expr = todo.pop() as number;
|
|
1532
|
+
for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
|
|
1148
1533
|
if (visited.has(expr)) continue;
|
|
1149
1534
|
visited.add(expr);
|
|
1150
1535
|
const family = manager.kinds[expr] === KIND_APP ? manager.getFamily(expr) : -1;
|
|
@@ -1168,13 +1553,19 @@ export const runSmtlibScript = (
|
|
|
1168
1553
|
const params = getCommandParams(list.items, APPLY_PARAMETERS);
|
|
1169
1554
|
if (list.items[1] === undefined)
|
|
1170
1555
|
throw new SmtParseError("apply needs a tactic argument", list.end);
|
|
1171
|
-
|
|
1556
|
+
expectClosed(list.items[1]);
|
|
1557
|
+
// apply_tactic_cmd, unlike check-sat-using, gives the tactic no logic.
|
|
1558
|
+
const builder = compileTactic(
|
|
1559
|
+
{ ...getTacticEnvironment(), setup: { ...getSetup(), logic: undefined } },
|
|
1560
|
+
list.items[1],
|
|
1561
|
+
);
|
|
1172
1562
|
const tactic = builder.build(params);
|
|
1563
|
+
const input = getCommandGoal(builder.isTrackingDependencies, list.end);
|
|
1173
1564
|
const isPrintingDependencies = params.get("print_dependencies") === true;
|
|
1174
1565
|
if (isPrintingDependencies && !builder.isTrackingDependencies && hasNames())
|
|
1175
1566
|
throw new SmtUnsupportedError("the dependencies of a tactic that drops dependencies");
|
|
1176
1567
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1177
|
-
|
|
1568
|
+
state.manager.limit.push(settings.rlimit);
|
|
1178
1569
|
const goals = (() => {
|
|
1179
1570
|
try {
|
|
1180
1571
|
return applyTactic(tactic, input);
|
|
@@ -1182,6 +1573,8 @@ export const runSmtlibScript = (
|
|
|
1182
1573
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
1183
1574
|
print(`(error "tactic failed: ${error.message}")`);
|
|
1184
1575
|
return undefined;
|
|
1576
|
+
} finally {
|
|
1577
|
+
state.manager.limit.pop();
|
|
1185
1578
|
}
|
|
1186
1579
|
})();
|
|
1187
1580
|
// apply_tactic_cmd releases the result goals and then the input goal.
|
|
@@ -1239,8 +1632,7 @@ export const runSmtlibScript = (
|
|
|
1239
1632
|
const decls = new Set<number>();
|
|
1240
1633
|
for (const assertion of assertions) {
|
|
1241
1634
|
const todo = [assertion];
|
|
1242
|
-
|
|
1243
|
-
const expr = todo.pop() as number;
|
|
1635
|
+
for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
|
|
1244
1636
|
if (visited.has(expr)) continue;
|
|
1245
1637
|
visited.add(expr);
|
|
1246
1638
|
if (manager.kinds[expr] === KIND_QUANTIFIER) {
|
|
@@ -1281,6 +1673,7 @@ export const runSmtlibScript = (
|
|
|
1281
1673
|
[
|
|
1282
1674
|
"get-assertions",
|
|
1283
1675
|
(list) => {
|
|
1676
|
+
checkArgumentCount(list, 0);
|
|
1284
1677
|
if (!settings.isInteractive)
|
|
1285
1678
|
throw new SmtParseError(
|
|
1286
1679
|
"command is only available in interactive mode, use command (set-option :interactive-mode true)",
|
|
@@ -1292,17 +1685,29 @@ export const runSmtlibScript = (
|
|
|
1292
1685
|
[
|
|
1293
1686
|
"get-unsat-core",
|
|
1294
1687
|
(list) => {
|
|
1688
|
+
checkArgumentCount(list, 0);
|
|
1295
1689
|
if (!settings.isProducingUnsatCores)
|
|
1296
1690
|
throw new SmtParseError(
|
|
1297
1691
|
"unsat core construction is not enabled, use command (set-option :produce-unsat-cores true)",
|
|
1298
1692
|
list.end,
|
|
1299
1693
|
);
|
|
1300
|
-
|
|
1301
|
-
if (check === undefined || check.status !== L_FALSE)
|
|
1694
|
+
if (state.check?.status !== L_FALSE)
|
|
1302
1695
|
throw new SmtParseError("unsat core is not available", list.end);
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1696
|
+
printCore();
|
|
1697
|
+
},
|
|
1698
|
+
],
|
|
1699
|
+
[
|
|
1700
|
+
"get-unsat-assumptions",
|
|
1701
|
+
(list) => {
|
|
1702
|
+
checkArgumentCount(list, 0);
|
|
1703
|
+
if (!settings.isProducingUnsatAssumptions)
|
|
1704
|
+
throw new SmtParseError(
|
|
1705
|
+
"unsat assumptions construction is not enabled, use command (set-option :produce-unsat-assumptions true)",
|
|
1706
|
+
list.end,
|
|
1707
|
+
);
|
|
1708
|
+
if (state.check?.status !== L_FALSE)
|
|
1709
|
+
throw new SmtParseError("unsat assumptions is not available", list.end);
|
|
1710
|
+
printCore();
|
|
1306
1711
|
},
|
|
1307
1712
|
],
|
|
1308
1713
|
[
|
|
@@ -1310,13 +1715,19 @@ export const runSmtlibScript = (
|
|
|
1310
1715
|
(list) => {
|
|
1311
1716
|
const target = list.items[1];
|
|
1312
1717
|
const term = target === undefined ? -1 : state.reader.parseTerm(target);
|
|
1313
|
-
|
|
1718
|
+
const parameter = list.items[2];
|
|
1719
|
+
if (parameter !== undefined && parameter.kind !== "keyword")
|
|
1720
|
+
throw new SmtParseError("invalid command argument, keyword expected", parameter);
|
|
1721
|
+
if (parameter !== undefined) throw new SmtUnsupportedError("the parameters of eval");
|
|
1314
1722
|
const model = getModel(list);
|
|
1315
1723
|
if (term === -1) throw new SmtParseError("no arguments passed to eval", list.end);
|
|
1316
1724
|
const manager = state.manager;
|
|
1317
1725
|
manager.incRef(term);
|
|
1318
|
-
const
|
|
1726
|
+
const evaluator = new ModelEvaluator(manager, model);
|
|
1727
|
+
const value = evaluator.rewrite(term);
|
|
1319
1728
|
display(value);
|
|
1729
|
+
// eval_cmd frees its model_evaluator before the value, and the parser frees the term last.
|
|
1730
|
+
evaluator.release();
|
|
1320
1731
|
manager.decRef(value);
|
|
1321
1732
|
manager.decRef(term);
|
|
1322
1733
|
},
|
|
@@ -1324,30 +1735,57 @@ export const runSmtlibScript = (
|
|
|
1324
1735
|
[
|
|
1325
1736
|
"get-value",
|
|
1326
1737
|
(list) => {
|
|
1327
|
-
const terms = list.items[1];
|
|
1328
|
-
if (terms
|
|
1329
|
-
throw new SmtParseError(
|
|
1738
|
+
const terms = list.items[1] ?? list.end;
|
|
1739
|
+
if (terms.kind !== "list")
|
|
1740
|
+
throw new SmtParseError(
|
|
1741
|
+
`invalid get-value command, '(' expected got ${terms.lastId}`,
|
|
1742
|
+
terms,
|
|
1743
|
+
);
|
|
1330
1744
|
const manager = state.manager;
|
|
1331
1745
|
const exprs = terms.items.map((item) => state.reader.parseTerm(item));
|
|
1332
1746
|
if (exprs.length === 0)
|
|
1333
1747
|
throw new SmtParseError("invalid get-value command, empty list of terms", terms.end);
|
|
1334
|
-
|
|
1748
|
+
const extra = list.items[2];
|
|
1749
|
+
if (
|
|
1750
|
+
extra?.kind === "keyword" &&
|
|
1751
|
+
(extra.text === ":model-index" || extra.text === ":model_index")
|
|
1752
|
+
)
|
|
1753
|
+
throw new SmtUnsupportedError("the model index of get-value");
|
|
1754
|
+
if (extra !== undefined)
|
|
1755
|
+
throw new SmtParseError("invalid get-value command, ')' expected", extra);
|
|
1335
1756
|
const model = getModel(list);
|
|
1757
|
+
pendingText += "(";
|
|
1336
1758
|
model.compact();
|
|
1337
1759
|
// Z3 prints each term as the script spells it, from the end of the term before.
|
|
1338
1760
|
const offsets = [
|
|
1339
1761
|
terms.offset + 1,
|
|
1340
1762
|
...terms.items.map((item) => (item.kind === "list" ? item.end : item).endOffset),
|
|
1341
1763
|
];
|
|
1342
|
-
|
|
1764
|
+
exprs.forEach((expr, index) => {
|
|
1343
1765
|
manager.incRef(expr);
|
|
1344
1766
|
const value = model.eval(expr, true);
|
|
1345
|
-
|
|
1767
|
+
pendingText += `${index > 0 ? "\n " : ""}(${text.slice(offsets[index], offsets[index + 1]).trim()} ${format(value)})`;
|
|
1346
1768
|
manager.decRef(value);
|
|
1347
1769
|
manager.decRef(expr);
|
|
1348
|
-
return line;
|
|
1349
1770
|
});
|
|
1350
|
-
print(
|
|
1771
|
+
print(")");
|
|
1772
|
+
},
|
|
1773
|
+
],
|
|
1774
|
+
[
|
|
1775
|
+
"get-assignment",
|
|
1776
|
+
(list) => {
|
|
1777
|
+
checkArgumentCount(list, 0);
|
|
1778
|
+
const manager = state.manager;
|
|
1779
|
+
const model = getModel(list);
|
|
1780
|
+
const assignments = state.reader.getConstantMacros().flatMap((macro) => {
|
|
1781
|
+
if (manager.sorts[macro.body] !== SORT_BOOL) return [];
|
|
1782
|
+
const value = model.eval(macro.body, true);
|
|
1783
|
+
const assignment = `(${getQuotedName(macro.name)} ${manager.isTrue(value)})`;
|
|
1784
|
+
const isDecided = manager.isTrue(value) || manager.isFalse(value);
|
|
1785
|
+
manager.decRef(value);
|
|
1786
|
+
return isDecided ? [assignment] : [];
|
|
1787
|
+
});
|
|
1788
|
+
print(`(${assignments.join(" ")})`);
|
|
1351
1789
|
},
|
|
1352
1790
|
],
|
|
1353
1791
|
[
|
|
@@ -1362,14 +1800,27 @@ export const runSmtlibScript = (
|
|
|
1362
1800
|
[
|
|
1363
1801
|
"get-model",
|
|
1364
1802
|
(list) => {
|
|
1365
|
-
|
|
1803
|
+
for (const index of list.items.slice(1)) {
|
|
1804
|
+
if (index.kind !== "numeral")
|
|
1805
|
+
throw new SmtParseError("invalid command argument, unsigned integer expected", index);
|
|
1806
|
+
if (!isUnsigned(index.text))
|
|
1807
|
+
throw new SmtParseError(
|
|
1808
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
1809
|
+
index,
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1366
1812
|
const manager = state.manager;
|
|
1367
1813
|
const model = getModel(list);
|
|
1814
|
+
const last = list.items[list.items.length - 1];
|
|
1815
|
+
// get_model_cmd takes any number of indices and keeps the last.
|
|
1816
|
+
if (last.kind === "numeral" && BigInt(last.text) > 0n)
|
|
1817
|
+
throw new SmtUnsupportedError("the index of get-model");
|
|
1368
1818
|
model.compact();
|
|
1369
1819
|
for (const decl of state.reader.getDeclaredFuncs()) {
|
|
1370
1820
|
const funcDecl = manager.funcDecls[decl];
|
|
1371
1821
|
if (
|
|
1372
1822
|
funcDecl.family !== FAMILY_USER ||
|
|
1823
|
+
manager.macros.has(decl) ||
|
|
1373
1824
|
model.constInterps.has(decl) ||
|
|
1374
1825
|
model.funcInterps.has(decl)
|
|
1375
1826
|
)
|
|
@@ -1387,7 +1838,13 @@ export const runSmtlibScript = (
|
|
|
1387
1838
|
print(`(\n${printModel(manager, getPrintEnvironment(), model, 2)})`);
|
|
1388
1839
|
},
|
|
1389
1840
|
],
|
|
1390
|
-
[
|
|
1841
|
+
[
|
|
1842
|
+
"display",
|
|
1843
|
+
(list) => {
|
|
1844
|
+
display(state.reader.parseTerm(getFirstArgument(list)));
|
|
1845
|
+
checkArgumentCount(list, 1);
|
|
1846
|
+
},
|
|
1847
|
+
],
|
|
1391
1848
|
[
|
|
1392
1849
|
"dbg-lt",
|
|
1393
1850
|
(list) => {
|
|
@@ -1400,7 +1857,13 @@ export const runSmtlibScript = (
|
|
|
1400
1857
|
"dbg-some-value",
|
|
1401
1858
|
(list) => {
|
|
1402
1859
|
display(
|
|
1403
|
-
getManagerSomeValue(
|
|
1860
|
+
getManagerSomeValue(
|
|
1861
|
+
state.manager,
|
|
1862
|
+
state.reader.parseSort(
|
|
1863
|
+
list.items[1] ?? list.end,
|
|
1864
|
+
"invalid command argument, sort expected",
|
|
1865
|
+
),
|
|
1866
|
+
),
|
|
1404
1867
|
);
|
|
1405
1868
|
},
|
|
1406
1869
|
],
|
|
@@ -1436,10 +1899,11 @@ export const runSmtlibScript = (
|
|
|
1436
1899
|
[
|
|
1437
1900
|
"echo",
|
|
1438
1901
|
(list) => {
|
|
1439
|
-
const message = list
|
|
1440
|
-
if (message
|
|
1441
|
-
throw new SmtParseError("invalid
|
|
1902
|
+
const message = getFirstArgument(list);
|
|
1903
|
+
if (message.kind !== "string")
|
|
1904
|
+
throw new SmtParseError("invalid command argument, string expected", message);
|
|
1442
1905
|
print(message.text);
|
|
1906
|
+
checkArgumentCount(list, 1);
|
|
1443
1907
|
},
|
|
1444
1908
|
],
|
|
1445
1909
|
[
|
|
@@ -1450,10 +1914,28 @@ export const runSmtlibScript = (
|
|
|
1450
1914
|
const optionName = `:${getParameterName(keyword)}`;
|
|
1451
1915
|
const value = list.items[2];
|
|
1452
1916
|
const isTrue = isSymbol(value, "true");
|
|
1917
|
+
if (
|
|
1918
|
+
(keyword === ":produce-proofs" ||
|
|
1919
|
+
keyword === ":produce-unsat-cores" ||
|
|
1920
|
+
keyword === ":produce-unsat-assumptions") &&
|
|
1921
|
+
state.assertions.length > 0
|
|
1922
|
+
)
|
|
1923
|
+
throw new SmtParseError(
|
|
1924
|
+
`error setting '${keyword}', option value cannot be modified after assertions have been added`,
|
|
1925
|
+
value ?? list.end,
|
|
1926
|
+
);
|
|
1453
1927
|
if (keyword === ":produce-models") settings.isProducingModels = isTrue;
|
|
1454
1928
|
if (keyword === ":produce-unsat-cores") settings.isProducingUnsatCores = isTrue;
|
|
1929
|
+
if (keyword === ":produce-unsat-assumptions") settings.isProducingUnsatAssumptions = isTrue;
|
|
1455
1930
|
if (keyword === ":produce-proofs") settings.isProducingProofs = isTrue;
|
|
1456
|
-
if (keyword === ":interactive-mode"
|
|
1931
|
+
if (keyword === ":interactive-mode" || keyword === ":produce-assertions") {
|
|
1932
|
+
if (state.isProofsEnabled !== undefined)
|
|
1933
|
+
throw new SmtParseError(
|
|
1934
|
+
"error setting ':produce-assertions', option value cannot be modified after initialization",
|
|
1935
|
+
value ?? list.end,
|
|
1936
|
+
);
|
|
1937
|
+
settings.isInteractive = isTrue;
|
|
1938
|
+
}
|
|
1457
1939
|
if (keyword === ":diagnostic-output-channel")
|
|
1458
1940
|
settings.isDiagnosticOnStdout = value?.kind === "string" && value.text === "stdout";
|
|
1459
1941
|
if (keyword === ":int-real-coercions" && !isTrue)
|
|
@@ -1466,13 +1948,12 @@ export const runSmtlibScript = (
|
|
|
1466
1948
|
);
|
|
1467
1949
|
settings.isExitingOnError = isSymbol(value, "immediate-exit");
|
|
1468
1950
|
}
|
|
1469
|
-
|
|
1951
|
+
const isParameter =
|
|
1470
1952
|
keyword !== "" &&
|
|
1471
1953
|
!BUILTIN_OPTIONS.has(keyword) &&
|
|
1472
1954
|
value !== undefined &&
|
|
1473
|
-
value.kind !== "list"
|
|
1474
|
-
)
|
|
1475
|
-
settings.parameters.set(getParameterName(keyword), value.text);
|
|
1955
|
+
value.kind !== "list";
|
|
1956
|
+
if (isParameter) settings.parameters.set(getParameterName(keyword), value.text);
|
|
1476
1957
|
if (optionName === ":print_success") settings.isPrintingSuccess = isTrue;
|
|
1477
1958
|
if (
|
|
1478
1959
|
!BUILTIN_OPTIONS.has(keyword) &&
|
|
@@ -1485,6 +1966,9 @@ export const runSmtlibScript = (
|
|
|
1485
1966
|
settings.mbqiMaxIterations = Number(value.text);
|
|
1486
1967
|
if (optionName === ":rlimit" && value?.kind === "numeral")
|
|
1487
1968
|
settings.rlimit = Number(value.text);
|
|
1969
|
+
const kernel = state.kernel;
|
|
1970
|
+
if (isParameter && kernel !== undefined)
|
|
1971
|
+
kernel.updateParams(getKernelParams(kernel.isSetUp));
|
|
1488
1972
|
if (optionName === ":rewriter.hi_div0") {
|
|
1489
1973
|
settings.isHiDiv0 = isTrue;
|
|
1490
1974
|
state.manager.isHiDiv0 = isTrue;
|
|
@@ -1519,6 +2003,9 @@ export const runSmtlibScript = (
|
|
|
1519
2003
|
[":print-success", settings.isPrintingSuccess],
|
|
1520
2004
|
[":produce-models", settings.isProducingModels],
|
|
1521
2005
|
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
2006
|
+
[":produce-unsat-assumptions", settings.isProducingUnsatAssumptions],
|
|
2007
|
+
[":interactive-mode", settings.isInteractive],
|
|
2008
|
+
[":produce-assertions", settings.isInteractive],
|
|
1522
2009
|
[":int-real-coercions", true],
|
|
1523
2010
|
[":error-behavior", settings.isExitingOnError ? "immediate-exit" : "continued-execution"],
|
|
1524
2011
|
]);
|
|
@@ -1536,44 +2023,20 @@ export const runSmtlibScript = (
|
|
|
1536
2023
|
"get-info",
|
|
1537
2024
|
(list) => {
|
|
1538
2025
|
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
|
-
);
|
|
2026
|
+
if (info === undefined)
|
|
2027
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2028
|
+
if (info.kind !== "keyword")
|
|
2029
|
+
throw new SmtParseError("invalid command argument, keyword expected", info);
|
|
2030
|
+
printInfo(list, info.text);
|
|
2031
|
+
checkArgumentCount(list, 1);
|
|
1569
2032
|
},
|
|
1570
2033
|
],
|
|
1571
2034
|
[
|
|
1572
2035
|
"set-logic",
|
|
1573
2036
|
(list) => {
|
|
1574
|
-
const logic = list
|
|
2037
|
+
const logic = getFirstArgument(list);
|
|
1575
2038
|
if (!isSymbol(logic))
|
|
1576
|
-
throw new SmtParseError("invalid
|
|
2039
|
+
throw new SmtParseError("invalid command argument, symbol expected", logic);
|
|
1577
2040
|
if (state.logic !== undefined)
|
|
1578
2041
|
throw new SmtParseError("the logic has already been set", logic);
|
|
1579
2042
|
if (state.assertions.length > 0)
|
|
@@ -1583,6 +2046,7 @@ export const runSmtlibScript = (
|
|
|
1583
2046
|
printDiagnostic(
|
|
1584
2047
|
`; ignoring unsupported logic ${logic.text} line: ${list.line} position: ${list.column}`,
|
|
1585
2048
|
);
|
|
2049
|
+
checkArgumentCount(list, 1);
|
|
1586
2050
|
return;
|
|
1587
2051
|
}
|
|
1588
2052
|
state.logic = logic.text;
|
|
@@ -1590,14 +2054,37 @@ export const runSmtlibScript = (
|
|
|
1590
2054
|
state.reader = createSmtlibReader(state.manager, logic.text, settings.parserOptions);
|
|
1591
2055
|
else {
|
|
1592
2056
|
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.
|
|
2057
|
+
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop and keeps what they asserted.
|
|
1595
2058
|
resetKernel();
|
|
1596
2059
|
}
|
|
1597
2060
|
if (settings.isPrintingSuccess) print("success");
|
|
2061
|
+
checkArgumentCount(list, 1);
|
|
2062
|
+
},
|
|
2063
|
+
],
|
|
2064
|
+
[
|
|
2065
|
+
"set-info",
|
|
2066
|
+
(list) => {
|
|
2067
|
+
const info = list.items[1];
|
|
2068
|
+
if (info === undefined)
|
|
2069
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2070
|
+
if (info.kind !== "keyword")
|
|
2071
|
+
throw new SmtParseError("invalid command argument, keyword expected", info);
|
|
2072
|
+
const value = list.items[2];
|
|
2073
|
+
if (value === undefined)
|
|
2074
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2075
|
+
if (value.kind === "list" || value.kind === "keyword" || value.kind === "eof")
|
|
2076
|
+
throw new SmtParseError("invalid option value", value);
|
|
2077
|
+
if (info.text === ":status" && value.kind === "symbol") {
|
|
2078
|
+
const status = [L_TRUE, L_FALSE, L_UNDEF].find(
|
|
2079
|
+
(innerStatus) => getVerdict(innerStatus) === value.text,
|
|
2080
|
+
);
|
|
2081
|
+
if (status === undefined) throw new SmtParseError("invalid ':status' attribute", value);
|
|
2082
|
+
settings.status = status;
|
|
2083
|
+
}
|
|
2084
|
+
if (list.items[3] !== undefined)
|
|
2085
|
+
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
1598
2086
|
},
|
|
1599
2087
|
],
|
|
1600
|
-
["set-info", () => {}],
|
|
1601
2088
|
]);
|
|
1602
2089
|
const run = (list: SmtList) => {
|
|
1603
2090
|
const head = list.items[0];
|
|
@@ -1606,18 +2093,34 @@ export const runSmtlibScript = (
|
|
|
1606
2093
|
const command = DECLARATIONS.has(head.text)
|
|
1607
2094
|
? (declaration: SmtList) => state.reader.declareCommand(declaration)
|
|
1608
2095
|
: runCommand.get(head.text);
|
|
1609
|
-
if (command === undefined
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
2096
|
+
if (command === undefined && UNPORTED_COMMANDS.has(head.text))
|
|
2097
|
+
throw new SmtUnsupportedError(`the command ${head.text}`);
|
|
2098
|
+
if (command === undefined) {
|
|
2099
|
+
expectClosed(list);
|
|
2100
|
+
print("unsupported");
|
|
2101
|
+
printDiagnostic(`; ${head.text} line: ${list.end.line} position: ${list.end.column}`);
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
// Z3's scoped_timer ends with the command that set it, so a command starts without one.
|
|
2105
|
+
state.manager.limit.restart(Infinity);
|
|
2106
|
+
if (!MANAGERLESS_COMMANDS.has(head.text)) initManager();
|
|
2107
|
+
try {
|
|
2108
|
+
command(list);
|
|
2109
|
+
} catch (error) {
|
|
2110
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
2111
|
+
throw new SmtParseError(error.message, list.end);
|
|
1613
2112
|
}
|
|
1614
|
-
command(list);
|
|
1615
2113
|
if (settings.isPrintingSuccess && SILENT_COMMANDS.has(head.text)) print("success");
|
|
1616
2114
|
};
|
|
1617
2115
|
for (;;) {
|
|
1618
2116
|
try {
|
|
1619
|
-
const list = commands.
|
|
1620
|
-
if (list === undefined
|
|
2117
|
+
const list = commands.readCommand();
|
|
2118
|
+
if (list === undefined) break;
|
|
2119
|
+
if (isSymbol(list.items[0], "exit")) {
|
|
2120
|
+
checkArgumentCount(list, 0);
|
|
2121
|
+
if (settings.isPrintingSuccess) print("success");
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
1621
2124
|
run(list);
|
|
1622
2125
|
} catch (error) {
|
|
1623
2126
|
if (!(error instanceof SmtParseError)) throw error;
|