package transform
Type Members
- abstract class AddInterfaces extends SubComponent with InfoTransform
- abstract class CleanUp extends Statics with Transform with TreeDSL
-
abstract
class
Constructors
extends Statics with Transform with TreeDSL
This phase converts classes with parameters into Java-like classes with fields, which are assigned to from constructors.
-
abstract
class
Delambdafy
extends SubComponent with Transform with TypingTransformers with TreeDSL with TypeAdaptingTransformer
This transformer is responsible for preparing lambdas for runtime, by either translating to anonymous classes or to a tree that will be convereted to invokedynamic by the JVM 1.8+ backend.
This transformer is responsible for preparing lambdas for runtime, by either translating to anonymous classes or to a tree that will be convereted to invokedynamic by the JVM 1.8+ backend.
The main assumption it makes is that a lambda {args => body} has been turned into {args => liftedBody()} where lifted body is a top level method that implements the body of the lambda. Currently Uncurry is responsible for that transformation.
From a lambda, Delambdafy will create:
Under GenASM
1) a new top level class that a) has fields and a constructor taking the captured environment (including possibly the "this" reference) b) an apply method that calls the target method c) if needed a bridge method for the apply method 2) an instantiation of the newly created class which replaces the lambda
Under GenBCode:
1) An application of the captured arguments to a fictional symbol representing the lambda factory. This will be translated by the backed into an invokedynamic using a bootstrap method in JDK8's
LambdaMetaFactory
. The captured arguments includethis
ifliftedBody
is unable to be made STATIC. - abstract class Erasure extends AddInterfaces with reflect.internal.transform.Erasure with Analyzer with TypingTransformers with TreeDSL with TypeAdaptingTransformer
-
abstract
class
ExplicitOuter
extends SubComponent with InfoTransform with TypingTransformers with TreeDSL
This class ...
This class ...
- Version
1.0
-
abstract
class
ExtensionMethods
extends SubComponent with Transform with TypingTransformers
Perform Step 1 in the inline classes SIP: Creates extension methods for all methods in a value class, except parameter or super accessors, or constructors.
Perform Step 1 in the inline classes SIP: Creates extension methods for all methods in a value class, except parameter or super accessors, or constructors.
- Version
2.10
- abstract class Flatten extends SubComponent with InfoTransform
-
trait
InfoTransform
extends SubComponent with Transform
An InfoTransform contains a compiler phase that transforms trees and symbol infos -- making sure they stay consistent.
An InfoTransform contains a compiler phase that transforms trees and symbol infos -- making sure they stay consistent. The symbol info is transformed assuming it is consistent right before this phase. The info transformation is triggered by Symbol::rawInfo, which caches the results in the symbol's type history. This way sym.info (during an enteringPhase(p)) can look up what the symbol's info should look like at the beginning of phase p. (If the transformed info had not been stored yet, rawInfo will compute the info by composing the info-transformers of the most recent phase before p, up to the transformer of the phase right before p.)
Concretely, enteringPhase(p) { sym.info } yields the info *before* phase p has transformed it. Imagine you're a phase and it all makes sense.
- abstract class LambdaLift extends SubComponent with InfoTransform
- abstract class LazyVals extends SubComponent with Transform with TypingTransformers with TreeDSL
- abstract class Mixin extends SubComponent with InfoTransform with TreeDSL
-
abstract
class
OverridingPairs
extends SymbolPairs
A class that yields a kind of iterator (
Cursor
), which yields pairs of corresponding symbols visible in some base class, unless there's a parent class that already contains the same pairs.A class that yields a kind of iterator (
Cursor
), which yields pairs of corresponding symbols visible in some base class, unless there's a parent class that already contains the same pairs. Most of the logic is in SymbolPairs, which contains generic pair-oriented traversal logic. -
trait
PostErasure
extends SubComponent with InfoTransform with TypingTransformers with reflect.internal.transform.PostErasure
This phase maps ErasedValueTypes to the underlying unboxed representation and performs peephole optimizations.
-
abstract
class
SampleTransform
extends SubComponent with Transform
A sample transform.
-
abstract
class
SpecializeTypes
extends SubComponent with InfoTransform with TypingTransformers
Specialize code on types.
Specialize code on types.
Make sure you've read the thesis:
Iulian Dragos: Compiling Scala for Performance (chapter 4)
There are some things worth noting, (possibly) not mentioned there: 0) Make sure you understand the meaning of various
SpecializedInfo
descriptors defined below.1) Specializing traits by introducing bridges in specialized methods of the specialized trait may introduce problems during mixin composition. Concretely, it may cause cyclic calls and result in a stack overflow. See ticket #4351. This was solved by introducing an
Abstract
specialized info descriptor. Instead of generating a bridge in the trait, an abstract method is generated.2) Specialized private members sometimes have to be switched to protected. In some cases, even this is not enough. Example:
class A[@specialized T](protected val d: T) { def foo(that: A[T]) = that.d }
Specialization will generate a specialized class and a specialized method:
class A$mcI$sp(protected val d: Int) extends A[Int] { def foo(that: A[Int]) = foo$mcI$sp(that) def foo(that: A[Int]) = that.d }
Above,
A$mcI$sp
cannot accessd
, so the method cannot be typechecked. - abstract class Statics extends SubComponent with Transform with TreeDSL
-
abstract
class
TailCalls
extends SubComponent with Transform
Perform tail recursive call elimination.
Perform tail recursive call elimination.
- Version
1.0
-
trait
Transform
extends SubComponent
A base class for transforms.
A base class for transforms.
A transform contains a compiler phase which applies a tree transformer.
- Version
1.0
-
trait
TypeAdaptingTransformer
extends AnyRef
A trait usable by transforms that need to adapt trees of one type to another type
-
trait
TypingTransformers
extends AnyRef
A base class for transforms.
A base class for transforms. A transform contains a compiler phase which applies a tree transformer.
-
abstract
class
UnCurry
extends SubComponent with InfoTransform with reflect.internal.transform.UnCurry with TypingTransformers with TreeDSL
- uncurry all symbol and tree types (@see UnCurryPhase) -- this includes normalizing all proper types.
- uncurry all symbol and tree types (@see UnCurryPhase) -- this includes normalizing all proper types.
- for every curried parameter list: (ps_1) ... (ps_n) ==> (ps_1, ..., ps_n)
- for every curried application: f(args_1)...(args_n) ==> f(args_1, ..., args_n)
- for every type application: f[Ts] ==> f[Ts]() unless followed by parameters
- for every use of a parameterless function: f ==> f() and q.f ==> q.f()
- for every def-parameter: x: => T ==> x: () => T
- for every use of a def-parameter: x ==> x.apply()
- for every argument to a def parameter
x: => T': if argument is not a reference to a def parameter: convert argument
eto (expansion of)
() => e' - for every repeated Scala parameter
x: T*' --> x: Seq[T].
- for every repeated Java parameter
x: T...' --> x: Array[T], except: if T is an unbounded abstract type, replace --> x: Array[Object]
- for every argument list that corresponds to a repeated Scala parameter (a_1, ..., a_n) => (Seq(a_1, ..., a_n))
- for every argument list that corresponds to a repeated Java parameter (a_1, ..., a_n) => (Array(a_1, ..., a_n))
- for every argument list that is an escaped sequence (a_1:_*) => (a_1) (possibly converted to sequence or array, as needed)
- convert implicit method types to method types
- convert non-trivial catches in try statements to matches
- convert non-local returns to throws with enclosing try statements.
- convert try-catch expressions in contexts where there might be values on the stack to a local method and a call to it (since an exception empties the evaluation stack):
meth(x_1,..., try { x_i } catch { ..}, .. x_b0) ==> { def liftedTry$1 = try { x_i } catch { .. } meth(x_1, .., liftedTry$1(), .. ) }
The Scala compiler API.
The following resources are useful for Scala plugin/compiler development: