Skip to content

Commit 2539e47

Browse files
committed
Renamings of creation methods
withfixedSym -> apply It's just apply with a different designator apply(Type, Symbol) -> withSym This one contains special cases.
1 parent d868f33 commit 2539e47

17 files changed

+44
-51
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
9797
def Closure(meth: TermSymbol, rhsFn: List[List[Tree]] => Tree, targs: List[Tree] = Nil, targetType: Type = NoType)(implicit ctx: Context): Block = {
9898
val targetTpt = if (targetType.exists) TypeTree(targetType) else EmptyTree
9999
val call =
100-
if (targs.isEmpty) Ident(TermRef(NoPrefix, meth))
101-
else TypeApply(Ident(TermRef(NoPrefix, meth)), targs)
100+
if (targs.isEmpty) Ident(TermRef.withSym(NoPrefix, meth))
101+
else TypeApply(Ident(TermRef.withSym(NoPrefix, meth)), targs)
102102
Block(
103103
DefDef(meth, rhsFn) :: Nil,
104104
Closure(Nil, call, targetTpt))

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Definitions {
174174
lazy val RootClass: ClassSymbol = ctx.newPackageSymbol(
175175
NoSymbol, nme.ROOT, (root, rootcls) => ctx.rootLoader(root)).moduleClass.asClass
176176
lazy val RootPackage: TermSymbol = ctx.newSymbol(
177-
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass))
177+
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef.withSym(NoPrefix, RootClass))
178178

179179
lazy val EmptyPackageVal = ctx.newPackageSymbol(
180180
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.rootLoader(emptypkg)).entered

