Skip to content

Commit

Permalink
Temporarily add replaceKeepPositions function to use Inox release
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-hamza committed Sep 17, 2019
1 parent 9f3380a commit a2f2600
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
9 changes: 9 additions & 0 deletions core/src/main/scala/stainless/ast/ExprOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,13 @@ trait ExprOps extends inox.ast.ExprOps {
other
}
}

def replaceKeepPositions(subst: Map[Variable, Expr], expr: Expr): Expr = {
new SelfTreeTransformer {
override def transform(expr: Expr): Expr = expr match {
case v: Variable => subst.getOrElse(v, v).copiedFrom(v)
case _ => super.transform(expr)
}
}.transform(expr)
}
}
9 changes: 9 additions & 0 deletions core/src/main/scala/stainless/ast/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ trait TypeOps extends inox.ast.TypeOps {
}
}
}

def replaceKeepPositions(subst: Map[Variable, Expr], tpe: Type): Type = {
new SelfTreeTransformer {
override def transform(expr: Expr): Expr = expr match {
case v: Variable => subst.getOrElse(v, v).copiedFrom(v)
case _ => super.transform(expr)
}
}.transform(tpe)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ trait ImperativeCodeElimination
override protected def extractFunction(symbols: s.Symbols, fd: s.FunDef): t.FunDef = {
import symbols._
import exprOps._
import exprOps.{ replaceKeepPositions => replace }

/* varsInScope refers to variable declared in the same level scope.
* Typically, when entering a nested function body, the scope should be
Expand Down Expand Up @@ -104,7 +105,7 @@ trait ImperativeCodeElimination
}

val newRhs = csesVals.zip(csesScope).map {
case (cVal, cScope) => replaceFromSymbols(scrutFun, cScope(cVal), true)
case (cVal, cScope) => replace(scrutFun, cScope(cVal))
}

val matchE = MatchExpr(scrutRes, cses.zip(newRhs).map {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/stainless/extraction/methods/Sealing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ trait Sealing extends oo.CachingPhase
.toMap

val (paramSubst, params) = fd.params
.foldLeft((Map.empty[ValDef, Expr], Seq.empty[ValDef])) { case ((paramSubst, params), vd) =>
val ntpe = typeOps.replaceFromSymbols(paramSubst, vd.tpe, true)
.foldLeft((Map.empty[Variable, Expr], Seq.empty[ValDef])) { case ((paramSubst, params), vd) =>
val ntpe = symbols.replaceKeepPositions(paramSubst, vd.tpe)
val nvd = pureParams.getOrElse(vd.id, vd).copy(tpe = ntpe).copiedFrom(vd)
(paramSubst + (vd -> nvd.toVariable), params :+ nvd)
(paramSubst + (vd.toVariable -> nvd.toVariable), params :+ nvd)
}

fd.copy(
params = params,
returnType = typeOps.replaceFromSymbols(paramSubst, fd.returnType, true),
fullBody = exprOps.replaceFromSymbols(paramSubst, fd.fullBody, true)
returnType = symbols.replaceKeepPositions(paramSubst, fd.returnType),
fullBody = exprOps.replaceKeepPositions(paramSubst, fd.fullBody)
).copiedFrom(fd)
}

Expand Down

0 comments on commit a2f2600

Please sign in to comment.