Skip to content

Commit 6872bdb

Browse files
committed
Remove Reflection.TypeOrBounds abstraction
* Align with TASTy format * Make it simpler to handle types with the reflection API * Remove ParamInfo from LambdaType (it was unused) This abstraction is there for historical reasons only, from the time when there was split between TypeTree, TypeBoundsTree and Tree. This distinction is no longer in the API and the types should follow the same design. Migration help: If there match on `Type` that matched agaist a `TypeOrBound` ```scala def f(t: TypeOrBound) = t match case t: Type => ... ``` The cases for `TypeBounds` and `NoPrefix` should be added before the `Type` test ```scala def f(t: Type) = t match case t: TypeBounds => case NoPrefix() => case t => // t: Type ... ```
1 parent 68d5d68 commit 6872bdb

File tree

17 files changed

+265
-296
lines changed

17 files changed

+265
-296
lines changed

compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionCompilerInterface.scala

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
10151015
case _ => None
10161016
}
10171017

1018-
def WildcardTypeTree_tpe(self: WildcardTypeTree)(using Context): TypeOrBounds = self.tpe.stripTypeVar
1018+
def WildcardTypeTree_tpe(self: WildcardTypeTree)(using Context): Type = self.tpe.stripTypeVar
10191019

10201020
type CaseDef = tpd.CaseDef
10211021

@@ -1117,34 +1117,9 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
11171117
// TYPES //
11181118
/////////////
11191119

1120-
type TypeOrBounds = Types.Type
1121-
1122-
type NoPrefix = Types.NoPrefix.type
1123-
1124-
def NoPrefix_TypeTest(using Context): TypeTest[TypeOrBounds, NoPrefix] = new {
1125-
def runtimeClass: Class[?] = classOf[Types.NoPrefix.type]
1126-
override def unapply(x: Any): Option[NoPrefix] =
1127-
if (x == Types.NoPrefix) Some(Types.NoPrefix) else None
1128-
}
1129-
1130-
type TypeBounds = Types.TypeBounds
1131-
1132-
def TypeBounds_TypeTest(using Context): TypeTest[TypeOrBounds, TypeBounds] = new {
1133-
def runtimeClass: Class[?] = classOf[TypeBounds]
1134-
override def unapply(x: Any): Option[TypeBounds] = x match
1135-
case x: Types.TypeBounds => Some(x)
1136-
case _ => None
1137-
}
1138-
1139-
def TypeBounds_apply(low: Type, hi: Type)(using Context): TypeBounds =
1140-
Types.TypeBounds(low, hi)
1141-
1142-
def TypeBounds_low(self: TypeBounds)(using Context): Type = self.lo
1143-
def TypeBounds_hi(self: TypeBounds)(using Context): Type = self.hi
1144-
11451120
type Type = Types.Type
11461121

