Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --unroll-bound option to bound the number of unrolling steps #111

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/scala/inox/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ trait MainHelpers {
solvers.optNoSimplifications -> Description(Solvers, "Disable selector/quantifier simplifications in solvers"),
solvers.optCheckModels -> Description(Solvers, "Double-check counter-examples with evaluator"),
solvers.optSilentErrors -> Description(Solvers, "Fail silently into UNKNOWN when encountering an error"),
solvers.unrolling.optUnrollFactor -> Description(Solvers, "Number of unrollings to perform in each unfold step"),
solvers.unrolling.optUnrollBound -> Description(Solvers, "Maximum number of unroll steps to perform"),
solvers.unrolling.optUnrollFactor -> Description(Solvers, "Number of unrollings to perform between each interaction with the SMT solver"),
solvers.unrolling.optFeelingLucky -> Description(Solvers, "Use evaluator to find counter-examples early"),
solvers.unrolling.optUnrollAssumptions -> Description(Solvers, "Use unsat-assumptions to drive unfolding while remaining fair"),
solvers.unrolling.optModelFinding -> Description(Solvers, "Enhance model-finding capabilities of solvers by given aggressivity"),
Expand Down
16 changes: 14 additions & 2 deletions src/main/scala/inox/solvers/unrolling/UnrollingSolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import combinators._

import scala.collection.mutable.{Map => MutableMap, ListBuffer}

object optUnrollBound extends IntOptionDef("unroll-bound", default = -1, "<Int> | -1 (unbounded)")
object optUnrollFactor extends IntOptionDef("unroll-factor", default = 1, "<PosInt>")
object optFeelingLucky extends FlagOptionDef("feeling-lucky", false)
object optUnrollAssumptions extends FlagOptionDef("unroll-assumptions", false)
Expand Down Expand Up @@ -77,6 +78,7 @@ trait AbstractUnrollingSolver extends Solver { self =>

lazy val checkModels = options.findOptionOrDefault(optCheckModels)
lazy val silentErrors = options.findOptionOrDefault(optSilentErrors)
lazy val unrollBound = options.findOptionOrDefault(optUnrollBound)
lazy val unrollFactor = options.findOptionOrDefault(optUnrollFactor)
lazy val feelingLucky = options.findOptionOrDefault(optFeelingLucky)
lazy val unrollAssumptions = options.findOptionOrDefault(optUnrollAssumptions)
Expand Down Expand Up @@ -606,6 +608,10 @@ trait AbstractUnrollingSolver extends Solver { self =>
}
}

var unrollCount: Int = 0

def canUnroll: Boolean = unrollBound < 0 || unrollCount < unrollBound

var currentState: CheckState = ModelCheck
while (!currentState.isInstanceOf[CheckResult]) {
currentState = currentState match {
Expand Down Expand Up @@ -797,18 +803,24 @@ trait AbstractUnrollingSolver extends Solver { self =>
}
}

case Unroll if !canUnroll =>
reporter.debug(s"- We need to keep going, but reached unroll bound ($unrollBound)")
CheckResult.cast(Unknown)

case Unroll => context.timers.solvers.unrolling.unroll.run {
reporter.debug("- We need to keep going")

// unfolling `unrollFactor` times
// Unrolling `unrollFactor` times
for (i <- 1 to unrollFactor.toInt if templates.canUnroll && !abort && !pause) {
val newClauses = templates.unroll
for (ncl <- newClauses) {
underlying.assertCnstr(ncl)
}
}

reporter.debug(" - finished unrolling")
unrollCount += 1

reporter.debug(" - Finished unrolling")
ModelCheck
}
}
Expand Down