blob: 8285bfe4b5e97fbd66ae3face27d879b9ab18038 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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.core.Flags.Trait
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
/** 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
* 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 {
import tpd._
def phaseName: String = "collectSuperCalls"
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = {
tree.qualifier match {
case sup: Super =>
if (tree.symbol.owner.is(Trait))
registerSuperCall(ctx.owner.enclosingClass.asClass, tree.symbol.owner.asClass)
case _ =>
}
tree
}
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(implicit ctx: Context) = {
ctx.genBCodePhase match {
case genBCodePhase: GenBCode =>
genBCodePhase.registerSuperCall(sym, calls)
case _ =>
}
}
}
|