Skip to content
Snippets Groups Projects
Commit dff5eafb authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Fix bug in EquivalentInputs where pc got simplified under itself

parent a452cb20
No related branches found
No related tags found
No related merge requests found
...@@ -9,15 +9,12 @@ import purescala.Path ...@@ -9,15 +9,12 @@ import purescala.Path
import purescala.Common._ import purescala.Common._
import purescala.Expressions._ import purescala.Expressions._
import purescala.ExprOps._ import purescala.ExprOps._
import purescala.Extractors._
import purescala.Constructors._ import purescala.Constructors._
import purescala.Types.CaseClassType import purescala.Types.CaseClassType
case object EquivalentInputs extends NormalizingRule("EquivalentInputs") { case object EquivalentInputs extends NormalizingRule("EquivalentInputs") {
def instantiateOn(implicit hctx: SearchContext, p: Problem): Traversable[RuleInstantiation] = { def instantiateOn(implicit hctx: SearchContext, p: Problem): Traversable[RuleInstantiation] = {
val simplifier = Simplifiers.bestEffort(hctx, hctx.program)(_:Expr, p.pc)
var subst = Map.empty[Identifier, Expr] var subst = Map.empty[Identifier, Expr]
var reverseSubst = Map.empty[Identifier, Expr] var reverseSubst = Map.empty[Identifier, Expr]
...@@ -57,12 +54,12 @@ case object EquivalentInputs extends NormalizingRule("EquivalentInputs") { ...@@ -57,12 +54,12 @@ case object EquivalentInputs extends NormalizingRule("EquivalentInputs") {
obsolete ++= equivalences.map(_._1) obsolete ++= equivalences.map(_._1)
free ++= unbound free ++= unbound
def replace(e: Expr) = simplifier(replaceFromIDs(equivalences.toMap, e)) def replace(e: Expr) = replaceFromIDs(equivalences.toMap, e)
subst = subst.mapValues(replace) ++ equivalences subst = subst.mapValues(replace) ++ equivalences
val reverse = equivalences.toMap.flatMap { case (id, CaseClass(cct, fields)) => val reverse = equivalences.toMap.flatMap { case (id, CaseClass(cct, fields)) =>
(cct.classDef.fields zip fields).map { case (vid, Variable(fieldId)) => (cct.classDef.fields zip fields).map { case (vid, Variable(fieldId)) =>
fieldId -> CaseClassSelector(cct, AsInstanceOf(Variable(id), cct), vid.id) fieldId -> caseClassSelector(cct, asInstOf(Variable(id), cct), vid.id)
} }
} }
...@@ -73,7 +70,7 @@ case object EquivalentInputs extends NormalizingRule("EquivalentInputs") { ...@@ -73,7 +70,7 @@ case object EquivalentInputs extends NormalizingRule("EquivalentInputs") {
// We could discover one equivalence, which could allow us to discover // We could discover one equivalence, which could allow us to discover
// other equivalences: We do a fixpoint with limit 5. // other equivalences: We do a fixpoint with limit 5.
val simplifiedPath = fixpoint({ (path: Path) => discoverEquivalences(path) }, 5)(p.pc) val newPC = fixpoint({ (path: Path) => discoverEquivalences(path) }, 5)(p.pc)
if (subst.nonEmpty) { if (subst.nonEmpty) {
// XXX: must take place in this order!! obsolete & free is typically non-empty // XXX: must take place in this order!! obsolete & free is typically non-empty
...@@ -88,10 +85,12 @@ case object EquivalentInputs extends NormalizingRule("EquivalentInputs") { ...@@ -88,10 +85,12 @@ case object EquivalentInputs extends NormalizingRule("EquivalentInputs") {
}) })
} }
val simplifier = Simplifiers.bestEffort(hctx, hctx.program)(_:Expr, newPC)
val sub = p.copy( val sub = p.copy(
as = newAs, as = newAs,
ws = replaceFromIDs(subst, p.ws), ws = replaceFromIDs(subst, p.ws),
pc = simplifiedPath, pc = newPC,
phi = simplifier(replaceFromIDs(subst, p.phi)), phi = simplifier(replaceFromIDs(subst, p.phi)),
eb = newBank eb = newBank
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment