Skip to content

Commit 9694021

Browse files
Merge pull request #4722 from dotty-staging/cherry-pick-4512
Cherry picks from #4512
2 parents 2014ffe + 0f4bf0d commit 9694021

13 files changed

+39
-41
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: 5 additions & 14 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
@@ -668,10 +662,7 @@ class Definitions {
668662
def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType")
669663

670664
lazy val TastyTopLevelSpliceModule = ctx.requiredModule("scala.tasty.TopLevelSplice")
671-
def TastyTopLevelSpliceModuleClass(implicit ctx: Context) = TastyTopLevelSpliceModule.symbol.asClass
672-
673-
lazy val TastyTopLevelSplice_compilationTopLevelSpliceR = TastyTopLevelSpliceModule.requiredMethod("tastyContext")
674-
def TastyTopLevelSplice_compilationTopLevelSplice(implicit ctx: Context) = TastyTopLevelSplice_compilationTopLevelSpliceR.symbol
665+
lazy val TastyTopLevelSplice_compilationTopLevelSplice = TastyTopLevelSpliceModule.requiredMethod("tastyContext")
675666

676667
lazy val EqType = ctx.requiredClassRef("scala.Eq")
677668
def EqClass(implicit ctx: Context) = EqType.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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,22 @@ 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+
* With the given setup, all such calls will give implicit-not found errors
579+
*/
580+
final def symbol(implicit ev: DontUseSymbolOnSymbol): Nothing = unsupported("symbol")
581+
type DontUseSymbolOnSymbol
582+
575583
/** The source file from which this class was generated, null if not applicable. */
576584
final def sourceFile(implicit ctx: Context): AbstractFile = {
577585
val file = associatedFile
@@ -797,5 +805,4 @@ object Symbols {
797805

798806
@inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
799807
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())
800-
801808
}

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/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
351351
val owner = if (atEnd) loadingMirror.RootClass else readSymbolRef()
352352

353353
def adjust(denot: Denotation) = {
354-
val denot1 = denot.disambiguate(d => p(d.symbol))
354+
val denot1 = denot.disambiguate(p)
355355
val sym = denot1.symbol
356356
if (denot.exists && !denot1.exists) { // !!!DEBUG
357357
val alts = denot.alternatives map (d => d + ":" + d.info + "/" + d.signature)

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/transform/TreeExtractors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ object TreeExtractors {
3636
object ValueClassUnbox {
3737
def unapply(t: Tree)(implicit ctx: Context): Option[Tree] = t match {
3838
case Apply(sel @ Select(ref, _), Nil) =>
39-
val d = ref.tpe.widenDealias.typeSymbol.denot
40-
if (isDerivedValueClass(d) && (sel.symbol eq valueClassUnbox(d.asClass))) {
39+
val sym = ref.tpe.widenDealias.typeSymbol
40+
if (isDerivedValueClass(sym) && (sel.symbol eq valueClassUnbox(sym.asClass))) {
4141
Some(ref)
4242
} else
4343
None

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package transform
44
import core._
55
import Types._
66
import Symbols._
7-
import SymDenotations._
87
import Contexts._
98
import Flags._
109
import StdNames._
@@ -13,7 +12,8 @@ import SymUtils._
1312
/** Methods that apply to user-defined value classes */
1413
object ValueClasses {
1514

16-
def isDerivedValueClass(d: SymDenotation)(implicit ctx: Context) = {
15+
def isDerivedValueClass(sym: Symbol)(implicit ctx: Context): Boolean = {
16+
val d = sym.denot
1717
!ctx.settings.XnoValueClasses.value &&
1818
!d.isRefinementClass &&
1919
d.isValueClass &&
@@ -33,27 +33,27 @@ object ValueClasses {
3333
}
3434

3535
/** The member of a derived value class that unboxes it. */
36-
def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =
36+
def valueClassUnbox(cls: ClassSymbol)(implicit ctx: Context): Symbol =
3737
// (info.decl(nme.unbox)).orElse(...) uncomment once we accept unbox methods
38-
d.classInfo.decls.find(_.is(ParamAccessor))
38+
cls.classInfo.decls.find(_.is(ParamAccessor))
3939

4040
/** For a value class `d`, this returns the synthetic cast from the underlying type to
4141
* ErasedValueType defined in the companion module. This method is added to the module
4242
* and further described in [[ExtensionMethods]].
4343
*/
44-
def u2evt(d: ClassDenotation)(implicit ctx: Context): Symbol =
45-
d.linkedClass.info.decl(nme.U2EVT).symbol
44+
def u2evt(cls: ClassSymbol)(implicit ctx: Context): Symbol =
45+
cls.linkedClass.info.decl(nme.U2EVT).symbol
4646

4747
/** For a value class `d`, this returns the synthetic cast from ErasedValueType to the
4848
* underlying type defined in the companion module. This method is added to the module
4949
* and further described in [[ExtensionMethods]].
5050
*/
51-
def evt2u(d: ClassDenotation)(implicit ctx: Context): Symbol =
52-
d.linkedClass.info.decl(nme.EVT2U).symbol
51+
def evt2u(cls: ClassSymbol)(implicit ctx: Context): Symbol =
52+
cls.linkedClass.info.decl(nme.EVT2U).symbol
5353

5454
/** The unboxed type that underlies a derived value class */
55-
def underlyingOfValueClass(d: ClassDenotation)(implicit ctx: Context): Type =
56-
valueClassUnbox(d).info.resultType
55+
def underlyingOfValueClass(sym: ClassSymbol)(implicit ctx: Context): Type =
56+
valueClassUnbox(sym).info.resultType
5757

5858
/** Whether a value class wraps itself */
5959
def isCyclic(cls: ClassSymbol)(implicit ctx: Context): Boolean = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
9292
case t @ NewCaseClassValDef(fun, args) if newFieldsMapping.contains(t.symbol) =>
9393
val newFields = newFieldsMapping(t.symbol).values.toList
9494
val newFieldsDefs = newFields.zip(args).map { case (nf, arg) =>
95-
val rhs = arg.changeOwnerAfter(t.symbol, nf.symbol, simplifyPhase)
95+
val rhs = arg.changeOwnerAfter(t.symbol, nf, simplifyPhase)
9696
ValDef(nf.asTerm, rhs)
9797
}
9898
val recreate = cpy.ValDef(t)(rhs = fun.appliedToArgs(newFields.map(x => ref(x))))

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)