Skip to content

Commit ddae49f

Browse files
committed
Join TermRef/TypeRef with NamedTermRef/NamedTypeRef
1 parent 32d7787 commit ddae49f

File tree

7 files changed

+26
-135
lines changed

7 files changed

+26
-135
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
282282

283283
def Ident_name(self: Ident) given Context: String = self.name.show
284284

285-
def Ident_apply(tmref: NamedTermRef) given Context: Term =
285+
def Ident_apply(tmref: TermRef) given Context: Term =
286286
withDefaultPos(tpd.ref(tmref).asInstanceOf[Term])
287287

288288
def Ident_copy(original: Tree)(name: String) given Context: Ident =
@@ -1150,26 +1150,21 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11501150
type TermRef = Types.NamedType
11511151

11521152
def matchTermRef(tpe: TypeOrBounds) given Context: Option[TermRef] = tpe match {
1153-
case tp: Types.NamedType =>
1154-
tp.designator match {
1155-
case sym: Symbol if sym.isTerm => Some(tp)
1156-
case _ => None
1157-
}
1153+
case tp: Types.TermRef => Some(tp)
11581154
case _ => None
11591155
}
11601156

1157+
def TermRef_apply(qual: TypeOrBounds, name: String) given Context: TermRef =
1158+
Types.TermRef(qual, name.toTermName)
1159+
11611160
def TermRef_qualifier(self: TermRef) given Context: TypeOrBounds = self.prefix
11621161

11631162
def TermRef_name(self: TermRef) given Context: String = self.name.toString
11641163

11651164
type TypeRef = Types.NamedType
11661165

11671166
def matchTypeRef(tpe: TypeOrBounds) given Context: Option[TypeRef] = tpe match {
1168-
case tp: Types.NamedType =>
1169-
tp.designator match {
1170-
case sym: Symbol if sym.isType => Some(tp)
1171-
case _ => None
1172-
}
1167+
case tp: Types.TypeRef => Some(tp)
11731168
case _ => None
11741169
}
11751170

@@ -1191,23 +1186,6 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11911186
def NamedTermRef_name(self: NamedTermRef) given Context: String = self.name.toString
11921187
def NamedTermRef_qualifier(self: NamedTermRef) given Context: TypeOrBounds = self.prefix
11931188

1194-
def NamedTermRef_apply(qual: TypeOrBounds, name: String) given Context: NamedTermRef =
1195-
Types.TermRef(qual, name.toTermName)
1196-
1197-
type NamedTypeRef = Types.NamedType
1198-
1199-
def matchNamedTypeRef(tpe: TypeOrBounds) given Context: Option[NamedTypeRef] = tpe match {
1200-
case tpe: Types.NamedType =>
1201-
tpe.designator match {
1202-
case name: Names.TypeName => Some(tpe)
1203-
case _ => None
1204-
}
1205-
case _ => None
1206-
}
1207-
1208-
def NamedTypeRef_name(self: NamedTypeRef) given Context: String = self.name.toString
1209-
def NamedTypeRef_qualifier(self: NamedTypeRef) given Context: TypeOrBounds = self.prefix
1210-
12111189
type SuperType = Types.SuperType
12121190

