Skip to content
Snippets Groups Projects
Commit 85505865 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Add --assumpre option to assume the precondition when unfolding

Implies(pre, f(x) = body)

becomes, with (--assumepre):

And(pre, f(x) = body)
parent 1949076d
No related branches found
No related tags found
No related merge requests found
...@@ -10,15 +10,16 @@ import purescala.Constructors._ ...@@ -10,15 +10,16 @@ import purescala.Constructors._
import purescala.Expressions._ import purescala.Expressions._
import purescala.ExprOps._ import purescala.ExprOps._
import z3.FairZ3Component.{optFeelingLucky, optUseCodeGen} import z3.FairZ3Component.{optFeelingLucky, optUseCodeGen, optAssumePre}
import templates._ import templates._
import utils.Interruptible import utils.Interruptible
import evaluators._ import evaluators._
class UnrollingSolver(val context: LeonContext, program: Program, underlying: IncrementalSolver with Interruptible) extends Solver with Interruptible { class UnrollingSolver(val context: LeonContext, program: Program, underlying: IncrementalSolver with Interruptible) extends Solver with Interruptible {
val feelingLucky = context.findOptionOrDefault(optFeelingLucky) val feelingLucky = context.findOptionOrDefault(optFeelingLucky)
val useCodeGen = context.findOptionOrDefault(optUseCodeGen) val useCodeGen = context.findOptionOrDefault(optUseCodeGen)
val assumePreHolds = context.findOptionOrDefault(optAssumePre)
private val evaluator : Evaluator = { private val evaluator : Evaluator = {
if(useCodeGen) { if(useCodeGen) {
...@@ -61,7 +62,7 @@ class UnrollingSolver(val context: LeonContext, program: Program, underlying: In ...@@ -61,7 +62,7 @@ class UnrollingSolver(val context: LeonContext, program: Program, underlying: In
def mkAnd(es: Expr*) = andJoin(es) def mkAnd(es: Expr*) = andJoin(es)
def mkEquals(l: Expr, r: Expr) = Equals(l, r) def mkEquals(l: Expr, r: Expr) = Equals(l, r)
def mkImplies(l: Expr, r: Expr) = implies(l, r) def mkImplies(l: Expr, r: Expr) = implies(l, r)
}) }, assumePreHolds)
val unrollingBank = new UnrollingBank(reporter, templateGenerator) val unrollingBank = new UnrollingBank(reporter, templateGenerator)
......
...@@ -14,7 +14,8 @@ import purescala.Constructors._ ...@@ -14,7 +14,8 @@ import purescala.Constructors._
import evaluators._ import evaluators._
class TemplateGenerator[T](val encoder: TemplateEncoder[T]) { class TemplateGenerator[T](val encoder: TemplateEncoder[T],
val assumePreHolds: Boolean) {
private var cache = Map[TypedFunDef, FunctionTemplate[T]]() private var cache = Map[TypedFunDef, FunctionTemplate[T]]()
private var cacheExpr = Map[Expr, FunctionTemplate[T]]() private var cacheExpr = Map[Expr, FunctionTemplate[T]]()
...@@ -89,7 +90,11 @@ class TemplateGenerator[T](val encoder: TemplateEncoder[T]) { ...@@ -89,7 +90,11 @@ class TemplateGenerator[T](val encoder: TemplateEncoder[T]) {
val postHolds : Expr = val postHolds : Expr =
if(tfd.hasPrecondition) { if(tfd.hasPrecondition) {
Implies(prec.get, newPost) if (assumePreHolds) {
And(prec.get, newPost)
} else {
Implies(prec.get, newPost)
}
} else { } else {
newPost newPost
} }
......
...@@ -12,9 +12,10 @@ trait FairZ3Component extends LeonComponent { ...@@ -12,9 +12,10 @@ trait FairZ3Component extends LeonComponent {
val optFeelingLucky = LeonFlagOptionDef("feelinglucky","Use evaluator to find counter-examples early", false) val optFeelingLucky = LeonFlagOptionDef("feelinglucky","Use evaluator to find counter-examples early", false)
val optUseCodeGen = LeonFlagOptionDef("codegen", "Use compiled evaluator instead of interpreter", false) val optUseCodeGen = LeonFlagOptionDef("codegen", "Use compiled evaluator instead of interpreter", false)
val optUnrollCores = LeonFlagOptionDef("unrollcores", "Use unsat-cores to drive unrolling while remaining fair", false) val optUnrollCores = LeonFlagOptionDef("unrollcores", "Use unsat-cores to drive unrolling while remaining fair", false)
val optAssumePre = LeonFlagOptionDef("assumepre", "Assume precondition holds (pre && f(x) = body) when unfolding", false)
override val definedOptions: Set[LeonOptionDef[Any]] = override val definedOptions: Set[LeonOptionDef[Any]] =
Set(optEvalGround, optCheckModels, optFeelingLucky, optUseCodeGen, optUnrollCores) Set(optEvalGround, optCheckModels, optFeelingLucky, optUseCodeGen, optUnrollCores, optAssumePre)
} }
object FairZ3Component extends FairZ3Component object FairZ3Component extends FairZ3Component
...@@ -32,6 +32,7 @@ class FairZ3Solver(val context : LeonContext, val program: Program) ...@@ -32,6 +32,7 @@ class FairZ3Solver(val context : LeonContext, val program: Program)
val useCodeGen = context.findOptionOrDefault(optUseCodeGen) val useCodeGen = context.findOptionOrDefault(optUseCodeGen)
val evalGroundApps = context.findOptionOrDefault(optEvalGround) val evalGroundApps = context.findOptionOrDefault(optEvalGround)
val unrollUnsatCores = context.findOptionOrDefault(optUnrollCores) val unrollUnsatCores = context.findOptionOrDefault(optUnrollCores)
val assumePreHolds = context.findOptionOrDefault(optAssumePre)
protected val errors = new IncrementalBijection[Unit, Boolean]() protected val errors = new IncrementalBijection[Unit, Boolean]()
protected def hasError = errors.getB(()) contains true protected def hasError = errors.getB(()) contains true
...@@ -142,7 +143,7 @@ class FairZ3Solver(val context : LeonContext, val program: Program) ...@@ -142,7 +143,7 @@ class FairZ3Solver(val context : LeonContext, val program: Program)
def mkAnd(es: Z3AST*) = z3.mkAnd(es : _*) def mkAnd(es: Z3AST*) = z3.mkAnd(es : _*)
def mkEquals(l: Z3AST, r: Z3AST) = z3.mkEq(l, r) def mkEquals(l: Z3AST, r: Z3AST) = z3.mkEq(l, r)
def mkImplies(l: Z3AST, r: Z3AST) = z3.mkImplies(l, r) def mkImplies(l: Z3AST, r: Z3AST) = z3.mkImplies(l, r)
}) }, assumePreHolds)
initZ3() initZ3()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment