Skip to content

Commit dee44eb

Browse files
committed
Remove all traces of TypeArgRef
1 parent 3a2eabc commit dee44eb

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
@@ -1742,6 +1742,12 @@ object Types {
17421742
def rebase(arg: Type) = arg.subst(typeParams, concretized)
17431743

17441744
val idx = typeParams.indexOf(param)
1745+
1746+
assert(args.nonEmpty,
1747+
i"""bad parameter reference $this at ${ctx.phase}
1748+
|the parameter is ${param.showLocated} but the prefix $prefix
1749+
|does not define any corresponding arguments."""
1750+
17451751
val argInfo = args(idx) match {
17461752
case arg: TypeBounds =>
17471753
val v = param.paramVariance
@@ -1877,9 +1883,7 @@ object Types {
18771883
while (tparams.nonEmpty && args.nonEmpty) {
18781884
if (tparams.head.eq(tparam))
18791885
return args.head match {
1880-
case _: TypeBounds =>
1881-
if (Config.newScheme) TypeRef(pre, tparam)
1882-
else TypeArgRef(pre, cls.typeRef, idx)
1886+
case _: TypeBounds => TypeRef(pre, tparam)
18831887
case arg => arg
18841888
}
18851889
tparams = tparams.tail
@@ -3045,7 +3049,7 @@ object Types {
30453049
final val Provisional: DependencyStatus = 4 // set if dependency status can still change due to type variable instantiations
30463050
}
30473051

3048-
// ----- Type application: LambdaParam, AppliedType, TypeArgRef ---------------------
3052+
// ----- Type application: LambdaParam, AppliedType ---------------------
30493053

30503054
/** The parameter of a type lambda */
30513055
case class LambdaParam(tl: TypeLambda, n: Int) extends ParamInfo {
@@ -3123,70 +3127,6 @@ object Types {
31233127
}
31243128
}
31253129

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

31923132
abstract class BoundType extends CachedProxyType with ValueType {
@@ -3787,13 +3727,7 @@ object Types {
37873727
def apply(tp: Type): Type
37883728

37893729
protected def derivedSelect(tp: NamedType, pre: Type): Type =
3790-
tp.derivedSelect(pre) match {
3791-
case tp: TypeArgRef if variance != 0 =>
3792-
val tp1 = tp.underlying
3793-
if (variance > 0) tp1.hiBound else tp1.loBound
3794-
case tp =>
3795-
tp
3796-
}
3730+
tp.derivedSelect(pre)
37973731
protected def derivedRefinedType(tp: RefinedType, parent: Type, info: Type): Type =
37983732
tp.derivedRefinedType(parent, tp.refinedName, info)
37993733
protected def derivedRecType(tp: RecType, parent: Type): Type =
@@ -3806,8 +3740,6 @@ object Types {
38063740
tp.derivedSuperType(thistp, supertp)
38073741
protected def derivedAppliedType(tp: AppliedType, tycon: Type, args: List[Type]): Type =
38083742
tp.derivedAppliedType(tycon, args)
3809-
protected def derivedTypeArgRef(tp: TypeArgRef, prefix: Type): Type =
3810-
tp.derivedTypeArgRef(prefix)
38113743
protected def derivedAndOrType(tp: AndOrType, tp1: Type, tp2: Type): Type =
38123744
tp.derivedAndOrType(tp1, tp2)
38133745
protected def derivedAnnotatedType(tp: AnnotatedType, underlying: Type, annot: Annotation): Type =
@@ -3892,9 +3824,6 @@ object Types {
38923824
}
38933825
mapOverLambda
38943826

3895-
case tp @ TypeArgRef(prefix, _, _) =>
3896-
derivedTypeArgRef(tp, atVariance(variance max 0)(this(prefix)))
3897-
38983827
case tp @ SuperType(thistp, supertp) =>
38993828
derivedSuperType(tp, this(thistp), this(supertp))
39003829

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

40433984
/** Derived selection.
40443985
* @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4048,21 +3989,7 @@ object Types {
40483989
else pre match {
40493990
case Range(preLo, preHi) =>
40503991
val forwarded =
4051-
if (tp.symbol.is(ClassTypeParam)) {
4052-
tp.argForParam(preHi) match {
4053-
case arg: TypeArgRef =>
4054-
arg.underlying match {
4055-
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
4056-
case arg => reapply(arg)
4057-
}
4058-
case arg @ TypeRef(pre, _) if pre.isArgPrefix(arg.symbol) =>
4059-
arg.info match {
4060-
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
4061-
case arg => reapply(arg)
4062-
}
4063-
case arg => reapply(arg)
4064-
}
4065-
}
3992+
if (tp.symbol.is(ClassTypeParam)) expandParam(tp, preHi)
40663993
else tryWiden(tp, preHi)
40673994
forwarded.orElse(
40683995
range(super.derivedSelect(tp, preLo), super.derivedSelect(tp, preHi)))
@@ -4165,14 +4092,6 @@ object Types {
41654092
else range(lower(tp1) | lower(tp2), upper(tp1) | upper(tp2))
41664093
else tp.derivedAndOrType(tp1, tp2)
41674094

4168-
override protected def derivedTypeArgRef(tp: TypeArgRef, prefix: Type): Type =
4169-
if (isRange(prefix)) // TODO: explain
4170-
tp.underlying match {
4171-
case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi))
4172-
case _ => range(tp.bottomType, tp.topType)
4173-
}
4174-
else tp.derivedTypeArgRef(prefix)
4175-
41764095
override protected def derivedAnnotatedType(tp: AnnotatedType, underlying: Type, annot: Annotation) =
41774096
underlying match {
41784097
case Range(lo, hi) =>
@@ -4308,9 +4227,6 @@ object Types {
43084227
case tp: SkolemType =>
43094228
this(x, tp.info)
43104229

4311-
case tp @ TypeArgRef(prefix, _, _) =>
4312-
atVariance(variance max 0)(this(x, prefix))
4313-
43144230
case SuperType(thistp, supertp) =>
43154231
this(this(x, thistp), supertp)
43164232

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ Standard-Section: "ASTs" TopLevelStat*
168168
// for type-variables defined in a type pattern
169169
BYNAMEtype underlying_Type
170170
PARAMtype Length binder_ASTref paramNum_Nat
171-
TYPEARGtype Length prefix_Type clsRef_Type idx_Nat
172171
POLYtype Length result_Type NamesTypes
173172
METHODtype Length result_Type NamesTypes // needed for refinements
174173
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
@@ -394,7 +393,6 @@ object TastyFormat {
394393
final val LAMBDAtpt = 173
395394
final val PARAMtype = 174
396395
final val ANNOTATION = 175
397-
final val TYPEARGtype = 176
398396
final val TERMREFin = 177
399397
final val TYPEREFin = 178
400398

@@ -580,7 +578,6 @@ object TastyFormat {
580578
case SYMBOLconst => "SYMBOLconst"
581579
case SINGLETONtpt => "SINGLETONtpt"
582580
case SUPERtype => "SUPERtype"
583-
case TYPEARGtype => "TYPEARGtype"
584581
case TERMREFin => "TERMREFin"
585582
case TYPEREFin => "TYPEREFin"
586583
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
@@ -211,9 +211,6 @@ class TreePickler(pickler: TastyPickler) {
211211
case tpe: SuperType =>
212212
writeByte(SUPERtype)
213213
withLength { pickleType(tpe.thistpe); pickleType(tpe.supertpe) }
214-
case tpe: TypeArgRef =>
215-
writeByte(TYPEARGtype)
216-
withLength { pickleType(tpe.prefix); pickleType(tpe.clsRef); writeNat(tpe.idx) }
217214
case tpe: RecThis =>
218215
writeByte(RECthis)
219216
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
@@ -176,11 +176,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
176176
"{" ~ selfRecName(openRecs.length) ~ " => " ~ toTextGlobal(tp.parent) ~ "}"
177177
}
178178
finally openRecs = openRecs.tail
179-
case TypeArgRef(prefix, clsRef, idx) =>
180-
val cls = clsRef.symbol
181-
val tparams = cls.typeParams
182-
val paramName = if (tparams.length > idx) nameString(tparams(idx)) else "<unknown>"
183-
toTextPrefix(prefix) ~ s"<parameter $paramName of " ~ toText(cls) ~ ">"
184179
case AndType(tp1, tp2) =>
185180
changePrec(AndPrec) { toText(tp1) ~ " & " ~ toText(tp2) }
186181
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
@@ -31,11 +31,6 @@ class UserFacingPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
3131

3232
override def toText(const: Constant): Text = Str(const.value.toString)
3333

34-
override def argText(tp: Type): Text = tp match {
35-
case arg: TypeArgRef => argText(arg.underlying)
36-
case _ => super.argText(tp)
37-
}
38-
3934
override def toText(tp: Type): Text = tp match {
4035
case ExprType(result) => ":" ~~ toText(result)
4136
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
@@ -96,6 +96,7 @@ class CompilationTests extends ParallelTesting {
9696
compileFilesInDir("../tests/new", defaultOptions) +
9797
compileFilesInDir("../tests/pos-scala2", scala2Mode) +
9898
compileFilesInDir("../tests/pos", defaultOptions) +
99+
compileFilesInDir("../tests/pos-no-optimise", defaultOptions) +
99100
compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) +
100101
compileDir("../tests/pos/i1137-1", defaultOptions and "-Yemit-tasty") +
101102
compileFile(

0 commit comments

Comments
 (0)