Skip to content

Commit

Permalink
Avoid occurrences of the same variable with different types
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-hamza committed Feb 24, 2021
1 parent dd0a383 commit ea380fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions core/src/main/scala/stainless/verification/TypeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ trait TypeChecker {
case Truth(t) =>
implies(t, acc)
case RefinementType(vd, pred) =>
implies(renameVar(pred, vd.id, v.id), acc)
implies(substVar(pred, vd.id, v), acc)
case _ =>
acc
}
Expand Down Expand Up @@ -1144,7 +1144,10 @@ trait TypeChecker {
tr ++ isSubtype(tc2, freshener.transform(to1), freshener.transform(to2))

case (RefinementType(vd1, prop1), RefinementType(vd2, prop2)) if (vd1.tpe == vd2.tpe) =>
buildVC(tc.bind(vd1).withTruth(prop1).withVCKind(VCKind.RefinementSubtype), renameVar(prop2, vd2.id, vd1.id))
buildVC(
tc.bind(vd1).withTruth(prop1).withVCKind(VCKind.RefinementSubtype),
substVar(prop2, vd2.id, vd1.toVariable)
)

case (_, RefinementType(vd, prop)) =>
isSubtype(tc, tp1, vd.tpe) ++ buildVC(tc.withVCKind(VCKind.RefinementSubtype), prop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ object TypeCheckerUtils {
def unapply(v: Variable): Option[(Variable, Expr)] = unapply(v.tpe)
}

def renameVar(e: Expr, id1: Identifier, id2: Identifier): Expr = {
def substVar(expr: Expr, id: Identifier, replacement: Expr): Expr = {
new SelfTreeTransformer {
override def transform(e: Expr) = e match {
case Variable(id, tpe, flags) if id == id1 => Variable(id2, transform(tpe), flags.map(transform))
case Variable(id2, _, _) if id2 == id => replacement
case _ => super.transform(e)
}
}.transform(e)
}.transform(expr)
}

// TODO: implement ite for more types (PiType, SigmaType, etc.)
Expand All @@ -87,8 +87,8 @@ object TypeCheckerUtils {
case (RefinementType(vd1, prop1), RefinementType(vd2, prop2)) =>
val newType = ite(b, vd1.tpe, vd2.tpe)
val vd = ValDef.fresh(vd1.id.name, newType)
val newProp1 = renameVar(prop1, vd1.id, vd.id)
val newProp2 = renameVar(prop2, vd2.id, vd.id)
val newProp1 = substVar(prop1, vd1.id, vd.toVariable)
val newProp2 = substVar(prop2, vd2.id, vd.toVariable)
RefinementType(vd, IfExpr(b, newProp1, newProp2))

case (RefinementType(vd1, prop1), _) if (vd1.tpe == t2) =>
Expand Down

0 comments on commit ea380fa

Please sign in to comment.