Skip to content

Commit 735b1e7

Browse files
committed
Eliminate TermRef.withSig
To do this, we needed a more robust version of Symbol#signature.
1 parent 1ef47da commit 735b1e7

File tree

8 files changed

+34
-40
lines changed

8 files changed

+34
-40
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.dotc.transform.{ExplicitOuter, Erasure}
66
import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped
77
import transform.SymUtils._
88
import core._
9-
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
9+
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
1010
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._
1111
import Denotations._, Decorators._, DenotTransformers._
1212
import collection.mutable
@@ -382,7 +382,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
382382
val targs = tp.argTypes
383383
val tycon = tp.typeConstructor
384384
New(tycon)
385-
.select(TermRef.withSig(tycon, constr))
385+
.select(TermRef(tycon, constr, constr.name))
386386
.appliedToTypes(targs)
387387
.appliedToArgs(args)
388388
}
@@ -704,14 +704,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
704704
else
705705
TermRef.withSigAndDenot(tree.tpe, sym.name.asTermName,
706706
sym.signature, sym.denot.asSeenFrom(tree.tpe))
707-
untpd.Select(tree, sym.name)
708-
.withType(tp)
707+
untpd.Select(tree, sym.name).withType(tp)
709708
}
710709

711710
/** A select node with the given selector name and signature and a computed type */
712711
def selectWithSig(name: Name, sig: Signature)(implicit ctx: Context): Tree =
713712
untpd.SelectWithSig(tree, name, sig)
714-
.withType(TermRef.withSig(tree.tpe, name.asTermName, sig))
713+
.withType(TermRef(tree.tpe, name.asTermName.withSig(sig)))
715714

716715
/** A select node with selector name and signature taken from `sym`.
717716
* Note: Use this method instead of select(sym) if the referenced symbol
@@ -918,8 +917,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
918917
alternatives.head
919918
}
920919
else denot.asSingleDenotation.termRef
920+
val selectedSym = selected.termSymbol.asTerm
921921
val fun = receiver
922-
.select(TermRef.withSig(receiver.tpe, selected.termSymbol.asTerm))
922+
.select(TermRef(receiver.tpe, selectedSym, selectedSym.name))
923923
.appliedToTypes(targs)
924924

925925
def adaptLastArg(lastParam: Tree, expectedType: Type) = {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,12 @@ object Symbols {
452452
)
453453
}
454454

455-
/** The symbol's signature if it is completed, NotAMethod otherwise. */
456-
final def unforcedSignature(implicit ctx: Context) =
457-
if (lastDenot != null && lastDenot.isCompleted) lastDenot.signature
458-
else Signature.NotAMethod
455+
/** The symbol's signature if it is completed or a method, NotAMethod otherwise. */
456+
final def signature(implicit ctx: Context) =
457+
if (lastDenot != null && (lastDenot.isCompleted || lastDenot.is(Method)))
458+
denot.signature
459+
else
460+
Signature.NotAMethod
459461

