Skip to content

Commit

Permalink
Readd freshenChooses parameter for freshenLocals
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-hamza committed Feb 17, 2021
1 parent 348ad79 commit 7e5ed12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/main/scala/inox/ast/ExprOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ trait ExprOps extends GenTreeOps {
* Note that we don't freshen choose ids as these are considered global
* and used to lookup their images within models!
*/
object Freshener extends SelfTransformer {
class Freshener(freshenChooses: Boolean = false) extends SelfTransformer {
type Env = Map[Identifier, Identifier]

override def transform(e: Expr, env: Env): Expr = e match {
Expand All @@ -95,8 +95,12 @@ trait ExprOps extends GenTreeOps {
}
Forall(sparams, transform(b, senv)).copiedFrom(e)

case Choose(res, pred) =>
Choose(transform(res, env), transform(pred, env)).copiedFrom(e)
case Choose(vd, pred) if !freshenChooses =>
Choose(transform(vd, env), transform(pred, env)).copiedFrom(e)

case Choose(vd, pred) if freshenChooses =>
val freshVd = vd.freshen
Choose(transform(freshVd, env), transform(pred, env.updated(vd.id, freshVd.id))).copiedFrom(e)

case _ =>
super.transform(e, env)
Expand Down Expand Up @@ -127,8 +131,12 @@ trait ExprOps extends GenTreeOps {
}
}

def freshenLocals(expr: Expr): Expr = {
Freshener.transform(expr, Map[Identifier, Identifier]())
val freshenerNoChooses = new Freshener(false)
val freshenerWithChooses = new Freshener(true)

def freshenLocals(expr: Expr, freshenChooses: Boolean = false): Expr = {
if (freshenChooses) freshenerWithChooses.transform(expr, Map.empty[Identifier, Identifier])
else freshenerNoChooses.transform(expr, Map.empty[Identifier, Identifier])
}

/** Returns true if the expression contains a function call */
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/inox/ast/GenTreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ trait GenTreeOps { self =>
(e: Source, c: C): Target = {

def rec(expr: Source, context: C): Target = {

val (newV, newCtx) = {
if(applyRec) {
var ctx = context
Expand Down

0 comments on commit 7e5ed12

Please sign in to comment.