Skip to content

Fix bootstrap, take 3 #1477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/dotty/tools/backend/jvm/CollectSuperCalls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Flags.Trait
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}

/** Collect all super calls except to the parent class.
/** Collect all super calls to trait members.
*
* For each super reference to trait member, register a call from the current class to the
* owner of the referenced member.
*
* This information is used to know if it is safe to remove a redundant mixin class.
* A redundant mixin class is one that is implemented by another mixin class. As the
Expand All @@ -20,9 +24,9 @@ class CollectSuperCalls extends MiniPhaseTransform {

override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = {
tree.qualifier match {
case Super(qual: This, mix) if mix.nonEmpty =>
val classSymbol = qual.symbol.asClass.classSymbol
registerSuperCall(classSymbol, tree.symbol.owner.asClass)
case sup: Super =>
if (tree.symbol.owner.is(Trait))
registerSuperCall(ctx.owner.enclosingClass.asClass, tree.symbol.owner.asClass)
case _ =>
}
tree
Expand Down
6 changes: 5 additions & 1 deletion src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,13 @@ 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 superCalls = superCallsMap.getOrElse(sym, Set.empty)
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCalls(t))
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait))
// if (additional.nonEmpty)
// println(s"$fullName: adding supertraits $additional")
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCalls(t)) ++ additional
}

/**
Expand Down
30 changes: 18 additions & 12 deletions src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ trait SymDenotations { this: Context =>
val initial = denot.initial
val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id)
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
ctx.withPhase(firstPhaseId).stillValidInOwner(initial.asSymDenotation)
ctx.withPhase(firstPhaseId).stillValidInOwner(initial)
else
stillValidInOwner(denot)
}
Expand All @@ -56,6 +56,7 @@ trait SymDenotations { this: Context =>
stillValid(owner) && (
!owner.isClass
|| owner.isRefinementClass
|| owner.is(Scala2x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me of 4b0cc8a which fixed an issue with stale Java symbol and outer fields, are you sure that the stale outer field here is not incorrectly generated by Dotty?

|| (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol)
|| denot.isSelfSym)
} catch {
Expand All @@ -77,7 +78,7 @@ trait SymDenotations { this: Context =>
implicit val ctx: Context = this
val initial = denot.initial
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial.asSymDenotation)
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
} else try {
val owner = denot.owner.denot
if (!traceInvalid(owner)) explainSym("owner is invalid")
Expand Down Expand Up @@ -346,14 +347,14 @@ object SymDenotations {
else {
def legalize(name: Name): Name = // JVM method names may not contain `<' or `>' characters
if (is(Method)) name.replace('<', '(').replace('>', ')') else name
legalize(name.expandedName(initial.asSymDenotation.owner))
legalize(name.expandedName(initial.owner))
}
// need to use initial owner to disambiguate, as multiple private symbols with the same name
// might have been moved from different origins into the same class

/** The name with which the denoting symbol was created */
final def originalName(implicit ctx: Context) = {
val d = initial.asSymDenotation
val d = initial
if (d is ExpandedName) d.name.unexpandedName else d.name // !!!DEBUG, was: effectiveName
}

Expand Down Expand Up @@ -435,13 +436,13 @@ object SymDenotations {

/** Is this symbol an anonymous class? */
final def isAnonymousClass(implicit ctx: Context): Boolean =
isClass && (initial.asSymDenotation.name startsWith tpnme.ANON_CLASS)
isClass && (initial.name startsWith tpnme.ANON_CLASS)

final def isAnonymousFunction(implicit ctx: Context) =
this.symbol.is(Method) && (initial.asSymDenotation.name startsWith nme.ANON_FUN)
this.symbol.is(Method) && (initial.name startsWith nme.ANON_FUN)

final def isAnonymousModuleVal(implicit ctx: Context) =
this.symbol.is(ModuleVal) && (initial.asSymDenotation.name startsWith nme.ANON_CLASS)
this.symbol.is(ModuleVal) && (initial.name startsWith nme.ANON_CLASS)

/** Is this a companion class method or companion object method?
* These methods are generated by Symbols#synthesizeCompanionMethod
Expand Down Expand Up @@ -606,7 +607,7 @@ object SymDenotations {

/** Is this symbol a class that extends `AnyVal`? */
final def isValueClass(implicit ctx: Context): Boolean = {
val di = this.initial.asSymDenotation
val di = initial
di.isClass &&
di.derivesFrom(defn.AnyValClass)(ctx.withPhase(di.validFor.firstPhaseId))
// We call derivesFrom at the initial phase both because AnyVal does not exist
Expand Down Expand Up @@ -1164,6 +1165,8 @@ object SymDenotations {
d
}

override def initial: SymDenotation = super.initial.asSymDenotation

/** Install this denotation as the result of the given denotation transformer. */
override def installAfter(phase: DenotTransformer)(implicit ctx: Context): Unit =
super.installAfter(phase)
Expand Down Expand Up @@ -1226,10 +1229,13 @@ object SymDenotations {
if (myTypeParams == null)
myTypeParams =
if (ctx.erasedTypes || is(Module)) Nil // fast return for modules to avoid scanning package decls
else if (this ne initial) initial.asSymDenotation.typeParams
else infoOrCompleter match {
case info: TypeParamsCompleter => info.completerTypeParams(symbol)
case _ => typeParamsFromDecls
else {
val di = initial
if (this ne di) di.typeParams
else infoOrCompleter match {
case info: TypeParamsCompleter => info.completerTypeParams(symbol)
case _ => typeParamsFromDecls
}
}
myTypeParams
}
Expand Down
24 changes: 10 additions & 14 deletions src/dotty/tools/dotc/transform/SelectStatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@ class SelectStatic extends MiniPhaseTransform with IdentityDenotTransformer { th
import ast.tpd._

override def phaseName: String = "selectStatic"
private val isPackage = FlagConjunction(PackageCreationFlags.bits)

override def transformSelect(tree: tpd.Select)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
val sym = tree.symbol
val r1 =
if (!sym.is(isPackage) && !sym.maybeOwner.is(isPackage) &&
(
((sym is Flags.Module) && sym.maybeOwner.isStaticOwner) ||
(sym is Flags.JavaStatic) ||
(sym.maybeOwner is Flags.ImplClass) ||
sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
)
)
if (!tree.qualifier.symbol.is(JavaModule) && !tree.qualifier.isType)
Block(List(tree.qualifier), ref(sym))
else tree
def isStaticMember =
(sym is Flags.Module) && sym.initial.maybeOwner.initial.isStaticOwner ||
(sym is Flags.JavaStatic) ||
(sym.maybeOwner is Flags.ImplClass) ||
sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
val isStaticRef = !sym.is(Package) && !sym.maybeOwner.is(Package) && isStaticMember
val tree1 =
if (isStaticRef && !tree.qualifier.symbol.is(JavaModule) && !tree.qualifier.isType)
Block(List(tree.qualifier), ref(sym))
else tree

normalize(r1)
normalize(tree1)
}

private def normalize(t: Tree)(implicit ctx: Context) = t match {
Expand Down