Skip to content

Commit

Permalink
Avoid duplication of scrutinee in lowered matches (from #860)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsps committed Aug 11, 2021
1 parent 2c77b59 commit e36f426
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/scala/stainless/ast/SymbolOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ trait SymbolOps extends inox.ast.SymbolOps { self: TypeOps =>

def rewritePM(e: Expr): Option[Expr] = e match {
case m @ MatchExpr(scrut, cases) =>
val scrutVd = ValDef.fresh("scrut", scrut.getType).setPos(m)
val scrutV = scrutVd.toVariable
val condsAndRhs = for (cse <- cases) yield {
val map = mapForPattern(scrut, cse.pattern)
val patCond = conditionForPattern[Path](scrut, cse.pattern, includeBinders = false)
val map = mapForPattern(scrutV, cse.pattern)
val patCond = conditionForPattern[Path](scrutV, cse.pattern, includeBinders = false)
val realCond = cse.optGuard match {
case Some(g) => patCond withCond replaceFromSymbols(map, g)
case None => patCond
Expand All @@ -170,7 +172,7 @@ trait SymbolOps extends inox.ast.SymbolOps { self: TypeOps =>
}
})

Some(bigIte)
Some(Let(scrutVd, scrut, bigIte).copiedFrom(m))

case _ => None
}
Expand Down

0 comments on commit e36f426

Please sign in to comment.