Skip to content

Commit 8db811f

Browse files
committed
Improvements for Z3 custom executables
1 parent f6ef8a9 commit 8db811f

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/main/scala/inox/Options.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ object optSelectedSolvers extends SetOptionDef[String] {
223223
val name = "solvers"
224224
val default = Set("nativez3")
225225
val elementParser: OptionParser[String] = { s =>
226-
stringParser(s).filter(name =>
227-
solvers.SolverFactory.solverNames.contains(name) ||
228-
name.startsWith("smt-z3:")
229-
)
226+
stringParser(s).filter(solvers.SolverFactory.supportedSolver)
230227
}
231228

232229
val usageRhs = "s1,s2,..."

src/main/scala/inox/solvers/SolverFactory.scala

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ object SolverFactory {
6565
import unrolling._
6666

6767
val solverNames = Map(
68-
"nativez3" -> "Native Z3 with z3-templates for unrolling",
69-
"nativez3-opt" -> "Native Z3 optimizer with z3-templates for unrolling",
70-
"unrollz3" -> "Native Z3 with inox-templates for unrolling",
71-
"smt-cvc4" -> "CVC4 through SMT-LIB",
72-
"smt-z3" -> "Z3 through SMT-LIB",
73-
"smt-z3-opt" -> "Z3 optimizer through SMT-LIB",
74-
"smt-z3:EXEC" -> "Z3 through SMT-LIB with custom executable name",
75-
"princess" -> "Princess with inox unrolling"
68+
"nativez3" -> "Native Z3 with z3-templates for unrolling",
69+
"nativez3-opt" -> "Native Z3 optimizer with z3-templates for unrolling",
70+
"unrollz3" -> "Native Z3 with inox-templates for unrolling",
71+
"smt-cvc4" -> "CVC4 through SMT-LIB",
72+
"smt-z3" -> "Z3 through SMT-LIB",
73+
"smt-z3-opt" -> "Z3 optimizer through SMT-LIB",
74+
"smt-z3:<exec>" -> "Z3 through SMT-LIB with custom executable name",
75+
"princess" -> "Princess with inox unrolling"
7676
)
7777

7878
private val fallbacks = Map(
@@ -87,6 +87,9 @@ object SolverFactory {
8787

8888
private var reported: Boolean = false
8989

90+
// extract <exec> in "smt-z3:<exec>"
91+
private def getZ3Executable(name: String): String = name.drop(7)
92+
9093
def getFromName(name: String, force: Boolean = false)
9194
(p: Program, ctx: Context)
9295
(enc: ProgramTransformer {
@@ -110,7 +113,17 @@ object SolverFactory {
110113
replacement
111114

112115
case Some(_) => name
113-
case None if name.startsWith("smt-z3:") => name
116+
case None if name.startsWith("smt-z3:") =>
117+
val z3Exec = getZ3Executable(name)
118+
val hasZ3Exec = try {
119+
new Z3Interpreter(z3Exec, Array("-in", "-smt2"))
120+
true
121+
} catch {
122+
case _: java.io.IOException => false
123+
}
124+
125+
if (hasZ3Exec) name
126+
else throw FatalError("Unknown solver: " + z3Exec)
114127

115128
case _ => throw FatalError("Unknown solver: " + name)
116129
}
@@ -228,7 +241,7 @@ object SolverFactory {
228241
val progEnc = fullEnc andThen theoryEnc
229242
val targetProg = progEnc.targetProgram
230243
val targetSem = targetProg.getSemantics
231-
val executableName = if (finalName == "smt-z3") "z3" else finalName.drop(7)
244+
val executableName = if (finalName == "smt-z3") "z3" else getZ3Executable(finalName)
232245

233246
() => new {
234247
val program: p.type = p
@@ -311,7 +324,7 @@ object SolverFactory {
311324
}
312325
}
313326

314-
val solvers: Set[String] = solverNames.map(_._1).toSet
327+
def supportedSolver(s: String) = solverNames.contains(s) || s.startsWith("smt-z3:")
315328

316329
def getFromSettings(p: Program, ctx: Context)
317330
(enc: ProgramTransformer {

0 commit comments

Comments
 (0)