Dotty Documentation


class Inliner
extends Object

Produces an inlined version of call via its inlined method.

[-] Constructors

Inliner ( call: Tree , rhsToInline: Tree )
Inliner ( implicit ctx: Context )

[-] Members

[+] class InlineTyper

A typer for inlined bodies. Beyond standard typing, an inline typer performs the following functions:

  1. Implement constant folding over inlined code
  2. Selectively expand ifs with constant conditions
  3. Inline arguments that are by-name closures
  4. Make sure inlined code is type-correct.
  5. Make sure that the tree's typing is idempotent (so that future -Ycheck passes succeed)
[+] object reducer

A utility object offering methods for rewriting inlined code

[+] private val bindingsBuf : ListBuffer [ ValOrDefDef ]

A buffer for bindings that define proxies for actual arguments

[+] private val call : Tree
[+] private val callTypeArgs : List [ Tree ]
[+] private val callValueArgss : List [ List [ Tree ] ]
[+] private implicit val ctx : Context
[+] private val inlineCallPrefix : Tree
[+] private val inlinedMethod : Symbol
[+] private val methPart : Tree [ Type ]
[+] private val paramBinding : HashMap [ Name, Type ]

A map from parameter names of the inlineable method to references of the actual arguments. For a type argument this is the full argument type. For a value argument, it is a reference to either the argument value (if the argument is a pure expression of singleton type), or to val or def acting as a proxy (if the argument is something else).

[+] private val paramProxy : HashMap [ Type, Type ]

A map from references to (type and value) parameters of the inlineable method to their corresponding argument or proxy references, as given by paramBinding.

[+] private val paramSpan : HashMap [ Name, Span ]

A map from parameter names of the inlineable method to spans of the actual arguments

[+] private val rhsToInline : Tree
[+] private val thisProxy : HashMap [ ClassSymbol, TermRef ]

A map from the classes of (direct and outer) this references in rhsToInline to references of their proxies. Note that we can't index by the ThisType itself since there are several possible forms to express what is logicaly the same ThisType. E.g.

ThisType(TypeRef(ThisType(p), cls))


ThisType(TypeRef(TermRef(ThisType(), p), cls))

These are different (wrt ==) types but represent logically the same key

[+] private def canElideThis ( tpe: ThisType ) : Boolean
[+] private def computeParamBindings ( tp: Type , targs: List [ Tree ] , argss: List [ List [ Tree ] ] ) : Unit

Populate paramBinding and bindingsBuf by matching parameters with corresponding arguments. bindingbuf will be further extended later by proxies to this-references.

[+] private def computeThisBindings ( ) : Unit
[+] def dropUnusedDefs ( bindings: List [ MemberDef ] , tree: Tree ) ( implicit ctx: Context ) : ( List [ MemberDef ], Tree )

Drop any side-effect-free bindings that are unused in expansion or other reachable bindings. Inline def bindings that are used only once.

[+] def inlined ( pt: Type , sourcePos: SourcePosition ) : Tree

The Inlined node representing the inlined call

[+] def integrate ( tree: Tree , originalOwner: Symbol ) ( implicit ctx: Context ) : Tree

Make tree part of inlined expansion. This means its owner has to be changed from its originalOwner, and, if it comes from outside the inlined method itself, it has to be marked as an inlined argument.

[+] private def newSym ( name: Name , flags: FlagSet , info: Type ) : Symbol
[+] private def paramBindingDef ( name: Name , paramtp: Type , arg: Tree , bindingsBuf: ListBuffer [ ValOrDefDef ] ) : ValOrDefDef

A binding for the parameter of an inline method. This is a val def for by-value parameters and a def def for by-name parameters. val defs inherit inline annotations from their parameters. The generated def is appended to bindingsBuf.

[+] private def registerLeaf ( tree: Tree ) : Unit

Register type of leaf node

[+] private def registerType ( tpe: Type ) : Unit

Populate thisProxy and paramProxy as follows:

1a. If given type refers to a static this, thisProxy binds it to corresponding global reference, 1b. If given type refers to an instance this to a class that is not contained in the inline method, create a proxy symbol and bind the thistype to refer to the proxy. The proxy is not yet entered in bindingsBuf; that will come later. 2. If given type refers to a parameter, make paramProxy refer to the entry stored in paramNames under the parameter's name. This roundabout way to bind parameter references to proxies is done because we don't know a priori what the parameter references of a method are (we only know the method's type, but that contains TypeParamRefs and MethodParams, not TypeRefs or TermRefs.

[+] def tryConstValue : Tree