460462
/** Special cased here, because it may be used on naked symbols in substituters */
461463
final def isStatic(implicit ctx: Context): Boolean =

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,10 @@ object Types {
707707
final def implicitMembers(implicit ctx: Context): List[TermRef] = track("implicitMembers") {
708708
memberDenots(implicitFilter,
709709
(name, buf) => buf ++= member(name).altsWith(_ is Implicit))
710-
.toList.map(d => TermRef.withSig(this, d.symbol.asTerm))
710+
.toList.map { d =>
711+
val mbr = d.symbol.asTerm
712+
TermRef(this, mbr, mbr.name)
713+
}
711714
}
712715

713716
/** The set of member classes of this type */
@@ -1733,7 +1736,7 @@ object Types {
17331736
}
17341737

17351738
private def withSig(sig: Signature)(implicit ctx: Context): NamedType =
1736-
TermRef.withSig(prefix, name.asTermName, sig)
1739+
TermRef(prefix, name.asTermName.withSig(sig))
17371740

17381741
protected def loadDenot(implicit ctx: Context): Denotation = {
17391742
val d = asMemberOf(prefix, allowPrivate = true)
@@ -1990,7 +1993,7 @@ object Types {
19901993
val candidate =
19911994
if (newSig ne curSig) {
19921995
core.println(i"sig change at ${ctx.phase} for $this, pre = $prefix, sig: $curSig --> $newSig")
1993-
TermRef.withSig(prefix, name, newSig)
1996+
TermRef(prefix, name.withSig(newSig))
19941997
}
19951998
else TermRef(prefix, designator)
19961999
fixDenot(candidate, prefix)
@@ -2055,41 +2058,30 @@ object Types {
20552058
* (2) the designator of the TermRef is either the symbol or its name & unforced signature.
20562059
*/
20572060
def apply(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef =
2058-
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically)
2059-
apply(prefix, sym)
2060-
else
2061-
withSig(prefix, name.asTermName, sym.unforcedSignature).withSym(sym)
2061+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically) apply(prefix, sym)
2062+
else apply(prefix, name.withSig(sym.signature)).withSym(sym)
20622063

20632064
/** Create term ref to given initial denotation, taking the signature
20642065
* from the denotation if it is completed, or creating a term ref without
20652066
* signature, if denotation is not yet completed.
20662067
*/
2067-
def apply(prefix: Type, designator: TermName, denot: Denotation)(implicit ctx: Context): TermRef = {
2068+
def apply(prefix: Type, name: TermName, denot: Denotation)(implicit ctx: Context): TermRef = {
20682069
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically)
20692070
apply(prefix, denot.symbol.asTerm)
20702071
else denot match {
2071-
case denot: SymDenotation if denot.isCompleted => withSig(prefix, designator, denot.signature)
2072-
case _ => apply(prefix, designator)
2072+
case denot: SymDenotation if denot.isCompleted =>
2073+
apply(prefix, name.withSig(denot.signature))
2074+
case _ =>
2075+
apply(prefix, name)
20732076
}
20742077
} withDenot denot
20752078

2076-
/** Create a term ref to given symbol, taking the signature from the symbol
2077-
* (which must be completed).
2078-
*/
2079-
def withSig(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2080-
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically) apply(prefix, sym)
2081-
else withSig(prefix, sym.name, sym.signature).withSym(sym)
2082-
2083-
/** Create a term ref with given prefix, name and signature */
2084-
def withSig(prefix: Type, name: TermName, sig: Signature)(implicit ctx: Context): TermRef =
2085-
apply(prefix, name.withSig(sig))
2086-
20872079
/** Create a term ref with given prefix, name, signature, and initial denotation */
20882080
def withSigAndDenot(prefix: Type, name: TermName, sig: Signature, denot: Denotation)(implicit ctx: Context): TermRef = {
20892081
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically)
20902082
apply(prefix, denot.symbol.asTerm)
20912083
else
2092-
withSig(prefix, name, sig)
2084+
apply(prefix, name.withSig(sig))
20932085
} withDenot denot
20942086
}
20952087

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
710710
val cls = ctx.owner.asClass
711711
val assumedSelfType =
712712
if (cls.is(Module) && cls.owner.isClass)
713-
TermRef.withSig(cls.owner.thisType, cls.name.sourceModuleName, Signature.NotAMethod)
713+
TermRef(cls.owner.thisType, cls.name.sourceModuleName.withSig(Signature.NotAMethod))
714714
else NoType
715715
cls.info = new TempClassInfo(cls.owner.thisType, cls, cls.unforcedDecls, assumedSelfType)
716716
val localDummy = symbolAtCurrent()
@@ -871,7 +871,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
871871
untpd.Ident(readName().toTypeName).withType(readType())
872872
case SELECT =>
873873
def readRest(name: Name, sig: Signature) =
874-
completeSelect(name, TermRef.withSig(_, name.asTermName, sig))
874+
completeSelect(name, TermRef(_, name.asTermName.withSig(sig)))
875875
readName() match {
876876
case SignedName(name, sig) => readRest(name, sig)
877877
case name => readRest(name, Signature.NotAMethod)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
704704
case SINGLEtpe =>
705705
val pre = readTypeRef()
706706
val sym = readDisambiguatedSymbolRef(_.info.isParameterless)
707-
if (isLocal(sym) || (pre == NoPrefix)) pre select sym
708-
else TermRef.withSig(pre, sym.name.asTermName, Signature.NotAMethod) // !!! should become redundant
707+
if (isLocal(sym) || (pre eq NoPrefix)) pre select sym
708+
else TermRef(pre, sym.name.asTermName.withSig(Signature.NotAMethod)) // !!! should become redundant
709709
case SUPERtpe =>
710710
val thistpe = readTypeRef()
711711
val supertpe = readTypeRef()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package transform
44
import core._
55
import ast.Trees._
66
import Contexts._, Types._, Symbols._, Flags._, TypeUtils._, DenotTransformers._, StdNames._
7-
import Decorators._
7+
import Decorators._, NameOps._
88
import config.Printers.typr
99

1010
/** For all parameter accessors
@@ -96,7 +96,7 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
9696
// It could be a param forwarder; adapt the signature
9797
val newSig = tpe.prefix.memberInfo(tpe.symbol).signature
9898
if (newSig == Signature.NotAMethod) tree
99-
else tree.withType(TermRef.withSig(tpe.prefix, tpe.name, newSig)).asInstanceOf[T]
99+
else tree.withType(TermRef(tpe.prefix, tpe.name.withSig(newSig))).asInstanceOf[T]
100100
case _ =>
101101
tree
102102
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
8686
private def fixSignature[T <: Tree](tree: T)(implicit ctx: Context): T = tree.tpe match {
8787
case tpe: TermRef if tpe.signature.isUnderDefined =>
8888
typr.println(i"fixing $tree with type ${tree.tpe.widen.toString} with sig ${tpe.signature} to ${tpe.widen.signature}")
89-
tree.withType(TermRef.withSig(tpe.prefix, tpe.name, tpe.widen.signature)).asInstanceOf[T]
89+
tree.withType(TermRef(tpe.prefix, tpe.name.withSig(tpe.widen.signature))).asInstanceOf[T]
9090
case _ => tree
9191
}
9292

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ trait ImplicitRunInfo { self: RunInfo =>
428428
def addRef(companion: TermRef): Unit = {
429429
val compSym = companion.symbol
430430
if (compSym is Package)
431-
addRef(TermRef.withSig(companion, nme.PACKAGE, Signature.NotAMethod))
431+
addRef(TermRef(companion, nme.PACKAGE.withSig(Signature.NotAMethod)))
432432
else if (compSym.exists)
433433
comps += companion.asSeenFrom(pre, compSym.owner).asInstanceOf[TermRef]
434434
}

0 commit comments

Comments
 (0)