Skip to content

Commit c4cc071

Browse files
committed
Replace Names with Strings
Semantic names are not used enough to be really useful for the macro API level. And they are an additionl concept to learn. So it's probablu better to just use strings. We had to duplicate one enum case for Types, to distinguish between TermNameRefs and TypeNameRefs.
1 parent 75b66c8 commit c4cc071

File tree

1 file changed

+47
-66
lines changed

1 file changed

+47
-66
lines changed

tests/pos/tasty/definitions.scala

Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,6 @@ package tasty
22

33
object definitions {
44

5-
// ====== Names ======================================
6-
7-
trait Name
8-
trait PossiblySignedName
9-
10-
enum TermName extends Name with PossiblySignedName {
11-
case Simple(str: String)
12-
case Qualified(prefix: TermName, selector: String) // s"$prefix.$name"
13-
14-
case DefaultGetter(methodName: TermName, idx: String) // s"$methodName${"$default$"}${idx+1}"
15-
case Variant(underlying: TermName, covariant: Boolean) // s"${if (covariant) "+" else "-"}$underlying"
16-
case SuperAccessor(underlying: TermName) // s"${"super$"}$underlying"
17-
case ProtectedAccessor(underlying: TermName) // s"${"protected$"}$underlying"
18-
case ProtectedSetter(underlying: TermName) // s"${"protected$set"}$underlying"
19-
case ObjectClass(underlying: TermName) // s"$underlying${"$"}"
20-
}
21-
22-
case class SignedName(name: TermName, resultSig: TypeName, paramSigs: List[TypeName]) extends PossiblySignedName
23-
24-
case class TypeName(name: TermName) extends Name
25-
26-
// ====== Positions ==================================
27-
28-
case class Position(firstOffset: Int, lastOffset: Int, sourceFile: String) {
29-
def startLine: Int = ???
30-
def startColumn: Int = ???
31-
def endLine: Int = ???
32-
def endColumn: Int = ???
33-
}
34-
35-
trait Positioned {
36-
def pos: Position = ???
37-
}
38-
395
// ====== Trees ======================================
406

417
trait Tree extends Positioned
@@ -64,34 +30,34 @@ object definitions {
6430
}
6531

6632
// Does DefDef need a `def tpe: MethodType | PolyType`?
67-
case class ValDef(name: TermName, tpt: TypeTree, rhs: Option[Term]) extends Definition {
33+
case class ValDef(name: String, tpt: TypeTree, rhs: Option[Term]) extends Definition {
6834
def mods: List[Modifier] = ???
6935
}
70-
case class DefDef(name: TermName, typeParams: List[TypeDef], paramss: List[List[ValDef]],
36+
case class DefDef(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]],
7137
returnTpt: TypeTree, rhs: Option[Term]) extends Definition {
7238
def mods: List[Modifier] = ???
7339
}
74-
case class TypeDef(name: TypeName, rhs: TypeTree | TypeBoundsTree) extends Definition {
40+
case class TypeDef(name: String, rhs: TypeTree | TypeBoundsTree) extends Definition {
7541
def mods: List[Modifier] = ???
7642
}
77-
case class ClassDef(name: TypeName, constructor: DefDef, parents: List[Term | TypeTree],
43+
case class ClassDef(name: String, constructor: DefDef, parents: List[Term | TypeTree],
7844
self: Option[ValDef], body: List[Statement]) extends Definition {
7945
def mods: List[Modifier] = ???
8046
}
81-
case class PackageDef(name: TermName, members: List[Statement]) extends Definition
47+
case class PackageDef(name: String, members: List[Statement]) extends Definition
8248

8349
// ------ Terms ---------------------------------
8450

8551
/** Trees denoting terms */
8652
enum Term extends Statement {
8753
def tpe: Type = ???
88-
case Ident(name: TermName, override val tpe: Type)
89-
case Select(prefix: Term, name: PossiblySignedName)
54+
case Ident(name: String, override val tpe: Type)
55+
case Select(prefix: Term, name: String, signature: Option[Signature])
9056
case Literal(value: Constant)
9157
case This(id: Option[Id])
9258
case New(tpt: TypeTree)
9359
case Throw(expr: Term)
94-
case NamedArg(name: TermName, arg: Term)
60+
case NamedArg(name: String, arg: Term)
9561
case Apply(fn: Term, args: List[Term])
9662
case TypeApply(fn: Term, args: List[TypeTree])
9763
case Super(thiz: Term, mixin: Option[Id])
@@ -112,8 +78,8 @@ object definitions {
11278
enum TypeTree extends Tree {
11379
def tpe: Type = ???
11480
case Synthetic()
115-
case Ident(name: TypeName, override val tpe: Type)
116-
case Select(prefix: Term, name: TypeName)
81+
case Ident(name: String, override val tpe: Type)
82+
case Select(prefix: Term, name: String)
11783
case Singleton(ref: Term)
11884
case Refined(underlying: TypeTree, refinements: List[Definition])
11985
case Applied(tycon: TypeTree, args: List[TypeTree])
@@ -132,7 +98,7 @@ object definitions {
13298
enum Pattern extends Tree {
13399
def tpe: Type = ???
134100
case Value(v: Term)
135-
case Bind(name: TermName, pat: Pattern)
101+
case Bind(name: String, pat: Pattern)
136102
case Unapply(unapply: Term, implicits: List[Term], pats: List[Pattern])
137103
case Alternative(pats: List[Pattern])
138104
case TypeTest(tpt: TypeTree)
@@ -150,15 +116,16 @@ object definitions {
150116

151117
case class ConstantType(value: Constant) extends Type
152118
case class SymRef(sym: Definition, qualifier: Type | NoPrefix = NoPrefix) extends Type
153-
case class NameRef(name: Name, qualifier: Type | NoPrefix = NoPrefix) extends Type // NoPrefix means: select from _root_
119+
case class TypeNameRef(name: String, qualifier: Type | NoPrefix = NoPrefix) extends Type // NoPrefix means: select from _root_
120+
case class TermNameRef(name: String, qualifier: Type | NoPrefix = NoPrefix) extends Type // NoPrefix means: select from _root_
154121
case class SuperType(thistp: Type, underlying: Type) extends Type
155-
case class Refinement(underlying: Type, name: Name, tpe: Type | TypeBounds) extends Type
122+
case class Refinement(underlying: Type, name: String, tpe: Type | TypeBounds) extends Type
156123
case class AppliedType(tycon: Type, args: List[Type | TypeBounds]) extends Type
157124
case class AnnotatedType(underlying: Type, annotation: Term) extends Type
158125
case class AndType(left: Type, right: Type) extends Type
159126
case class OrType(left: Type, right: Type) extends Type
160127
case class ByNameType(underlying: Type) extends Type
161-
case class ParamRef(binder: LambdaType[_, _, _], idx: Int) extends Type
128+
case class ParamRef(binder: LambdaType[_, _], idx: Int) extends Type
162129
case class ThisType(tp: Type) extends Type
163130
case class RecursiveThis(binder: RecursiveType) extends Type
164131

@@ -173,46 +140,46 @@ object definitions {
173140
}
174141
}
175142

176-
abstract class LambdaType[ParamName, ParamInfo, This <: LambdaType[ParamName, ParamInfo, This]](
177-
val companion: LambdaTypeCompanion[ParamName, ParamInfo, This]
143+
abstract class LambdaType[ParamInfo, This <: LambdaType[ParamInfo, This]](
144+
val companion: LambdaTypeCompanion[ParamInfo, This]
178145
) extends Type {
179146
private[Type] var _pinfos: List[ParamInfo]
180147
private[Type] var _restpe: Type
181148

182-
def paramNames: List[ParamName]
149+
def paramNames: List[String]
183150
def paramInfos: List[ParamInfo] = _pinfos
184151
def resultType: Type = _restpe
185152
}
186153

187-
abstract class LambdaTypeCompanion[ParamName, ParamInfo, This <: LambdaType[ParamName, ParamInfo, This]] {
188-
def apply(pnames: List[ParamName], ptypes: List[ParamInfo], restpe: Type): This
154+
abstract class LambdaTypeCompanion[ParamInfo, This <: LambdaType[ParamInfo, This]] {
155+
def apply(pnames: List[String], ptypes: List[ParamInfo], restpe: Type): This
189156

190-
def apply(pnames: List[ParamName], ptypesExp: This => List[ParamInfo], restpeExp: This => Type): This = {
157+
def apply(pnames: List[String], ptypesExp: This => List[ParamInfo], restpeExp: This => Type): This = {
191158
val lambda = apply(pnames, Nil, PlaceHolder)
192159
lambda._pinfos = ptypesExp(lambda)
193160
lambda._restpe = restpeExp(lambda)
194161
lambda
195162
}
196163
}
197164

198-
case class MethodType(paramNames: List[TermName], private[Type] var _pinfos: List[Type], private[Type] var _restpe: Type)
199-
extends LambdaType[TermName, Type, MethodType](MethodType) {
165+
case class MethodType(paramNames: List[String], private[Type] var _pinfos: List[Type], private[Type] var _restpe: Type)
166+
extends LambdaType[Type, MethodType](MethodType) {
200167
def isImplicit = (companion `eq` ImplicitMethodType) || (companion `eq` ErasedImplicitMethodType)
201168
def isErased = (companion `eq` ErasedMethodType) || (companion `eq` ErasedImplicitMethodType)
202169
}
203170

204-
case class PolyType(paramNames: List[TypeName], private[Type] var _pinfos: List[TypeBounds], private[Type] var _restpe: Type)
205-
extends LambdaType[TypeName, TypeBounds, PolyType](PolyType)
171+
case class PolyType(paramNames: List[String], private[Type] var _pinfos: List[TypeBounds], private[Type] var _restpe: Type)
172+
extends LambdaType[TypeBounds, PolyType](PolyType)
206173

207-
case class TypeLambda(paramNames: List[TypeName], private[Type] var _pinfos: List[TypeBounds], private[Type] var _restpe: Type)
208-
extends LambdaType[TypeName, TypeBounds, TypeLambda](TypeLambda)
174+
case class TypeLambda(paramNames: List[String], private[Type] var _pinfos: List[TypeBounds], private[Type] var _restpe: Type)
175+
extends LambdaType[TypeBounds, TypeLambda](TypeLambda)
209176

210-
object TypeLambda extends LambdaTypeCompanion[TypeName, TypeBounds, TypeLambda]
211-
object PolyType extends LambdaTypeCompanion[TypeName, TypeBounds, PolyType]
212-
object MethodType extends LambdaTypeCompanion[TermName, Type, MethodType]
177+
object TypeLambda extends LambdaTypeCompanion[TypeBounds, TypeLambda]
178+
object PolyType extends LambdaTypeCompanion[TypeBounds, PolyType]
179+
object MethodType extends LambdaTypeCompanion[Type, MethodType]
213180

214-
class SpecializedMethodTypeCompanion extends LambdaTypeCompanion[TermName, Type, MethodType] { self =>
215-
def apply(pnames: List[TermName], ptypes: List[Type], restpe: Type): MethodType =
181+
class SpecializedMethodTypeCompanion extends LambdaTypeCompanion[Type, MethodType] { self =>
182+
def apply(pnames: List[String], ptypes: List[Type], restpe: Type): MethodType =
216183
new MethodType(pnames, ptypes, restpe) { override val companion = self }
217184
}
218185
object ImplicitMethodType extends SpecializedMethodTypeCompanion
@@ -227,7 +194,6 @@ object definitions {
227194

228195
// ====== Modifiers ==================================
229196

230-
231197
enum Modifier {
232198
case Flags(flags: FlagSet)
233199
case QualifiedPrivate(boundary: Type)
@@ -264,6 +230,21 @@ object definitions {
264230
def isStable: Boolean // Method that is assumed to be stable
265231
}
266232

233+
case class Signature(paramSigs: List[String], resultSig: String)
234+
235+
// ====== Positions ==================================
236+
237+
case class Position(firstOffset: Int, lastOffset: Int, sourceFile: String) {
238+
def startLine: Int = ???
239+
def startColumn: Int = ???
240+
def endLine: Int = ???
241+
def endColumn: Int = ???
242+
}
243+
244+
trait Positioned {
245+
def pos: Position = ???
246+
}
247+
267248
// ====== Constants ==================================
268249

269250
enum Constant(val value: Any) {

0 commit comments

Comments
 (0)