diff --git a/compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala b/compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala index 8e7cfc688724..7965a8f4c880 100644 --- a/compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala +++ b/compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala @@ -61,11 +61,11 @@ object CollectEntryPoints{ val StringType = d.StringType // The given class has a main method. def hasJavaMainMethod(sym: Symbol): Boolean = - (toDenot(sym).info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol)) + (sym.info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol)) def fail(msg: String, pos: Position = sym.pos) = { ctx.warning( sym.name + - s" has a main method with parameter type Array[String], but ${toDenot(sym).fullName} will not be a runnable program.\n Reason: $msg", + s" has a main method with parameter type Array[String], but ${sym.fullName} will not be a runnable program.\n Reason: $msg", sourcePos(sym.pos) // TODO: make this next claim true, if possible // by generating valid main methods as static in module classes @@ -77,7 +77,7 @@ object CollectEntryPoints{ def failNoForwarder(msg: String) = { fail(s"$msg, which means no static forwarder can be generated.\n") } - val possibles = if (sym.flags is Flags.Module) (toDenot(sym).info nonPrivateMember nme.main).alternatives else Nil + val possibles = if (sym.flags is Flags.Module) (sym.info nonPrivateMember nme.main).alternatives else Nil val hasApproximate = possibles exists { m => m.info match { case MethodTpe(_, p :: Nil, _) => p.typeSymbol == defn.ArrayClass @@ -94,7 +94,7 @@ object CollectEntryPoints{ if (hasJavaMainMethod(companion)) failNoForwarder("companion contains its own main method") - else if (toDenot(companion).info.member(nme.main) != NoDenotation) + else if (companion.info.member(nme.main) != NoDenotation) // this is only because forwarders aren't smart enough yet failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)") else if (companion.flags is Flags.Trait) @@ -103,7 +103,7 @@ object CollectEntryPoints{ // attempts to be java main methods. else (possibles exists(x=> isJavaMainMethod(x.symbol))) || { possibles exists { m => - toDenot(m.symbol).info match { + m.symbol.info match { case t: PolyType => fail("main methods cannot be generic.") case MethodTpe(paramNames, paramTypes, resultType) => diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 32061e0d7561..bbf2f2edb826 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -39,7 +39,6 @@ import dotty.tools.dotc.core.Names.TypeName import scala.annotation.tailrec class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(implicit ctx: Context) extends BackendInterface{ - import Symbols.{toDenot, toClassDenot} // Dotty deviation: Need to (re-)import implicit decorators here because otherwise // they would be shadowed by the more deeply nested `symHelper` decorator. @@ -143,7 +142,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma val externalEqualsNumNum: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum) val externalEqualsNumChar: Symbol = NoSymbol // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private val externalEqualsNumObject: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject) - val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(toDenot(_).info.firstParamTypes.size == 2).symbol + val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(_.info.firstParamTypes.size == 2).symbol val MaxFunctionArity: Int = Definitions.MaxImplementedFunctionArity val FunctionClass: Array[Symbol] = defn.FunctionClassPerRun() val AbstractFunctionClass: Array[Symbol] = defn.AbstractFunctionClassPerRun() @@ -214,7 +213,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma implicit val ClosureTag: ClassTag[Closure] = ClassTag[Closure](classOf[Closure]) def isRuntimeVisible(annot: Annotation): Boolean = - if (toDenot(annot.atp.typeSymbol).hasAnnotation(AnnotationRetentionAttr)) + if (annot.atp.typeSymbol.hasAnnotation(AnnotationRetentionAttr)) retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr else { // SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the @@ -264,8 +263,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma av.visitEnum(name, edesc, evalue) } else { // println(i"not an enum: ${t.symbol} / ${t.symbol.denot.owner} / ${t.symbol.denot.owner.isTerm} / ${t.symbol.denot.owner.flags}") - assert(toDenot(t.symbol).name.is(DefaultGetterName), - s"${toDenot(t.symbol).name.debugString}") // this should be default getter. do not emmit. + assert(t.symbol.name.is(DefaultGetterName), + s"${t.symbol.name.debugString}") // this should be default getter. do not emmit. } case t: SeqLiteral => val arrAnnotV: AnnotationVisitor = av.visitArray(name) @@ -273,7 +272,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma arrAnnotV.visitEnd() case Apply(fun, args) if fun.symbol == defn.ArrayClass.primaryConstructor || - toDenot(fun.symbol).owner == defn.ArrayClass.linkedClass && fun.symbol.name == nme_apply => + fun.symbol.owner == defn.ArrayClass.linkedClass && fun.symbol.name == nme_apply => val arrAnnotV: AnnotationVisitor = av.visitArray(name) var actualArgs = if (fun.tpe.isImplicitMethod) { @@ -655,29 +654,29 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def fullName(sep: Char): String = sym.showFullName def fullName: String = sym.showFullName def simpleName: Name = sym.name - def javaSimpleName: String = toDenot(sym).name.mangledString // addModuleSuffix(simpleName.dropLocal) + def javaSimpleName: String = sym.name.mangledString // addModuleSuffix(simpleName.dropLocal) def javaBinaryName: String = javaClassName.replace('.', '/') // TODO: can we make this a string? addModuleSuffix(fullNameInternal('/')) - def javaClassName: String = toDenot(sym).fullName.mangledString // addModuleSuffix(fullNameInternal('.')).toString + def javaClassName: String = sym.fullName.mangledString // addModuleSuffix(fullNameInternal('.')).toString def name: Name = sym.name def rawname: String = { - val original = toDenot(sym).initial + val original = sym.initial sym.name(ctx.withPhase(original.validFor.phaseId)).mangledString } // types - def info: Type = toDenot(sym).info - def tpe: Type = toDenot(sym).info // todo whats the differentce between tpe and info? - def thisType: Type = toDenot(sym).thisType + def info: Type = sym.info + def tpe: Type = sym.info // todo whats the differentce between tpe and info? + def thisType: Type = sym.thisType // tests def isClass: Boolean = { sym.isPackageObject || (sym.isClass) } def isType: Boolean = sym.isType - def isAnonymousClass: Boolean = toDenot(sym).isAnonymousClass - def isConstructor: Boolean = toDenot(sym).isConstructor + def isAnonymousClass: Boolean = sym.isAnonymousClass + def isConstructor: Boolean = sym.isConstructor def isExpanded: Boolean = sym.name.is(ExpandedName) - def isAnonymousFunction: Boolean = toDenot(sym).isAnonymousFunction + def isAnonymousFunction: Boolean = sym.isAnonymousFunction def isMethod: Boolean = sym is Flags.Method def isPublic: Boolean = sym.flags.is(Flags.EmptyFlags, Flags.Private | Flags.Protected) def isSynthetic: Boolean = sym is Flags.Synthetic @@ -689,22 +688,22 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def hasPackageFlag: Boolean = sym is Flags.Package def isImplClass: Boolean = sym is Flags.ImplClass def isInterface: Boolean = (sym is Flags.PureInterface) || (sym is Flags.Trait) - def isGetter: Boolean = toDenot(sym).isGetter - def isSetter: Boolean = toDenot(sym).isSetter + def isGetter: Boolean = sym.isGetter + def isSetter: Boolean = sym.isSetter def isGetClass: Boolean = sym eq defn.Any_getClass def isJavaDefined: Boolean = sym is Flags.JavaDefined - def isJavaDefaultMethod: Boolean = !((sym is Flags.Deferred) || toDenot(sym).isClassConstructor) + def isJavaDefaultMethod: Boolean = !((sym is Flags.Deferred) || sym.isClassConstructor) def isDeferred: Boolean = sym is Flags.Deferred def isPrivate: Boolean = sym is Flags.Private def getsJavaFinalFlag: Boolean = - isFinal && !toDenot(sym).isClassConstructor && !(sym is Flags.Mutable) && !(sym.enclosingClass is Flags.Trait) + isFinal && !sym.isClassConstructor && !(sym is Flags.Mutable) && !(sym.enclosingClass is Flags.Trait) def getsJavaPrivateFlag: Boolean = isPrivate //|| (sym.isPrimaryConstructor && sym.owner.isTopLevelModuleClass) def isFinal: Boolean = sym is Flags.Final def isStaticMember: Boolean = (sym ne NoSymbol) && - ((sym is Flags.JavaStatic) || (owner is Flags.ImplClass) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot)) + ((sym is Flags.JavaStatic) || (owner is Flags.ImplClass) || sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)) // guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass) @@ -720,12 +719,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def hasModuleFlag: Boolean = sym is Flags.Module def isSynchronized: Boolean = sym is Flags.Synchronized def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other) - def hasAnnotation(ann: Symbol): Boolean = toDenot(sym).hasAnnotation(ann) + def hasAnnotation(ann: Symbol): Boolean = sym.hasAnnotation(ann) def shouldEmitForwarders: Boolean = (sym is Flags.Module) && !(sym is Flags.ImplClass) && sym.isStatic def isJavaEntryPoint: Boolean = CollectEntryPoints.isJavaEntryPoint(sym) - def isClassConstructor: Boolean = toDenot(sym).isClassConstructor + def isClassConstructor: Boolean = sym.isClassConstructor /** * True for module classes of modules that are top-level or owned only by objects. Module classes @@ -736,17 +735,17 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma // scalac uses atPickling here // this would not work if modules are created after pickling // for example by specialization - val original = toDenot(sym).initial + val original = sym.initial val validity = original.validFor val shiftedContext = ctx.withPhase(validity.phaseId) - toDenot(sym)(shiftedContext).isStatic(shiftedContext) + sym.denot(shiftedContext).isStatic(shiftedContext) } def isStaticConstructor: Boolean = (isStaticMember && isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR) // navigation - def owner: Symbol = toDenot(sym).owner + def owner: Symbol = sym.owner def rawowner: Symbol = { originalOwner } @@ -754,15 +753,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma // used to populate the EnclosingMethod attribute. // it is very tricky in presence of classes(and annonymous classes) defined inside supper calls. if (sym.exists) { - val original = toDenot(sym).initial + val original = sym.initial val validity = original.validFor val shiftedContext = ctx.withPhase(validity.phaseId) - val r = toDenot(sym)(shiftedContext).maybeOwner.lexicallyEnclosingClass(shiftedContext) + val r = sym.denot(shiftedContext).maybeOwner.lexicallyEnclosingClass(shiftedContext) r } else NoSymbol - def parentSymbols: List[Symbol] = toDenot(sym).info.parents.map(_.typeSymbol) + def parentSymbols: List[Symbol] = sym.info.parents.map(_.typeSymbol) def superClass: Symbol = { - val t = toDenot(sym).asClass.superClass + val t = sym.asClass.superClass if (t.exists) t else if (sym is Flags.ModuleClass) { // workaround #371 @@ -772,23 +771,23 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma } else t } - def enclClass: Symbol = toDenot(sym).enclosingClass + def enclClass: Symbol = sym.enclosingClass def linkedClassOfClass: Symbol = linkedClass - def linkedClass: Symbol = toDenot(sym)(ctx).linkedClass(ctx) //exitingPickler(sym.linkedClassOfClass) - def companionClass: Symbol = toDenot(sym).companionClass - def companionModule: Symbol = toDenot(sym).companionModule + def linkedClass: Symbol = sym.linkedClass(ctx) //exitingPickler(sym.linkedClassOfClass) + def companionClass: Symbol = sym.companionClass + def companionModule: Symbol = sym.companionModule def companionSymbol: Symbol = if (sym is Flags.Module) companionClass else companionModule - def moduleClass: Symbol = toDenot(sym).moduleClass + def moduleClass: Symbol = sym.moduleClass def enclosingClassSym: Symbol = { if (this.isClass) { val ct = ctx.withPhase(ctx.flattenPhase.prev) - toDenot(sym)(ct).owner.enclosingClass(ct) + sym.denot(ct).owner.enclosingClass(ct) } else sym.enclosingClass(ctx.withPhase(ctx.flattenPhase.prev)) } //todo is handled specially for JavaDefined symbols in scalac // members - def primaryConstructor: Symbol = toDenot(sym).primaryConstructor + def primaryConstructor: Symbol = sym.primaryConstructor /** For currently compiled classes: All locally defined classes including local classes. * The empty list for classes that are not currently compiled. @@ -803,11 +802,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma private def definedClasses(phase: Phase) = if (sym.isDefinedInCurrentRun) ctx.atPhase(phase) { implicit ctx => - toDenot(sym).info.decls.filter(_.isClass) + sym.info.decls.filter(_.isClass) } else Nil - def annotations: List[Annotation] = toDenot(sym).annotations + def annotations: List[Annotation] = sym.annotations def companionModuleMembers: List[Symbol] = { // phase travel to exitingPickler: this makes sure that memberClassesOf only sees member classes, // not local classes of the companion module (E in the exmaple) that were lifted by lambdalift. @@ -815,10 +814,10 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma else Nil } def fieldSymbols: List[Symbol] = { - toDenot(sym).info.decls.filter(p => p.isTerm && !p.is(Flags.Method)) + sym.info.decls.filter(p => p.isTerm && !p.is(Flags.Method)) } def methodSymbols: List[Symbol] = - for (f <- toDenot(sym).info.decls.toList if f.isMethod && f.isTerm && !f.isModule) yield f + for (f <- sym.info.decls.toList if f.isMethod && f.isTerm && !f.isModule) yield f def serialVUID: Option[Long] = None @@ -842,7 +841,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(_.baseClasses.drop(1)).toSet val superCalls = superCallsMap.getOrElse(sym, Set.empty) val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait)) // if (additional.nonEmpty) @@ -856,7 +855,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma */ def isTopLevelModuleClass: Boolean = sym.isModuleClass && ctx.atPhase(ctx.flattenPhase) { implicit ctx => - toDenot(sym).owner.is(Flags.PackageClass) + sym.owner.is(Flags.PackageClass) } /** @@ -874,7 +873,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def addRemoteRemoteExceptionAnnotation: Unit = () def samMethod(): Symbol = - toDenot(sym).info.abstractTermMembers.headOption.getOrElse(toDenot(sym).info.member(nme.apply)).symbol + sym.info.abstractTermMembers.headOption.getOrElse(sym.info.member(nme.apply)).symbol } diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 62fd9cc45751..99ec12b68f3d 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -697,7 +697,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { val sym = tree.symbol val prevDenot = sym.denot(ctx.withPhase(trans)) if (prevDenot.effectiveOwner == from.skipWeakOwner) { - val d = sym.copySymDenotation(owner = to) + val d = sym.denot.copySymDenotation(owner = to) d.installAfter(trans) d.transformAfter(trans, d => if (d.owner eq from) d.copySymDenotation(owner = to) else d) } diff --git a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala index 08a67ab3d1f0..41e9c93fbfb9 100644 --- a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala +++ b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala @@ -21,7 +21,7 @@ class JavaPlatform extends Platform { } // The given symbol is a method with the right name and signature to be a runnable java program. - def isMainMethod(sym: SymDenotation)(implicit ctx: Context) = + def isMainMethod(sym: Symbol)(implicit ctx: Context) = (sym.name == nme.main) && (sym.info match { case MethodTpe(_, defn.ArrayOf(el) :: Nil, restpe) => el =:= defn.StringType && (restpe isRef defn.UnitClass) case _ => false diff --git a/compiler/src/dotty/tools/dotc/config/Platform.scala b/compiler/src/dotty/tools/dotc/config/Platform.scala index 71e0d9cd107c..d8378ed2f560 100644 --- a/compiler/src/dotty/tools/dotc/config/Platform.scala +++ b/compiler/src/dotty/tools/dotc/config/Platform.scala @@ -39,13 +39,10 @@ abstract class Platform { def newClassLoader(bin: AbstractFile)(implicit ctx: Context): SymbolLoader /** The given symbol is a method with the right name and signature to be a runnable program. */ - def isMainMethod(sym: SymDenotation)(implicit ctx: Context): Boolean + def isMainMethod(sym: Symbol)(implicit ctx: Context): Boolean /** The given class has a main method. */ final def hasMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = - sym.info.member(nme.main).hasAltWith { - case x: SymDenotation => isMainMethod(x) - case _ => false - } + sym.info.member(nme.main).hasAltWith(d => isMainMethod(d.symbol)) } diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 2da8c95f0b71..6290d002f95d 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -148,7 +148,7 @@ object Annotations { def makeAlias(sym: TermSymbol)(implicit ctx: Context) = apply(defn.AliasAnnot, List( - ref(TermRef(sym.owner.thisType, sym.name, sym)))) + ref(TermRef(sym.owner.thisType, sym.name, sym.denot)))) /** Extractor for child annotations */ object Child { @@ -157,7 +157,7 @@ object Annotations { def apply(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = { def makeChildLater(implicit ctx: Context) = { val sym = delayedSym(ctx) - New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil) + New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym.denot)), Nil) } deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx)) } diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index ef5d0d1f7022..ade8caf0abcf 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") @@ -642,12 +642,12 @@ class Definitions { 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 + def QuotedExpr_~(implicit ctx: Context) = QuotedExpr_spliceR lazy val QuotedExpr_runR = QuotedExprClass.requiredMethodRef(nme.run) def QuotedExpr_run(implicit ctx: Context) = QuotedExpr_runR.symbol 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 diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 0443f346476e..25a522e8648b 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -198,7 +198,7 @@ object Denotations { /** Denotation points to unique symbol; false for overloaded denotations * and JointRef denotations. */ - def hasUniqueSym: Boolean + protected def hasUniqueSym: Boolean /** The name of the denotation */ def name(implicit ctx: Context): Name @@ -273,7 +273,7 @@ object Denotations { * if generateStubs is specified, return a stubsymbol if denotation is a missing ref. * Throw a `TypeError` if predicate fails to disambiguate symbol or no alternative matches. */ - def requiredSymbol(p: Symbol => Boolean, source: AbstractFile = null, generateStubs: Boolean = true)(implicit ctx: Context): Symbol = + final def requiredSymbol(p: Symbol => Boolean, source: AbstractFile = null, generateStubs: Boolean = true)(implicit ctx: Context): Symbol = disambiguate(p) match { case m @ MissingRef(ownerd, name) => if (generateStubs) { @@ -287,35 +287,6 @@ object Denotations { denot.symbol } - def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol = - info.member(name.toTermName).requiredSymbol(_ is Method).asTerm - def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef = - requiredMethod(name).termRef - - def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = { - info.member(name.toTermName).requiredSymbol { x => - (x is Method) && { - x.info.paramInfoss match { - case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _) - case _ => false - } - } - }.asTerm - } - def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef = - requiredMethod(name, argTypes).termRef - - def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol = - info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm - def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef = - requiredValue(name).termRef - - def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol = - info.member(name.toTypeName).requiredSymbol(_.isClass).asClass - - def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol = - info.member(name.toTypeName).requiredSymbol(_.isType).asType - /** The alternative of this denotation that has a type matching `targetType` when seen * as a member of type `site`, `NoDenotation` if none exists. */ @@ -935,7 +906,7 @@ object Denotations { val targetId = phase.next.id if (ctx.phaseId != targetId) installAfter(phase)(ctx.withPhase(phase.next)) else { - val current = symbol.current + val current = symbol.denot.current // println(s"installing $this after $phase/${phase.id}, valid = ${current.validFor}") // printPeriods(current) this.validFor = Period(ctx.runId, targetId, current.validFor.lastPhaseId) @@ -953,7 +924,7 @@ object Denotations { * given phase. Denotations are replaced while keeping the same validity periods. */ protected def transformAfter(phase: DenotTransformer, f: SymDenotation => SymDenotation)(implicit ctx: Context): Unit = { - var current = symbol.current + var current = symbol.denot.current while (current.validFor.firstPhaseId < phase.id && (current.nextInRun.validFor.code > current.validFor.code)) current = current.nextInRun var hasNext = true diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index e1caf677ea1e..954efa962815 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -129,9 +129,11 @@ object SymDenotations { initInfo: Type, initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) { + Stats.record("SymDenotation") + //assert(symbol.id != 4940, name) - override def hasUniqueSym: Boolean = exists + override protected def hasUniqueSym: Boolean = exists /** Debug only override def validFor_=(p: Period) = { @@ -268,7 +270,7 @@ object SymDenotations { * - if this is a companion object with a clash-avoiding name, strip the * "avoid clash" suffix */ - def effectiveName(implicit ctx: Context) = + def effectiveName(implicit ctx: Context): Name = if (this is ModuleClass) name.stripModuleClassSuffix else name.exclude(AvoidClashName) @@ -492,7 +494,7 @@ object SymDenotations { * and used in SymDenotations#companionClass and * SymDenotations#companionModule . */ - final def isCompanionMethod(implicit ctx: Context) = + final def isCompanionMethod(implicit ctx: Context): Boolean = name.toTermName == nme.COMPANION_CLASS_METHOD || name.toTermName == nme.COMPANION_MODULE_METHOD @@ -500,20 +502,21 @@ object SymDenotations { * These methods are generated in ExtensionMethods * and used in ElimErasedValueType. */ - final def isValueClassConvertMethod(implicit ctx: Context) = + final def isValueClassConvertMethod(implicit ctx: Context): Boolean = name.toTermName == nme.U2EVT || name.toTermName == nme.EVT2U /** Is symbol a primitive value class? */ - def isPrimitiveValueClass(implicit ctx: Context) = + def isPrimitiveValueClass(implicit ctx: Context): Boolean = maybeOwner == defn.ScalaPackageClass && defn.ScalaValueClasses().contains(symbol) /** Is symbol a primitive numeric value class? */ - def isNumericValueClass(implicit ctx: Context) = + def isNumericValueClass(implicit ctx: Context): Boolean = maybeOwner == defn.ScalaPackageClass && defn.ScalaNumericValueClasses().contains(symbol) /** Is symbol a class for which no runtime representation exists? */ - def isNotRuntimeClass(implicit ctx: Context) = defn.NotRuntimeClasses contains symbol + def isNotRuntimeClass(implicit ctx: Context): Boolean = + defn.NotRuntimeClasses contains symbol /** Is this symbol a class representing a refinement? These classes * are used only temporarily in Typer and Unpickler as an intermediate @@ -531,16 +534,16 @@ object SymDenotations { } /** Is this symbol an abstract type? */ - final def isAbstractType(implicit ctx: Context) = this is DeferredType + final def isAbstractType(implicit ctx: Context): Boolean = this is DeferredType /** Is this symbol an alias type? */ - final def isAliasType(implicit ctx: Context) = isAbstractOrAliasType && !(this is Deferred) + final def isAliasType(implicit ctx: Context): Boolean = isAbstractOrAliasType && !(this is Deferred) /** Is this symbol an abstract or alias type? */ - final def isAbstractOrAliasType = isType & !isClass + final def isAbstractOrAliasType: Boolean = isType & !isClass /** Is this symbol an abstract type or type parameter? */ - final def isAbstractOrParamType(implicit ctx: Context) = this is DeferredOrTypeParam + final def isAbstractOrParamType(implicit ctx: Context): Boolean = this is DeferredOrTypeParam /** Is this the denotation of a self symbol of some class? * This is the case if one of two conditions holds: @@ -552,7 +555,7 @@ object SymDenotations { * TODO: Find a more robust way to characterize self symbols, maybe by * spending a Flag on them? */ - final def isSelfSym(implicit ctx: Context) = owner.infoOrCompleter match { + final def isSelfSym(implicit ctx: Context): Boolean = owner.infoOrCompleter match { case ClassInfo(_, _, _, _, selfInfo) => selfInfo == symbol || selfInfo.isInstanceOf[Type] && name == nme.WILDCARD @@ -575,7 +578,7 @@ object SymDenotations { symbol != boundary && isContainedIn(boundary) /** Is this denotation static (i.e. with no outer instance)? */ - final def isStatic(implicit ctx: Context) = + final def isStatic(implicit ctx: Context): Boolean = (if (maybeOwner eq NoSymbol) isRoot else maybeOwner.originDenotation.isStaticOwner) || myFlags.is(JavaStatic) @@ -584,13 +587,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) = + final def isCoDefinedWith(that: Symbol)(implicit ctx: Context): Boolean = (this.effectiveOwner == that.effectiveOwner) && ( !(this.effectiveOwner is PackageClass) || this.unforcedIsAbsent || that.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 = that.associatedFile ( thisFile == null || thatFile == null || thisFile.path == thatFile.path // Cheap possibly wrong check, then expensive normalization @@ -600,7 +603,7 @@ object SymDenotations { ) /** Is this a denotation of a stable term (or an arbitrary type)? */ - final def isStable(implicit ctx: Context) = + final def isStable(implicit ctx: Context): Boolean = isType || !is(Erased) && (is(Stable) || !(is(UnstableValue) || info.isInstanceOf[ExprType])) /** Is this a "real" method? A real method is a method which is: @@ -609,53 +612,53 @@ object SymDenotations { * - not an anonymous function * - not a companion method */ - final def isRealMethod(implicit ctx: Context) = + final def isRealMethod(implicit ctx: Context): Boolean = this.is(Method, butNot = AccessorOrLabel) && !isAnonymousFunction && !isCompanionMethod /** Is this a getter? */ - final def isGetter(implicit ctx: Context) = + final def isGetter(implicit ctx: Context): Boolean = (this is Accessor) && !originalName.isSetterName && !originalName.isScala2LocalSuffix /** Is this a setter? */ - final def isSetter(implicit ctx: Context) = + final def isSetter(implicit ctx: Context): Boolean = (this is Accessor) && originalName.isSetterName && (!isCompleted || info.firstParamTypes.nonEmpty) // to avoid being fooled by var x_= : Unit = ... /** is this a symbol representing an import? */ - final def isImport = name == nme.IMPORT + final def isImport: Boolean = name == nme.IMPORT /** is this the constructor of a class? */ - final def isClassConstructor = name == nme.CONSTRUCTOR + final def isClassConstructor: Boolean = name == nme.CONSTRUCTOR /** Is this the constructor of a trait? */ - final def isImplClassConstructor = name == nme.TRAIT_CONSTRUCTOR + final def isImplClassConstructor: Boolean = name == nme.TRAIT_CONSTRUCTOR /** Is this the constructor of a trait or a class */ - final def isConstructor = name.isConstructorName + final def isConstructor: Boolean = name.isConstructorName /** Is this a local template dummmy? */ final def isLocalDummy: Boolean = name.isLocalDummyName /** Does this symbol denote the primary constructor of its enclosing class? */ - final def isPrimaryConstructor(implicit ctx: Context) = + final def isPrimaryConstructor(implicit ctx: Context): Boolean = isConstructor && owner.primaryConstructor == symbol /** Does this symbol denote the static constructor of its enclosing class? */ - final def isStaticConstructor(implicit ctx: Context) = + final def isStaticConstructor(implicit ctx: Context): Boolean = name.isStaticConstructorName /** Is this a subclass of the given class `base`? */ - def isSubClass(base: Symbol)(implicit ctx: Context) = false + def isSubClass(base: Symbol)(implicit ctx: Context): Boolean = false /** Is this a subclass of `base`, * and is the denoting symbol also different from `Null` or `Nothing`? * @note erroneous classes are assumed to derive from all other classes * and all classes derive from them. */ - def derivesFrom(base: Symbol)(implicit ctx: Context) = false + def derivesFrom(base: Symbol)(implicit ctx: Context): Boolean = false /** Is this symbol a class that extends `AnyVal`? */ final def isValueClass(implicit ctx: Context): Boolean = { @@ -751,7 +754,7 @@ object SymDenotations { /** Do members of this symbol need translation via asSeenFrom when * accessed via prefix `pre`? */ - def membersNeedAsSeenFrom(pre: Type)(implicit ctx: Context) = + def membersNeedAsSeenFrom(pre: Type)(implicit ctx: Context): Boolean = !( this.isTerm || this.isStaticOwner || ctx.erasedTypes @@ -846,7 +849,7 @@ object SymDenotations { } /** The field accessed by this getter or setter, or if it does not exist, the getter */ - def accessedFieldOrGetter(implicit ctx: Context): Symbol = { + final def accessedFieldOrGetter(implicit ctx: Context): Symbol = { val fieldName = if (isSetter) name.asTermName.getterName else name val d = owner.info.decl(fieldName) val field = d.suchThat(!_.is(Method)).symbol @@ -858,7 +861,7 @@ object SymDenotations { * if it does not exists, the getter of a setter, or * if that does not exist the symbol itself. */ - def underlyingSymbol(implicit ctx: Context): Symbol = + final def underlyingSymbol(implicit ctx: Context): Symbol = if (is(Accessor)) accessedFieldOrGetter orElse symbol else symbol /** The chain of owners of this denotation, starting with the denoting symbol itself */ @@ -930,9 +933,9 @@ object SymDenotations { * except for a toplevel module, where its module class is returned. */ final def topLevelClass(implicit ctx: Context): Symbol = { - @tailrec def topLevel(d: SymDenotation): Symbol = { + @tailrec def topLevel(d: SymDenotation): Symbol = { // TODO: rewrite to take Symbols? if (d.isTopLevelClass) d.symbol - else topLevel(d.owner) + else topLevel(d.owner.denot) } val sym = topLevel(this) @@ -990,7 +993,7 @@ object SymDenotations { */ private def companionNamed(name: TypeName)(implicit ctx: Context): Symbol = if (owner.isClass) - owner.unforcedDecls.lookup(name).suchThat(_.isCoDefinedWith(symbol)).symbol + owner.unforcedDecls.lookup(name).ensuring(_.isCoDefinedWith(symbol)) else if (!owner.exists || ctx.compilationUnit == null) NoSymbol else if (!ctx.compilationUnit.tpdTree.isEmpty) @@ -1097,8 +1100,7 @@ object SymDenotations { final def superSymbolIn(base: Symbol)(implicit ctx: Context): Symbol = { @tailrec def loop(bcs: List[ClassSymbol]): Symbol = bcs match { case bc :: bcs1 => - val sym = matchingDecl(bcs.head, base.thisType) - .suchThat(alt => !(alt is Deferred)).symbol + val sym = matchingDecl(bcs.head, base.thisType).ensuring(!_.is(Deferred)) if (sym.exists) sym else loop(bcs.tail) case _ => NoSymbol @@ -1115,7 +1117,7 @@ object SymDenotations { (this is Deferred) || (this is AbsOverride) && { val supersym = superSymbolIn(base) - supersym == NoSymbol || supersym.isIncompleteIn(base) + supersym == NoSymbol || supersym.denot.isIncompleteIn(base) } /** The class or term symbol up to which this symbol is accessible, @@ -1139,7 +1141,7 @@ object SymDenotations { /** The current declaration in this symbol's class owner that has the same name * as this one, and, if there are several, also has the same signature. */ - def currentSymbol(implicit ctx: Context): Symbol = { + final def currentSymbol(implicit ctx: Context): Symbol = { val candidates = owner.info.decls.lookupAll(name) def test(sym: Symbol): Symbol = if (sym == symbol || sym.signature == signature) sym @@ -1289,6 +1291,8 @@ object SymDenotations { import util.LRUCache + Stats.record("ClassDenotation") + // ----- caches ------------------------------------------------------- private[this] var myTypeParams: List[TypeSymbol] = null @@ -1358,7 +1362,7 @@ object SymDenotations { def classSymbol: ClassSymbol = symbol.asInstanceOf[ClassSymbol] /** The info asserted to have type ClassInfo */ - def classInfo(implicit ctx: Context): ClassInfo = info.asInstanceOf[ClassInfo] + final def classInfo(implicit ctx: Context): ClassInfo = info.asInstanceOf[ClassInfo] /** The type parameters in this class, in the order they appear in the current * scope `decls`. This might be temporarily the incorrect order when @@ -1393,13 +1397,13 @@ object SymDenotations { super.info_=(tp) } - def classParents(implicit ctx: Context): List[Type] = info match { + final def classParents(implicit ctx: Context): List[Type] = info match { case classInfo: ClassInfo => classInfo.parents case _ => Nil } /** The symbol of the superclass, NoSymbol if no superclass exists */ - def superClass(implicit ctx: Context): Symbol = classParents match { + final def superClass(implicit ctx: Context): Symbol = classParents match { case parent :: _ => val cls = parent.classSymbol if (cls is Trait) NoSymbol else cls @@ -1410,7 +1414,7 @@ object SymDenotations { /** The explicitly given self type (self types of modules are assumed to be * explcitly given here). */ - def givenSelfType(implicit ctx: Context) = classInfo.selfInfo match { + final def givenSelfType(implicit ctx: Context) = classInfo.selfInfo match { case tp: Type => tp case self: Symbol => self.info } @@ -1424,7 +1428,7 @@ object SymDenotations { * - for a module class `m`: A term ref to m's source module. * - for all other classes `c` with owner `o`: ThisType(TypeRef(o.thisType, c)) */ - override def thisType(implicit ctx: Context): Type = { + final override def thisType(implicit ctx: Context): Type = { if (myThisType == null) myThisType = computeThisType myThisType } @@ -1437,12 +1441,12 @@ object SymDenotations { private[this] var myTypeRef: TypeRef = null - override def typeRef(implicit ctx: Context): TypeRef = { + final override def typeRef(implicit ctx: Context): TypeRef = { if (myTypeRef == null) myTypeRef = super.typeRef myTypeRef } - override def appliedRef(implicit ctx: Context): Type = classInfo.appliedRef + final override def appliedRef(implicit ctx: Context): Type = classInfo.appliedRef private def baseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = { if (!baseDataCache.isValid) baseDataCache = BaseData.newCache() @@ -1452,14 +1456,14 @@ object SymDenotations { /** The base classes of this class in linearization order, * with the class itself as first element. */ - def baseClasses(implicit onBehalf: BaseData, ctx: Context): List[ClassSymbol] = + final def baseClasses(implicit onBehalf: BaseData, ctx: Context): List[ClassSymbol] = baseData._1 /** A bitset that contains the superId's of all base classes */ private def baseClassSet(implicit onBehalf: BaseData, ctx: Context): BaseClassSet = baseData._2 - def computeBaseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = { + final def computeBaseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = { def emptyParentsExpected = is(Package) || (symbol == defn.AnyClass) || ctx.erasedTypes && (symbol == defn.ObjectClass) if (classParents.isEmpty && !emptyParentsExpected) @@ -1497,7 +1501,7 @@ object SymDenotations { * @param scope The scope in which symbol should be entered. * If this is EmptyScope, the scope is `decls`. */ - def enter(sym: Symbol, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = { + final def enter(sym: Symbol, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = { val mscope = scope match { case scope: MutableScope => // if enter gets a scope as an argument, @@ -1520,7 +1524,7 @@ object SymDenotations { } /** Enter a symbol in given `scope` without potentially replacing the old copy. */ - def enterNoReplace(sym: Symbol, scope: MutableScope)(implicit ctx: Context): Unit = { + final def enterNoReplace(sym: Symbol, scope: MutableScope)(implicit ctx: Context): Unit = { scope.enter(sym) if (myMemberCache != null) myMemberCache.invalidate(sym.name) if (!sym.flagsUNSAFE.is(Private)) invalidateMemberNamesCache() @@ -1530,7 +1534,7 @@ object SymDenotations { * If `prev` is not defined in current class, do nothing. * @pre `prev` and `replacement` have the same name. */ - def replace(prev: Symbol, replacement: Symbol)(implicit ctx: Context): Unit = { + final def replace(prev: Symbol, replacement: Symbol)(implicit ctx: Context): Unit = { unforcedDecls.openForMutations.replace(prev, replacement) if (myMemberCache != null) myMemberCache.invalidate(replacement.name) } @@ -1539,7 +1543,7 @@ object SymDenotations { * Note: We require that this does not happen after the first time * someone does a findMember on a subclass. */ - def delete(sym: Symbol)(implicit ctx: Context) = { + final def delete(sym: Symbol)(implicit ctx: Context) = { info.decls.openForMutations.unlink(sym) if (myMemberCache != null) myMemberCache.invalidate(sym.name) if (!sym.flagsUNSAFE.is(Private)) invalidateMemberNamesCache() @@ -1548,7 +1552,7 @@ object SymDenotations { /** Make sure the type parameters of this class appear in the order given * by `typeParams` in the scope of the class. Reorder definitions in scope if necessary. */ - def ensureTypeParamsInCorrectOrder()(implicit ctx: Context): Unit = { + final def ensureTypeParamsInCorrectOrder()(implicit ctx: Context): Unit = { val tparams = typeParams if (!ctx.erasedTypes && !typeParamsFromDecls.corresponds(tparams)(_.name == _.name)) { val decls = info.decls @@ -1743,7 +1747,7 @@ object SymDenotations { memberNamesCache(keepOnly, this) } - def computeMemberNames(keepOnly: NameFilter)(implicit onBehalf: MemberNames, ctx: Context): Set[Name] = { + final def computeMemberNames(keepOnly: NameFilter)(implicit onBehalf: MemberNames, ctx: Context): Set[Name] = { var names = Set[Name]() def maybeAdd(name: Name) = if (keepOnly(thisType, name)) names += name for (p <- classParents) @@ -1758,7 +1762,7 @@ object SymDenotations { names } - override final def fullNameSeparated(kind: QualifiedNameKind)(implicit ctx: Context): Name = { + final override def fullNameSeparated(kind: QualifiedNameKind)(implicit ctx: Context): Name = { val cached = fullNameCache(kind) if (cached != null) cached else { @@ -1769,9 +1773,9 @@ object SymDenotations { } // to avoid overloading ambiguities - override def fullName(implicit ctx: Context): Name = super.fullName + final override def fullName(implicit ctx: Context): Name = super.fullName - override def primaryConstructor(implicit ctx: Context): Symbol = { + final override def primaryConstructor(implicit ctx: Context): Symbol = { def constrNamed(cname: TermName) = info.decls.denotsNamed(cname).last.symbol // denotsNamed returns Symbols in reverse order of occurrence if (this.is(ImplClass)) constrNamed(nme.TRAIT_CONSTRUCTOR) // ignore normal constructor @@ -1782,13 +1786,13 @@ object SymDenotations { /** The term parameter accessors of this class. * Both getters and setters are returned in this list. */ - def paramAccessors(implicit ctx: Context): List[Symbol] = + final def paramAccessors(implicit ctx: Context): List[Symbol] = unforcedDecls.filter(_.is(ParamAccessor)) /** If this class has the same `decls` scope reference in `phase` and * `phase.next`, install a new denotation with a cloned scope in `phase.next`. */ - def ensureFreshScopeAfter(phase: DenotTransformer)(implicit ctx: Context): Unit = + final def ensureFreshScopeAfter(phase: DenotTransformer)(implicit ctx: Context): Unit = if (ctx.phaseId != phase.next.id) ensureFreshScopeAfter(phase)(ctx.withPhase(phase.next)) else { val prevCtx = ctx.withPhase(phase) diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index 40c3bce68592..ed9878815ba3 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -268,7 +268,7 @@ class SymbolLoaders { val pre = root.owner.thisType root.info = ClassInfo(pre, root.symbol.asClass, Nil, currentDecls, pre select sourceModule) if (!sourceModule.isCompleted) - sourceModule.completer.complete(sourceModule) + sourceModule.completer.complete(sourceModule.denot) val packageName = if (root.isEffectiveRoot) "" else root.fullName.mangledString diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 6e4df46b6530..4817737a1ab5 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -19,13 +19,13 @@ import util.Positions._ import DenotTransformers._ import StdNames._ import NameOps._ -import NameKinds.LazyImplicitName +import NameKinds.{LazyImplicitName, QualifiedNameKind} import ast.tpd import tpd.{Tree, TreeProvider, TreeOps} import ast.TreeTypeMap import Constants.Constant import reporting.diagnostic.Message -import Denotations.{ Denotation, SingleDenotation, MultiDenotation } +import Denotations.{ Denotation, SingleDenotation, MultiDenotation, PreDenotation } import collection.mutable import io.AbstractFile import language.implicitConversions @@ -412,6 +412,8 @@ object Symbols { */ class Symbol private[Symbols] (private[this] var myCoord: Coord, val id: Int) extends Designator with ParamInfo with printing.Showable { + util.Stats.record("Symbol") + type ThisName <: Name //assert(id != 723) @@ -541,7 +543,7 @@ object Symbols { else { if (this.owner.is(Package)) { denot.validFor |= InitialPeriod - if (this is Module) this.moduleClass.validFor |= InitialPeriod + if (this is Module) this.moduleClass.denot.validFor = this.moduleClass.denot.validFor | InitialPeriod } else this.owner.asClass.ensureFreshScopeAfter(phase) if (!isPrivate) @@ -556,15 +558,12 @@ object Symbols { /** If this symbol satisfies predicate `p` this symbol, otherwise `NoSymbol` */ def filter(p: Symbol => Boolean): Symbol = if (p(this)) this else NoSymbol - /** The current name of this symbol */ - final def name(implicit ctx: Context): ThisName = denot.name.asInstanceOf[ThisName] - /** The source or class file from which this class or * the class containing this symbol was generated, null if not applicable. * 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 = { @@ -597,6 +596,181 @@ object Symbols { */ def pos: Position = if (coord.isPosition) coord.toPosition else NoPosition +// -------- Denot Forwarders------------------------------------------------- + + final def exists(implicit ctx: Context): Boolean = lastDenot.exists // no renaming necessary, any denot will do + final def ensuring(p: Symbol => Boolean)(implicit ctx: Context): Symbol = denot.suchThat(p).symbol + + final def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol = + info.member(name.toTermName).requiredSymbol(_ is Method).asTerm + final def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef = + requiredMethod(name).termRef + + final def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = { + info.member(name.toTermName).requiredSymbol { x => + (x is Method) && { + x.info.paramInfoss match { + case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _) + case _ => false + } + } + }.asTerm + } + final def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef = + requiredMethod(name, argTypes).termRef + + final def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol = + info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm + final def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef = + requiredValue(name).termRef + + final def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol = + info.member(name.toTypeName).requiredSymbol(_.isClass).asClass + + final def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol = + info.member(name.toTypeName).requiredSymbol(_.isType).asType + + final def name(implicit ctx: Context): ThisName = denot.name.asInstanceOf[ThisName] + final def maybeOwner(implicit ctx: Context): Symbol = denot.maybeOwner + final def owner(implicit ctx: Context): Symbol = denot.owner + final def flags(implicit ctx: Context): FlagSet = denot.flags + final private[dotc] def flagsUNSAFE(implicit ctx: Context): FlagSet = denot.flagsUNSAFE + final def flags_=(flags: FlagSet)(implicit ctx: Context): Unit = denot.flags_=(flags) + final def setFlag(flags: FlagSet)(implicit ctx: Context): Unit = denot.setFlag(flags) + final def resetFlag(flags: FlagSet)(implicit ctx: Context): Unit = denot.resetFlag(flags) + final def setNoInitsFlags(flags: FlagSet)(implicit ctx: Context): Unit = denot.setNoInitsFlags(flags) + final def is(fs: FlagSet)(implicit ctx: Context): Boolean = denot.is(fs) + final def is(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = denot.is(fs, butNot) + final def is(fs: FlagConjunction)(implicit ctx: Context): Boolean = denot.is(fs) + final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean = denot.is(fs, butNot) + final def info(implicit ctx: Context): Type = denot.info + final def infoOrCompleter(implicit ctx: Context): Type = denot.infoOrCompleter + final def unforcedInfo(implicit ctx: Context): Option[Type] = denot.unforcedInfo + final private[dotc] def info_=(tp: Type)(implicit ctx: Context): Unit = denot.info_=(tp) + final def effectiveName(implicit ctx: Context): Name = denot.effectiveName + final def privateWithin(implicit ctx: Context): Symbol = denot.privateWithin + final private[dotc] def privateWithin_=(sym: Symbol)(implicit ctx: Context): Unit = denot.privateWithin_=(sym) + final def annotations(implicit ctx: Context): List[Annotation] = denot.annotations + final def annotations_=(annots: List[Annotation])(implicit ctx: Context): Unit = denot.annotations_=(annots) + final def hasAnnotation(cls: Symbol)(implicit ctx: Context): Boolean = denot.hasAnnotation(cls) + final def transformAnnotations(f: Annotation => Annotation)(implicit ctx: Context): Unit = denot.transformAnnotations(f) + final def filterAnnotations(p: Annotation => Boolean)(implicit ctx: Context): Unit = denot.filterAnnotations(p) + final def getAnnotation(cls: Symbol)(implicit ctx: Context): Option[Annotation] = denot.getAnnotation(cls) + final def unforcedAnnotation(cls: Symbol)(implicit ctx: Context): Option[Annotation] = denot.unforcedAnnotation(cls) + final def addAnnotation(annot: Annotation)(implicit ctx: Context): Unit = denot.addAnnotation(annot) + final def removeAnnotation(cls: Symbol)(implicit ctx: Context): Unit = denot.removeAnnotation(cls) + final def updateAnnotation(annot: Annotation)(implicit ctx: Context): Unit = denot.updateAnnotation(annot) + final def addAnnotations(annots: TraversableOnce[Annotation])(implicit ctx: Context): Unit = denot.addAnnotations(annots) + final def isCompleted(implicit ctx: Context): Boolean = denot.isCompleted + final def isCompleting(implicit ctx: Context): Boolean = denot.isCompleting + final def completer(implicit ctx: Context): LazyType = denot.completer + final def ensureCompleted()(implicit ctx: Context): Unit = denot.ensureCompleted() + final def unforcedDecls(implicit ctx: Context): Scope = denot.unforcedDecls + final private[core] def currentPackageDecls(implicit ctx: Context): MutableScope = denot.currentPackageDecls + final def expandedName(implicit ctx: Context) = denot.expandedName + final def originalName(implicit ctx: Context) = denot.originalName + final def fullNameSeparated(kind: QualifiedNameKind)(implicit ctx: Context): Name = denot.fullNameSeparated(kind) + final def fullNameSeparated(prefixKind: QualifiedNameKind, kind: QualifiedNameKind, name: Name)(implicit ctx: Context): Name = denot.fullNameSeparated(prefixKind, kind, name) + final def flatName(implicit ctx: Context): Name = denot.flatName + final def fullName(implicit ctx: Context): Name = denot.fullName + final def isRealClass(implicit ctx: Context): Boolean = denot.isRealClass + final def isError(implicit ctx: Context): Boolean = denot.isError + final def markAbsent()(implicit ctx: Context): Unit = denot.markAbsent() + final def unforcedIsAbsent(implicit ctx: Context): Boolean = denot.unforcedIsAbsent + final def isAbsent(implicit ctx: Context): Boolean = denot.isAbsent + final def isRoot(implicit ctx: Context): Boolean = denot.isRoot + final def isEmptyPackage(implicit ctx: Context): Boolean = denot.isEmptyPackage + final def isEffectiveRoot(implicit ctx: Context): Boolean = denot.isEffectiveRoot + final def isAnonymousClass(implicit ctx: Context): Boolean = denot.isAnonymousClass + final def isAnonymousFunction(implicit ctx: Context): Boolean = denot.isAnonymousFunction + final def isAnonymousModuleVal(implicit ctx: Context): Boolean = denot.isAnonymousModuleVal + final def isCompanionMethod(implicit ctx: Context): Boolean = denot.isCompanionMethod + final def isValueClassConvertMethod(implicit ctx: Context): Boolean = denot.isValueClassConvertMethod + final def isPrimitiveValueClass(implicit ctx: Context): Boolean = denot.isPrimitiveValueClass + final def isNumericValueClass(implicit ctx: Context): Boolean = denot.isNumericValueClass + final def isNotRuntimeClass(implicit ctx: Context): Boolean = denot.isNotRuntimeClass + final def isRefinementClass(implicit ctx: Context): Boolean = denot.isRefinementClass + final def isPackageObject(implicit ctx: Context): Boolean = denot.isPackageObject + final def isAbstractType(implicit ctx: Context): Boolean = denot.isAbstractType + final def isAliasType(implicit ctx: Context): Boolean = denot.isAliasType + final def isAbstractOrAliasType(implicit ctx: Context): Boolean = denot.isAbstractOrAliasType + final def isAbstractOrParamType(implicit ctx: Context): Boolean = denot.isAbstractOrParamType + final def isSelfSym(implicit ctx: Context): Boolean = denot.isSelfSym + final def isContainedIn(boundary: Symbol)(implicit ctx: Context): Boolean = denot.isContainedIn(boundary) + final def isProperlyContainedIn(boundary: Symbol)(implicit ctx: Context): Boolean = denot.isProperlyContainedIn(boundary) + final def isStaticOwner(implicit ctx: Context): Boolean = denot.isStaticOwner + final def isCoDefinedWith(that: Symbol)(implicit ctx: Context): Boolean = denot.isCoDefinedWith(that) + final def isStable(implicit ctx: Context): Boolean = denot.isStable + final def isRealMethod(implicit ctx: Context): Boolean = denot.isRealMethod + final def isGetter(implicit ctx: Context): Boolean = denot.isGetter + final def isSetter(implicit ctx: Context): Boolean = denot.isSetter + final def isImport(implicit ctx: Context): Boolean = denot.isImport + final def isClassConstructor(implicit ctx: Context): Boolean = denot.isClassConstructor + final def isImplClassConstructor(implicit ctx: Context): Boolean = denot.isImplClassConstructor + final def isConstructor(implicit ctx: Context): Boolean = denot.isConstructor + final def isLocalDummy(implicit ctx: Context): Boolean = denot.isLocalDummy + final def isPrimaryConstructor(implicit ctx: Context): Boolean = denot.isPrimaryConstructor + final def isStaticConstructor(implicit ctx: Context): Boolean = denot.isStaticConstructor + final def isSubClass(base: Symbol)(implicit ctx: Context): Boolean = denot.isSubClass(base) + final def derivesFrom(base: Symbol)(implicit ctx: Context): Boolean = denot.derivesFrom(base) + final def isValueClass(implicit ctx: Context): Boolean = denot.isValueClass + final def isNullableClass(implicit ctx: Context): Boolean = denot.isNullableClass + final def isAccessibleFrom(pre: Type, superAccess: Boolean = false, whyNot: StringBuffer = null)(implicit ctx: Context): Boolean = denot.isAccessibleFrom(pre, superAccess, whyNot) + final def membersNeedAsSeenFrom(pre: Type)(implicit ctx: Context): Boolean = denot.membersNeedAsSeenFrom(pre) + final def isAsConcrete(that: Symbol)(implicit ctx: Context): Boolean = denot.isAsConcrete(that) + final def hasDefaultParams(implicit ctx: Context): Boolean = denot.hasDefaultParams + final def isWeakOwner(implicit ctx: Context): Boolean = denot.isWeakOwner + final def isSkolem(implicit ctx: Context): Boolean = denot.isSkolem + final def isInlineMethod(implicit ctx: Context): Boolean = denot.isInlineMethod + final def matchNullaryLoosely(implicit ctx: Context): Boolean = denot.matchNullaryLoosely + final def moduleClass(implicit ctx: Context): Symbol = denot.moduleClass + final def sourceModule(implicit ctx: Context): Symbol = denot.sourceModule + final def accessedFieldOrGetter(implicit ctx: Context): Symbol = denot.accessedFieldOrGetter + final def underlyingSymbol(implicit ctx: Context): Symbol = denot.underlyingSymbol + final def ownersIterator(implicit ctx: Context) = denot.ownersIterator + final def skipWeakOwner(implicit ctx: Context): Symbol = denot.skipWeakOwner + final def effectiveOwner(implicit ctx: Context) = denot.effectiveOwner + final def enclosingClass(implicit ctx: Context): Symbol = denot.enclosingClass + final def lexicallyEnclosingClass(implicit ctx: Context): Symbol = denot.lexicallyEnclosingClass + final def isEffectivelyFinal(implicit ctx: Context): Boolean = denot.isEffectivelyFinal + final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = denot.enclosingClassNamed(name) + final def enclosingMethod(implicit ctx: Context): Symbol = denot.enclosingMethod + final def topLevelClass(implicit ctx: Context): Symbol = denot.topLevelClass + final def isTopLevelClass(implicit ctx: Context): Boolean = denot.isTopLevelClass + final def enclosingPackageClass(implicit ctx: Context): Symbol = denot.enclosingPackageClass + final def companionModule(implicit ctx: Context): Symbol = denot.companionModule + final def companionClass(implicit ctx: Context): Symbol = denot.companionClass + final def scalacLinkedClass(implicit ctx: Context): Symbol = denot.scalacLinkedClass + final def isLinkedWith(sym: Symbol)(implicit ctx: Context): Boolean = denot.isLinkedWith(sym) + final def linkedClass(implicit ctx: Context): Symbol = denot.linkedClass + final def enclosingSubClass(implicit ctx: Context) = denot.enclosingSubClass + final def matchingDecl(inClass: Symbol, site: Type)(implicit ctx: Context): Symbol = denot.matchingDecl(inClass, site) + final def matchingMember(site: Type)(implicit ctx: Context): Symbol = denot.matchingMember(site) + final def canMatchInheritedSymbols(implicit ctx: Context): Boolean = denot.canMatchInheritedSymbols + final def memberCanMatchInheritedSymbols(implicit ctx: Context): Boolean = denot.memberCanMatchInheritedSymbols + final def overriddenSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol = denot.overriddenSymbol(inClass) + final def allOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] = denot.allOverriddenSymbols + final def extendedOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] = denot.extendedOverriddenSymbols + final def overridingSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol = denot.overridingSymbol(inClass) + final def superSymbolIn(base: Symbol)(implicit ctx: Context): Symbol = denot.superSymbolIn(base) + final def isIncompleteIn(base: Symbol)(implicit ctx: Context): Boolean = denot.isIncompleteIn(base) + final def accessBoundary(base: Symbol)(implicit ctx: Context): Symbol = denot.accessBoundary(base) + final def primaryConstructor(implicit ctx: Context): Symbol = denot.primaryConstructor + final def currentSymbol(implicit ctx: Context): Symbol = denot.currentSymbol + final def typeParams(implicit ctx: Context): List[TypeSymbol] = denot.typeParams + final def thisType(implicit ctx: Context): Type = denot.thisType + final def appliedRef(implicit ctx: Context): Type = denot.appliedRef + final def namedType(implicit ctx: Context): NamedType = denot.namedType + final def typeRef(implicit ctx: Context): TypeRef = denot.typeRef + final def termRef(implicit ctx: Context): TermRef = denot.termRef + final def variance(implicit ctx: Context): Int = denot.variance + final def typeParamCreationFlags(implicit ctx: Context): FlagSet = denot.typeParamCreationFlags + final def debugString(implicit ctx: Context) = denot.debugString + final def hasSkolems(tp: Type)(implicit ctx: Context): Boolean = denot.hasSkolems(tp) + final def assertNoSkolems(tp: Type)(implicit ctx: Context) = denot.assertNoSkolems(tp) + final def initial(implicit ctx: Context): SymDenotation = denot.initial + final def ensureNotPrivate(implicit ctx: Context) = denot.ensureNotPrivate + // ParamInfo types and methods def isTypeParam(implicit ctx: Context) = denot.is(TypeParam) def paramName(implicit ctx: Context) = name.asInstanceOf[ThisName] @@ -700,6 +874,25 @@ object Symbols { denot.asInstanceOf[ClassDenotation] override protected def prefixString = "ClassSymbol" + +// -------- Denot Forwarders------------------------------------------------- + + final def classInfo(implicit ctx: Context): ClassInfo = classDenot.classInfo + final def classParents(implicit ctx: Context): List[Type] = classDenot.classParents + final def superClass(implicit ctx: Context): Symbol = classDenot.superClass + final def givenSelfType(implicit ctx: Context) = classDenot.givenSelfType + final def baseClasses(implicit onBehalf: BaseData, ctx: Context): List[ClassSymbol] = classDenot.baseClasses + final def enter(sym: Symbol, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = classDenot.enter(sym, scope) + final def enterNoReplace(sym: Symbol, scope: MutableScope)(implicit ctx: Context): Unit = classDenot.enterNoReplace(sym, scope) + final def replace(prev: Symbol, replacement: Symbol)(implicit ctx: Context): Unit = classDenot.replace(prev, replacement) + final def delete(sym: Symbol)(implicit ctx: Context) = classDenot.delete(sym) + final def ensureTypeParamsInCorrectOrder()(implicit ctx: Context): Unit = classDenot.ensureTypeParamsInCorrectOrder() + final def membersNamed(name: Name)(implicit ctx: Context): PreDenotation = classDenot.membersNamed(name) + final def nonPrivateMembersNamed(name: Name)(implicit ctx: Context): PreDenotation = classDenot.nonPrivateMembersNamed(name) + final def baseTypeOf(tp: Type)(implicit ctx: Context): Type = classDenot.baseTypeOf(tp) + final def memberNames(keepOnly: NameFilter)(implicit onBehalf: MemberNames, ctx: Context): Set[Name] = classDenot.memberNames(keepOnly) + final def paramAccessors(implicit ctx: Context): List[Symbol] = classDenot.paramAccessors + final def ensureFreshScopeAfter(phase: DenotTransformer)(implicit ctx: Context): Unit = classDenot.ensureFreshScopeAfter(phase) } class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord, ctx.nextId) { @@ -730,12 +923,6 @@ object Symbols { ctx.newSymbol(owner, name, flags, info, privateWithin, coord) } - /** Makes all denotation operations available on symbols */ - implicit def toDenot(sym: Symbol)(implicit ctx: Context): SymDenotation = sym.denot - - /** Makes all class denotation operations available on class symbols */ - implicit def toClassDenot(cls: ClassSymbol)(implicit ctx: Context): ClassDenotation = cls.classDenot - /** The Definitions object */ def defn(implicit ctx: Context): Definitions = ctx.definitions diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 1ff312dae475..a6397a2969c0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -230,8 +230,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object. tpe else tpe.prefix match { - case pre: ThisType if pre.cls is Package => tryInsert(pre.cls) - case pre: TermRef if pre.symbol is Package => tryInsert(pre.symbol.moduleClass) + case pre: ThisType if pre.cls is Package => tryInsert(pre.cls.denot) + case pre: TermRef if pre.symbol is Package => tryInsert(pre.symbol.moduleClass.denot) case _ => tpe } } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 183bd53c287b..45575aba0982 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -484,7 +484,7 @@ object Types { case tp: TypeProxy => tp.underlying.findDecl(name, excluded) case err: ErrorType => - ctx.newErrorSymbol(classSymbol orElse defn.RootClass, name, err.msg) + ctx.newErrorSymbol(classSymbol orElse defn.RootClass, name, err.msg).denot case _ => NoDenotation } @@ -548,7 +548,7 @@ object Types { case tp: TypeProxy => go(tp.underlying) case tp: ClassInfo => - tp.cls.findMember(name, pre, excluded) + tp.cls.denot.findMember(name, pre, excluded) case AndType(l, r) => goAnd(l, r) case tp: OrType => @@ -560,7 +560,7 @@ object Types { case tp: JavaArrayType => defn.ObjectType.findMember(name, pre, excluded) case err: ErrorType => - ctx.newErrorSymbol(pre.classSymbol orElse defn.RootClass, name, err.msg) + ctx.newErrorSymbol(pre.classSymbol orElse defn.RootClass, name, err.msg).denot case _ => NoDenotation } @@ -1629,7 +1629,7 @@ object Types { def computeSignature(implicit ctx: Context): Signature = { val lastd = lastDenotation if (lastd != null) lastd.signature - else symbol.asSeenFrom(prefix).signature + else symbol.denot.asSeenFrom(prefix).signature } /** The signature of the current denotation if it is known without forcing. @@ -1642,8 +1642,8 @@ object Types { val lastd = lastDenotation if (lastd != null) lastd.signature else { - val sym = currentSymbol - if (sym.exists) sym.asSeenFrom(prefix).signature + val symd = currentSymbol.denot + if (symd.exists) symd.asSeenFrom(prefix).signature else Signature.NotAMethod } } @@ -1694,6 +1694,7 @@ object Types { /** The denotation currently denoted by this type */ final def denot(implicit ctx: Context): Denotation = { + record("NamedType.denot") val now = ctx.period // Even if checkedPeriod == now we still need to recheck lastDenotation.validFor // as it may have been mutated by SymDenotation#installAfter @@ -1805,7 +1806,7 @@ object Types { else arg recoverable_& rebase(pbounds) case arg => TypeAlias(arg) } - param.derivedSingleDenotation(param, argInfo) + param.denot.derivedSingleDenotation(param, argInfo) } else { if (!ctx.reporter.errorsReported) @@ -1880,7 +1881,7 @@ object Types { /** Is this a reference to a class or object member? */ def isMemberRef(implicit ctx: Context) = designator match { - case sym: Symbol => infoDependsOnPrefix(sym, prefix) + case sym: Symbol => infoDependsOnPrefix(sym.denot, prefix) case _ => true } @@ -2031,14 +2032,14 @@ object Types { if (d.isOverloaded && lastSymbol.exists) d = disambiguate(d, if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod - else lastSymbol.asSeenFrom(prefix).signature) + else lastSymbol.denot.asSeenFrom(prefix).signature) NamedType(prefix, name, d) } if (prefix eq this.prefix) this else if (lastDenotation == null) NamedType(prefix, designator) else designator match { case sym: Symbol => - if (infoDependsOnPrefix(sym, prefix) && !prefix.isArgPrefixOf(sym)) { + if (infoDependsOnPrefix(sym.denot, prefix) && !prefix.isArgPrefixOf(sym.denot)) { val candidate = reload() val falseOverride = sym.isClass && candidate.symbol.exists && candidate.symbol != symbol // A false override happens if we rebind an inner class to another type with the same name @@ -3584,7 +3585,7 @@ object Types { // Note: Taking a normal typeRef does not work here. A normal ref might contain // also other information about the named type (e.g. bounds). contains( - TypeRef(tp.prefix, cls).withDenot(new UniqueRefDenotation(cls, tp, cls.validFor))) + TypeRef(tp.prefix, cls).withDenot(new UniqueRefDenotation(cls, tp, cls.denot.validFor))) case _ => lo <:< tp && tp <:< hi } @@ -4159,7 +4160,7 @@ object Types { * underlying bounds to a range, otherwise return the expansion. */ def expandParam(tp: NamedType, pre: Type) = tp.argForParam(pre) match { - case arg @ TypeRef(pre, _) if pre.isArgPrefixOf(arg.symbol) => + case arg @ TypeRef(pre, _) if pre.isArgPrefixOf(arg.symbol.denot) => arg.info match { case TypeBounds(lo, hi) => range(atVariance(-variance)(reapply(lo)), reapply(hi)) case arg => reapply(arg) @@ -4588,6 +4589,8 @@ object Types { } ex } + def apply(sym: Symbol)(implicit ctx: Context): CyclicReference = + apply(sym.denot) } class MergeError(msg: String, val tp1: Type, val tp2: Type) extends TypeError(msg) diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 2898db135a3b..96509be149b2 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -157,7 +157,7 @@ class ClassfileParser( moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags) setPrivateWithin(classRoot, jflags) setPrivateWithin(moduleRoot, jflags) - setPrivateWithin(moduleRoot.sourceModule, jflags) + setPrivateWithin(moduleRoot.sourceModule.denot, jflags) for (i <- 0 until in.nextChar) parseMember(method = false) for (i <- 0 until in.nextChar) parseMember(method = true) @@ -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 @@ -758,7 +758,7 @@ class ClassfileParser( def unpickleTASTY(bytes: Array[Byte]): Some[Embedded] = { val unpickler = new tasty.DottyUnpickler(bytes) - unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule)) + unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule.denot)) Some(unpickler) } diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index 2c88c5464ef9..fc1ffd0e873d 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -116,7 +116,7 @@ object PickledQuotes { /** Unpickle TASTY bytes into it's tree */ private def unpickle(bytes: Array[Byte], splices: Seq[Any])(implicit ctx: Context): Tree = { val unpickler = new TastyUnpickler(bytes, splices) - unpickler.enter(roots = Set(defn.RootPackage)) + unpickler.enter(roots = Set(defn.RootPackage.denot)) val tree = unpickler.tree if (pickling ne noPrinter) { println(i"**** unpickled quote for \n${tree.show}") diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index e9fbd6fc5278..d24c68787a36 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -260,7 +260,7 @@ class TreeUnpickler(reader: TastyReader, val prefix = readType() val space = readType() space.decl(name) match { - case symd: SymDenotation if prefix.isArgPrefixOf(symd.symbol) => TypeRef(prefix, symd.symbol) + case symd: SymDenotation if prefix.isArgPrefixOf(symd) => TypeRef(prefix, symd.symbol) case _ => TypeRef(prefix, name, space.decl(name).asSeenFrom(prefix)) } case REFINEDtype => diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index f7dbda218e0e..805c16d3cb7f 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -88,7 +88,7 @@ object Scala2Unpickler { def ensureConstructor(cls: ClassSymbol, scope: Scope)(implicit ctx: Context) = if (scope.lookup(nme.CONSTRUCTOR) == NoSymbol) { val constr = ctx.newDefaultConstructor(cls) - addConstructorTypeParams(constr) + addConstructorTypeParams(constr.denot) cls.enter(constr, scope) } @@ -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) @@ -406,7 +406,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas // (3) Try as a nested object symbol. nestedObjectSymbol orElse { // (4) Call the mirror's "missing" hook. - adjust(ctx.base.missingHook(owner, name)) orElse { + adjust(ctx.base.missingHook(owner, name).denot) orElse { // println(owner.info.decls.toList.map(_.debugString).mkString("\n ")) // !!! DEBUG // } // (5) Create a stub symbol to defer hard failure a little longer. @@ -513,8 +513,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val unpickler = new ClassUnpickler(infoRef) withDecls symScope(cls) if (flags is ModuleClass) unpickler withSourceModule (implicit ctx => - cls.owner.info.decls.lookup(cls.name.sourceModuleName) - .suchThat(_ is Module).symbol) + cls.owner.info.decls.lookup(cls.name.sourceModuleName).ensuring(_ is Module)) else unpickler } ctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start) @@ -527,8 +526,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas moduleRoot.symbol } else ctx.newSymbol(owner, name.asTermName, flags, new LocalUnpickler() withModuleClass(implicit ctx => - owner.info.decls.lookup(name.moduleClassName) - .suchThat(_ is Module).symbol) + owner.info.decls.lookup(name.moduleClassName).ensuring(_ is Module)) , coord = start) case _ => errorBadSignature("bad symbol tag: " + tag) 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/AugmentScala2Traits.scala b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala index 940037903b56..adae112c3b76 100644 --- a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala @@ -66,7 +66,7 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer with F def implMethod(meth: TermSymbol): Symbol = { val mold = if (meth.isConstructor) - meth.copySymDenotation( + meth.denot.copySymDenotation( name = nme.TRAIT_CONSTRUCTOR, info = MethodType(Nil, defn.UnitType)) else meth.ensureNotPrivate diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 89a3d16772a4..ed73a06b6589 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -204,7 +204,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = } else if (!stat.rhs.isEmpty) { dropped += sym - sym.copySymDenotation( + sym.denot.copySymDenotation( initFlags = sym.flags &~ Private, owner = constr.symbol).installAfter(thisPhase) constrStats += intoConstr(stat, sym) diff --git a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala index ba1c572f45c6..6172e49b2637 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala @@ -71,7 +71,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer { override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = ctx.atPhase(next) { implicit ctx => - if (exprBecomesFunction(tree.symbol)) + if (exprBecomesFunction(tree.symbol.denot)) cpy.ValDef(tree)(tpt = tree.tpt.withType(tree.symbol.info)) else tree } @@ -81,7 +81,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer { case _ => tp } - override def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && exprBecomesFunction(sym) + override def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && exprBecomesFunction(sym.denot) } object ElimByName { diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala index ec82050366d9..45a6af2f8dfa 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -96,12 +96,12 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase } override def transformIdent(tree: Ident)(implicit ctx: Context) = { - ensurePrivateAccessible(tree.symbol) + ensurePrivateAccessible(tree.symbol.denot) tree } override def transformSelect(tree: Select)(implicit ctx: Context) = { - ensurePrivateAccessible(tree.symbol) + ensurePrivateAccessible(tree.symbol.denot) tree } @@ -112,7 +112,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase if sym.is(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name => sym.ensureNotPrivate.installAfter(thisPhase) case _ => - if (isVCPrivateParamAccessor(sym)) + if (isVCPrivateParamAccessor(sym.denot)) sym.ensureNotPrivate.installAfter(thisPhase) } tree diff --git a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala index d5b1ec9cc72f..652a404aaa85 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -165,7 +165,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete val origMeth = tree.symbol val origClass = ctx.owner.asClass val staticClass = origClass.linkedClass - assert(staticClass.exists, s"$origClass lacks companion, ${origClass.owner.definedPeriodsString} ${origClass.owner.info.decls} ${origClass.owner.info.decls}") + assert(staticClass.exists, s"$origClass lacks companion, ${origClass.owner.denot.definedPeriodsString} ${origClass.owner.info.decls} ${origClass.owner.info.decls}") val extensionMeth = extensionMethod(origMeth) ctx.log(s"Value class $origClass spawns extension method.\n Old: ${origMeth.showDcl}\n New: ${extensionMeth.showDcl}") val store: ListBuffer[Tree] = extensionDefs.get(staticClass) match { diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 6cd1ad06156a..7f6f8accdfe6 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 @@ -338,7 +338,7 @@ object LambdaLift { else (topClass, JavaStatic) } else (lOwner, EmptyFlags) - local.copySymDenotation( + local.denot.copySymDenotation( owner = newOwner, name = newName(local), initFlags = local.flags &~ Module &~ Final | Private | Lifted | maybeStatic, @@ -347,7 +347,7 @@ object LambdaLift { } for (local <- free.keys) if (!liftedOwner.contains(local)) - local.copySymDenotation(info = liftedInfo(local)).installAfter(thisPhase) + local.denot.copySymDenotation(info = liftedInfo(local)).installAfter(thisPhase) } // initialization diff --git a/compiler/src/dotty/tools/dotc/transform/Memoize.scala b/compiler/src/dotty/tools/dotc/transform/Memoize.scala index aee354a077c7..19203fb4be79 100644 --- a/compiler/src/dotty/tools/dotc/transform/Memoize.scala +++ b/compiler/src/dotty/tools/dotc/transform/Memoize.scala @@ -98,9 +98,9 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase => case _ => () } - def removeAnnotations(denot: SymDenotation): Unit = + def removeAnnotations(): Unit = if (sym.annotations.nonEmpty) { - val cpy = sym.copySymDenotation() + val cpy = sym.denot.copySymDenotation() cpy.annotations = Nil cpy.installAfter(thisPhase) } @@ -136,7 +136,7 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase => else transformFollowingDeep(ref(field))(ctx.withOwner(sym)) val getterDef = cpy.DefDef(tree)(rhs = getterRhs) addAnnotations(fieldDef.denot) - removeAnnotations(sym) + removeAnnotations() Thicket(fieldDef, getterDef) } else if (sym.isSetter) { if (!sym.is(ParamAccessor)) { val Literal(Constant(())) = tree.rhs } // This is intended as an assertion @@ -145,7 +145,7 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase => else { val initializer = Assign(ref(field), adaptToField(ref(tree.vparamss.head.head.symbol))) val setterDef = cpy.DefDef(tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym))) - removeAnnotations(sym) + removeAnnotations() setterDef } } 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/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index b876a3a9b47e..ec83dac84d2d 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -65,7 +65,7 @@ class ParamForwarding(thisPhase: DenotTransformer) { val alias = inheritedAccessor(sym) if (alias.exists) { def forwarder(implicit ctx: Context) = { - sym.copySymDenotation(initFlags = sym.flags | Method | Stable, info = sym.info.ensureMethodic) + sym.denot.copySymDenotation(initFlags = sym.flags | Method | Stable, info = sym.info.ensureMethodic) .installAfter(thisPhase) val superAcc = Super(This(currentClass), tpnme.EMPTY, inConstrCall = false).select(alias) diff --git a/compiler/src/dotty/tools/dotc/transform/RestoreScopes.scala b/compiler/src/dotty/tools/dotc/transform/RestoreScopes.scala index b88d46fdda6a..f8b0f2738338 100644 --- a/compiler/src/dotty/tools/dotc/transform/RestoreScopes.scala +++ b/compiler/src/dotty/tools/dotc/transform/RestoreScopes.scala @@ -58,7 +58,7 @@ class RestoreScopes extends MiniPhase with IdentityDenotTransformer { thisPhase pkg.enter(cls) val cinfo = cls.classInfo - tree.symbol.copySymDenotation( + tree.symbol.denot.copySymDenotation( info = cinfo.derivedClassInfo( // Dotty deviation: Cannot expand cinfo inline without a type error decls = restoredDecls: Scope)).installAfter(thisPhase) tree diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index aabd341533e2..8742f7645a3d 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -125,7 +125,7 @@ class SymUtils(val self: Symbol) extends AnyVal { def registerCompanionMethod(name: Name, target: Symbol)(implicit ctx: Context) = { if (!self.unforcedDecls.lookup(name).exists) { - val companionMethod = ctx.synthesizeCompanionMethod(name, target, self) + val companionMethod = ctx.synthesizeCompanionMethod(name, target.denot, self.denot) if (companionMethod.exists) { companionMethod.entered } 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..449befa67c81 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 = + def u2evt(d: ClassSymbol)(implicit ctx: Context): Symbol = d.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 = + def evt2u(d: ClassSymbol)(implicit ctx: Context): Symbol = d.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/DropNoEffects.scala b/compiler/src/dotty/tools/dotc/transform/localopt/DropNoEffects.scala index f84ec732e25c..7044e5a0812f 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/DropNoEffects.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/DropNoEffects.scala @@ -116,7 +116,7 @@ class DropNoEffects(val simplifyPhase: Simplify) extends Optimisation { case et: ExprType => et.derivedExprType(defn.UnitType) } - val newD = app.symbol.asSymDenotation.copySymDenotation(info = newLabelType) + val newD = app.symbol.denot.copySymDenotation(info = newLabelType) newD.installAfter(simplifyPhase) } diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala b/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala index 8134764fd3cf..6f326cfdaf78 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/InlineLocalObjects.scala @@ -51,11 +51,11 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation { if (newFieldsMapping == null) { newFieldsMapping = candidates.intersect(gettersCalled).map { refVal => val accessors = refVal.info.classSymbol.caseAccessors.filter(_.isGetter) - val newLocals = accessors.map { x => + val newLocals = accessors.map { accessor => val owner: Symbol = refVal.owner val name: Name = LocalOptInlineLocalObj.fresh() val flags: FlagSet = Synthetic - val info: Type = x.asSeenFrom(refVal.info).info.finalResultType.widenDealias + val info: Type = accessor.denot.asSeenFrom(refVal.info).info.finalResultType.widenDealias ctx.newSymbol(owner, name, flags, info) } (refVal, LinkedHashMap[Symbol, Symbol](accessors.zip(newLocals): _*)) @@ -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/transform/localopt/Valify.scala b/compiler/src/dotty/tools/dotc/transform/localopt/Valify.scala index a3b18f72169e..67afeb88875e 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/Valify.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/Valify.scala @@ -78,7 +78,7 @@ class Valify(val simplifyPhase: Simplify) extends Optimisation { case x: ValDef if valsToDrop.contains(x) => EmptyTree case t: Assign => assignsToReplace.get(t) match { case Some(vd) => - val newD = vd.symbol.asSymDenotation.copySymDenotation(initFlags = vd.symbol.flags.&~(Mutable)) + val newD = vd.symbol.denot.copySymDenotation(initFlags = vd.symbol.flags.&~(Mutable)) newD.installAfter(simplifyPhase) ValDef(vd.symbol.asTerm, t.rhs) case None => t diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 41989b04e66f..aa08a22518c1 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -823,7 +823,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { /** does the companion object of the given symbol have custom unapply */ def hasCustomUnapply(sym: Symbol): Boolean = { - val companion = sym.companionModule + val companion = sym.companionModule.denot companion.findMember(nme.unapply, NoPrefix, excluded = Synthetic).exists || companion.findMember(nme.unapplySeq, NoPrefix, excluded = Synthetic).exists } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 7c5d0894a18a..9cb4cec4ca06 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -662,7 +662,7 @@ trait Checking { def checkDecl(decl: Symbol): Unit = { for (other <- seen(decl.name)) { typr.println(i"conflict? $decl $other") - if (decl.matches(other)) { + if (decl.denot.matches(other.denot)) { def doubleDefError(decl: Symbol, other: Symbol): Unit = if (!decl.info.isErroneous && !other.info.isErroneous) ctx.error(DoubleDeclaration(decl, other), decl.pos) 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 } diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 1cb9bf0936ae..89a56f1c50bd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -206,7 +206,7 @@ object Inliner { * to have the inlined method as owner. */ def registerInlineInfo( - sym: SymDenotation, treeExpr: Context => Tree)(implicit ctx: Context): Unit = { + sym: Symbol, treeExpr: Context => Tree)(implicit ctx: Context): Unit = { sym.unforcedAnnotation(defn.BodyAnnot) match { case Some(ann: ConcreteBodyAnnotation) => case Some(ann: LazyBodyAnnotation) if ann.isEvaluated => @@ -225,10 +225,10 @@ object Inliner { /** `sym` has an inline method with a known body to inline (note: definitions coming * from Scala2x class files might be `@inline`, but still lack that body. */ - def hasBodyToInline(sym: SymDenotation)(implicit ctx: Context): Boolean = + def hasBodyToInline(sym: Symbol)(implicit ctx: Context): Boolean = sym.isInlineMethod && sym.hasAnnotation(defn.BodyAnnot) - private def bodyAndAccessors(sym: SymDenotation)(implicit ctx: Context): (Tree, List[MemberDef]) = + private def bodyAndAccessors(sym: Symbol)(implicit ctx: Context): (Tree, List[MemberDef]) = sym.unforcedAnnotation(defn.BodyAnnot).get.tree match { case Thicket(body :: accessors) => (body, accessors.asInstanceOf[List[MemberDef]]) case body => (body, Nil) @@ -237,14 +237,14 @@ object Inliner { /** The body to inline for method `sym`. * @pre hasBodyToInline(sym) */ - def bodyToInline(sym: SymDenotation)(implicit ctx: Context): Tree = + def bodyToInline(sym: Symbol)(implicit ctx: Context): Tree = bodyAndAccessors(sym)._1 /** The accessors to non-public members needed by the inlinable body of `sym`. * These accessors are dropped as a side effect of calling this method. * @pre hasBodyToInline(sym) */ - def removeInlineAccessors(sym: SymDenotation)(implicit ctx: Context): List[MemberDef] = { + def removeInlineAccessors(sym: Symbol)(implicit ctx: Context): List[MemberDef] = { val (body, accessors) = bodyAndAccessors(sym) if (accessors.nonEmpty) sym.updateAnnotation(ConcreteBodyAnnotation(body)) accessors diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 2d6ecae78fe4..aa8c537564ae 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -56,7 +56,7 @@ trait NamerContextOps { this: Context => owner.thisType.member(name) } else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext. - owner.findMember(name, owner.thisType, EmptyFlags) + owner.denot.findMember(name, owner.thisType, EmptyFlags) else scope.denotsNamed(name).toDenot(NoPrefix) @@ -611,8 +611,8 @@ class Namer { typer: Typer => /** Create links between companion object and companion class */ def createLinks(classTree: TypeDef, moduleTree: TypeDef)(implicit ctx: Context) = { - val claz = ctx.effectiveScope.lookup(classTree.name) - val modl = ctx.effectiveScope.lookup(moduleTree.name) + val claz = ctx.effectiveScope.lookup(classTree.name).denot + val modl = ctx.effectiveScope.lookup(moduleTree.name).denot if (claz.isClass && modl.isClass) { ctx.synthesizeCompanionMethod(nme.COMPANION_CLASS_METHOD, claz, modl).entered ctx.synthesizeCompanionMethod(nme.COMPANION_MODULE_METHOD, modl, claz).entered @@ -821,12 +821,12 @@ class Namer { typer: Typer => else completeInCreationContext(denot) } - private def addInlineInfo(denot: SymDenotation) = original match { - case original: untpd.DefDef if denot.isInlineMethod => + private def addInlineInfo(sym: Symbol) = original match { + case original: untpd.DefDef if sym.isInlineMethod => Inliner.registerInlineInfo( - denot, + sym, implicit ctx => typedAheadExpr(original).asInstanceOf[tpd.DefDef].rhs - )(localContext(denot.symbol)) + )(localContext(sym)) case _ => } @@ -839,7 +839,7 @@ class Namer { typer: Typer => case original: MemberDef => addAnnotations(sym, original) case _ => } - addInlineInfo(denot) + addInlineInfo(sym) denot.info = typeSig(sym) Checking.checkWellFormed(sym) denot.info = avoidPrivateLeaks(sym, sym.pos) @@ -990,7 +990,7 @@ class Namer { typer: Typer => Checking.checkWellFormed(cls) if (isDerivedValueClass(cls)) cls.setFlag(Final) cls.info = avoidPrivateLeaks(cls, cls.pos) - cls.baseClasses.foreach(_.invalidateBaseTypeCache()) // we might have looked before and found nothing + cls.baseClasses.foreach(_.classDenot.invalidateBaseTypeCache()) // we might have looked before and found nothing } } @@ -1033,7 +1033,7 @@ class Namer { typer: Typer => def moduleValSig(sym: Symbol)(implicit ctx: Context): Type = { val clsName = sym.name.moduleClassName val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass) - .orElse(ctx.newStubSymbol(ctx.owner, clsName).assertingErrorsReported) + .orElse(ctx.newStubSymbol(ctx.owner, clsName).assertingErrorsReported.denot) ctx.owner.thisType.select(clsName, cls) } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 628c069d99d5..423169f9cd9e 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -96,9 +96,9 @@ object RefChecks { private def checkParents(cls: Symbol)(implicit ctx: Context): Unit = cls.info match { case cinfo: ClassInfo => def checkSelfConforms(other: ClassSymbol, category: String, relation: String) = { - val otherSelf = other.givenSelfType.asSeenFrom(cls.thisType, other.classSymbol) + val otherSelf = other.givenSelfType.asSeenFrom(cls.thisType, other) if (otherSelf.exists && !(cinfo.selfType <:< otherSelf)) - ctx.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other.classSymbol), + ctx.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other), cls.pos) } for (parent <- cinfo.classParents) @@ -441,7 +441,7 @@ object RefChecks { clazz.info.nonPrivateMember(sym.name).hasAltWith { alt => alt.symbol.is(JavaDefined, butNot = Deferred) && !sym.owner.derivesFrom(alt.symbol.owner) && - alt.matches(sym) + alt.matches(sym.denot) } } @@ -581,7 +581,7 @@ object RefChecks { // (3) is violated but not (2). def checkNoAbstractDecls(bc: Symbol): Unit = { for (decl <- bc.info.decls) { - if (decl.is(Deferred) && !ignoreDeferred(decl)) { + if (decl.is(Deferred) && !ignoreDeferred(decl.denot)) { val impl = decl.matchingMember(clazz.thisType) if (impl == NoSymbol || (decl.owner isSubClass impl.owner)) { val impl1 = clazz.thisType.nonPrivateMember(decl.name) // DEBUG diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 9bb608be7736..64042b97749b 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -49,12 +49,13 @@ trait TypeAssigner { val parentType = info.parents.reduceLeft(ctx.typeComparer.andType(_, _)) def addRefinement(parent: Type, decl: Symbol) = { + val decld = decl.denot val inherited = - parentType.findMember(decl.name, cls.thisType, excluded = Private) - .suchThat(decl.matches(_)) + parentType.findMember(decld.name, cls.thisType, excluded = Private) + .suchThat(sym => decld.matches(sym.denot)) val inheritedInfo = inherited.info - if (inheritedInfo.exists && decl.info <:< inheritedInfo && !(inheritedInfo <:< decl.info)) { - val r = RefinedType(parent, decl.name, decl.info) + if (inheritedInfo.exists && decld.info <:< inheritedInfo && !(inheritedInfo <:< decld.info)) { + val r = RefinedType(parent, decld.name, decld.info) typr.println(i"add ref $parent $decl --> " + r) r }