Skip to content
Snippets Groups Projects
Commit c9a9a67d authored by Emmanouil (Manos) Koukoutos's avatar Emmanouil (Manos) Koukoutos Committed by Etienne Kneuss
Browse files

Try to salvage erroneous/ugly name handling in Guided Match split

parent 1675d9f2
Branches
Tags
No related merge requests found
...@@ -52,40 +52,69 @@ case object GuidedDecomp extends Rule("Guided Decomp") { ...@@ -52,40 +52,69 @@ case object GuidedDecomp extends Rule("Guided Decomp") {
Some(RuleInstantiation.immediateDecomp(p, this, List(sub1, sub2), onSuccess, "Guided If-Split on '"+c+"'")) Some(RuleInstantiation.immediateDecomp(p, this, List(sub1, sub2), onSuccess, "Guided If-Split on '"+c+"'"))
case m @ MatchExpr(scrut, cs) => case m @ MatchExpr(scrut0, cs) =>
var pcSoFar: Expr = BooleanLiteral(true)
val scrut = scrut0 match {
case v : Variable => v
case _ => Variable(FreshIdentifier("scrut", true).setType(scrut0.getType))
}
var pcSoFar: Expr = if (scrut == scrut0) BooleanLiteral(true) else Equals(scrut0, scrut)
val subs = for (c <- cs) yield { val subs = for (c <- cs) yield {
val s = scrut match {
case Variable(_) => scrut //println("="*40)
case _ => Variable(FreshIdentifier("scrut", true).setType(scrut.getType))
} val localScrut = c.pattern.binder.map(Variable) getOrElse scrut
val sConstr = scrut match { //println("PC so far:")
case Variable(_) => BooleanLiteral(true) //println(replace(Map(scrut -> localScrut), pcSoFar))
case _ => Equals(s,scrut) val scrutConstraint = if (localScrut == scrut) BooleanLiteral(true) else Equals(localScrut, scrut)
} val substs = patternSubstitutions(localScrut, c.pattern)
val substs = patternSubstitutions(s, c.pattern)
val cond = conditionForPattern(scrut, c.pattern) //println("Pattern : " + c.pattern)
//println("SUBST")
//substs foreach println
val cond = conditionForPattern(localScrut, c.pattern)
//println("cond: " + cond)
val g = c.theGuard.getOrElse(BooleanLiteral(true)) val g = c.theGuard.getOrElse(BooleanLiteral(true))
val pc = simplify(doSubstitute(substs, And(Seq(pcSoFar, g, sConstr, replace(Map(m -> c.rhs), p.pc))))) val pc = simplify(doSubstitute(substs,
And(Seq(
scrutConstraint,
replace(Map(scrut -> localScrut), pcSoFar),
cond,
g,
replace(Map(m -> c.rhs), p.pc)
))
))
//println("PC")
//println(pc)
val phi = doSubstitute(substs, p.phi) val phi = doSubstitute(substs, p.phi)
val free = variablesOf(And(pc, phi)) -- p.xs val free = variablesOf(And(pc, phi)) -- p.xs
val guardSafe = replaceFromIDs(mapForPattern(scrut, c.pattern),g)
pcSoFar = And(pcSoFar, Not(cond)) val condSafe = conditionForPattern(scrut, c.pattern)
//println("GUARD SAFE:")
//println(guardSafe)
//println("="*40)
pcSoFar = simplify(And(Not(And(condSafe, guardSafe)), pcSoFar))
val asPrefix = p.as.filter(free) val asPrefix = p.as.filter(free)
Problem(asPrefix ++ (free -- asPrefix), pc, phi, p.xs) Problem(asPrefix ++ (free -- asPrefix), pc, phi, p.xs)
} }
val onSuccess: List[Solution] => Option[Solution] = { val onSuccess: List[Solution] => Option[Solution] = { subs =>
case subs => val cases = for ((c, s) <- cs zip subs) yield {
val cases = for ((c, s) <- cs zip subs) yield { c match {
c match { case SimpleCase(c, rhs) => SimpleCase(c, s.term)
case SimpleCase(c, rhs) => SimpleCase(c, s.term) case GuardedCase(c, g, rhs) => GuardedCase(c, g, s.term)
case GuardedCase(c, g, rhs) => GuardedCase(c, g, s.term)
}
} }
}
Some(Solution(Or(subs.map(_.pre)), subs.map(_.defs).foldLeft(Set[FunDef]())(_ ++ _), MatchExpr(scrut, cases))) Some(Solution(
Or(subs.map(_.pre)),
subs.map(_.defs).foldLeft(Set[FunDef]())(_ ++ _),
Let(scrut.id, scrut0, MatchExpr(scrut, cases))
))
} }
Some(RuleInstantiation.immediateDecomp(p, this, subs.toList, onSuccess, "Guided Match-Split")) Some(RuleInstantiation.immediateDecomp(p, this, subs.toList, onSuccess, "Guided Match-Split"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment