Skip to content

Commit fb99490

Browse files
Merge pull request #7001 from dotty-staging/join-type-and-term-ref-api
Remove NamedTermRef and NamedTypeRef
2 parents 963719e + ddae49f commit fb99490

File tree

17 files changed

+179
-293
lines changed

17 files changed

+179
-293
lines changed

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

Lines changed: 10 additions & 44 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 =
@@ -1114,6 +1114,8 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11141114

11151115
def Type_typeSymbol(self: Type) given Context: Symbol = self.typeSymbol
11161116

1117+
def Type_termSymbol(self: Type) given Context: Symbol = self.termSymbol
1118+
11171119
def Type_isSingleton(self: Type) given Context: Boolean = self.isSingleton
11181120

11191121
def Type_memberType(self: Type)(member: Symbol) given Context: Type =
@@ -1148,46 +1150,27 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11481150
type TermRef = Types.NamedType
11491151

11501152
def matchTermRef(tpe: TypeOrBounds) given Context: Option[TermRef] = tpe match {
1151-
case tp: Types.NamedType =>
1152-
tp.designator match {
1153-
case sym: Symbol if sym.isTerm => Some(tp)
1154-
case _ => None
1155-
}
1153+
case tp: Types.TermRef => Some(tp)
11561154
case _ => None
11571155
}
11581156

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

1161-
def matchTermRef_unapply(tpe: TypeOrBounds) given Context: Option[(Symbol, Type | NoPrefix)] = tpe match {
1162-
case tpe: Types.NamedType =>
1163-
tpe.designator match {
1164-
case sym: Symbol if sym.isTerm => Some((sym, tpe.prefix))
1165-
case _ => None
1166-
}
1167-
case _ => None
1168-
}
1162+
def TermRef_name(self: TermRef) given Context: String = self.name.toString
11691163

11701164
type TypeRef = Types.NamedType
11711165

11721166
def matchTypeRef(tpe: TypeOrBounds) given Context: Option[TypeRef] = tpe match {
1173-
case tp: Types.NamedType =>
1174-
tp.designator match {
1175-
case sym: Symbol if sym.isType => Some(tp)
1176-
case _ => None
1177-
}
1167+
case tp: Types.TypeRef => Some(tp)
11781168
case _ => None
11791169
}
11801170

11811171
def TypeRef_qualifier(self: TypeRef) given Context: TypeOrBounds = self.prefix
11821172

1183-
def matchTypeRef_unapply(tpe: TypeOrBounds) given Context: Option[(Symbol, Type | NoPrefix)] = tpe match {
1184-
case tpe: Types.NamedType =>
1185-
tpe.designator match {
1186-
case sym: Symbol if sym.isType => Some((sym, tpe.prefix))
1187-
case _ => None
1188-
}
1189-
case _ => None
1190-
}
1173+
def TypeRef_name(self: TypeRef) given Context: String = self.name.toString
11911174

11921175
type NamedTermRef = Types.NamedType
11931176

@@ -1203,23 +1186,6 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12031186
def NamedTermRef_name(self: NamedTermRef) given Context: String = self.name.toString
12041187
def NamedTermRef_qualifier(self: NamedTermRef) given Context: TypeOrBounds = self.prefix
12051188

1206-
def NamedTermRef_apply(qual: TypeOrBounds, name: String) given Context: NamedTermRef =
1207-
Types.TermRef(qual, name.toTermName)
1208-
1209-
type NamedTypeRef = Types.NamedType
1210-
1211-
def matchNamedTypeRef(tpe: TypeOrBounds) given Context: Option[NamedTypeRef] = tpe match {
1212-
case tpe: Types.NamedType =>
1213-
tpe.designator match {
1214-
case name: Names.TypeName => Some(tpe)
1215-
case _ => None
1216-
}
1217-
case _ => None
1218-
}
1219-
1220-
def NamedTypeRef_name(self: NamedTypeRef) given Context: String = self.name.toString
1221-
def NamedTypeRef_qualifier(self: NamedTypeRef) given Context: TypeOrBounds = self.prefix
1222-
12231189
type SuperType = Types.SuperType
12241190

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

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

Lines changed: 7 additions & 25 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 */
@@ -878,10 +876,12 @@ trait CompilerInterface {
878876
*/
879877
def Type_dealias(self: Type) given (ctx: Context): Type
880878

881-
def Type_classSymbol(self: Type) given (ctx: Context): Option[ClassDefSymbol]
879+
def Type_classSymbol(self: Type) given (ctx: Context): Option[ClassDefSymbol] // TODO remove Option and use NoSymbol
882880

883881
def Type_typeSymbol(self: Type) given (ctx: Context): Symbol
884882

883+
def Type_termSymbol(self: Type) given (ctx: Context): Symbol
884+
885885
def Type_isSingleton(self: Type) given (ctx: Context): Boolean
886886

887887
def Type_memberType(self: Type)(member: Symbol) given (ctx: Context): Type
@@ -931,36 +931,18 @@ trait CompilerInterface {
931931

932932
def matchTermRef(tpe: TypeOrBounds) given (ctx: Context): Option[TermRef]
933933

934-
def matchTermRef_unapply(tpe: TypeOrBounds) given (ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)]
934+
def TermRef_apply(qual: TypeOrBounds, name: String) given (ctx: Context): TermRef
935935

936936
def TermRef_qualifier(self: TermRef) given (ctx: Context): TypeOrBounds
937+
def TermRef_name(self: TermRef) given (ctx: Context): String
937938

938939
/** Type of a reference to a type symbol */
939940
type TypeRef <: Type
940941

941942
def matchTypeRef(tpe: TypeOrBounds) given (ctx: Context): Option[TypeRef]
942943

943-
def matchTypeRef_unapply(tpe: TypeOrBounds) given (ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)]
944-
945944
def TypeRef_qualifier(self: TypeRef) given (ctx: Context): TypeOrBounds
946-
947-
/** Type of a reference to a term by it's name */
948-
type NamedTermRef <: Type
949-
950-
def matchNamedTermRef(tpe: TypeOrBounds) given (ctx: Context): Option[NamedTermRef]
951-
952-
def NamedTermRef_name(self: NamedTermRef) given (ctx: Context): String
953-
def NamedTermRef_qualifier(self: NamedTermRef) given (ctx: Context): TypeOrBounds
954-
955-
def NamedTermRef_apply(qual: TypeOrBounds, name: String) given (ctx: Context): NamedTermRef
956-
957-
/** Type of a reference to a type by it's name */
958-
type NamedTypeRef <: Type
959-
960-
def matchNamedTypeRef(tpe: TypeOrBounds) given (ctx: Context): Option[NamedTypeRef]
961-
962-
def NamedTypeRef_name(self: NamedTypeRef) given (ctx: Context): String
963-
def NamedTypeRef_qualifier(self: NamedTypeRef) given (ctx: Context): TypeOrBounds
945+
def TypeRef_name(self: TypeRef) given Context: String
964946

965947
/** Type of a `super` refernce */
966948
type SuperType <: Type

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

0 commit comments

Comments
 (0)