Dotty Documentation

0.11.0-bin-SNAPSHOT

class ShortcutImplicits

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.

Note: The phase adds direct methods for all methods with IFT results that are defined in the transformed compilation unit, as well as for all methods that are referenced from inside the unit. It does NOT do an info transformer that adds these methods everywhere where an IFT returning method exists (including in separately compiled classes). Adding such an info transformer is impractical because it would mean that we have to force the types of all members of classes that are referenced. But not adding an info transformer can lead to inconsistencies in RefChecks. We solve that by ignoring direct methods in Refchecks. Another, related issue is bridge generation, where we also generate shortcut methods on the fly.

[-] 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.

[+] 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 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
[+] 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
[+] 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