Skip to content

Commit 41abffe

Browse files
committed
Refactorings of GenericTypes and underlying/upperbound
1. Make genericType a trait instead of a class. 2. Make TypeLambda a type proxy 3. Split underlying in TypeProxy into underlying and superType 4. Cleanups in many other places
1 parent b1440d2 commit 41abffe

File tree

9 files changed

+100
-146
lines changed

9 files changed

+100
-146
lines changed

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,12 +1661,10 @@ object SymDenotations {
16611661
if (cdenot.superClassBits contains symbol.superId) foldGlb(NoType, tp.parents)
16621662
else NoType
16631663
case _ =>
1664-
baseTypeRefOf(tp.underlying)
1664+
baseTypeRefOf(tp.superType)
16651665
}
1666-
case tp: HKApply =>
1667-
baseTypeRefOf(tp.upperBound) // TODO drop?
16681666
case tp: TypeProxy =>
1669-
baseTypeRefOf(tp.underlying)
1667+
baseTypeRefOf(tp.superType)
16701668
case AndType(tp1, tp2) =>
16711669
baseTypeRefOf(tp1) & baseTypeRefOf(tp2)
16721670
case OrType(tp1, tp2) =>

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class TypeApplications(val self: Type) extends AnyVal {
275275
if (params.exists(_.name == self.refinedName)) parent1
276276
else self.derivedRefinedType(parent1, self.refinedName, self.refinedInfo)
277277
case self: TypeProxy =>
278-
self.underlying.widenToNamedTypeParams(params)
278+
self.superType.widenToNamedTypeParams(params)
279279
case self: AndOrType =>
280280
self.derivedAndOrType(
281281
self.tp1.widenToNamedTypeParams(params), self.tp2.widenToNamedTypeParams(params))
@@ -317,7 +317,6 @@ class TypeApplications(val self: Type) extends AnyVal {
317317
case self: SingletonType => -1
318318
case self: TypeVar => self.origin.knownHK
319319
case self: WildcardType => self.optBounds.knownHK
320-
case self: PolyParam => self.underlying.knownHK
321320
case self: TypeProxy => self.underlying.knownHK
322321
case NoType | _: LazyType => 0
323322
case _ => -1
@@ -568,7 +567,7 @@ class TypeApplications(val self: Type) extends AnyVal {
568567
final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] =
569568
if (self derivesFrom base)
570569
self match {
571-
case self: HKApply => self.upperBound.baseArgInfos(base)
570+
case self: HKApply => self.superType.baseArgInfos(base)
572571
case _ => base.typeParams.map(param => self.member(param.name).info.argInfo)
573572
}
574573
else
@@ -596,7 +595,7 @@ class TypeApplications(val self: Type) extends AnyVal {
596595
final def firstBaseArgInfo(base: Symbol)(implicit ctx: Context): Type = base.typeParams match {
597596
case param :: _ if self derivesFrom base =>
598597
self match {
599-
case self: HKApply => self.upperBound.firstBaseArgInfo(base)
598+
case self: HKApply => self.superType.firstBaseArgInfo(base)
600599
case _ => self.member(param.name).info.argInfo
601600
}
602601
case _ =>
@@ -621,7 +620,7 @@ class TypeApplications(val self: Type) extends AnyVal {
621620
case tp: TermRef =>
622621
tp.underlying.baseTypeWithArgs(base)
623622
case tp: HKApply =>
624-
tp.upperBound.baseTypeWithArgs(base)
623+
tp.superType.baseTypeWithArgs(base)
625624
case AndType(tp1, tp2) =>
626625
tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base)
627626
case OrType(tp1, tp2) =>

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
677677
canConstrain(param1) && canInstantiate ||
678678
isSubType(bounds(param1).hi.applyIfParameterized(args1), tp2)
679679
case tycon1: TypeProxy =>
680-
isSubType(tycon1.underlying.bounds.hi.applyIfParameterized(args1), tp2)
680+
isSubType(tycon1.superType.applyIfParameterized(args1), tp2)
681681
case _ =>
682682
false
683683
}
@@ -1218,20 +1218,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12181218
else original(tp1, tp2.appliedTo(tp2.typeParams.map(_.paramBoundsAsSeenFrom(tp2))))
12191219
else if (tparams2.isEmpty)
12201220
original(tp1.appliedTo(tp1.typeParams.map(_.paramBoundsAsSeenFrom(tp1))), tp2)
1221-
else {
1222-
val numArgs = tparams1.length
1223-
def argRefs(tl: GenericType) = List.range(0, numArgs).map(PolyParam(tl, _))
1221+
else
12241222
TypeLambda(
1225-
paramNames = tpnme.syntheticLambdaParamNames(numArgs),
1223+
paramNames = tpnme.syntheticLambdaParamNames(tparams1.length),
12261224
variances = (tparams1, tparams2).zipped.map((tparam1, tparam2) =>
12271225
(tparam1.paramVariance + tparam2.paramVariance) / 2))(
12281226
paramBoundsExp = tl => (tparams1, tparams2).zipped.map((tparam1, tparam2) =>
12291227
tl.lifted(tparams1, tparam1.paramBoundsAsSeenFrom(tp1)).bounds &
12301228
tl.lifted(tparams2, tparam2.paramBoundsAsSeenFrom(tp2)).bounds),
12311229
resultTypeExp = tl =>
1232-
original(tl.lifted(tparams1, tp1).appliedTo(argRefs(tl)),
1233-
tl.lifted(tparams2, tp2).appliedTo(argRefs(tl))))
1234-
}
1230+
original(tl.lifted(tparams1, tp1).appliedTo(tl.paramRefs),
1231+
tl.lifted(tparams2, tp2).appliedTo(tl.paramRefs)))
12351232
}
12361233

12371234
/** Try to distribute `&` inside type, detect and handle conflicts

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
356356
case rt =>
357357
tp.derivedMethodType(tp.paramNames, formals, rt)
358358
}
359-
case tp: TypeLambda =>
360-
this(tp.resultType)
361359
case tp: PolyType =>
362360
this(tp.resultType) match {
363361
case rt: MethodType => rt

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
194194
case tp: RefinedType => isClassRef(tp.parent)
195195
case _ => false
196196
}
197-
def next(tp: TypeProxy) = tp.underlying match {
198-
case TypeBounds(_, hi) => hi
199-
case nx => nx
200-
}
197+
201198
/** If `tp1` and `tp2` are typebounds, try to make one fit into the other
202199
* or to make them equal, by instantiating uninstantiated type variables.
203200
*/
@@ -238,13 +235,13 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
238235
case tp1: RecType =>
239236
tp1.rebind(approximateOr(tp1.parent, tp2))
240237
case tp1: TypeProxy if !isClassRef(tp1) =>
241-
approximateUnion(next(tp1) | tp2)
238+
approximateUnion(tp1.superType | tp2)
242239
case _ =>
243240
tp2 match {
244241
case tp2: RecType =>
245242
tp2.rebind(approximateOr(tp1, tp2.parent))
246243
case tp2: TypeProxy if !isClassRef(tp2) =>
247-
approximateUnion(tp1 | next(tp2))
244+
approximateUnion(tp1 | tp2.superType)
248245
case _ =>
249246
val commonBaseClasses = tp.mapReduceOr(_.baseClasses)(intersect)
250247
val doms = dominators(commonBaseClasses, Nil)

0 commit comments

Comments
 (0)