diff options
author | Nicolas Stucki <nicolas.stucki@gmail.com> | 2016-07-05 10:50:47 +0200 |
---|---|---|
committer | Nicolas Stucki <nicolas.stucki@gmail.com> | 2016-07-13 10:30:12 +0200 |
commit | 468ff9c0fd341395d39eb57959755fb718990035 (patch) | |
tree | 4fcdbb476adc8772c70a80e370a0be3786287669 /src/dotty/tools/backend/jvm/CollectSuperCalls.scala | |
parent | bef40b45f6c15bf55fa73ea7923cb4da74cf77d0 (diff) | |
download | dotty-468ff9c0fd341395d39eb57959755fb718990035.tar.gz dotty-468ff9c0fd341395d39eb57959755fb718990035.tar.bz2 dotty-468ff9c0fd341395d39eb57959755fb718990035.zip |
Fix #1209: Skip redundant superclasses\supertraits.
Diffstat (limited to 'src/dotty/tools/backend/jvm/CollectSuperCalls.scala')
-rw-r--r-- | src/dotty/tools/backend/jvm/CollectSuperCalls.scala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/dotty/tools/backend/jvm/CollectSuperCalls.scala b/src/dotty/tools/backend/jvm/CollectSuperCalls.scala new file mode 100644 index 000000000..d19228364 --- /dev/null +++ b/src/dotty/tools/backend/jvm/CollectSuperCalls.scala @@ -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 _ => + } + } +} |