12131191
def matchSuperType(tpe: TypeOrBounds) given Context: Option[SuperType] = tpe match {

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ import scala.runtime.quoted.Unpickler
7474
* +- Type -------+- ConstantType
7575
* +- TermRef
7676
* +- TypeRef
77-
* +- NamedTermRef
78-
* +- NamedTypeRef
7977
* +- SuperType
8078
* +- Refinement
8179
* +- AppliedType
@@ -330,7 +328,7 @@ trait CompilerInterface {
330328

331329
def Ident_name(self: Ident) given (ctx: Context): String
332330

333-
def Ident_apply(tmref: NamedTermRef) given (ctx: Context): Term
331+
def Ident_apply(tmref: TermRef) given (ctx: Context): Term
334332
def Ident_copy(original: Tree)(name: String) given (ctx: Context): Ident
335333

336334
/** Tree representing a selection of definition with a given name on a given prefix */
@@ -933,10 +931,11 @@ trait CompilerInterface {
933931

934932
def matchTermRef(tpe: TypeOrBounds) given (ctx: Context): Option[TermRef]
935933

934+
def TermRef_apply(qual: TypeOrBounds, name: String) given (ctx: Context): TermRef
935+
936936
def TermRef_qualifier(self: TermRef) given (ctx: Context): TypeOrBounds
937937
def TermRef_name(self: TermRef) given (ctx: Context): String
938938

939-
940939
/** Type of a reference to a type symbol */
941940
type TypeRef <: Type
942941

@@ -945,24 +944,6 @@ trait CompilerInterface {
945944
def TypeRef_qualifier(self: TypeRef) given (ctx: Context): TypeOrBounds
946945
def TypeRef_name(self: TypeRef) given Context: String
947946

948-
/** Type of a reference to a term by it's name */
949-
type NamedTermRef <: Type
950-
951-
def matchNamedTermRef(tpe: TypeOrBounds) given (ctx: Context): Option[NamedTermRef]
952-
953-
def NamedTermRef_name(self: NamedTermRef) given (ctx: Context): String
954-
def NamedTermRef_qualifier(self: NamedTermRef) given (ctx: Context): TypeOrBounds
955-
956-
def NamedTermRef_apply(qual: TypeOrBounds, name: String) given (ctx: Context): NamedTermRef
957-
958-
/** Type of a reference to a type by it's name */
959-
type NamedTypeRef <: Type
960-
961-
def matchNamedTypeRef(tpe: TypeOrBounds) given (ctx: Context): Option[NamedTypeRef]
962-
963-
def NamedTypeRef_name(self: NamedTypeRef) given (ctx: Context): String
964-
def NamedTypeRef_qualifier(self: NamedTypeRef) given (ctx: Context): TypeOrBounds
965-
966947
/** Type of a `super` refernce */
967948
type SuperType <: Type
968949

library/src/scala/tasty/reflect/Core.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ package scala.tasty.reflect
7171
* +- Type -------+- ConstantType
7272
* +- TermRef
7373
* +- TypeRef
74-
* +- NamedTermRef
75-
* +- NamedTypeRef
7674
* +- SuperType
7775
* +- Refinement
7876
* +- AppliedType
@@ -338,12 +336,6 @@ trait Core {
338336
/** Type of a reference to a type symbol */
339337
type TypeRef = internal.TypeRef
340338

341-
/** Type of a reference to a term */
342-
type NamedTermRef = internal.NamedTermRef
343-
344-
/** Type of a reference to a type */
345-
type NamedTypeRef = internal.NamedTypeRef
346-
347339
/** Type of a `super` refernce */
348340
type SuperType = internal.SuperType
349341

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,6 @@ trait Printers
312312
this += "Type.TermRef(" += qual+= ", \"" += name += "\")"
313313
case Type.TypeRef(qual, name) =>
314314
this += "Type.TypeRef(" += qual += ", \"" += name += "\")"
315-
case Type.NamedTermRef(qual, name) =>
316-
this += "Type.NamedTermRef(" += qual += ", \"" += name += "\")"
317-
case Type.NamedTypeRef(qual, name) =>
318-
this += "Type.NamedTypeRef(" += qual += ", \"" += name += "\")"
319315
case Type.Refinement(parent, name, info) =>
320316
this += "Type.Refinement(" += parent += ", " += name += ", " += info += ")"
321317
case Type.AppliedType(tycon, args) =>
@@ -1555,35 +1551,14 @@ trait Printers
15551551
this
15561552
}
15571553

1558-
case Type.NamedTermRef(prefix, name) =>
1559-
prefix match {
1560-
case Type.ThisType(Types.EmptyPackage()) =>
1561-
this += highlightTypeDef(name)
1562-
case IsType(prefix) =>
1563-
printType(prefix)
1564-
if (name != "package")
1565-
this += "." += highlightTypeDef(name)
1566-
this
1567-
case NoPrefix() =>
1568-
this += highlightTypeDef(name)
1569-
}
1570-
1571-
case Type.NamedTypeRef(prefix, name) =>
1572-
prefix match {
1573-
case NoPrefix() | Type.ThisType(Types.EmptyPackage()) =>
1574-
case IsType(prefix) => printType(prefix) += "."
1575-
}
1576-
if (name.endsWith("$")) this += highlightTypeDef(name.stripSuffix("$")) += ".type"
1577-
else this += highlightTypeDef(name)
1578-
15791554
case tpe @ Type.Refinement(_, _, _) =>
15801555
printRefinement(tpe)
15811556

15821557
case Type.AppliedType(tp, args) =>
15831558
tp match {
15841559
case Type.IsTypeLambda(tp) =>
15851560
printType(tpe.dealias)
1586-
case Type.NamedTypeRef(Types.ScalaPackage(), "<repeated>") =>
1561+
case Type.TypeRef(Types.ScalaPackage(), "<repeated>") =>
15871562
this += "_*"
15881563
case _ =>
15891564
printType(tp)
@@ -1620,7 +1595,7 @@ trait Printers
16201595
case Type.IsTypeRef(tp) if !tp.typeSymbol.flags.is(Flags.Object) =>
16211596
printFullClassName(tp)
16221597
this += highlightTypeDef(".this")
1623-
case Type.NamedTypeRef(prefix, name) if name.endsWith("$") =>
1598+
case Type.TypeRef(prefix, name) if name.endsWith("$") =>
16241599
prefix match {
16251600
case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
16261601
case _ =>
@@ -1707,9 +1682,9 @@ trait Printers
17071682
val annots = definition.symbol.annots.filter {
17081683
case Annotation(annot, _) =>
17091684
annot.tpe match {
1710-
case Type.NamedTypeRef(Type.IsTermRef(prefix), _) if prefix.termSymbol.fullName == "scala.annotation.internal" => false
1711-
case Type.NamedTypeRef(Type.IsTypeRef(prefix), _) if prefix.typeSymbol.fullName == "scala.annotation.internal" => false
1712-
case Type.NamedTypeRef(Types.ScalaPackage(), "forceInline") => false
1685+
case Type.TypeRef(Type.IsTermRef(prefix), _) if prefix.termSymbol.fullName == "scala.annotation.internal" => false
1686+
case Type.TypeRef(Type.IsTypeRef(prefix), _) if prefix.typeSymbol.fullName == "scala.annotation.internal" => false
1687+
case Type.TypeRef(Types.ScalaPackage(), "forceInline") => false
17131688
case _ => true
17141689
}
17151690
case x => throw new MatchError(x.showExtractors)
@@ -1893,30 +1868,30 @@ trait Printers
18931868

18941869
object JavaLangObject {
18951870
def unapply(tpe: Type) given (ctx: Context): Boolean = tpe match {
1896-
case Type.NamedTypeRef(Type.IsTermRef(prefix), "Object") => prefix.typeSymbol.fullName == "java.lang"
1871+
case Type.TypeRef(Type.IsTermRef(prefix), "Object") => prefix.typeSymbol.fullName == "java.lang"
18971872
case _ => false
18981873
}
18991874
}
19001875

19011876
object Sequence {
19021877
def unapply(tpe: Type) given (ctx: Context): Option[Type] = tpe match {
1903-
case Type.AppliedType(Type.NamedTypeRef(Type.IsTermRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.termSymbol.fullName == "scala.collection" => Some(tp)
1904-
case Type.AppliedType(Type.NamedTypeRef(Type.IsTypeRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.typeSymbol.fullName == "scala.collection" => Some(tp)
1878+
case Type.AppliedType(Type.TypeRef(Type.IsTermRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.termSymbol.fullName == "scala.collection" => Some(tp)
1879+
case Type.AppliedType(Type.TypeRef(Type.IsTypeRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.typeSymbol.fullName == "scala.collection" => Some(tp)
19051880
case _ => None
19061881
}
19071882
}
19081883

19091884
object RepeatedAnnotation {
19101885
def unapply(tpe: Type) given (ctx: Context): Boolean = tpe match {
1911-
case Type.NamedTypeRef(Type.IsTermRef(prefix), "Repeated") => prefix.termSymbol.fullName == "scala.annotation.internal"
1912-
case Type.NamedTypeRef(Type.IsTypeRef(prefix), "Repeated") => prefix.typeSymbol.fullName == "scala.annotation.internal"
1886+
case Type.TypeRef(Type.IsTermRef(prefix), "Repeated") => prefix.termSymbol.fullName == "scala.annotation.internal"
1887+
case Type.TypeRef(Type.IsTypeRef(prefix), "Repeated") => prefix.typeSymbol.fullName == "scala.annotation.internal"
19131888
case _ => false
19141889
}
19151890
}
19161891

19171892
object Repeated {
19181893
def unapply(tpe: Type) given (ctx: Context): Option[Type] = tpe match {
1919-
case Type.AppliedType(Type.NamedTypeRef(ScalaPackage(), "<repeated>"), IsType(tp) :: Nil) => Some(tp)
1894+
case Type.AppliedType(Type.TypeRef(ScalaPackage(), "<repeated>"), IsType(tp) :: Nil) => Some(tp)
19201895
case _ => None
19211896
}
19221897
}

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ trait TreeOps extends Core {
250250

251251
/** Scala term identifier */
252252
object Ident {
253-
def apply(tmref: NamedTermRef) given (ctx: Context): Term =
253+
def apply(tmref: TermRef) given (ctx: Context): Term =
254254
internal.Ident_apply(tmref)
255255

256256
def copy(original: Tree)(name: String) given (ctx: Context): Ident =

library/src/scala/tasty/reflect/TypeOrBoundsOps.scala

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ trait TypeOrBoundsOps extends Core {
8585
}
8686

8787
object TermRef {
88+
def apply(qual: TypeOrBounds, name: String) given (ctx: Context): TermRef =
89+
internal.TermRef_apply(qual, name)
8890
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] =
8991
internal.matchTermRef(typeOrBounds).map(x => (x.qualifier, x.name))
9092
}
@@ -100,31 +102,6 @@ trait TypeOrBoundsOps extends Core {
100102
internal.matchTypeRef(typeOrBounds).map(x => (x.qualifier, x.name))
101103
}
102104

103-
object IsNamedTermRef {
104-
/** Matches any NamedTermRef and returns it */
105-
def unapply(tpe: TypeOrBounds) given (ctx: Context): Option[NamedTermRef] =
106-
internal.matchNamedTermRef(tpe)
107-
}
108-
109-
object NamedTermRef {
110-
// TODO should qual be a Type?
111-
def apply(qual: TypeOrBounds, name: String) given (ctx: Context): NamedTermRef =
112-
internal.NamedTermRef_apply(qual, name)
113-
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] =
114-
internal.matchNamedTermRef(typeOrBounds).map(x => (x.qualifier, x.name))
115-
}
116-
117-
object IsNameTypeRef {
118-
/** Matches any TypeRef and returns it */
119-
def unapply(tpe: TypeOrBounds) given (ctx: Context): Option[NamedTypeRef] =
120-
internal.matchNamedTypeRef(tpe)
121-
}
122-
123-
object NamedTypeRef {
124-
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] =
125-
internal.matchNamedTypeRef(typeOrBounds).map(x => (x.qualifier, x.name))
126-
}
127-
128105
object IsSuperType {
129106
/** Matches any SuperType and returns it */
130107
def unapply(tpe: TypeOrBounds) given (ctx: Context): Option[SuperType] =
@@ -308,16 +285,6 @@ trait TypeOrBoundsOps extends Core {
308285
def name given (ctx: Context): String = internal.TypeRef_name(self)
309286
}
310287

311-
implicit class Type_NamedTermRefAPI(self: NamedTermRef) {
312-
def name given (ctx: Context): String = internal.NamedTermRef_name(self)
313-
def qualifier given (ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.NamedTermRef_qualifier(self)
314-
}
315-
316-
implicit class Type_NamedTypeRefAPI(self: NamedTypeRef) {
317-
def name given (ctx: Context): String = internal.NamedTypeRef_name(self)
318-
def qualifier given (ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.NamedTypeRef_qualifier(self)
319-
}
320-
321288
implicit class Type_SuperTypeAPI(self: SuperType) {
322289
def thistpe given (ctx: Context): Type = internal.SuperType_thistpe(self)
323290
def supertpe given (ctx: Context): Type = internal.SuperType_supertpe(self)

tests/run-macros/i5941/macro_1.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ object Iso {
102102
val cls = tpS.classSymbol.get
103103

104104
val companion = tpS match {
105-
case Type.TypeRef(prefix, name) => Type.NamedTermRef(prefix, name)
106-
case Type.NamedTypeRef(prefix, name) => Type.NamedTermRef(prefix, name)
105+
case Type.TypeRef(prefix, name) => Type.TermRef(prefix, name)
107106
}
108107

109108
if (cls.caseFields.size != 1) {
@@ -131,7 +130,7 @@ object Iso {
131130
val tpS = typeOf[S]
132131

133132
if (tpS.isSingleton) {
134-
val ident = Ident(tpS.asInstanceOf[NamedTermRef]).seal.cast[S]
133+
val ident = Ident(tpS.asInstanceOf[TermRef]).seal.cast[S]
135134
'{
136135
Iso[S, 1](Function.const($ident))(Function.const(1))
137136
}
@@ -145,8 +144,7 @@ object Iso {
145144
}
146145

147146
val companion = tpS match {
148-
case Type.TypeRef(prefix, name) => Type.NamedTermRef(prefix, name)
149-
case Type.NamedTypeRef(prefix, name) => Type.NamedTermRef(prefix, name)
147+
case Type.TypeRef(prefix, name) => Type.TermRef(prefix, name)
150148
}
151149

152150
val obj = Select.overloaded(Ident(companion), "apply", Nil, Nil).seal.cast[S]

0 commit comments

Comments
 (0)