Skip to content

Commit a395cb8

Browse files
committed
Eliminate forwarders Symbol => Denotation
Operations on Denotations (not SymDenotations) should not be invokable with a Symbol receiver.
1 parent 09c6471 commit a395cb8

File tree

10 files changed

+59
-68
lines changed

10 files changed

+59
-68
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -287,35 +287,6 @@ object Denotations {
287287
denot.symbol
288288
}
289289

290-
final def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol =
291-
info.member(name.toTermName).requiredSymbol(_ is Method).asTerm
292-
final def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef =
293-
requiredMethod(name).termRef
294-
295-
final def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = {
296-
info.member(name.toTermName).requiredSymbol { x =>
297-
(x is Method) && {
298-
x.info.paramInfoss match {
299-
case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _)
300-
case _ => false
301-
}
302-
}
303-
}.asTerm
304-
}
305-
final def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef =
306-
requiredMethod(name, argTypes).termRef
307-
308-
final def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol =
309-
info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm
310-
final def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef =
311-
requiredValue(name).termRef
312-
313-
final def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol =
314-
info.member(name.toTypeName).requiredSymbol(_.isClass).asClass
315-
316-
final def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol =
317-
info.member(name.toTypeName).requiredSymbol(_.isType).asType
318-
319290
/** The alternative of this denotation that has a type matching `targetType` when seen
320291
* as a member of type `site`, `NoDenotation` if none exists.
321292
*/

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ object SymDenotations {
129129
initInfo: Type,
130130
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
131131

132+
Stats.record("SymDenotation")
133+
132134
//assert(symbol.id != 4940, name)
133135

134136
override protected def hasUniqueSym: Boolean = exists
@@ -991,7 +993,7 @@ object SymDenotations {
991993
*/
992994
private def companionNamed(name: TypeName)(implicit ctx: Context): Symbol =
993995
if (owner.isClass)
994-
owner.unforcedDecls.lookup(name).suchThat(_.isCoDefinedWith(symbol)).symbol
996+
owner.unforcedDecls.lookup(name).ensuring(_.isCoDefinedWith(symbol))
995997
else if (!owner.exists || ctx.compilationUnit == null)
996998
NoSymbol
997999
else if (!ctx.compilationUnit.tpdTree.isEmpty)
@@ -1098,8 +1100,7 @@ object SymDenotations {
10981100
final def superSymbolIn(base: Symbol)(implicit ctx: Context): Symbol = {
10991101
@tailrec def loop(bcs: List[ClassSymbol]): Symbol = bcs match {
11001102
case bc :: bcs1 =>
1101-
val sym = matchingDecl(bcs.head, base.thisType)
1102-
.suchThat(alt => !(alt is Deferred)).symbol
1103+
val sym = matchingDecl(bcs.head, base.thisType).ensuring(!_.is(Deferred))
11031104
if (sym.exists) sym else loop(bcs.tail)
11041105
case _ =>
11051106
NoSymbol
@@ -1290,6 +1291,8 @@ object SymDenotations {
12901291

12911292
import util.LRUCache
12921293

1294+
Stats.record("ClassDenotation")
1295+
12931296
// ----- caches -------------------------------------------------------
12941297

12951298
private[this] var myTypeParams: List[TypeSymbol] = null

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

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ object Symbols {
412412
*/
413413
class Symbol private[Symbols] (private[this] var myCoord: Coord, val id: Int) extends Designator with ParamInfo with printing.Showable {
414414

415+
util.Stats.record("Symbol")
416+
415417
type ThisName <: Name
416418

417419
//assert(id != 723)
@@ -541,7 +543,7 @@ object Symbols {
541543
else {
542544
if (this.owner.is(Package)) {
543545
denot.validFor |= InitialPeriod
544-
if (this is Module) this.moduleClass.validFor = this.moduleClass.validFor | InitialPeriod
546+
if (this is Module) this.moduleClass.denot.validFor = this.moduleClass.denot.validFor | InitialPeriod
545547
}
546548
else this.owner.asClass.ensureFreshScopeAfter(phase)
547549
if (!isPrivate)
@@ -596,22 +598,37 @@ object Symbols {
596598

597599
// -------- Denot Forwarders-------------------------------------------------
598600

599-
final def exists(implicit ctx: Context): Boolean = denot.exists
600-
final def validFor(implicit ctx: Context): Period = denot.validFor
601-
final def validFor_=(p: Period)(implicit ctx: Context): Unit = denot.validFor_=(p)
602-
final def suchThat(p: Symbol => Boolean)(implicit ctx: Context): SingleDenotation = denot.suchThat(p)
603-
final def requiredSymbol(p: Symbol => Boolean, source: AbstractFile = null, generateStubs: Boolean = true)(implicit ctx: Context): Symbol = denot.requiredSymbol(p, source, generateStubs)
604-
final def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol = denot.requiredMethod(name)
605-
final def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef = denot.requiredMethodRef(name)
606-
final def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = denot.requiredMethod(name, argTypes)
607-
final def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef = denot.requiredMethodRef(name, argTypes)
608-
final def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol = denot.requiredValue(name)
609-
final def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef = denot.requiredValueRef(name)
610-
final def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol = denot.requiredClass(name)
611-
final def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol = denot.requiredType(name)
612-
final def asSeenFrom(pre: Type)(implicit ctx: Context) = denot.asSeenFrom(pre)
613-
final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = denot.findMember(name, pre, excluded)
614-
final def matches(other: SingleDenotation)(implicit ctx: Context): Boolean = denot.matches(other)
601+
final def exists(implicit ctx: Context): Boolean = lastDenot.exists // no renaming necessary, any denot will do
602+
final def ensuring(p: Symbol => Boolean)(implicit ctx: Context): Symbol = denot.suchThat(p).symbol
603+
604+
final def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol =
605+
info.member(name.toTermName).requiredSymbol(_ is Method).asTerm
606+
final def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef =
607+
requiredMethod(name).termRef
608+
609+
final def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = {
610+
info.member(name.toTermName).requiredSymbol { x =>
611+
(x is Method) && {
612+
x.info.paramInfoss match {
613+
case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _)
614+
case _ => false
615+
}
616+
}
617+
}.asTerm
618+
}
619+
final def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef =
620+
requiredMethod(name, argTypes).termRef
621+
622+
final def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol =
623+
info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm
624+
final def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef =
625+
requiredValue(name).termRef
626+
627+
final def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol =
628+
info.member(name.toTypeName).requiredSymbol(_.isClass).asClass
629+
630+
final def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol =
631+
info.member(name.toTypeName).requiredSymbol(_.isType).asType
615632

616633
final def name(implicit ctx: Context): ThisName = denot.name.asInstanceOf[ThisName]
617634
final def maybeOwner(implicit ctx: Context): Symbol = denot.maybeOwner

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ object Types {
548548
case tp: TypeProxy =>
549549
go(tp.underlying)
550550
case tp: ClassInfo =>
551-
tp.cls.findMember(name, pre, excluded)
551+
tp.cls.denot.findMember(name, pre, excluded)
552552
case AndType(l, r) =>
553553
goAnd(l, r)
554554
case tp: OrType =>
@@ -1629,7 +1629,7 @@ object Types {
16291629
def computeSignature(implicit ctx: Context): Signature = {
16301630
val lastd = lastDenotation
16311631
if (lastd != null) lastd.signature
1632-
else symbol.asSeenFrom(prefix).signature
1632+
else symbol.denot.asSeenFrom(prefix).signature
16331633
}
16341634

16351635
/** The signature of the current denotation if it is known without forcing.
@@ -1642,8 +1642,8 @@ object Types {
16421642
val lastd = lastDenotation
16431643
if (lastd != null) lastd.signature
16441644
else {
1645-
val sym = currentSymbol
1646-
if (sym.exists) sym.asSeenFrom(prefix).signature
1645+
val symd = currentSymbol.denot
1646+
if (symd.exists) symd.asSeenFrom(prefix).signature
16471647
else Signature.NotAMethod
16481648
}
16491649
}
@@ -1694,6 +1694,7 @@ object Types {
16941694

16951695
/** The denotation currently denoted by this type */
16961696
final def denot(implicit ctx: Context): Denotation = {
1697+
record("NamedType.denot")
16971698
val now = ctx.period
16981699
// Even if checkedPeriod == now we still need to recheck lastDenotation.validFor
16991700
// as it may have been mutated by SymDenotation#installAfter
@@ -2031,7 +2032,7 @@ object Types {
20312032
if (d.isOverloaded && lastSymbol.exists)
20322033
d = disambiguate(d,
20332034
if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod
2034-
else lastSymbol.asSeenFrom(prefix).signature)
2035+
else lastSymbol.denot.asSeenFrom(prefix).signature)
20352036
NamedType(prefix, name, d)
20362037
}
20372038
if (prefix eq this.prefix) this
@@ -3584,7 +3585,7 @@ object Types {
35843585
// Note: Taking a normal typeRef does not work here. A normal ref might contain
35853586
// also other information about the named type (e.g. bounds).
35863587
contains(
3587-
TypeRef(tp.prefix, cls).withDenot(new UniqueRefDenotation(cls, tp, cls.validFor)))
3588+
TypeRef(tp.prefix, cls).withDenot(new UniqueRefDenotation(cls, tp, cls.denot.validFor)))
35883589
case _ =>
35893590
lo <:< tp && tp <:< hi
35903591
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
513513
val unpickler = new ClassUnpickler(infoRef) withDecls symScope(cls)
514514
if (flags is ModuleClass)
515515
unpickler withSourceModule (implicit ctx =>
516-
cls.owner.info.decls.lookup(cls.name.sourceModuleName)
517-
.suchThat(_ is Module).symbol)
516+
cls.owner.info.decls.lookup(cls.name.sourceModuleName).ensuring(_ is Module))
518517
else unpickler
519518
}
520519
ctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start)
@@ -527,8 +526,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
527526
moduleRoot.symbol
528527
} else ctx.newSymbol(owner, name.asTermName, flags,
529528
new LocalUnpickler() withModuleClass(implicit ctx =>
530-
owner.info.decls.lookup(name.moduleClassName)
531-
.suchThat(_ is Module).symbol)
529+
owner.info.decls.lookup(name.moduleClassName).ensuring(_ is Module))
532530
, coord = start)
533531
case _ =>
534532
errorBadSignature("bad symbol tag: " + tag)

compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
5151
if (newFieldsMapping == null) {
5252
newFieldsMapping = candidates.intersect(gettersCalled).map { refVal =>
5353
val accessors = refVal.info.classSymbol.caseAccessors.filter(_.isGetter)
54-
val newLocals = accessors.map { x =>
54+
val newLocals = accessors.map { accessor =>
5555
val owner: Symbol = refVal.owner
5656
val name: Name = LocalOptInlineLocalObj.fresh()
5757
val flags: FlagSet = Synthetic
58-
val info: Type = x.asSeenFrom(refVal.info).info.finalResultType.widenDealias
58+
val info: Type = accessor.denot.asSeenFrom(refVal.info).info.finalResultType.widenDealias
5959
ctx.newSymbol(owner, name, flags, info)
6060
}
6161
(refVal, LinkedHashMap[Symbol, Symbol](accessors.zip(newLocals): _*))

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
823823

824824
/** does the companion object of the given symbol have custom unapply */
825825
def hasCustomUnapply(sym: Symbol): Boolean = {
826-
val companion = sym.companionModule
826+
val companion = sym.companionModule.denot
827827
companion.findMember(nme.unapply, NoPrefix, excluded = Synthetic).exists ||
828828
companion.findMember(nme.unapplySeq, NoPrefix, excluded = Synthetic).exists
829829
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ trait Checking {
662662
def checkDecl(decl: Symbol): Unit = {
663663
for (other <- seen(decl.name)) {
664664
typr.println(i"conflict? $decl $other")
665-
if (decl.matches(other.denot)) {
665+
if (decl.denot.matches(other.denot)) {
666666
def doubleDefError(decl: Symbol, other: Symbol): Unit =
667667
if (!decl.info.isErroneous && !other.info.isErroneous)
668668
ctx.error(DoubleDeclaration(decl, other), decl.pos)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ trait NamerContextOps { this: Context =>
5656
owner.thisType.member(name)
5757
}
5858
else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext.
59-
owner.findMember(name, owner.thisType, EmptyFlags)
59+
owner.denot.findMember(name, owner.thisType, EmptyFlags)
6060
else
6161
scope.denotsNamed(name).toDenot(NoPrefix)
6262

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ trait TypeAssigner {
4949
val parentType = info.parents.reduceLeft(ctx.typeComparer.andType(_, _))
5050

5151
def addRefinement(parent: Type, decl: Symbol) = {
52+
val decld = decl.denot
5253
val inherited =
53-
parentType.findMember(decl.name, cls.thisType, excluded = Private)
54-
.suchThat(sym => decl.matches(sym.denot))
54+
parentType.findMember(decld.name, cls.thisType, excluded = Private)
55+
.suchThat(sym => decld.matches(sym.denot))
5556
val inheritedInfo = inherited.info
56-
if (inheritedInfo.exists && decl.info <:< inheritedInfo && !(inheritedInfo <:< decl.info)) {
57-
val r = RefinedType(parent, decl.name, decl.info)
57+
if (inheritedInfo.exists && decld.info <:< inheritedInfo && !(inheritedInfo <:< decld.info)) {
58+
val r = RefinedType(parent, decld.name, decld.info)
5859
typr.println(i"add ref $parent $decl --> " + r)
5960
r
6061
}

0 commit comments

Comments
 (0)