Skip to content
Snippets Groups Projects
Commit b4a11d0a authored by Mikaël Mayer's avatar Mikaël Mayer Committed by Ravi
Browse files

Now deterministic eval by default check if the model is ground, else evaluate it.

parent 4882f9c7
Branches
Tags
No related merge requests found
...@@ -25,7 +25,7 @@ abstract class Evaluator(val context: LeonContext, val program: Program) extends ...@@ -25,7 +25,7 @@ abstract class Evaluator(val context: LeonContext, val program: Program) extends
/** Evaluates an expression given a simple model (assumes expr is quantifier-free). /** Evaluates an expression given a simple model (assumes expr is quantifier-free).
* Mainly useful for compatibility reasons. * Mainly useful for compatibility reasons.
*/ */
final def eval(expr: Expr, mapping: Map[Identifier, Expr]) : EvaluationResult = eval(expr, new Model(mapping)) def eval(expr: Expr, mapping: Map[Identifier, Expr]) : EvaluationResult = eval(expr, new Model(mapping))
/** Evaluates a ground expression. */ /** Evaluates a ground expression. */
final def eval(expr: Expr) : EvaluationResult = eval(expr, Model.empty) final def eval(expr: Expr) : EvaluationResult = eval(expr, Model.empty)
...@@ -48,14 +48,14 @@ trait DeterministicEvaluator extends Evaluator { ...@@ -48,14 +48,14 @@ trait DeterministicEvaluator extends Evaluator {
type Value = Expr type Value = Expr
/**Evaluates the environment first, resolving non-cyclic dependencies, and then evaluate the expression */ /**Evaluates the environment first, resolving non-cyclic dependencies, and then evaluate the expression */
final def evalEnvExpr(expr: Expr, mapping: Iterable[(Identifier, Expr)]) : EvaluationResult = { override def eval(expr: Expr, mapping: Map[Identifier, Expr]) : EvaluationResult = {
if(mapping.forall{ case (key, value) => purescala.ExprOps.isValue(value) }) { if(mapping.forall{ case (key, value) => purescala.ExprOps.isValue(value) }) {
eval(expr, mapping.toMap) super.eval(expr, mapping.toMap)
} else (_evalEnv(mapping) match { } else (_evalEnv(mapping) match {
case Left(m) => eval(expr, m) case Left(m) => super.eval(expr, m)
case Right(errorMessage) => case Right(errorMessage) =>
val m = mapping.filter{ case (k, v) => purescala.ExprOps.isValue(v) }.toMap val m = mapping.filter{ case (k, v) => purescala.ExprOps.isValue(v) }.toMap
eval(expr, m) match { super.eval(expr, m) match {
case res @ evaluators.EvaluationResults.Successful(result) => res case res @ evaluators.EvaluationResults.Successful(result) => res
case _ => evaluators.EvaluationResults.EvaluatorError(errorMessage) case _ => evaluators.EvaluationResults.EvaluatorError(errorMessage)
} }
......
...@@ -66,7 +66,7 @@ case object Focus extends PreprocessingRule("Focus") { ...@@ -66,7 +66,7 @@ case object Focus extends PreprocessingRule("Focus") {
def existsFailing(e: Expr, env: Map[Identifier, Expr], evaluator: DeterministicEvaluator): Boolean = { def existsFailing(e: Expr, env: Map[Identifier, Expr], evaluator: DeterministicEvaluator): Boolean = {
p.eb.invalids.exists { ex => p.eb.invalids.exists { ex =>
evaluator.evalEnvExpr(e, (p.as zip ex.ins).toMap ++ env).result match { evaluator.eval(e, (p.as zip ex.ins).toMap ++ env).result match {
case Some(BooleanLiteral(b)) => b case Some(BooleanLiteral(b)) => b
case _ => true case _ => true
} }
......
...@@ -184,7 +184,7 @@ case class QualifiedExamplesBank(as: List[Identifier], xs: List[Identifier], eb: ...@@ -184,7 +184,7 @@ case class QualifiedExamplesBank(as: List[Identifier], xs: List[Identifier], eb:
/** Filter inputs through expr which is an expression evaluating to a boolean */ /** Filter inputs through expr which is an expression evaluating to a boolean */
def filterIns(expr: Expr): QualifiedExamplesBank = { def filterIns(expr: Expr): QualifiedExamplesBank = {
filterIns(m => filterIns(m =>
hctx.defaultEvaluator.evalEnvExpr(expr, m) hctx.defaultEvaluator.eval(expr, m)
.result == Some(BooleanLiteral(true))) .result == Some(BooleanLiteral(true)))
} }
......
...@@ -107,7 +107,7 @@ class ExamplesFinder(ctx0: LeonContext, program: Program) { ...@@ -107,7 +107,7 @@ class ExamplesFinder(ctx0: LeonContext, program: Program) {
((p.as zip i.ins).toMap, p.pc.toClause) ((p.as zip i.ins).toMap, p.pc.toClause)
} }
evaluator.evalEnvExpr(cond, mapping) match { evaluator.eval(cond, mapping) match {
case EvaluationResults.Successful(BooleanLiteral(true)) => true case EvaluationResults.Successful(BooleanLiteral(true)) => true
case _ => false case _ => false
} }
......
...@@ -453,11 +453,11 @@ abstract class CEGISLike(name: String) extends Rule(name) { ...@@ -453,11 +453,11 @@ abstract class CEGISLike(name: String) extends Rule(name) {
timers.testForProgram.start() timers.testForProgram.start()
val res = ex match { val res = ex match {
case InExample(ins) => case InExample(ins) =>
evaluator.evalEnvExpr(cnstr, p.as.zip(ins).toMap ++ p.pc.bindings) evaluator.eval(cnstr, p.as.zip(ins).toMap ++ p.pc.bindings)
case InOutExample(ins, outs) => case InOutExample(ins, outs) =>
val eq = equality(innerSol, tupleWrap(outs)) val eq = equality(innerSol, tupleWrap(outs))
evaluator.evalEnvExpr(eq, p.as.zip(ins).toMap ++ p.pc.bindings) evaluator.eval(eq, p.as.zip(ins).toMap ++ p.pc.bindings)
} }
timers.testForProgram.stop() timers.testForProgram.stop()
......
...@@ -67,7 +67,7 @@ case object IntroduceRecCalls extends NormalizingRule("Introduce rec. calls") { ...@@ -67,7 +67,7 @@ case object IntroduceRecCalls extends NormalizingRule("Introduce rec. calls") {
val evaluator = new NoChooseEvaluator(hctx, hctx.program) val evaluator = new NoChooseEvaluator(hctx, hctx.program)
def mapExample(ex: Example): List[Example] = { def mapExample(ex: Example): List[Example] = {
val results = calls map (evaluator.evalEnvExpr(_, p.as.zip(ex.ins)).result) val results = calls map (evaluator.eval(_, p.as.zip(ex.ins).toMap).result)
if (results forall (_.isDefined)) List({ if (results forall (_.isDefined)) List({
val extra = results map (_.get) val extra = results map (_.get)
ex match { ex match {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment