Skip to content

Commit 43df1a2

Browse files
oderskyallanrenucci
authored andcommitted
Eliminate redundant "symbol" calls on Symbols.
Everyone of these is a roundtrip `toDenot(stm).symbol`.
1 parent 53865ff commit 43df1a2

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
842842
def superInterfaces: List[Symbol] = {
843843
val directlyInheritedTraits = decorateSymbol(sym).directlyInheritedTraits
844844
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
845-
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.symbol.asClass.baseClasses.drop(1)).toSet
845+
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
846846
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
847847
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait))
848848
// if (additional.nonEmpty)

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class Definitions {
625625
lazy val Product_productPrefixR = ProductClass.requiredMethodRef(nme.productPrefix)
626626
def Product_productPrefix(implicit ctx: Context) = Product_productPrefixR.symbol
627627
lazy val LanguageModuleRef = ctx.requiredModule("scala.language")
628-
def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.symbol.moduleClass.asClass
628+
def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.moduleClass.asClass
629629
lazy val NonLocalReturnControlType: TypeRef = ctx.requiredClassRef("scala.runtime.NonLocalReturnControl")
630630
lazy val SelectableType: TypeRef = ctx.requiredClassRef("scala.Selectable")
631631

@@ -635,19 +635,13 @@ class Definitions {
635635

636636
lazy val QuotedExprType = ctx.requiredClassRef("scala.quoted.Expr")
637637
def QuotedExprClass(implicit ctx: Context) = QuotedExprType.symbol.asClass
638-
639-
lazy val QuotedExprModuleType = ctx.requiredModuleRef("scala.quoted.Expr")
640-
def QuotedExprModule(implicit ctx: Context) = QuotedExprModuleType.symbol
638+
def QuotedExprModule(implicit ctx: Context) = QuotedExprClass.companionModule
641639
lazy val QuotedExpr_applyR = QuotedExprModule.requiredMethodRef(nme.apply)
642640
def QuotedExpr_apply(implicit ctx: Context) = QuotedExpr_applyR.symbol
643-
644-
lazy val QuotedExpr_spliceR = QuotedExprClass.requiredMethod(nme.UNARY_~)
645-
def QuotedExpr_~(implicit ctx: Context) = QuotedExpr_spliceR.symbol
646-
lazy val QuotedExpr_runR = QuotedExprClass.requiredMethodRef(nme.run)
647-
def QuotedExpr_run(implicit ctx: Context) = QuotedExpr_runR.symbol
641+
lazy val QuotedExpr_~ = QuotedExprClass.requiredMethod(nme.UNARY_~)
648642

649643
lazy val QuotedExprsModule = ctx.requiredModule("scala.quoted.Exprs")
650-
def QuotedExprsClass(implicit ctx: Context) = QuotedExprsModule.symbol.asClass
644+
def QuotedExprsClass(implicit ctx: Context) = QuotedExprsModule.asClass
651645

652646
lazy val QuotedTypeType = ctx.requiredClassRef("scala.quoted.Type")
653647
def QuotedTypeClass(implicit ctx: Context) = QuotedTypeType.symbol.asClass

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,13 @@ object SymDenotations {
580580
myFlags.is(ModuleClass) && (myFlags.is(PackageClass) || isStatic)
581581

582582
/** Is this denotation defined in the same scope and compilation unit as that symbol? */
583-
final def isCoDefinedWith(that: Symbol)(implicit ctx: Context) =
584-
(this.effectiveOwner == that.effectiveOwner) &&
583+
final def isCoDefinedWith(other: Symbol)(implicit ctx: Context) =
584+
(this.effectiveOwner == other.effectiveOwner) &&
585585
( !(this.effectiveOwner is PackageClass)
586-
|| this.unforcedIsAbsent || that.unforcedIsAbsent
586+
|| this.unforcedIsAbsent || other.unforcedIsAbsent
587587
|| { // check if they are defined in the same file(or a jar)
588588
val thisFile = this.symbol.associatedFile
589-
val thatFile = that.symbol.associatedFile
589+
val thatFile = other.associatedFile
590590
( thisFile == null
591591
|| thatFile == null
592592
|| thisFile.path == thatFile.path // Cheap possibly wrong check, then expensive normalization

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,20 @@ object Symbols {
564564
* Overridden in ClassSymbol
565565
*/
566566
def associatedFile(implicit ctx: Context): AbstractFile =
567-
if (lastDenot == null) null else lastDenot.topLevelClass.symbol.associatedFile
567+
if (lastDenot == null) null else lastDenot.topLevelClass.associatedFile
568568

569569
/** The class file from which this class was generated, null if not applicable. */
570570
final def binaryFile(implicit ctx: Context): AbstractFile = {
571571
val file = associatedFile
572572
if (file != null && file.extension == "class") file else null
573573
}
574574

575+
/** A trap to avoid calling x.symbol on something that is already a symbol.
576+
* This would be expanded to `toDenot(x).symbol` which is guaraneteed to be
577+
* the same as `x`
578+
*/
579+
final def symbol: Nothing = unsupported("symbol")
580+
575581
/** The source file from which this class was generated, null if not applicable. */
576582
final def sourceFile(implicit ctx: Context): AbstractFile = {
577583
val file = associatedFile

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ClassfileParser(
172172
setClassInfo(classRoot, classInfo)
173173
setClassInfo(moduleRoot, staticInfo)
174174
} else if (result == Some(NoEmbedded)) {
175-
for (sym <- List(moduleRoot.sourceModule.symbol, moduleRoot.symbol, classRoot.symbol)) {
175+
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
176176
classRoot.owner.asClass.delete(sym)
177177
if (classRoot.owner == defn.ScalaShadowingPackageClass) {
178178
// Symbols in scalaShadowing are also added to scala

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ object Interactive {
231231
val boundaryCtx = ctx.withOwner(boundary)
232232
def exclude(sym: Symbol) = sym.isAbsent || sym.is(Synthetic) || sym.is(Artifact)
233233
def addMember(name: Name, buf: mutable.Buffer[SingleDenotation]): Unit =
234-
buf ++= prefix.member(name).altsWith(d =>
235-
!exclude(d) && d.symbol.isAccessibleFrom(prefix)(boundaryCtx))
234+
buf ++= prefix.member(name).altsWith(sym =>
235+
!exclude(sym) && sym.isAccessibleFrom(prefix)(boundaryCtx))
236236
prefix.memberDenots(completionsFilter, addMember).map(_.symbol).toList
237237
}
238238
else Nil

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ object LambdaLift {
190190
def traverse(tree: Tree)(implicit ctx: Context) = try { //debug
191191
val sym = tree.symbol
192192

193-
def enclosure = ctx.owner.enclosingMethod.symbol
193+
def enclosure = ctx.owner.enclosingMethod
194194

195195
def narrowTo(thisClass: ClassSymbol) = {
196196
val enclMethod = enclosure

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
132132
initName,
133133
Protected | Synthetic | Method,
134134
sym.info,
135-
coord = sym.symbol.coord).enteredAfter(thisPhase))
135+
coord = sym.coord).enteredAfter(thisPhase))
136136
}
137137
}.asTerm
138138

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ object Inferencing {
279279
case tp: TypeRef =>
280280
val companion = tp.classSymbol.companionModule
281281
if (companion.exists)
282-
companion.termRef.asSeenFrom(tp.prefix, companion.symbol.owner)
282+
companion.termRef.asSeenFrom(tp.prefix, companion.owner)
283283
else NoType
284284
case _ => NoType
285285
}

0 commit comments

Comments
 (0)