Skip to content

Commit b3c3bf7

Browse files
committed
Splict dealias 1 WIP
1 parent c7cb901 commit b3c3bf7

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ object Types {
171171
case this1: RefinedOrRecType =>
172172
this1.parent.isRef(sym)
173173
case this1: AppliedType =>
174-
val this2 = this1.dealias
174+
val this2 = this1.dealiasStripAnnots
175175
if (this2 ne this1) this2.isRef(sym)
176176
else this1.underlying.isRef(sym)
177177
case _ => false
@@ -244,7 +244,7 @@ object Types {
244244
}
245245

246246
/** Is this type a (possibly aliased) singleton type? */
247-
def isSingleton(implicit ctx: Context) = dealias.isInstanceOf[SingletonType]
247+
def isSingleton(implicit ctx: Context) = dealiasStripAnnots.isInstanceOf[SingletonType]
248248

249249
/** Is this type of kind `AnyKind`? */
250250
def hasAnyKind(implicit ctx: Context): Boolean = {
@@ -931,6 +931,11 @@ object Types {
931931
*/
932932
def stripAnnots(implicit ctx: Context): Type = this
933933

934+
def rewrapAnnots(tp: Type)(implicit ctx: Context): Type = tp.stripTypeVar match {
935+
case AnnotatedType(tp1, annot) => AnnotatedType(rewrapAnnots(tp1), annot)
936+
case _ => this
937+
}
938+
934939
/** Strip PolyType prefix */
935940
def stripPoly(implicit ctx: Context): Type = this match {
936941
case tp: PolyType => tp.resType.stripPoly
@@ -1046,18 +1051,21 @@ object Types {
10461051
final def dealiasKeepAnnots(implicit ctx: Context): Type =
10471052
dealias1(keepAnnots = true)
10481053

1054+
final def dealias(implicit ctx: Context): Type = dealiasStripAnnots
1055+
10491056
/** Follow aliases and dereferences LazyRefs, annotated types and instantiated
10501057
* TypeVars until type is no longer alias type, annotated type, LazyRef,
10511058
* or instantiated type variable.
10521059
*/
1053-
final def dealias(implicit ctx: Context): Type =
1060+
final def dealiasStripAnnots(implicit ctx: Context): Type =
10541061
dealias1(keepAnnots = false)
10551062

10561063
/** Perform successive widenings and dealiasings until none can be applied anymore */
1057-
@tailrec final def widenDealias(implicit ctx: Context): Type = {
1058-
val res = this.widen.dealias
1059-
if (res eq this) res else res.widenDealias
1064+
@tailrec final def widenDealiasStripAnnots(implicit ctx: Context): Type = {
1065+
val res = this.widen.dealiasStripAnnots
1066+
if (res eq this) res else res.widenDealiasStripAnnots
10601067
}
1068+
final def widenDealias(implicit ctx: Context): Type = widenDealiasStripAnnots
10611069

10621070
/** Widen from constant type to its underlying non-constant
10631071
* base type.
@@ -1068,7 +1076,7 @@ object Types {
10681076
}
10691077

10701078
/** Dealias, and if result is a dependent function type, drop the `apply` refinement. */
1071-
final def dropDependentRefinement(implicit ctx: Context): Type = dealias match {
1079+
final def dropDependentRefinement(implicit ctx: Context): Type = dealiasStripAnnots match {
10721080
case RefinedType(parent, nme.apply, _) => parent
10731081
case tp => tp
10741082
}
@@ -1083,7 +1091,7 @@ object Types {
10831091
* a class, the class type ref, otherwise NoType.
10841092
* @param refinementOK If `true` we also skip refinements.
10851093
*/
1086-
def underlyingClassRef(refinementOK: Boolean)(implicit ctx: Context): Type = dealias match {
1094+
def underlyingClassRef(refinementOK: Boolean)(implicit ctx: Context): Type = dealiasStripAnnots match {
10871095
case tp: TypeRef =>
10881096
if (tp.symbol.isClass) tp
10891097
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
@@ -1805,8 +1813,8 @@ object Types {
18051813
case arg: TypeBounds =>
18061814
val v = param.paramVariance
18071815
val pbounds = param.paramInfo
1808-
if (v > 0 && pbounds.loBound.dealias.isBottomType) TypeAlias(arg.hiBound & rebase(pbounds.hiBound))
1809-
else if (v < 0 && pbounds.hiBound.dealias.isTopType) TypeAlias(arg.loBound | rebase(pbounds.loBound))
1816+
if (v > 0 && pbounds.loBound.dealiasKeepAnnots.isBottomType) TypeAlias(arg.hiBound & rebase(pbounds.hiBound))
1817+
else if (v < 0 && pbounds.hiBound.dealiasKeepAnnots.isTopType) TypeAlias(arg.loBound | rebase(pbounds.loBound))
18101818
else arg recoverable_& rebase(pbounds)
18111819
case arg => TypeAlias(arg)
18121820
}
@@ -4165,11 +4173,12 @@ object Types {
41654173
*/
41664174
def tryWiden(tp: NamedType, pre: Type): Type = pre.member(tp.name) match {
41674175
case d: SingleDenotation =>
4168-
d.info.dealias match {
4176+
val tp1 = d.info.dealiasKeepAnnots
4177+
tp1.stripAnnots match {
41694178
case TypeAlias(alias) =>
41704179
// if H#T = U, then for any x in L..H, x.T =:= U,
41714180
// hence we can replace with U under all variances
4172-
reapply(alias)
4181+
reapply(alias.rewrapAnnots(tp1))
41734182
case TypeBounds(lo, hi) =>
41744183
// If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
41754184
// hence we can replace with S..U under all variances

0 commit comments

Comments
 (0)