1147-
def Type_TypeTest(using Context): TypeTest[TypeOrBounds, Type] = new {
1122+
def Type_TypeTest(using Context): TypeTest[Type, Type] = new {
11481123
def runtimeClass: Class[?] = classOf[Type]
11491124
override def unapply(x: Any): Option[Type] = x match
11501125
case x: TypeBounds => None
@@ -1224,12 +1199,12 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12241199
def Type_select(self: Type)(sym: Symbol)(using Context): Type =
12251200
self.select(sym)
12261201

1227-
def Type_appliedTo(self: Type)(targs: List[TypeOrBounds]): Type =
1202+
def Type_appliedTo(self: Type)(targs: List[Type]): Type =
12281203
self.appliedTo(targs)
12291204

12301205
type ConstantType = Types.ConstantType
12311206

1232-
def ConstantType_TypeTest(using Context): TypeTest[TypeOrBounds, ConstantType] = new {
1207+
def ConstantType_TypeTest(using Context): TypeTest[Type, ConstantType] = new {
12331208
def runtimeClass: Class[?] = classOf[ConstantType]
12341209
override def unapply(x: Any): Option[ConstantType] = x match
12351210
case tpe: Types.ConstantType => Some(tpe)
@@ -1243,30 +1218,30 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12431218

12441219
type TermRef = Types.NamedType
12451220

1246-
def TermRef_TypeTest(using Context): TypeTest[TypeOrBounds, TermRef] = new {
1221+
def TermRef_TypeTest(using Context): TypeTest[Type, TermRef] = new {
12471222
def runtimeClass: Class[?] = classOf[TermRef]
12481223
override def unapply(x: Any): Option[TermRef] = x match
12491224
case tp: Types.TermRef => Some(tp)
12501225
case _ => None
12511226
}
12521227

1253-
def TermRef_apply(qual: TypeOrBounds, name: String)(using Context): TermRef =
1228+
def TermRef_apply(qual: Type, name: String)(using Context): TermRef =
12541229
Types.TermRef(qual, name.toTermName)
12551230

1256-
def TermRef_qualifier(self: TermRef)(using Context): TypeOrBounds = self.prefix
1231+
def TermRef_qualifier(self: TermRef)(using Context): Type = self.prefix
12571232

12581233
def TermRef_name(self: TermRef)(using Context): String = self.name.toString
12591234

12601235
type TypeRef = Types.NamedType
12611236

1262-
def TypeRef_TypeTest(using Context): TypeTest[TypeOrBounds, TypeRef] = new {
1237+
def TypeRef_TypeTest(using Context): TypeTest[Type, TypeRef] = new {
12631238
def runtimeClass: Class[?] = classOf[TypeRef]
12641239
override def unapply(x: Any): Option[TypeRef] = x match
12651240
case tp: Types.TypeRef => Some(tp)
12661241
case _ => None
12671242
}
12681243

1269-
def TypeRef_qualifier(self: TypeRef)(using Context): TypeOrBounds = self.prefix
1244+
def TypeRef_qualifier(self: TypeRef)(using Context): Type = self.prefix
12701245

12711246
def TypeRef_name(self: TypeRef)(using Context): String = self.name.toString
12721247

@@ -1276,7 +1251,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12761251

12771252
type NamedTermRef = Types.NamedType
12781253

1279-
def NamedTermRef_TypeTest(using Context): TypeTest[TypeOrBounds, NamedTermRef] = new {
1254+
def NamedTermRef_TypeTest(using Context): TypeTest[Type, NamedTermRef] = new {
12801255
def runtimeClass: Class[?] = classOf[NamedTermRef]
12811256
override def unapply(x: Any): Option[NamedTermRef] = x match
12821257
case tpe: Types.NamedType =>
@@ -1288,11 +1263,11 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12881263
}
12891264

12901265
def NamedTermRef_name(self: NamedTermRef)(using Context): String = self.name.toString
1291-
def NamedTermRef_qualifier(self: NamedTermRef)(using Context): TypeOrBounds = self.prefix
1266+
def NamedTermRef_qualifier(self: NamedTermRef)(using Context): Type = self.prefix
12921267

12931268
type SuperType = Types.SuperType
12941269

1295-
def SuperType_TypeTest(using Context): TypeTest[TypeOrBounds, SuperType] = new {
1270+
def SuperType_TypeTest(using Context): TypeTest[Type, SuperType] = new {
12961271
def runtimeClass: Class[?] = classOf[SuperType]
12971272
override def unapply(x: Any): Option[SuperType] = x match
12981273
case tpe: Types.SuperType => Some(tpe)
@@ -1307,14 +1282,14 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13071282

13081283
type Refinement = Types.RefinedType
13091284

1310-
def Refinement_TypeTest(using Context): TypeTest[TypeOrBounds, Refinement] = new {
1285+
def Refinement_TypeTest(using Context): TypeTest[Type, Refinement] = new {
13111286
def runtimeClass: Class[?] = classOf[Refinement]
13121287
override def unapply(x: Any): Option[Refinement] = x match
13131288
case tpe: Types.RefinedType => Some(tpe)
13141289
case _ => None
13151290
}
13161291

1317-
def Refinement_apply(parent: Type, name: String, info: TypeOrBounds /* Type | TypeBounds */)(using Context): Refinement = {
1292+
def Refinement_apply(parent: Type, name: String, info: Type)(using Context): Refinement = {
13181293
val name1 =
13191294
info match
13201295
case _: TypeBounds => name.toTypeName
@@ -1324,23 +1299,23 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13241299

13251300
def Refinement_parent(self: Refinement)(using Context): Type = self.parent
13261301
def Refinement_name(self: Refinement)(using Context): String = self.refinedName.toString
1327-
def Refinement_info(self: Refinement)(using Context): TypeOrBounds = self.refinedInfo
1302+
def Refinement_info(self: Refinement)(using Context): Type = self.refinedInfo
13281303

13291304
type AppliedType = Types.AppliedType
13301305

1331-
def AppliedType_TypeTest(using Context): TypeTest[TypeOrBounds, AppliedType] = new {
1306+
def AppliedType_TypeTest(using Context): TypeTest[Type, AppliedType] = new {
13321307
def runtimeClass: Class[?] = classOf[AppliedType]
13331308
override def unapply(x: Any): Option[AppliedType] = x match
13341309
case tpe: Types.AppliedType => Some(tpe)
13351310
case _ => None
13361311
}
13371312

13381313
def AppliedType_tycon(self: AppliedType)(using Context): Type = self.tycon
1339-
def AppliedType_args(self: AppliedType)(using Context): List[TypeOrBounds] = self.args
1314+
def AppliedType_args(self: AppliedType)(using Context): List[Type] = self.args
13401315

13411316
type AnnotatedType = Types.AnnotatedType
13421317

1343-
def AnnotatedType_TypeTest(using Context): TypeTest[TypeOrBounds, AnnotatedType] = new {
1318+
def AnnotatedType_TypeTest(using Context): TypeTest[Type, AnnotatedType] = new {
13441319
def runtimeClass: Class[?] = classOf[AnnotatedType]
13451320
override def unapply(x: Any): Option[AnnotatedType] = x match
13461321
case tpe: Types.AnnotatedType => Some(tpe)
@@ -1355,7 +1330,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13551330

13561331
type AndType = Types.AndType
13571332

1358-
def AndType_TypeTest(using Context): TypeTest[TypeOrBounds, AndType] = new {
1333+
def AndType_TypeTest(using Context): TypeTest[Type, AndType] = new {
13591334
def runtimeClass: Class[?] = classOf[AndType]
13601335
override def unapply(x: Any): Option[AndType] = x match
13611336
case tpe: Types.AndType => Some(tpe)
@@ -1370,7 +1345,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13701345

13711346
type OrType = Types.OrType
13721347

1373-
def OrType_TypeTest(using Context): TypeTest[TypeOrBounds, OrType] = new {
1348+
def OrType_TypeTest(using Context): TypeTest[Type, OrType] = new {
13741349
def runtimeClass: Class[?] = classOf[OrType]
13751350
override def unapply(x: Any): Option[OrType] = x match
13761351
case tpe: Types.OrType => Some(tpe)
@@ -1385,7 +1360,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13851360

13861361
type MatchType = Types.MatchType
13871362

1388-
def MatchType_TypeTest(using Context): TypeTest[TypeOrBounds, MatchType] = new {
1363+
def MatchType_TypeTest(using Context): TypeTest[Type, MatchType] = new {
13891364
def runtimeClass: Class[?] = classOf[MatchType]
13901365
override def unapply(x: Any): Option[MatchType] = x match
13911366
case tpe: Types.MatchType => Some(tpe)
@@ -1401,7 +1376,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14011376

14021377
type ByNameType = Types.ExprType
14031378

1404-
def ByNameType_TypeTest(using Context): TypeTest[TypeOrBounds, ByNameType] = new {
1379+
def ByNameType_TypeTest(using Context): TypeTest[Type, ByNameType] = new {
14051380
def runtimeClass: Class[?] = classOf[ByNameType]
14061381
override def unapply(x: Any): Option[ByNameType] = x match
14071382
case tpe: Types.ExprType => Some(tpe)
@@ -1414,21 +1389,21 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14141389

14151390
type ParamRef = Types.ParamRef
14161391

1417-
def ParamRef_TypeTest(using Context): TypeTest[TypeOrBounds, ParamRef] = new {
1392+
def ParamRef_TypeTest(using Context): TypeTest[Type, ParamRef] = new {
14181393
def runtimeClass: Class[?] = classOf[ParamRef]
14191394
override def unapply(x: Any): Option[ParamRef] = x match
14201395
case tpe: Types.TypeParamRef => Some(tpe)
14211396
case tpe: Types.TermParamRef => Some(tpe)
14221397
case _ => None
14231398
}
14241399

1425-
def ParamRef_binder(self: ParamRef)(using Context): LambdaType[TypeOrBounds] =
1426-
self.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd
1400+
def ParamRef_binder(self: ParamRef)(using Context): LambdaType =
1401+
self.binder.asInstanceOf[LambdaType] // Cast to tpd
14271402
def ParamRef_paramNum(self: ParamRef)(using Context): Int = self.paramNum
14281403

14291404
type ThisType = Types.ThisType
14301405

1431-
def ThisType_TypeTest(using Context): TypeTest[TypeOrBounds, ThisType] = new {
1406+
def ThisType_TypeTest(using Context): TypeTest[Type, ThisType] = new {
14321407
def runtimeClass: Class[?] = classOf[ThisType]
14331408
override def unapply(x: Any): Option[ThisType] = x match
14341409
case tpe: Types.ThisType => Some(tpe)
@@ -1439,7 +1414,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14391414

14401415
type RecursiveThis = Types.RecThis
14411416

1442-
def RecursiveThis_TypeTest(using Context): TypeTest[TypeOrBounds, RecursiveThis] = new {
1417+
def RecursiveThis_TypeTest(using Context): TypeTest[Type, RecursiveThis] = new {
14431418
def runtimeClass: Class[?] = classOf[RecursiveThis]
14441419
override def unapply(x: Any): Option[RecursiveThis] = x match
14451420
case tpe: Types.RecThis => Some(tpe)
@@ -1450,7 +1425,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14501425

14511426
type RecursiveType = Types.RecType
14521427

1453-
def RecursiveType_TypeTest(using Context): TypeTest[TypeOrBounds, RecursiveType] = new {
1428+
def RecursiveType_TypeTest(using Context): TypeTest[Type, RecursiveType] = new {
14541429
def runtimeClass: Class[?] = classOf[RecursiveType]
14551430
override def unapply(x: Any): Option[RecursiveType] = x match
14561431
case tpe: Types.RecType => Some(tpe)
@@ -1464,11 +1439,11 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14641439

14651440
def RecursiveThis_recThis(self: RecursiveType)(using Context): RecursiveThis = self.recThis
14661441

1467-
type LambdaType[ParamInfo] = Types.LambdaType { type PInfo = ParamInfo }
1442+
type LambdaType = Types.LambdaType
14681443

14691444
type MethodType = Types.MethodType
14701445

1471-
def MethodType_TypeTest(using Context): TypeTest[TypeOrBounds, MethodType] = new {
1446+
def MethodType_TypeTest(using Context): TypeTest[Type, MethodType] = new {
14721447
def runtimeClass: Class[?] = classOf[MethodType]
14731448
override def unapply(x: Any): Option[MethodType] = x match
14741449
case tpe: Types.MethodType => Some(tpe)
@@ -1487,7 +1462,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14871462

14881463
type PolyType = Types.PolyType
14891464

1490-
def PolyType_TypeTest(using Context): TypeTest[TypeOrBounds, PolyType] = new {
1465+
def PolyType_TypeTest(using Context): TypeTest[Type, PolyType] = new {
14911466
def runtimeClass: Class[?] = classOf[PolyType]
14921467
override def unapply(x: Any): Option[PolyType] = x match
14931468
case tpe: Types.PolyType => Some(tpe)
@@ -1504,7 +1479,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
15041479

15051480
type TypeLambda = Types.TypeLambda
15061481

1507-
def TypeLambda_TypeTest(using Context): TypeTest[TypeOrBounds, TypeLambda] = new {
1482+
def TypeLambda_TypeTest(using Context): TypeTest[Type, TypeLambda] = new {
15081483
def runtimeClass: Class[?] = classOf[TypeLambda]
15091484
override def unapply(x: Any): Option[TypeLambda] = x match
15101485
case tpe: Types.TypeLambda => Some(tpe)
@@ -1520,6 +1495,28 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
15201495
self.newParamRef(idx)
15211496
def TypeLambda_resType(self: TypeLambda)(using Context): Type = self.resType
15221497

1498+
type NoPrefix = Types.NoPrefix.type
1499+
1500+
def NoPrefix_TypeTest(using Context): TypeTest[Type, NoPrefix] = new {
1501+
def runtimeClass: Class[?] = classOf[Types.NoPrefix.type]
1502+
override def unapply(x: Any): Option[NoPrefix] =
1503+
if (x == Types.NoPrefix) Some(Types.NoPrefix) else None
1504+
}
1505+
1506+
type TypeBounds = Types.TypeBounds
1507+
1508+
def TypeBounds_TypeTest(using Context): TypeTest[Type, TypeBounds] = new {
1509+
def runtimeClass: Class[?] = classOf[TypeBounds]
1510+
override def unapply(x: Any): Option[TypeBounds] = x match
1511+
case x: Types.TypeBounds => Some(x)
1512+
case _ => None
1513+
}
1514+
1515+
def TypeBounds_apply(low: Type, hi: Type)(using Context): TypeBounds =
1516+
Types.TypeBounds(low, hi)
1517+
1518+
def TypeBounds_low(self: TypeBounds)(using Context): Type = self.lo
1519+
def TypeBounds_hi(self: TypeBounds)(using Context): Type = self.hi
15231520

15241521
//////////////////////
15251522
// IMPORT SELECTORS //

0 commit comments

Comments
 (0)