aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Skolemization.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/core/Skolemization.scala')
-rw-r--r--src/dotty/tools/dotc/core/Skolemization.scala30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/core/Skolemization.scala b/src/dotty/tools/dotc/core/Skolemization.scala
index 1d0067a4f..fb47cb62a 100644
--- a/src/dotty/tools/dotc/core/Skolemization.scala
+++ b/src/dotty/tools/dotc/core/Skolemization.scala
@@ -5,42 +5,42 @@ import Symbols._, Types._, Contexts._
import collection.mutable
/** Methods to add and remove skolemtypes.
- *
- * Skolem types are generated when comparing refinements.
+ *
+ * Skolem types are generated when comparing refinements.
* A skolem type is simply a fresh singleton type that has a given type
* as underlying type.
- * Two skolem types are equal if they refer to the same underlying type.
+ * Two skolem types are equal if they refer to the same underlying type.
* To avoid unsoundness, skolem types have to be kept strictly local to the
* comparison, they are not allowed to escape the lifetime of a comparison
- * by surviving in a context or in GADT bounds.
+ * by surviving in a context or in GADT bounds.
*/
trait Skolemization {
-
+
implicit val ctx: Context
protected var skolemsOutstanding = false
-
+
def ensureStableSingleton(tp: Type): SingletonType = tp.stripTypeVar match {
- case tp: SingletonType if tp.isStable =>
+ case tp: SingletonType if tp.isStable =>
tp
- case tp: ValueType =>
+ case tp: ValueType =>
skolemsOutstanding = true
SkolemType(tp)
- case tp: TypeProxy =>
+ case tp: TypeProxy =>
ensureStableSingleton(tp.underlying)
}
-
+
/** Approximate a type `tp` with a type that does not contain skolem types.
* @param toSuper if true, return the smallest supertype of `tp` with this property
* else return the largest subtype.
*/
- final def deSkolemize(tp: Type, toSuper: Boolean): Type =
- if (skolemsOutstanding) deSkolemize(tp, if (toSuper) 1 else -1, Set())
+ final def deSkolemize(tp: Type, toSuper: Boolean): Type =
+ if (skolemsOutstanding) deSkolemize(tp, if (toSuper) 1 else -1, Set())
else tp
private def deSkolemize(tp: Type, variance: Int, seen: Set[SkolemType]): Type =
ctx.traceIndented(s"deskolemize $tp, variance = $variance, seen = $seen = ") {
- def approx(lo: Type = defn.NothingType, hi: Type = defn.AnyType, newSeen: Set[SkolemType] = seen) =
+ def approx(lo: Type = defn.NothingType, hi: Type = defn.AnyType, newSeen: Set[SkolemType] = seen) =
if (variance == 0) NoType
else deSkolemize(if (variance < 0) lo else hi, variance, newSeen)
tp match {
@@ -71,7 +71,7 @@ trait Skolemization {
tp.derivedRefinedType(parent1, tp.refinedName, refinedInfo1)
else
approx(hi = parent1)
- }
+ }
else approx()
case tp: TypeAlias =>
val alias1 = deSkolemize(tp.alias, variance * tp.variance, seen)
@@ -107,7 +107,7 @@ trait Skolemization {
deSkolemizeMap.mapOver(tp, variance, seen)
}
}
-
+
object deSkolemizeMap extends TypeMap {
private var seen: Set[SkolemType] = _
def apply(tp: Type) = deSkolemize(tp, variance, seen)