Skip to content

Commit 1e45b0d

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 28ab1af commit 1e45b0d

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
@@ -177,7 +177,7 @@ class Definitions {
177177
lazy val RootClass: ClassSymbol = ctx.newPackageSymbol(
178178
NoSymbol, nme.ROOT, (root, rootcls) => ctx.rootLoader(root)).moduleClass.asClass
179179
lazy val RootPackage: TermSymbol = ctx.newSymbol(
180-
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass))
180+
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef.withSym(NoPrefix, RootClass))
181181

182182
lazy val EmptyPackageVal = ctx.newPackageSymbol(
183183
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
@@ -1127,6 +1127,11 @@ object Types {
11271127
loop(this)
11281128
}
11291129

1130+
private def isReferencedSymbolically(sym: Symbol)(implicit ctx: Context) =
1131+
sym.isFresh ||
1132+
sym.isClass && sym.is(Scala2x) && !sym.owner.is(Package) ||
1133+
ctx.phase.symbolicRefs
1134+
11301135
/** The type <this . name> , reduced if possible */
11311136
def select(name: Name)(implicit ctx: Context): Type = name match {
11321137
case name: TermName => TermRef(this, name)
@@ -1141,8 +1146,8 @@ object Types {
11411146

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

11471152
// ----- Access to parts --------------------------------------------
11481153

@@ -1980,7 +1985,7 @@ object Types {
19801985

19811986
def newLikeThis(prefix: Type)(implicit ctx: Context): NamedType = designator match {
19821987
case designator: TermSymbol =>
1983-
TermRef.withFixedSym(prefix, designator)
1988+
TermRef(prefix, designator)
19841989
case designator: TermName =>
19851990
// If symbol exists, the new signature is the symbol's signature as seen
19861991
// from the new prefix, modulo consistency
@@ -2032,12 +2037,12 @@ object Types {
20322037
def apply(prefix: Type, designator: Name)(implicit ctx: Context) =
20332038
if (designator.isTermName) TermRef(prefix, designator.asTermName)
20342039
else TypeRef(prefix, designator.asTypeName)
2040+
def apply(prefix: Type, sym: Symbol)(implicit ctx: Context) =
2041+
if (sym.isType) TypeRef(prefix, sym.asType)
2042+
else TermRef(prefix, sym.asTerm)
20352043
def apply(prefix: Type, designator: Name, denot: Denotation)(implicit ctx: Context) =
20362044
if (designator.isTermName) TermRef(prefix, designator.asTermName, denot)
20372045
else TypeRef(prefix, designator.asTypeName, denot)
2038-
def withFixedSym(prefix: Type, sym: Symbol)(implicit ctx: Context) =
2039-
if (sym.isType) TypeRef.withFixedSym(prefix, sym.asType)
2040-
else TermRef.withFixedSym(prefix, sym.asTerm)
20412046
def withSymAndName(prefix: Type, sym: Symbol, name: Name)(implicit ctx: Context): NamedType =
20422047
if (sym.isType) TypeRef.withSymAndName(prefix, sym.asType, name.asTypeName)
20432048
else TermRef.withSymAndName(prefix, sym.asTerm, name.asTermName)
@@ -2051,14 +2056,14 @@ object Types {
20512056
* Its meaning is the (potentially multi-) denotation of the member(s)
20522057
* of prefix with given name.
20532058
*/
2054-
def apply(prefix: Type, designator: TermName)(implicit ctx: Context): TermRef =
2059+
def apply(prefix: Type, designator: TermDesignator)(implicit ctx: Context): TermRef =
20552060
ctx.uniqueNamedTypes.enterIfNew(prefix, designator, isTerm = true).asInstanceOf[TermRef]
20562061

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

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

2077-
/** Create a non-member term ref (which cannot be reloaded using `member`),
2078-
* with given prefix, name, and signature
2079-
*/
2080-
def withFixedSym(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2081-
ctx.uniqueNamedTypes.enterIfNew(prefix, sym, isTerm = true).asInstanceOf[TermRef]
2082-
20832082
/** Create a term ref referring to given symbol with given name, taking the signature
20842083
* from the symbol if it is completed, or creating a term ref without
20852084
* signature, if symbol is not yet completed. This is very similar to TermRef(Type, Symbol),
@@ -2089,7 +2088,7 @@ object Types {
20892088
*/
20902089
def withSymAndName(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef =
20912090
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs)
2092-
withFixedSym(prefix, sym)
2091+
apply(prefix, sym)
20932092
else if (sym.defRunId != NoRunId && sym.isCompleted)
20942093
withSig(prefix, name, sym.signature).withSym(sym)
20952094
// Linker note:
@@ -2103,7 +2102,7 @@ object Types {
21032102
* (which must be completed).
21042103
*/
21052104
def withSig(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2106-
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) withFixedSym(prefix, sym)
2105+
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) apply(prefix, sym)
21072106
else withSig(prefix, sym.name, sym.signature).withSym(sym)
21082107

21092108
/** Create a term ref with given prefix, name and signature */
@@ -2113,7 +2112,7 @@ object Types {
21132112
/** Create a term ref with given prefix, name, signature, and initial denotation */
21142113
def withSigAndDenot(prefix: Type, name: TermName, sig: Signature, denot: Denotation)(implicit ctx: Context): TermRef = {
21152114
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2116-
withFixedSym(prefix, denot.symbol.asTerm)
2115+
apply(prefix, denot.symbol.asTerm)
21172116
else
21182117
withSig(prefix, name, sig)
21192118
} withDenot denot
@@ -2125,28 +2124,22 @@ object Types {
21252124
ctx.uniqueNamedTypes.enterIfNew(prefix, desig, isTerm = false).asInstanceOf[TypeRef]
21262125

21272126
/** Create type ref to given symbol */
2128-
def apply(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
2127+
def withSym(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
21292128
withSymAndName(prefix, sym, sym.name)
21302129

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

21472140
/** Create a type ref with given name and initial denotation */
21482141
def apply(prefix: Type, name: TypeName, denot: Denotation)(implicit ctx: Context): TypeRef = {
2149-
if ((prefix eq NoPrefix) || denot.symbol.isFresh) apply(prefix, denot.symbol.asType)
2142+
if ((prefix eq NoPrefix) || denot.symbol.isFresh) withSym(prefix, denot.symbol.asType)
21502143
else apply(prefix, name)
21512144
} withDenot denot
21522145
}
@@ -3425,15 +3418,15 @@ object Types {
34253418
def clsDenot = if (prefix eq cls.owner.thisType) cls.denot else cls.denot.copySymDenotation(info = this)
34263419
if (appliedRefCache == null) {
34273420
val tref =
3428-
if ((cls is PackageClass) || cls.owner.isTerm) symbolicTypeRef
3421+
if ((cls is PackageClass) || cls.owner.isTerm) symbolicTypeRef // ??? not always symbolicRef
34293422
else TypeRef(prefix, cls.name, clsDenot)
34303423
appliedRefCache =
34313424
tref.appliedTo(cls.typeParams.map(_.typeRef))
34323425
}
34333426
appliedRefCache
34343427
}
34353428

3436-
def symbolicTypeRef(implicit ctx: Context): TypeRef = TypeRef(prefix, cls)
3429+
def symbolicTypeRef(implicit ctx: Context): TypeRef = TypeRef.withSym(prefix, cls)
34373430

34383431
// cached because baseType needs parents
34393432
private var parentsCache: List[Type] = null
@@ -3498,7 +3491,7 @@ object Types {
34983491
case tp: ClassInfo =>
34993492
// Note: Taking a normal typeRef does not work here. A normal ref might contain
35003493
// also other information about the named type (e.g. bounds).
3501-
contains(tp.symbolicTypeRef)
3494+
contains(tp.symbolicTypeRef) // ??? not clear
35023495
case _ => lo <:< tp && tp <:< hi
35033496
}
35043497

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 =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ object ExplicitOuter {
321321
*/
322322
private def fixThis(tpe: Type)(implicit ctx: Context): Type = tpe match {
323323
case tpe: ThisType if tpe.cls.is(Module) && !ctx.owner.isContainedIn(tpe.cls) =>
324-
fixThis(TermRef(tpe.cls.owner.thisType, tpe.cls.sourceModule.asTerm))
324+
fixThis(TermRef.withSym(tpe.cls.owner.thisType, tpe.cls.sourceModule.asTerm))
325325
case tpe: TermRef =>
326326
tpe.derivedSelect(fixThis(tpe.prefix))
327327
case _ =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx:
1717
lazy val JUnit4Annotations: List[Symbol] = List("Test", "Ignore", "Before", "After", "BeforeClass", "AfterClass").
1818
map(n => ctx.getClassIfDefined("org.junit." + n)).
1919
filter(_.exists)
20-
20+
2121
def implementation(member: TermSymbol): TermSymbol = {
2222
val res = member.copy(
2323
owner = cls,
@@ -35,7 +35,7 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx:
3535
Super(This(cls), target.owner.name.asTypeName, false, target.owner)
3636
//println(i"super ref $target on $sup")
3737
ast.untpd.Select(sup.withPos(pos), target.name)
38-
.withType(NamedType.withFixedSym(sup.tpe, target))
38+
.withType(NamedType(sup.tpe, target))
3939
//sup.select(target)
4040
}
4141

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
384384
val companion = cls.companionModule
385385
if (companion.isTerm) {
386386
val prefix = receiver.tpe.baseType(cls).normalizedPrefix
387-
if (prefix.exists) selectGetter(ref(TermRef(prefix, companion.asTerm)))
387+
if (prefix.exists) selectGetter(ref(TermRef.withSym(prefix, companion.asTerm)))
388388
else EmptyTree
389389
}
390390
else EmptyTree

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ class TermRefSet(implicit ctx: Context) extends mutable.Traversable[TermRef] {
10081008
override def foreach[U](f: TermRef => U): Unit =
10091009
for (sym <- elems.keysIterator)
10101010
for (pre <- elems(sym))
1011-
f(TermRef(pre, sym))
1011+
f(TermRef.withSym(pre, sym))
10121012
}
10131013

10141014
@sharable object EmptyTermRefSet extends TermRefSet()(NoContext)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class Namer { typer: Typer =>
325325
privateWithinClass(tree.mods), tree.namePos), tree)
326326
case tree: Import =>
327327
recordSym(ctx.newSymbol(
328-
ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos), tree)
328+
ctx.owner, nme.IMPORT, Synthetic | Fresh, new Completer(tree), NoSymbol, tree.pos), tree)
329329
case _ =>
330330
NoSymbol
331331
}

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ trait TypeAssigner {
506506
else inSameUniverse(TypeBounds(_, _), lo.tpe, hi, "type bounds"))
507507

508508
def assignType(tree: untpd.Bind, sym: Symbol)(implicit ctx: Context) =
509-
tree.withType(NamedType.withFixedSym(NoPrefix, sym))
509+
tree.withType(NamedType(NoPrefix, sym))
510510

511511
def assignType(tree: untpd.Alternative, trees: List[Tree])(implicit ctx: Context) =
512512
tree.withType(ctx.typeComparer.lub(trees.tpes))
@@ -532,7 +532,7 @@ trait TypeAssigner {
532532
// reference, since there is less pressure on the uniqueness tables that way
533533
// and less work to update all the different references. That's why symbolic references
534534
// are only used if necessary.
535-
NamedType.withFixedSym(owner.thisType, sym)
535+
NamedType(owner.thisType, sym)
536536
else NoType
537537
}
538538

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
989989
else if (!owner.isCompleted)
990990
(EmptyTree, errorType(em"$owner has return statement; needs result type", tree.pos))
991991
else {
992-
val from = Ident(TermRef(NoPrefix, owner.asTerm))
992+
val from = Ident(TermRef.withSym(NoPrefix, owner.asTerm))
993993
val proto = returnProto(owner, cx.scope)
994994
(from, proto)
995995
}

0 commit comments

Comments
 (0)