Dotty Documentation

0.5.0-bin-SNAPSHOT

class ShortcutImplicits
extends MiniPhase with IdentityDenotTransformer

This phase optimizes code using implicit function types, by applying two rewrite rules. Let IF be the implicit function type

implicit Us => R

(1) A method definition

def m(xs: Ts): IF = implicit (ys: Us) => E

is expanded to two methods:

def m(xs: Ts): IF = implicit (ys: Us) => m$direct(xs)(ys)
def m$direct(xs: Ts)(ys: Us): R = E

(and equivalently for methods with type parameters or a different number of value parameter lists). An abstract method definition

def m(xs: Ts): IF

is expanded to:

def m(xs: Ts): IF def m$direct(xs: Ts)(ys: Us): R

(2) A reference qual.apply where qual has implicit function type and qual refers to a method m is rewritten to a reference to m$direct, keeping the same type and value arguments as they are found in qual.

[-] Constructors

ShortcutImplicits ( )

[-] Members

[+] private var DirectMeth : Location [ MutableSymbolMap [ Symbol ] ]

A map to cache mapping local methods to their direct counterparts. A fresh map is created for each unit.

[+] final val specializeMonoTargets : true

If this option is true, we don't specialize symbols that are known to be only targets of monomorphic calls. The reason for this option is that benchmarks show that on the JVM for monomorphic dispatch scenarios inlining and escape analysis can often remove all calling overhead, so we might as well not duplicate the code. We need more experience to decide on the best setting of this option.

[+] private def DirectMeth_= ( x$1: Location [ MutableSymbolMap [ Symbol ] ] ) : Unit

A map to cache mapping local methods to their direct counterparts. A fresh map is created for each unit.

[+] override def changesMembers : Boolean

Can this transform create or delete non-private members?

[+] private def directInfo ( info: Type ) ( implicit ctx: Context ) : Type
[+] private def directMeth ( implicit ctx: Context ) : MutableSymbolMap [ Symbol ]
[+] private def directMethod ( sym: Symbol ) ( implicit ctx: Context ) : Symbol

The direct method m$direct that accompanies the given method m. Create one if it does not exist already.

[+] override def initContext ( ctx: FreshContext ) : Unit
[+] private def newDirectMethod ( sym: Symbol ) ( implicit ctx: Context ) : Symbol

A new m$direct method to accompany the given method m

[+] override def phaseName : String

A name given to the Phase that can be used to debug the compiler. For instance, it is possible to print trees after a given phase using:

$ ./bin/dotc -Xprint:<phaseNameHere> sourceFile.scala
[+] override def prepareForUnit ( tree: Tree ) ( implicit ctx: Context ) : Context
[+] private def shouldBeSpecialized ( sym: Symbol ) ( implicit ctx: Context ) : Boolean

Should sym get a ..$direct companion? This is the case if (1) sym is a method with an implicit function type as final result type. However if specializeMonoTargets is false, we exclude symbols that are known to be only targets of monomorphic calls because they are effectively final and don't override anything.

[+] override def transformDefDef ( mdef: DefDef ) ( implicit ctx: Context ) : Tree

Transform methods with implicit function type result according to rewrite rule (1) above

[+] override def transformSelect ( tree: Select ) ( implicit ctx: Context ) : Tree

Transform qual.apply occurrences according to rewrite rule (2) above