diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index c3ad297c860b..45ac2570e643 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -842,7 +842,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def superInterfaces: List[Symbol] = { val directlyInheritedTraits = decorateSymbol(sym).directlyInheritedTraits val directlyInheritedTraitsSet = directlyInheritedTraits.toSet - val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.symbol.asClass.baseClasses.drop(1)).toSet + val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet val superCalls = superCallsMap.getOrElse(sym, Set.empty) val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait)) // if (additional.nonEmpty) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index f5cfb43745f8..77cca3dffe85 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -625,7 +625,7 @@ class Definitions { lazy val Product_productPrefixR = ProductClass.requiredMethodRef(nme.productPrefix) def Product_productPrefix(implicit ctx: Context) = Product_productPrefixR.symbol lazy val LanguageModuleRef = ctx.requiredModule("scala.language") - def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.symbol.moduleClass.asClass + def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.moduleClass.asClass lazy val NonLocalReturnControlType: TypeRef = ctx.requiredClassRef("scala.runtime.NonLocalReturnControl") lazy val SelectableType: TypeRef = ctx.requiredClassRef("scala.Selectable") @@ -635,19 +635,13 @@ class Definitions { lazy val QuotedExprType = ctx.requiredClassRef("scala.quoted.Expr") def QuotedExprClass(implicit ctx: Context) = QuotedExprType.symbol.asClass - - lazy val QuotedExprModuleType = ctx.requiredModuleRef("scala.quoted.Expr") - def QuotedExprModule(implicit ctx: Context) = QuotedExprModuleType.symbol + def QuotedExprModule(implicit ctx: Context) = QuotedExprClass.companionModule lazy val QuotedExpr_applyR = QuotedExprModule.requiredMethodRef(nme.apply) def QuotedExpr_apply(implicit ctx: Context) = QuotedExpr_applyR.symbol - - lazy val QuotedExpr_spliceR = QuotedExprClass.requiredMethod(nme.UNARY_~) - def QuotedExpr_~(implicit ctx: Context) = QuotedExpr_spliceR.symbol - lazy val QuotedExpr_runR = QuotedExprClass.requiredMethodRef(nme.run) - def QuotedExpr_run(implicit ctx: Context) = QuotedExpr_runR.symbol + lazy val QuotedExpr_~ = QuotedExprClass.requiredMethod(nme.UNARY_~) lazy val QuotedExprsModule = ctx.requiredModule("scala.quoted.Exprs") - def QuotedExprsClass(implicit ctx: Context) = QuotedExprsModule.symbol.asClass + def QuotedExprsClass(implicit ctx: Context) = QuotedExprsModule.asClass lazy val QuotedTypeType = ctx.requiredClassRef("scala.quoted.Type") def QuotedTypeClass(implicit ctx: Context) = QuotedTypeType.symbol.asClass @@ -668,10 +662,7 @@ class Definitions { def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType") lazy val TastyTopLevelSpliceModule = ctx.requiredModule("scala.tasty.TopLevelSplice") - def TastyTopLevelSpliceModuleClass(implicit ctx: Context) = TastyTopLevelSpliceModule.symbol.asClass - - lazy val TastyTopLevelSplice_compilationTopLevelSpliceR = TastyTopLevelSpliceModule.requiredMethod("tastyContext") - def TastyTopLevelSplice_compilationTopLevelSplice(implicit ctx: Context) = TastyTopLevelSplice_compilationTopLevelSpliceR.symbol + lazy val TastyTopLevelSplice_compilationTopLevelSplice = TastyTopLevelSpliceModule.requiredMethod("tastyContext") lazy val EqType = ctx.requiredClassRef("scala.Eq") def EqClass(implicit ctx: Context) = EqType.symbol.asClass diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 95301176d78f..7fc436d79126 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -580,13 +580,13 @@ object SymDenotations { myFlags.is(ModuleClass) && (myFlags.is(PackageClass) || isStatic) /** Is this denotation defined in the same scope and compilation unit as that symbol? */ - final def isCoDefinedWith(that: Symbol)(implicit ctx: Context) = - (this.effectiveOwner == that.effectiveOwner) && + final def isCoDefinedWith(other: Symbol)(implicit ctx: Context) = + (this.effectiveOwner == other.effectiveOwner) && ( !(this.effectiveOwner is PackageClass) - || this.unforcedIsAbsent || that.unforcedIsAbsent + || this.unforcedIsAbsent || other.unforcedIsAbsent || { // check if they are defined in the same file(or a jar) val thisFile = this.symbol.associatedFile - val thatFile = that.symbol.associatedFile + val thatFile = other.associatedFile ( thisFile == null || thatFile == null || thisFile.path == thatFile.path // Cheap possibly wrong check, then expensive normalization diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 7cae7b1822ab..51ad8507f4aa 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -564,7 +564,7 @@ object Symbols { * Overridden in ClassSymbol */ def associatedFile(implicit ctx: Context): AbstractFile = - if (lastDenot == null) null else lastDenot.topLevelClass.symbol.associatedFile + if (lastDenot == null) null else lastDenot.topLevelClass.associatedFile /** The class file from which this class was generated, null if not applicable. */ final def binaryFile(implicit ctx: Context): AbstractFile = { @@ -572,6 +572,14 @@ object Symbols { if (file != null && file.extension == "class") file else null } + /** A trap to avoid calling x.symbol on something that is already a symbol. + * This would be expanded to `toDenot(x).symbol` which is guaraneteed to be + * the same as `x`. + * With the given setup, all such calls will give implicit-not found errors + */ + final def symbol(implicit ev: DontUseSymbolOnSymbol): Nothing = unsupported("symbol") + type DontUseSymbolOnSymbol + /** The source file from which this class was generated, null if not applicable. */ final def sourceFile(implicit ctx: Context): AbstractFile = { val file = associatedFile @@ -797,5 +805,4 @@ object Symbols { @inline def newMutableSymbolMap[T]: MutableSymbolMap[T] = new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]()) - } diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 86d7866041ad..2379ddfc610b 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -172,7 +172,7 @@ class ClassfileParser( setClassInfo(classRoot, classInfo) setClassInfo(moduleRoot, staticInfo) } else if (result == Some(NoEmbedded)) { - for (sym <- List(moduleRoot.sourceModule.symbol, moduleRoot.symbol, classRoot.symbol)) { + for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) { classRoot.owner.asClass.delete(sym) if (classRoot.owner == defn.ScalaShadowingPackageClass) { // Symbols in scalaShadowing are also added to scala diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index f7dbda218e0e..29a311a16f1f 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -351,7 +351,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val owner = if (atEnd) loadingMirror.RootClass else readSymbolRef() def adjust(denot: Denotation) = { - val denot1 = denot.disambiguate(d => p(d.symbol)) + val denot1 = denot.disambiguate(p) val sym = denot1.symbol if (denot.exists && !denot1.exists) { // !!!DEBUG val alts = denot.alternatives map (d => d + ":" + d.info + "/" + d.signature) diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index 5cd531338e6d..5c17f62a79da 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -231,8 +231,8 @@ object Interactive { val boundaryCtx = ctx.withOwner(boundary) def exclude(sym: Symbol) = sym.isAbsent || sym.is(Synthetic) || sym.is(Artifact) def addMember(name: Name, buf: mutable.Buffer[SingleDenotation]): Unit = - buf ++= prefix.member(name).altsWith(d => - !exclude(d) && d.symbol.isAccessibleFrom(prefix)(boundaryCtx)) + buf ++= prefix.member(name).altsWith(sym => + !exclude(sym) && sym.isAccessibleFrom(prefix)(boundaryCtx)) prefix.memberDenots(completionsFilter, addMember).map(_.symbol).toList } else Nil diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 6cd1ad06156a..f7ffb7289568 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -190,7 +190,7 @@ object LambdaLift { def traverse(tree: Tree)(implicit ctx: Context) = try { //debug val sym = tree.symbol - def enclosure = ctx.owner.enclosingMethod.symbol + def enclosure = ctx.owner.enclosingMethod def narrowTo(thisClass: ClassSymbol) = { val enclMethod = enclosure diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 437a8a45af3c..04ececdc2b1b 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -132,7 +132,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => initName, Protected | Synthetic | Method, sym.info, - coord = sym.symbol.coord).enteredAfter(thisPhase)) + coord = sym.coord).enteredAfter(thisPhase)) } }.asTerm diff --git a/compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala b/compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala index 7a5c5df9db98..680f21bff1ac 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala @@ -36,8 +36,8 @@ object TreeExtractors { object ValueClassUnbox { def unapply(t: Tree)(implicit ctx: Context): Option[Tree] = t match { case Apply(sel @ Select(ref, _), Nil) => - val d = ref.tpe.widenDealias.typeSymbol.denot - if (isDerivedValueClass(d) && (sel.symbol eq valueClassUnbox(d.asClass))) { + val sym = ref.tpe.widenDealias.typeSymbol + if (isDerivedValueClass(sym) && (sel.symbol eq valueClassUnbox(sym.asClass))) { Some(ref) } else None diff --git a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala index a186ec0feee0..120424204274 100644 --- a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -4,7 +4,6 @@ package transform import core._ import Types._ import Symbols._ -import SymDenotations._ import Contexts._ import Flags._ import StdNames._ @@ -13,7 +12,8 @@ import SymUtils._ /** Methods that apply to user-defined value classes */ object ValueClasses { - def isDerivedValueClass(d: SymDenotation)(implicit ctx: Context) = { + def isDerivedValueClass(sym: Symbol)(implicit ctx: Context): Boolean = { + val d = sym.denot !ctx.settings.XnoValueClasses.value && !d.isRefinementClass && d.isValueClass && @@ -33,27 +33,27 @@ object ValueClasses { } /** The member of a derived value class that unboxes it. */ - def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol = + def valueClassUnbox(cls: ClassSymbol)(implicit ctx: Context): Symbol = // (info.decl(nme.unbox)).orElse(...) uncomment once we accept unbox methods - d.classInfo.decls.find(_.is(ParamAccessor)) + cls.classInfo.decls.find(_.is(ParamAccessor)) /** For a value class `d`, this returns the synthetic cast from the underlying type to * ErasedValueType defined in the companion module. This method is added to the module * and further described in [[ExtensionMethods]]. */ - def u2evt(d: ClassDenotation)(implicit ctx: Context): Symbol = - d.linkedClass.info.decl(nme.U2EVT).symbol + def u2evt(cls: ClassSymbol)(implicit ctx: Context): Symbol = + cls.linkedClass.info.decl(nme.U2EVT).symbol /** For a value class `d`, this returns the synthetic cast from ErasedValueType to the * underlying type defined in the companion module. This method is added to the module * and further described in [[ExtensionMethods]]. */ - def evt2u(d: ClassDenotation)(implicit ctx: Context): Symbol = - d.linkedClass.info.decl(nme.EVT2U).symbol + def evt2u(cls: ClassSymbol)(implicit ctx: Context): Symbol = + cls.linkedClass.info.decl(nme.EVT2U).symbol /** The unboxed type that underlies a derived value class */ - def underlyingOfValueClass(d: ClassDenotation)(implicit ctx: Context): Type = - valueClassUnbox(d).info.resultType + def underlyingOfValueClass(sym: ClassSymbol)(implicit ctx: Context): Type = + valueClassUnbox(sym).info.resultType /** Whether a value class wraps itself */ def isCyclic(cls: ClassSymbol)(implicit ctx: Context): Boolean = { diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala b/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala index 8134764fd3cf..64bff5521381 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala @@ -92,7 +92,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation { case t @ NewCaseClassValDef(fun, args) if newFieldsMapping.contains(t.symbol) => val newFields = newFieldsMapping(t.symbol).values.toList val newFieldsDefs = newFields.zip(args).map { case (nf, arg) => - val rhs = arg.changeOwnerAfter(t.symbol, nf.symbol, simplifyPhase) + val rhs = arg.changeOwnerAfter(t.symbol, nf, simplifyPhase) ValDef(nf.asTerm, rhs) } val recreate = cpy.ValDef(t)(rhs = fun.appliedToArgs(newFields.map(x => ref(x)))) diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 9b6c128d023b..f0611878b666 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -279,7 +279,7 @@ object Inferencing { case tp: TypeRef => val companion = tp.classSymbol.companionModule if (companion.exists) - companion.termRef.asSeenFrom(tp.prefix, companion.symbol.owner) + companion.termRef.asSeenFrom(tp.prefix, companion.owner) else NoType case _ => NoType }