compiler/src/dotty/tools/dotc/core/Substituters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ trait Substituters { this: Context =>
131131
while (fs.nonEmpty) {
132132
if (fs.head eq sym)
133133
return {
134-
if (tp.hasFixedSym) NamedType.withFixedSym(tp.prefix, ts.head) // ### why the different treatement of prefix?
134+
if (tp.hasFixedSym) NamedType(tp.prefix, ts.head) // ### why the different treatement of prefix?
135135
else substSym(tp.prefix, from, to, theMap) select ts.head
136136
}
137137
fs = fs.tail

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ object SymDenotations {
11361136
TermRef.withSigAndDenot(owner.thisType, name.asTermName, signature, this)
11371137

11381138
def nonMemberTermRef(implicit ctx: Context): TermRef =
1139-
TermRef.withFixedSym(owner.thisType, symbol.asTerm)
1139+
TermRef(owner.thisType, symbol.asTerm)
11401140

11411141
/** The variance of this type parameter or type member as an Int, with
11421142
* +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter
@@ -1402,7 +1402,7 @@ object SymDenotations {
14021402
}
14031403

14041404
private def computeThisType(implicit ctx: Context): Type =
1405-
ThisType.raw(TypeRef(
1405+
ThisType.raw(TypeRef.withSym(
14061406
if (this is Package) NoPrefix else owner.thisType, symbol.asType))
14071407

14081408
private[this] var myTypeRef: TypeRef = null

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ trait Symbols { this: Context =>
246246
* would be `fld2`. There is a single local dummy per template.
247247
*/
248248
def newLocalDummy(cls: Symbol, coord: Coord = NoCoord) =
249-
newSymbol(cls, nme.localDummyName(cls), EmptyFlags, NoType)
249+
newSymbol(cls, nme.localDummyName(cls), Fresh, NoType)
250250

251251
/** Create an import symbol pointing back to given qualifier `expr`. */
252252
def newImportSymbol(owner: Symbol, expr: Tree, coord: Coord = NoCoord) =

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object TypeErasure {
150150
assert(tp.symbol.exists, tp)
151151
val tp1 = ctx.makePackageObjPrefixExplicit(tp)
152152
if (tp1 ne tp) erasedRef(tp1)
153-
else TermRef(erasedRef(tp.prefix), tp.symbol.asTerm)
153+
else TermRef.withSym(erasedRef(tp.prefix), tp.symbol.asTerm)
154154
case tp: ThisType =>
155155
tp
156156
case tp =>

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,11 @@ object Types {
11231123
loop(this)
11241124
}
11251125

1126+
private def isReferencedSymbolically(sym: Symbol)(implicit ctx: Context) =
1127+
sym.isFresh ||
1128+
sym.isClass && sym.is(Scala2x) && !sym.owner.is(Package) ||
1129+
ctx.phase.symbolicRefs
1130+
11261131
/** The type <this . name> , reduced if possible */
11271132
def select(name: Name)(implicit ctx: Context): Type = name match {
11281133
case name: TermName => TermRef(this, name)
@@ -1137,8 +1142,8 @@ object Types {
11371142

11381143
/** The type <this . name> with given symbol, reduced if possible */
11391144
def select(sym: Symbol)(implicit ctx: Context): Type =
1140-
if (sym.isTerm) TermRef(this, sym.asTerm)
1141-
else TypeRef(this, sym.asType).reduceProjection
1145+
if (sym.isTerm) TermRef.withSym(this, sym.asTerm)
1146+
else TypeRef.withSym(this, sym.asType).reduceProjection
11421147

11431148
// ----- Access to parts --------------------------------------------
11441149

@@ -1975,7 +1980,7 @@ object Types {
19751980

19761981
def newLikeThis(prefix: Type)(implicit ctx: Context): NamedType = designator match {
19771982
case designator: TermSymbol =>
1978-
TermRef.withFixedSym(prefix, designator)
1983+
TermRef(prefix, designator)
19791984
case designator: TermName =>
19801985
// If symbol exists, the new signature is the symbol's signature as seen
19811986
// from the new prefix, modulo consistency
@@ -2027,12 +2032,12 @@ object Types {
20272032
def apply(prefix: Type, designator: Name)(implicit ctx: Context) =
20282033
if (designator.isTermName) TermRef(prefix, designator.asTermName)
20292034
else TypeRef(prefix, designator.asTypeName)
2035+
def apply(prefix: Type, sym: Symbol)(implicit ctx: Context) =
2036+
if (sym.isType) TypeRef(prefix, sym.asType)
2037+
else TermRef(prefix, sym.asTerm)
20302038
def apply(prefix: Type, designator: Name, denot: Denotation)(implicit ctx: Context) =
20312039
if (designator.isTermName) TermRef(prefix, designator.asTermName, denot)
20322040
else TypeRef(prefix, designator.asTypeName, denot)
2033-
def withFixedSym(prefix: Type, sym: Symbol)(implicit ctx: Context) =
2034-
if (sym.isType) TypeRef.withFixedSym(prefix, sym.asType)
2035-
else TermRef.withFixedSym(prefix, sym.asTerm)
20362041
def withSymAndName(prefix: Type, sym: Symbol, name: Name)(implicit ctx: Context): NamedType =
20372042
if (sym.isType) TypeRef.withSymAndName(prefix, sym.asType, name.asTypeName)
20382043
else TermRef.withSymAndName(prefix, sym.asTerm, name.asTermName)
@@ -2046,14 +2051,14 @@ object Types {
20462051
* Its meaning is the (potentially multi-) denotation of the member(s)
20472052
* of prefix with given name.
20482053
*/
2049-
def apply(prefix: Type, designator: TermName)(implicit ctx: Context): TermRef =
2054+
def apply(prefix: Type, designator: TermDesignator)(implicit ctx: Context): TermRef =
20502055
ctx.uniqueNamedTypes.enterIfNew(prefix, designator, isTerm = true).asInstanceOf[TermRef]
20512056

20522057
/** Create term ref referring to given symbol, taking the signature
20532058
* from the symbol if it is completed, or creating a term ref without
20542059
* signature, if symbol is not yet completed.
20552060
*/
2056-
def apply(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2061+
def withSym(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
20572062
withSymAndName(prefix, sym, sym.name)
20582063

20592064
/** Create term ref to given initial denotation, taking the signature
@@ -2062,19 +2067,13 @@ object Types {
20622067
*/
20632068
def apply(prefix: Type, designator: TermName, denot: Denotation)(implicit ctx: Context): TermRef = {
20642069
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2065-
apply(prefix, denot.symbol.asTerm)
2070+
withSym(prefix, denot.symbol.asTerm)
20662071
else denot match {
20672072
case denot: SymDenotation if denot.isCompleted => withSig(prefix, designator, denot.signature)
20682073
case _ => apply(prefix, designator)
20692074
}
20702075
} withDenot denot
20712076

2072-
/** Create a non-member term ref (which cannot be reloaded using `member`),
2073-
* with given prefix, name, and signature
2074-
*/
2075-
def withFixedSym(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2076-
ctx.uniqueNamedTypes.enterIfNew(prefix, sym, isTerm = true).asInstanceOf[TermRef]
2077-
20782077
/** Create a term ref referring to given symbol with given name, taking the signature
20792078
* from the symbol if it is completed, or creating a term ref without
20802079
* signature, if symbol is not yet completed. This is very similar to TermRef(Type, Symbol),
@@ -2084,7 +2083,7 @@ object Types {
20842083
*/
20852084
def withSymAndName(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef =
20862085
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs)
2087-
withFixedSym(prefix, sym)
2086+
apply(prefix, sym)
20882087
else if (sym.defRunId != NoRunId && sym.isCompleted)
20892088
withSig(prefix, name, sym.signature).withSym(sym)
20902089
// Linker note:
@@ -2098,7 +2097,7 @@ object Types {
20982097
* (which must be completed).
20992098
*/
21002099
def withSig(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2101-
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) withFixedSym(prefix, sym)
2100+
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) apply(prefix, sym)
21022101
else withSig(prefix, sym.name, sym.signature).withSym(sym)
21032102

21042103
/** Create a term ref with given prefix, name and signature */
@@ -2108,7 +2107,7 @@ object Types {
21082107
/** Create a term ref with given prefix, name, signature, and initial denotation */
21092108
def withSigAndDenot(prefix: Type, name: TermName, sig: Signature, denot: Denotation)(implicit ctx: Context): TermRef = {
21102109
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2111-
withFixedSym(prefix, denot.symbol.asTerm)
2110+
apply(prefix, denot.symbol.asTerm)
21122111
else
21132112
withSig(prefix, name, sig)
21142113
} withDenot denot
@@ -2120,28 +2119,22 @@ object Types {
21202119
ctx.uniqueNamedTypes.enterIfNew(prefix, desig, isTerm = false).asInstanceOf[TypeRef]
21212120

21222121
/** Create type ref to given symbol */
2123-
def apply(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
2122+
def withSym(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
21242123
withSymAndName(prefix, sym, sym.name)
21252124

2126-
/** Create a non-member type ref (which cannot be reloaded using `member`),
2127-
* with given prefix, name, and symbol.
2128-
*/
2129-
def withFixedSym(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
2130-
ctx.uniqueNamedTypes.enterIfNew(prefix, sym, isTerm = false).asInstanceOf[TypeRef]
2131-
21322125
/** Create a type ref referring to given symbol with given name.
21332126
* This is very similar to TypeRef(Type, Symbol),
21342127
* except for two differences:
21352128
* (1) The symbol might not yet have a denotation, so the name needs to be given explicitly.
21362129
* (2) The name in the type ref need not be the same as the name of the Symbol.
21372130
*/
21382131
def withSymAndName(prefix: Type, sym: TypeSymbol, name: TypeName)(implicit ctx: Context): TypeRef =
2139-
if ((prefix eq NoPrefix) || sym.isFresh) withFixedSym(prefix, sym)
2132+
if ((prefix eq NoPrefix) || sym.isFresh) apply(prefix, sym)
21402133
else apply(prefix, name).withSym(sym)
21412134

21422135
/** Create a type ref with given name and initial denotation */
21432136
def apply(prefix: Type, name: TypeName, denot: Denotation)(implicit ctx: Context): TypeRef = {
2144-
if ((prefix eq NoPrefix) || denot.symbol.isFresh) apply(prefix, denot.symbol.asType)
2137+
if ((prefix eq NoPrefix) || denot.symbol.isFresh) withSym(prefix, denot.symbol.asType)
21452138
else apply(prefix, name)
21462139
} withDenot denot
21472140
}
@@ -3420,15 +3413,15 @@ object Types {
34203413
def clsDenot = if (prefix eq cls.owner.thisType) cls.denot else cls.denot.copySymDenotation(info = this)
34213414
if (appliedRefCache == null) {
34223415
val tref =
3423-
if ((cls is PackageClass) || cls.owner.isTerm) symbolicTypeRef
3416+
if ((cls is PackageClass) || cls.owner.isTerm) symbolicTypeRef // ??? not always symbolicRef
34243417
else TypeRef(prefix, cls.name, clsDenot)
34253418
appliedRefCache =
34263419
tref.appliedTo(cls.typeParams.map(_.typeRef))
34273420
}
34283421
appliedRefCache
34293422
}
34303423

3431-
def symbolicTypeRef(implicit ctx: Context): TypeRef = TypeRef(prefix, cls)
3424+
def symbolicTypeRef(implicit ctx: Context): TypeRef = TypeRef.withSym(prefix, cls)
34323425

34333426
// cached because baseType needs parents
34343427
private[this] var parentsCache: List[Type] = null
@@ -3493,7 +3486,7 @@ object Types {
34933486
case tp: ClassInfo =>
34943487
// Note: Taking a normal typeRef does not work here. A normal ref might contain
34953488
// also other information about the named type (e.g. bounds).
3496-
contains(tp.symbolicTypeRef)
3489+
contains(tp.symbolicTypeRef) // ??? not clear
34973490
case _ => lo <:< tp && tp <:< hi
34983491
}
34993492

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
246246
val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType, readType())
247247
registerSym(start, sym)
248248
if (currentAddr != end) readType()
249-
TypeRef.withFixedSym(NoPrefix, sym)
249+
TypeRef(NoPrefix, sym)
250250
case POLYtype =>
251251
readMethodic(PolyType, _.toTypeName)
252252
case METHODtype =>
@@ -268,7 +268,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
268268

269269
def readSimpleType(): Type = (tag: @switch) match {
270270
case TYPEREFdirect | TERMREFdirect =>
271-
NamedType.withFixedSym(NoPrefix, readSymRef())
271+
NamedType(NoPrefix, readSymRef())
272272
case TYPEREFsymbol | TERMREFsymbol =>
273273
readSymNameRef()
274274
case TYPEREFpkg =>

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
735735
val tycon =
736736
if (sym.isClass && sym.is(Scala2x) && !sym.owner.is(Package))
737737
// used fixed sym for Scala 2 inner classes, because they might be shadowed
738-
TypeRef.withFixedSym(pre, sym.asType)
738+
TypeRef(pre, sym.asType)
739739
else if (isLocal(sym) || pre == NoPrefix) {
740740
val pre1 = if ((pre eq NoPrefix) && (sym is TypeParam)) sym.owner.thisType else pre
741741
pre1 select sym

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ object Erasure {
391391
case _ => sym.name
392392
}
393393
untpd.cpy.Select(tree)(qual, sym.name)
394-
.withType(NamedType.withFixedSym(qual.tpe, sym))
394+
.withType(NamedType(qual.tpe, sym))
395395
}
396396

397397
def selectArrayMember(qual: Tree, erasedPre: Type): Tree =

0 commit comments

Comments
 (0)