Skip to content

Commit a0a0cd4

Browse files
committed
Remove all traces of TypeArgRef
1 parent 68d45ce commit a0a0cd4

File tree

11 files changed

+46
-168
lines changed

11 files changed

+46
-168
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,4 @@ object Config {
179179

180180
/** When in IDE, turn StaleSymbol errors into warnings instead of crashing */
181181
final val ignoreStaleInIDE = true
182-
183-
val newScheme = true
184182
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
527527
case _ => isSubType(tp1.widenExpr, restpe2)
528528
}
529529
compareExpr
530-
case tp2: TypeArgRef =>
531-
def sameTypeArgRef = tp1 match {
532-
case tp1: TypeArgRef =>
533-
tp1.clsRef == tp2.clsRef && tp1.idx == tp2.idx && tp1.prefix =:= tp2.prefix
534-
case _ =>
535-
false
536-
}
537-
sameTypeArgRef || isSubType(tp1, tp2.underlying.loBound) || fourthTry(tp1, tp2)
538530
case tp2 @ TypeBounds(lo2, hi2) =>
539531
def compareTypeBounds = tp1 match {
540532
case tp1 @ TypeBounds(lo1, hi1) =>
@@ -605,8 +597,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
605597
isNewSubType(tp1.parent, tp2)
606598
case tp1: RecType =>
607599
isNewSubType(tp1.parent, tp2)
608-
case tp1: TypeArgRef =>
609-
isSubType(tp1.underlying.hiBound, tp2)
610600
case tp1: HKTypeLambda =>
611601
def compareHKLambda = tp1 match {
612602
case EtaExpansion(tycon1) => isSubType(tycon1, tp2)
@@ -829,9 +819,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
829819

830820
def compareCaptured(arg1: Type, arg2: Type): Boolean = arg1 match {
831821
case arg1: TypeBounds =>
832-
val captured =
833-
if (Config.newScheme) TypeRef(tp1, tparam.asInstanceOf[TypeSymbol])
834-
else TypeArgRef.fromParam(tp1, tparam.asInstanceOf[TypeSymbol])
822+
val captured = TypeRef(tp1, tparam.asInstanceOf[TypeSymbol])
835823
isSubArg(captured, arg2)
836824
case _ =>
837825
false

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

Lines changed: 44 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ object Types {
187187
* from the ThisType of `symd`'s owner.
188188
*/
189189
def isArgPrefix(symd: SymDenotation)(implicit ctx: Context) =
190-
Config.newScheme && symd.is(ClassTypeParam) && {
190+
symd.is(ClassTypeParam) && {
191191
this match {
192192
case tp: ThisType => tp.cls ne symd.owner
193193
case _ => true
@@ -1736,6 +1736,12 @@ object Types {
17361736
def rebase(arg: Type) = arg.subst(typeParams, concretized)
17371737

17381738
val idx = typeParams.indexOf(param)
1739+
1740+
assert(args.nonEmpty,
1741+
i"""bad parameter reference $this at ${ctx.phase}
1742+
|the parameter is ${param.showLocated} but the prefix $prefix
1743+
|does not define any corresponding arguments."""
1744+
17391745
val argInfo = args(idx) match {
17401746
case arg: TypeBounds =>
17411747
val v = param.paramVariance
@@ -1871,9 +1877,7 @@ object Types {
18711877
while (tparams.nonEmpty && args.nonEmpty) {
18721878
if (tparams.head.eq(tparam))
18731879
return args.head match {
1874-
case _: TypeBounds =>
1875-
if (Config.newScheme) TypeRef(pre, tparam)
1876-
else TypeArgRef(pre, cls.typeRef, idx)
1880+
case _: TypeBounds => TypeRef(pre, tparam)
18771881
case arg => arg
18781882
}
18791883
tparams = tparams.tail
@@ -3039,7 +3043,7 @@ object Types {
30393043
final val Provisional: DependencyStatus = 4 // set if dependency status can still change due to type variable instantiations
30403044
}
30413045

3042-
// ----- Type application: LambdaParam, AppliedType, TypeArgRef ---------------------
3046+
// ----- Type application: LambdaParam, AppliedType ---------------------
30433047

30443048
/** The parameter of a type lambda */
30453049
case class LambdaParam(tl: TypeLambda, n: Int) extends ParamInfo {
@@ -3117,70 +3121,6 @@ object Types {
31173121
}
31183122
}
31193123

3120-
/** A reference to wildcard argument `p.<parameter X of class C>`
3121-
* where `p: C[... _ ...]`
3122-
*/
3123-
abstract case class TypeArgRef(prefix: Type, clsRef: TypeRef, idx: Int) extends CachedProxyType with ValueType {
3124-
assert(prefix.isInstanceOf[ValueType])
3125-
assert(idx >= 0)
3126-
3127-
private[this] var underlyingCache: Type = _
3128-
private[this] var underlyingCachePeriod = Nowhere
3129-
3130-
def computeUnderlying(implicit ctx: Context): Type = {
3131-
val cls = clsRef.symbol
3132-
val args = prefix.baseType(cls).argInfos
3133-
val typeParams = cls.typeParams
3134-
3135-
val concretized = TypeArgRef.concretizeArgs(args, prefix, clsRef)
3136-
def rebase(arg: Type) = arg.subst(typeParams, concretized)
3137-
3138-
val arg = args(idx)
3139-
val tparam = typeParams(idx)
3140-
val v = tparam.paramVariance
3141-
val pbounds = tparam.paramInfo
3142-
if (v > 0 && pbounds.loBound.dealias.isBottomType) arg.hiBound & rebase(pbounds.hiBound)
3143-
else if (v < 0 && pbounds.hiBound.dealias.isTopType) arg.loBound | rebase(pbounds.loBound)
3144-
else arg recoverable_& rebase(pbounds)
3145-
}
3146-
3147-
override def underlying(implicit ctx: Context): Type = {
3148-
if (!ctx.hasSameBaseTypesAs(underlyingCachePeriod)) {
3149-
underlyingCache = computeUnderlying
3150-
underlyingCachePeriod = ctx.period
3151-
}
3152-
underlyingCache
3153-
}
3154-
3155-
def derivedTypeArgRef(prefix: Type)(implicit ctx: Context): Type =
3156-
if (prefix eq this.prefix) this else TypeArgRef(prefix, clsRef, idx)
3157-
override def computeHash = doHash(idx, prefix, clsRef)
3158-
3159-
override def eql(that: Type) = that match {
3160-
case that: TypeArgRef => prefix.eq(that.prefix) && clsRef.eq(that.clsRef) && idx == that.idx
3161-
case _ => false
3162-
}
3163-
}
3164-
3165-
final class CachedTypeArgRef(prefix: Type, clsRef: TypeRef, idx: Int) extends TypeArgRef(prefix, clsRef, idx)
3166-
3167-
object TypeArgRef {
3168-
def apply(prefix: Type, clsRef: TypeRef, idx: Int)(implicit ctx: Context) =
3169-
unique(new CachedTypeArgRef(prefix, clsRef, idx))
3170-
def fromParam(prefix: Type, tparam: TypeSymbol)(implicit ctx: Context) = {
3171-
val cls = tparam.owner
3172-
apply(prefix, cls.typeRef, cls.typeParams.indexOf(tparam))
3173-
}
3174-
3175-
def concretizeArgs(args: List[Type], prefix: Type, clsRef: TypeRef)(implicit ctx: Context): List[Type] = {
3176-
def concretize(arg: Type, j: Int) = arg match {
3177-
case arg: TypeBounds => TypeArgRef(prefix, clsRef, j)
3178-
case arg => arg
3179-
}
3180-
args.zipWithConserve(args.indices.toList)(concretize)
3181-
}
3182-
}
3183-
31843124
// ----- BoundTypes: ParamRef, RecThis ----------------------------------------
31853125

31863126
abstract class BoundType extends CachedProxyType with ValueType {
@@ -3781,13 +3721,7 @@ object Types {
37813721
def apply(tp: Type): Type
37823722

37833723
protected def derivedSelect(tp: NamedType, pre: Type): Type =
3784-
tp.derivedSelect(pre) match {
3785-
case tp: TypeArgRef if variance != 0 =>
3786-
val tp1 = tp.underlying
3787-
if (variance > 0) tp1.hiBound else tp1.loBound
3788-
case tp =>
3789-
tp
3790-
}
3724+
tp.derivedSelect(pre)
37913725
protected def derivedRefinedType(tp: RefinedType, parent: Type, info: Type): Type =
37923726
tp.derivedRefinedType(parent, tp.refinedName, info)
37933727
protected def derivedRecType(tp: RecType, parent: Type): Type =
@@ -3800,8 +3734,6 @@ object Types {
38003734
tp.derivedSuperType(thistp, supertp)
38013735
protected def derivedAppliedType(tp: AppliedType, tycon: Type, args: List[Type]): Type =
38023736
tp.derivedAppliedType(tycon, args)
3803-
protected def derivedTypeArgRef(tp: TypeArgRef, prefix: Type): Type =
3804-
tp.derivedTypeArgRef(prefix)
38053737
protected def derivedAndOrType(tp: AndOrType, tp1: Type, tp2: Type): Type =
38063738
tp.derivedAndOrType(tp1, tp2)
38073739
protected def derivedAnnotatedType(tp: AnnotatedType, underlying: Type, annot: Annotation): Type =
@@ -3886,9 +3818,6 @@ object Types {
38863818
}
38873819
mapOverLambda
38883820

3889-
case tp @ TypeArgRef(prefix, _, _) =>
3890-
derivedTypeArgRef(tp, atVariance(variance max 0)(this(prefix)))
3891-
38923821
case tp @ SuperType(thistp, supertp) =>
38933822
derivedSuperType(tp, this(thistp), this(supertp))
38943823

@@ -4012,27 +3941,39 @@ object Types {
40123941
/** Try to widen a named type to its info relative to given prefix `pre`, where possible.
40133942
* The possible cases are listed inline in the code.
40143943
*/
4015-
def tryWiden(tp: NamedType, pre: Type): Type =
4016-
pre.member(tp.name) match {
4017-
case d: SingleDenotation =>
4018-
d.info match {
4019-
case TypeAlias(alias) =>
4020-
// if H#T = U, then for any x in L..H, x.T =:= U,
4021-
// hence we can replace with U under all variances
4022-
reapply(alias)
4023-
case TypeBounds(lo, hi) =>
4024-
// If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
4025-
// hence we can replace with S..U under all variances
4026-
range(atVariance(-variance)(reapply(lo)), reapply(hi))
4027-
case info: SingletonType =>
4028-
// if H#x: y.type, then for any x in L..H, x.type =:= y.type,
4029-
// hence we can replace with y.type under all variances
4030-
reapply(info)
4031-
case _ =>
4032-
NoType
4033-
}
4034-
case _ => NoType
4035-
}
3944+
def tryWiden(tp: NamedType, pre: Type): Type = pre.member(tp.name) match {
3945+
case d: SingleDenotation =>
3946+
d.info match {
3947+
case TypeAlias(alias) =>
3948+
// if H#T = U, then for any x in L..H, x.T =:= U,
3949+
// hence we can replace with U under all variances
3950+
reapply(alias)
3951+
case TypeBounds(lo, hi) =>
3952+
// If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
3953+
// hence we can replace with S..U under all variances
3954+
range(atVariance(-variance)(reapply(lo)), reapply(hi))
3955+
case info: SingletonType =>
3956+
// if H#x: y.type, then for any x in L..H, x.type =:= y.type,
3957+
// hence we can replace with y.type under all variances
3958+
reapply(info)
3959+
case _ =>
3960+
NoType
3961+
}
3962+
case _ => NoType
3963+
}
3964+
3965+
/** Expand parameter reference corresponding to prefix `pre`;
3966+
* If the expansion is a wildcard parameter reference, convert its
3967+
* underlying bounds to a range, otherwise return the expansion.
3968+
*/
3969+
def expandParam(tp: NamedType, pre: Type) = tp.argForParam(pre) match {
3970+
case arg @ TypeRef(pre, _) if pre.isArgPrefix(arg.symbol) =>
3971+
arg.info match {
3972+
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
3973+
case arg => reapply(arg)
3974+
}
3975+
case arg => reapply(arg)
3976+
}
40363977

40373978
/** Derived selection.
40383979
* @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4042,21 +3983,7 @@ object Types {
40423983
else pre match {
40433984
case Range(preLo, preHi) =>
40443985
val forwarded =
4045-
if (tp.symbol.is(ClassTypeParam)) {
4046-
tp.argForParam(preHi) match {
4047-
case arg: TypeArgRef =>
4048-
arg.underlying match {
4049-
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
4050-
case arg => reapply(arg)
4051-
}
4052-
case arg @ TypeRef(pre, _) if pre.isArgPrefix(arg.symbol) =>
4053-
arg.info match {
4054-
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
4055-
case arg => reapply(arg)
4056-
}
4057-
case arg => reapply(arg)
4058-
}
4059-
}
3986+
if (tp.symbol.is(ClassTypeParam)) expandParam(tp, preHi)
40603987
else tryWiden(tp, preHi)
40613988
forwarded.orElse(
40623989
range(super.derivedSelect(tp, preLo), super.derivedSelect(tp, preHi)))
@@ -4159,14 +4086,6 @@ object Types {
41594086
else range(lower(tp1) | lower(tp2), upper(tp1) | upper(tp2))
41604087
else tp.derivedAndOrType(tp1, tp2)
41614088

4162-
override protected def derivedTypeArgRef(tp: TypeArgRef, prefix: Type): Type =
4163-
if (isRange(prefix)) // TODO: explain
4164-
tp.underlying match {
4165-
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
4166-
case _ => range(tp.bottomType, tp.topType)
4167-
}
4168-
else tp.derivedTypeArgRef(prefix)
4169-
41704089
override protected def derivedAnnotatedType(tp: AnnotatedType, underlying: Type, annot: Annotation) =
41714090
underlying match {
41724091
case Range(lo, hi) =>
@@ -4302,9 +4221,6 @@ object Types {
43024221
case tp: SkolemType =>
43034222
this(x, tp.info)
43044223

4305-
case tp @ TypeArgRef(prefix, _, _) =>
4306-
atVariance(variance max 0)(this(x, prefix))
4307-
43084224
case SuperType(thistp, supertp) =>
43094225
this(this(x, thistp), supertp)
43104226

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ Standard-Section: "ASTs" TopLevelStat*
167167
// for type-variables defined in a type pattern
168168
BYNAMEtype underlying_Type
169169
PARAMtype Length binder_ASTref paramNum_Nat
170-
TYPEARGtype Length prefix_Type clsRef_Type idx_Nat
171170
POLYtype Length result_Type NamesTypes
172171
METHODtype Length result_Type NamesTypes // needed for refinements
173172
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
@@ -392,7 +391,6 @@ object TastyFormat {
392391
final val LAMBDAtpt = 173
393392
final val PARAMtype = 174
394393
final val ANNOTATION = 175
395-
final val TYPEARGtype = 176
396394
final val TERMREFin = 177
397395
final val TYPEREFin = 178
398396

@@ -577,7 +575,6 @@ object TastyFormat {
577575
case ENUMconst => "ENUMconst"
578576
case SINGLETONtpt => "SINGLETONtpt"
579577
case SUPERtype => "SUPERtype"
580-
case TYPEARGtype => "TYPEARGtype"
581578
case TERMREFin => "TERMREFin"
582579
case TYPEREFin => "TYPEREFin"
583580
case REFINEDtype => "REFINEDtype"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ class TreePickler(pickler: TastyPickler) {
208208
case tpe: SuperType =>
209209
writeByte(SUPERtype)
210210
withLength { pickleType(tpe.thistpe); pickleType(tpe.supertpe) }
211-
case tpe: TypeArgRef =>
212-
writeByte(TYPEARGtype)
213-
withLength { pickleType(tpe.prefix); pickleType(tpe.clsRef); writeNat(tpe.idx) }
214211
case tpe: RecThis =>
215212
writeByte(RECthis)
216213
val binderAddr = pickledTypes.get(tpe.binder)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
259259
OrType(readType(), readType())
260260
case SUPERtype =>
261261
SuperType(readType(), readType())
262-
case TYPEARGtype =>
263-
TypeArgRef(readType(), readType().asInstanceOf[TypeRef], readNat())
264262
case BIND =>
265263
val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType, readType())
266264
registerSym(start, sym)

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
166166
"{" ~ selfRecName(openRecs.length) ~ " => " ~ toTextGlobal(tp.parent) ~ "}"
167167
}
168168
finally openRecs = openRecs.tail
169-
case TypeArgRef(prefix, clsRef, idx) =>
170-
val cls = clsRef.symbol
171-
val tparams = cls.typeParams
172-
val paramName = if (tparams.length > idx) nameString(tparams(idx)) else "<unknown>"
173-
toTextPrefix(prefix) ~ s"<parameter $paramName of " ~ toText(cls) ~ ">"
174169
case AndType(tp1, tp2) =>
175170
changePrec(AndPrec) { toText(tp1) ~ " & " ~ toText(tp2) }
176171
case OrType(tp1, tp2) =>

compiler/src/dotty/tools/dotc/printing/UserFacingPrinter.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
4747

4848
override def toText(const: Constant): Text = Str(const.value.toString)
4949

50-
override def argText(tp: Type): Text = tp match {
51-
case arg: TypeArgRef => argText(arg.underlying)
52-
case _ => super.argText(tp)
53-
}
54-
5550
override def toText(tp: Type): Text = tp match {
5651
case ExprType(result) => ":" ~~ toText(result)
5752
case tp: ConstantType => toText(tp.value)

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
147147
new api.Annotated(tp, Array(marker))
148148
private def marker(name: String) =
149149
new api.Annotation(new api.Constant(Constants.emptyType, name), Array())
150-
val typeArgRefMarker = marker("TypeArgRef")
151150
val orMarker = marker("Or")
152151
val byNameMarker = marker("ByName")
153152

@@ -478,9 +477,6 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
478477
apiType(tp.ref)
479478
case tp: TypeVar =>
480479
apiType(tp.underlying)
481-
case TypeArgRef(prefix, clsRef, idx) =>
482-
val apiClsWithIdx = withMarker(apiType(clsRef), marker(idx.toString))
483-
withMarker(combineApiTypes(apiType(prefix), apiClsWithIdx), typeArgRefMarker)
484480
case _ => {
485481
ctx.warning(i"sbt-api: Unhandled type ${tp.getClass} : $tp")
486482
Constants.emptyType

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class CompilationTests extends ParallelTesting {
9595
compileFilesInDir("../tests/new", defaultOptions) +
9696
compileFilesInDir("../tests/pos-scala2", scala2Mode) +
9797
compileFilesInDir("../tests/pos", defaultOptions) +
98+
compileFilesInDir("../tests/pos-no-optimise", defaultOptions) +
9899
compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) +
99100
compileDir("../tests/pos/i1137-1", defaultOptions and "-Yemit-tasty") +
100101
compileFile(

0 commit comments

Comments
 (0)