Skip to content

Commit 01cfd6d

Browse files
committed
Eliminate forwarders Symbol -> Denotation
Some of these methods are now only defined on Denotations, others have been moved to Symbol. The motivation is that we want to avoid having to rename one version of these methods.
1 parent 6619927 commit 01cfd6d

File tree

10 files changed

+52
-68
lines changed

10 files changed

+52
-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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ object SymDenotations {
991991
*/
992992
private def companionNamed(name: TypeName)(implicit ctx: Context): Symbol =
993993
if (owner.isClass)
994-
owner.unforcedDecls.lookup(name).suchThat(_.isCoDefinedWith(symbol)).symbol
994+
owner.unforcedDecls.lookup(name).ensuring(_.isCoDefinedWith(symbol))
995995
else if (!owner.exists || ctx.compilationUnit == null)
996996
NoSymbol
997997
else if (!ctx.compilationUnit.tpdTree.isEmpty)
@@ -1098,8 +1098,7 @@ object SymDenotations {
10981098
final def superSymbolIn(base: Symbol)(implicit ctx: Context): Symbol = {
10991099
@tailrec def loop(bcs: List[ClassSymbol]): Symbol = bcs match {
11001100
case bc :: bcs1 =>
1101-
val sym = matchingDecl(bcs.head, base.thisType)
1102-
.suchThat(alt => !(alt is Deferred)).symbol
1101+
val sym = matchingDecl(bcs.head, base.thisType).ensuring(!_.is(Deferred))
11031102
if (sym.exists) sym else loop(bcs.tail)
11041103
case _ =>
11051104
NoSymbol

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ object Symbols {
541541
else {
542542
if (this.owner.is(Package)) {
543543
denot.validFor |= InitialPeriod
544-
if (this is Module) this.moduleClass.validFor = this.moduleClass.validFor | InitialPeriod
544+
if (this is Module) this.moduleClass.denot.validFor = this.moduleClass.denot.validFor | InitialPeriod
545545
}
546546
else this.owner.asClass.ensureFreshScopeAfter(phase)
547547
if (!isPrivate)
@@ -596,22 +596,37 @@ object Symbols {
596596

597597
// -------- Denot Forwarders-------------------------------------------------
598598

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)
599+
final def exists(implicit ctx: Context): Boolean = lastDenot.exists // no renaming necessary, any denot will do
600+
final def ensuring(p: Symbol => Boolean)(implicit ctx: Context): Symbol = denot.suchThat(p).symbol
601+
602+
final def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol =
603+
info.member(name.toTermName).requiredSymbol(_ is Method).asTerm
604+
final def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef =
605+
requiredMethod(name).termRef
606+
607+
final def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = {
608+
info.member(name.toTermName).requiredSymbol { x =>
609+
(x is Method) && {
610+
x.info.paramInfoss match {
611+
case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _)
612+
case _ => false
613+
}
614+
}
615+
}.asTerm
616+
}
617+
final def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef =
618+
requiredMethodRef(name, argTypes)
619+
620+
final def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol =
621+
info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm
622+
final def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef =
623+
requiredValue(name).termRef
624+
625+
final def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol =
626+
info.member(name.toTypeName).requiredSymbol(_.isClass).asClass
627+
628+
final def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol =
629+
info.member(name.toTypeName).requiredSymbol(_.isType).asType
615630

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

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

Lines changed: 6 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.classDenot.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
}
@@ -2031,7 +2031,7 @@ object Types {
20312031
if (d.isOverloaded && lastSymbol.exists)
20322032
d = disambiguate(d,
20332033
if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod
2034-
else lastSymbol.asSeenFrom(prefix).signature)
2034+
else lastSymbol.denot.asSeenFrom(prefix).signature)
20352035
NamedType(prefix, name, d)
20362036
}
20372037
if (prefix eq this.prefix) this
@@ -3584,7 +3584,7 @@ object Types {
35843584
// Note: Taking a normal typeRef does not work here. A normal ref might contain
35853585
// also other information about the named type (e.g. bounds).
35863586
contains(
3587-
TypeRef(tp.prefix, cls).withDenot(new UniqueRefDenotation(cls, tp, cls.validFor)))
3587+
TypeRef(tp.prefix, cls).withDenot(new UniqueRefDenotation(cls, tp, cls.denot.validFor)))
35883588
case _ =>
35893589
lo <:< tp && tp <:< hi
35903590
}

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)