Skip to content

Commit 65b3a8e

Browse files
committed
Remove implicit conversions from Symbols to SymDenotations
1 parent d14c89b commit 65b3a8e

39 files changed

+380
-204
lines changed

compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ object CollectEntryPoints{
6161
val StringType = d.StringType
6262
// The given class has a main method.
6363
def hasJavaMainMethod(sym: Symbol): Boolean =
64-
(toDenot(sym).info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))
64+
(sym.info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))
6565

6666
def fail(msg: String, pos: Position = sym.pos) = {
6767
ctx.warning( sym.name +
68-
s" has a main method with parameter type Array[String], but ${toDenot(sym).fullName} will not be a runnable program.\n Reason: $msg",
68+
s" has a main method with parameter type Array[String], but ${sym.fullName} will not be a runnable program.\n Reason: $msg",
6969
sourcePos(sym.pos)
7070
// TODO: make this next claim true, if possible
7171
// by generating valid main methods as static in module classes
@@ -77,7 +77,7 @@ object CollectEntryPoints{
7777
def failNoForwarder(msg: String) = {
7878
fail(s"$msg, which means no static forwarder can be generated.\n")
7979
}
80-
val possibles = if (sym.flags is Flags.Module) (toDenot(sym).info nonPrivateMember nme.main).alternatives else Nil
80+
val possibles = if (sym.flags is Flags.Module) (sym.info nonPrivateMember nme.main).alternatives else Nil
8181
val hasApproximate = possibles exists { m =>
8282
m.info match {
8383
case MethodTpe(_, p :: Nil, _) => p.typeSymbol == defn.ArrayClass
@@ -94,7 +94,7 @@ object CollectEntryPoints{
9494

9595
if (hasJavaMainMethod(companion))
9696
failNoForwarder("companion contains its own main method")
97-
else if (toDenot(companion).info.member(nme.main) != NoDenotation)
97+
else if (companion.info.member(nme.main) != NoDenotation)
9898
// this is only because forwarders aren't smart enough yet
9999
failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
100100
else if (companion.flags is Flags.Trait)
@@ -103,7 +103,7 @@ object CollectEntryPoints{
103103
// attempts to be java main methods.
104104
else (possibles exists(x=> isJavaMainMethod(x.symbol))) || {
105105
possibles exists { m =>
106-
toDenot(m.symbol).info match {
106+
m.symbol.info match {
107107
case t: PolyType =>
108108
fail("main methods cannot be generic.")
109109
case MethodTpe(paramNames, paramTypes, resultType) =>

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import dotty.tools.dotc.core.Names.TypeName
3939
import scala.annotation.tailrec
4040

4141
class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(implicit ctx: Context) extends BackendInterface{
42-
import Symbols.{toDenot, toClassDenot}
4342
// Dotty deviation: Need to (re-)import implicit decorators here because otherwise
4443
// they would be shadowed by the more deeply nested `symHelper` decorator.
4544

@@ -143,7 +142,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
143142
val externalEqualsNumNum: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
144143
val externalEqualsNumChar: Symbol = NoSymbol // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
145144
val externalEqualsNumObject: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
146-
val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(toDenot(_).info.firstParamTypes.size == 2).symbol
145+
val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(_.info.firstParamTypes.size == 2).symbol
147146
val MaxFunctionArity: Int = Definitions.MaxImplementedFunctionArity
148147
val FunctionClass: Array[Symbol] = defn.FunctionClassPerRun()
149148
val AbstractFunctionClass: Array[Symbol] = defn.AbstractFunctionClassPerRun()
@@ -214,7 +213,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
214213
implicit val ClosureTag: ClassTag[Closure] = ClassTag[Closure](classOf[Closure])
215214

216215
def isRuntimeVisible(annot: Annotation): Boolean =
217-
if (toDenot(annot.atp.typeSymbol).hasAnnotation(AnnotationRetentionAttr))
216+
if (annot.atp.typeSymbol.hasAnnotation(AnnotationRetentionAttr))
218217
retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr
219218
else {
220219
// SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the
@@ -264,16 +263,16 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
264263
av.visitEnum(name, edesc, evalue)
265264
} else {
266265
// println(i"not an enum: ${t.symbol} / ${t.symbol.denot.owner} / ${t.symbol.denot.owner.isTerm} / ${t.symbol.denot.owner.flags}")
267-
assert(toDenot(t.symbol).name.is(DefaultGetterName),
268-
s"${toDenot(t.symbol).name.debugString}") // this should be default getter. do not emmit.
266+
assert(t.symbol.name.is(DefaultGetterName),
267+
s"${t.symbol.name.debugString}") // this should be default getter. do not emmit.
269268
}
270269
case t: SeqLiteral =>
271270
val arrAnnotV: AnnotationVisitor = av.visitArray(name)
272271
for (arg <- t.elems) { emitArgument(arrAnnotV, null, arg, bcodeStore)(innerClasesStore) }
273272
arrAnnotV.visitEnd()
274273

275274
case Apply(fun, args) if fun.symbol == defn.ArrayClass.primaryConstructor ||
276-
toDenot(fun.symbol).owner == defn.ArrayClass.linkedClass && fun.symbol.name == nme_apply =>
275+
fun.symbol.owner == defn.ArrayClass.linkedClass && fun.symbol.name == nme_apply =>
277276
val arrAnnotV: AnnotationVisitor = av.visitArray(name)
278277

279278
var actualArgs = if (fun.tpe.isImplicitMethod) {
@@ -655,29 +654,29 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
655654
def fullName(sep: Char): String = sym.showFullName
656655
def fullName: String = sym.showFullName
657656
def simpleName: Name = sym.name
658-
def javaSimpleName: String = toDenot(sym).name.mangledString // addModuleSuffix(simpleName.dropLocal)
657+
def javaSimpleName: String = sym.name.mangledString // addModuleSuffix(simpleName.dropLocal)
659658
def javaBinaryName: String = javaClassName.replace('.', '/') // TODO: can we make this a string? addModuleSuffix(fullNameInternal('/'))
660-
def javaClassName: String = toDenot(sym).fullName.mangledString // addModuleSuffix(fullNameInternal('.')).toString
659+
def javaClassName: String = sym.fullName.mangledString // addModuleSuffix(fullNameInternal('.')).toString
661660
def name: Name = sym.name
662661
def rawname: String = {
663-
val original = toDenot(sym).initial
662+
val original = sym.initial
664663
sym.name(ctx.withPhase(original.validFor.phaseId)).mangledString
665664
}
666665

667666
// types
668-
def info: Type = toDenot(sym).info
669-
def tpe: Type = toDenot(sym).info // todo whats the differentce between tpe and info?
670-
def thisType: Type = toDenot(sym).thisType
667+
def info: Type = sym.info
668+
def tpe: Type = sym.info // todo whats the differentce between tpe and info?
669+
def thisType: Type = sym.thisType
671670

672671
// tests
673672
def isClass: Boolean = {
674673
sym.isPackageObject || (sym.isClass)
675674
}
676675
def isType: Boolean = sym.isType
677-
def isAnonymousClass: Boolean = toDenot(sym).isAnonymousClass
678-
def isConstructor: Boolean = toDenot(sym).isConstructor
676+
def isAnonymousClass: Boolean = sym.isAnonymousClass
677+
def isConstructor: Boolean = sym.isConstructor
679678
def isExpanded: Boolean = sym.name.is(ExpandedName)
680-
def isAnonymousFunction: Boolean = toDenot(sym).isAnonymousFunction
679+
def isAnonymousFunction: Boolean = sym.isAnonymousFunction
681680
def isMethod: Boolean = sym is Flags.Method
682681
def isPublic: Boolean = sym.flags.is(Flags.EmptyFlags, Flags.Private | Flags.Protected)
683682
def isSynthetic: Boolean = sym is Flags.Synthetic
@@ -689,22 +688,22 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
689688
def hasPackageFlag: Boolean = sym is Flags.Package
690689
def isImplClass: Boolean = sym is Flags.ImplClass
691690
def isInterface: Boolean = (sym is Flags.PureInterface) || (sym is Flags.Trait)
692-
def isGetter: Boolean = toDenot(sym).isGetter
693-
def isSetter: Boolean = toDenot(sym).isSetter
691+
def isGetter: Boolean = sym.isGetter
692+
def isSetter: Boolean = sym.isSetter
694693
def isGetClass: Boolean = sym eq defn.Any_getClass
695694
def isJavaDefined: Boolean = sym is Flags.JavaDefined
696-
def isJavaDefaultMethod: Boolean = !((sym is Flags.Deferred) || toDenot(sym).isClassConstructor)
695+
def isJavaDefaultMethod: Boolean = !((sym is Flags.Deferred) || sym.isClassConstructor)
697696
def isDeferred: Boolean = sym is Flags.Deferred
698697
def isPrivate: Boolean = sym is Flags.Private
699698
def getsJavaFinalFlag: Boolean =
700-
isFinal && !toDenot(sym).isClassConstructor && !(sym is Flags.Mutable) && !(sym.enclosingClass is Flags.Trait)
699+
isFinal && !sym.isClassConstructor && !(sym is Flags.Mutable) && !(sym.enclosingClass is Flags.Trait)
701700

702701
def getsJavaPrivateFlag: Boolean =
703702
isPrivate //|| (sym.isPrimaryConstructor && sym.owner.isTopLevelModuleClass)
704703

705704
def isFinal: Boolean = sym is Flags.Final
706705
def isStaticMember: Boolean = (sym ne NoSymbol) &&
707-
((sym is Flags.JavaStatic) || (owner is Flags.ImplClass) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot))
706+
((sym is Flags.JavaStatic) || (owner is Flags.ImplClass) || sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot))
708707
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
709708

710709
def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass)
@@ -720,12 +719,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
720719
def hasModuleFlag: Boolean = sym is Flags.Module
721720
def isSynchronized: Boolean = sym is Flags.Synchronized
722721
def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other)
723-
def hasAnnotation(ann: Symbol): Boolean = toDenot(sym).hasAnnotation(ann)
722+
def hasAnnotation(ann: Symbol): Boolean = sym.hasAnnotation(ann)
724723
def shouldEmitForwarders: Boolean =
725724
(sym is Flags.Module) && !(sym is Flags.ImplClass) && sym.isStatic
726725
def isJavaEntryPoint: Boolean = CollectEntryPoints.isJavaEntryPoint(sym)
727726

728-
def isClassConstructor: Boolean = toDenot(sym).isClassConstructor
727+
def isClassConstructor: Boolean = sym.isClassConstructor
729728

730729
/**
731730
* True for module classes of modules that are top-level or owned only by objects. Module classes
@@ -736,33 +735,33 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
736735
// scalac uses atPickling here
737736
// this would not work if modules are created after pickling
738737
// for example by specialization
739-
val original = toDenot(sym).initial
738+
val original = sym.initial
740739
val validity = original.validFor
741740
val shiftedContext = ctx.withPhase(validity.phaseId)
742-
toDenot(sym)(shiftedContext).isStatic(shiftedContext)
741+
sym.denot(shiftedContext).isStatic(shiftedContext)
743742
}
744743

745744
def isStaticConstructor: Boolean = (isStaticMember && isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
746745

747746

748747
// navigation
749-
def owner: Symbol = toDenot(sym).owner
748+
def owner: Symbol = sym.owner
750749
def rawowner: Symbol = {
751750
originalOwner
752751
}
753752
def originalOwner: Symbol =
754753
// used to populate the EnclosingMethod attribute.
755754
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
756755
if (sym.exists) {
757-
val original = toDenot(sym).initial
756+
val original = sym.initial
758757
val validity = original.validFor
759758
val shiftedContext = ctx.withPhase(validity.phaseId)
760-
val r = toDenot(sym)(shiftedContext).maybeOwner.lexicallyEnclosingClass(shiftedContext)
759+
val r = sym.denot(shiftedContext).maybeOwner.lexicallyEnclosingClass(shiftedContext)
761760
r
762761
} else NoSymbol
763-
def parentSymbols: List[Symbol] = toDenot(sym).info.parents.map(_.typeSymbol)
762+
def parentSymbols: List[Symbol] = sym.info.parents.map(_.typeSymbol)
764763
def superClass: Symbol = {
765-
val t = toDenot(sym).asClass.superClass
764+
val t = sym.asClass.superClass
766765
if (t.exists) t
767766
else if (sym is Flags.ModuleClass) {
768767
// workaround #371
@@ -772,23 +771,23 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
772771
}
773772
else t
774773
}
775-
def enclClass: Symbol = toDenot(sym).enclosingClass
774+
def enclClass: Symbol = sym.enclosingClass
776775
def linkedClassOfClass: Symbol = linkedClass
777-
def linkedClass: Symbol = toDenot(sym)(ctx).linkedClass(ctx) //exitingPickler(sym.linkedClassOfClass)
778-
def companionClass: Symbol = toDenot(sym).companionClass
779-
def companionModule: Symbol = toDenot(sym).companionModule
776+
def linkedClass: Symbol = sym.linkedClass(ctx) //exitingPickler(sym.linkedClassOfClass)
777+
def companionClass: Symbol = sym.companionClass
778+
def companionModule: Symbol = sym.companionModule
780779
def companionSymbol: Symbol = if (sym is Flags.Module) companionClass else companionModule
781-
def moduleClass: Symbol = toDenot(sym).moduleClass
780+
def moduleClass: Symbol = sym.moduleClass
782781
def enclosingClassSym: Symbol = {
783782
if (this.isClass) {
784783
val ct = ctx.withPhase(ctx.flattenPhase.prev)
785-
toDenot(sym)(ct).owner.enclosingClass(ct)
784+
sym.denot(ct).owner.enclosingClass(ct)
786785
}
787786
else sym.enclosingClass(ctx.withPhase(ctx.flattenPhase.prev))
788787
} //todo is handled specially for JavaDefined symbols in scalac
789788

790789
// members
791-
def primaryConstructor: Symbol = toDenot(sym).primaryConstructor
790+
def primaryConstructor: Symbol = sym.primaryConstructor
792791

793792
/** For currently compiled classes: All locally defined classes including local classes.
794793
* The empty list for classes that are not currently compiled.
@@ -803,22 +802,22 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
803802
private def definedClasses(phase: Phase) =
804803
if (sym.isDefinedInCurrentRun)
805804
ctx.atPhase(phase) { implicit ctx =>
806-
toDenot(sym).info.decls.filter(_.isClass)
805+
sym.info.decls.filter(_.isClass)
807806
}
808807
else Nil
809808

810-
def annotations: List[Annotation] = toDenot(sym).annotations
809+
def annotations: List[Annotation] = sym.annotations
811810
def companionModuleMembers: List[Symbol] = {
812811
// phase travel to exitingPickler: this makes sure that memberClassesOf only sees member classes,
813812
// not local classes of the companion module (E in the exmaple) that were lifted by lambdalift.
814813
if (linkedClass.isTopLevelModuleClass) /*exitingPickler*/ linkedClass.memberClasses
815814
else Nil
816815
}
817816
def fieldSymbols: List[Symbol] = {
818-
toDenot(sym).info.decls.filter(p => p.isTerm && !p.is(Flags.Method))
817+
sym.info.decls.filter(p => p.isTerm && !p.is(Flags.Method))
819818
}
820819
def methodSymbols: List[Symbol] =
821-
for (f <- toDenot(sym).info.decls.toList if f.isMethod && f.isTerm && !f.isModule) yield f
820+
for (f <- sym.info.decls.toList if f.isMethod && f.isTerm && !f.isModule) yield f
822821
def serialVUID: Option[Long] = None
823822

824823

@@ -842,7 +841,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
842841
def superInterfaces: List[Symbol] = {
843842
val directlyInheritedTraits = decorateSymbol(sym).directlyInheritedTraits
844843
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
845-
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.symbol.asClass.baseClasses.drop(1)).toSet
844+
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.baseClasses.drop(1)).toSet
846845
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
847846
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait))
848847
// if (additional.nonEmpty)
@@ -856,7 +855,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
856855
*/
857856
def isTopLevelModuleClass: Boolean = sym.isModuleClass &&
858857
ctx.atPhase(ctx.flattenPhase) { implicit ctx =>
859-
toDenot(sym).owner.is(Flags.PackageClass)
858+
sym.owner.is(Flags.PackageClass)
860859
}
861860

862861
/**
@@ -874,7 +873,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
874873
def addRemoteRemoteExceptionAnnotation: Unit = ()
875874

876875
def samMethod(): Symbol =
877-
toDenot(sym).info.abstractTermMembers.headOption.getOrElse(toDenot(sym).info.member(nme.apply)).symbol
876+
sym.info.abstractTermMembers.headOption.getOrElse(sym.info.member(nme.apply)).symbol
878877
}
879878

880879

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
697697
val sym = tree.symbol
698698
val prevDenot = sym.denot(ctx.withPhase(trans))
699699
if (prevDenot.effectiveOwner == from.skipWeakOwner) {
700-
val d = sym.copySymDenotation(owner = to)
700+
val d = sym.denot.copySymDenotation(owner = to)
701701
d.installAfter(trans)
702702
d.transformAfter(trans, d => if (d.owner eq from) d.copySymDenotation(owner = to) else d)
703703
}

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class JavaPlatform extends Platform {
2121
}
2222

2323
// The given symbol is a method with the right name and signature to be a runnable java program.
24-
def isMainMethod(sym: SymDenotation)(implicit ctx: Context) =
24+
def isMainMethod(sym: Symbol)(implicit ctx: Context) =
2525
(sym.name == nme.main) && (sym.info match {
2626
case MethodTpe(_, defn.ArrayOf(el) :: Nil, restpe) => el =:= defn.StringType && (restpe isRef defn.UnitClass)
2727
case _ => false

compiler/src/dotty/tools/dotc/config/Platform.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ abstract class Platform {
3939
def newClassLoader(bin: AbstractFile)(implicit ctx: Context): SymbolLoader
4040

4141
/** The given symbol is a method with the right name and signature to be a runnable program. */
42-
def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean
42+
def isMainMethod(sym: Symbol)(implicit ctx: Context): Boolean
4343

4444
/** The given class has a main method. */
4545
final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean =
46-
sym.info.member(nme.main).hasAltWith {
47-
case x: SymDenotation => isMainMethod(x)
48-
case _ => false
49-
}
46+
sym.info.member(nme.main).hasAltWith(d => isMainMethod(d.symbol))
5047
}
5148

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ object Annotations {
148148

149149
def makeAlias(sym: TermSymbol)(implicit ctx: Context) =
150150
apply(defn.AliasAnnot, List(
151-
ref(TermRef(sym.owner.thisType, sym.name, sym))))
151+
ref(TermRef(sym.owner.thisType, sym.name, sym.denot))))
152152

153153
/** Extractor for child annotations */
154154
object Child {
@@ -157,7 +157,7 @@ object Annotations {
157157
def apply(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = {
158158
def makeChildLater(implicit ctx: Context) = {
159159
val sym = delayedSym(ctx)
160-
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
160+
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym.denot)), Nil)
161161
}
162162
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
163163
}

0 commit comments

Comments
 (0)