-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Skip redundant superclasses\supertraits. #1368
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
DarkDimius
merged 1 commit into
scala:master
from
dotty-staging:skip-redundant-superclasses
Jul 15, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dotty.tools.backend.jvm | ||
|
||
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.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo} | ||
|
||
/** Collect all super calls except to the parent class. | ||
* | ||
* 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 | ||
* methods in a redundant mixin class could be implemented with a default abstract method, | ||
* the redundant mixin class could be required as a parent by the JVM. | ||
*/ | ||
class CollectSuperCalls extends MiniPhaseTransform { | ||
|
||
def phaseName: String = "collectSuperCalls" | ||
|
||
override def transformSuper(tree: Super)(implicit ctx: Context, info: TransformerInfo): Tree = { | ||
tree match { | ||
case Trees.Super(qual: This, mix) if mix.nonEmpty => | ||
val classSymbol = qual.symbol.asClass.classSymbol | ||
registerSuperCall(classSymbol, tree.tpe.baseClasses.head) | ||
case _ => | ||
} | ||
super.transformSuper(tree) | ||
} | ||
|
||
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(implicit ctx: Context) = { | ||
ctx.genBCodePhase match { | ||
case genBCodePhase: GenBCode => | ||
genBCodePhase.registerSuperCall(sym, calls) | ||
case _ => | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
C1 super class: class java.lang.Object | ||
C1 interfaces: List(interface T2) | ||
C2 super class: class C1 | ||
C2 interfaces: List(interface T4, interface T5) | ||
C3 super class: class C1 | ||
C3 interfaces: List(interface T5) | ||
C4 super class: class C2 | ||
C4 interfaces: List() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
trait T1 | ||
trait T2 extends T1 | ||
trait T3 extends T2 | ||
trait T4 extends T3 | ||
|
||
trait T5 | ||
|
||
class C1 extends T2 | ||
class C2 extends C1 with T4 with T5 with T1 with T2 | ||
class C3 extends C1 with T5 | ||
class C4 extends C2 with T5 | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val c1 = (new C1).getClass | ||
val c2 = (new C2).getClass | ||
val c3 = (new C3).getClass | ||
val c4 = (new C4).getClass | ||
|
||
println("C1 super class: " + c1.getSuperclass) | ||
println("C1 interfaces: " + c1.getInterfaces.toList) | ||
println("C2 super class: " + c2.getSuperclass) | ||
println("C2 interfaces: " + c2.getInterfaces.toList) | ||
println("C3 super class: " + c3.getSuperclass) | ||
println("C3 interfaces: " + c3.getInterfaces.toList) | ||
println("C4 super class: " + c4.getSuperclass) | ||
println("C4 interfaces: " + c4.getInterfaces.toList) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining what the purpose of this phase is in some details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew that I was missing something important but could not remember what.