Base class for all compound nodes with schedule (e.g.
Base class for all compound nodes with schedule (e.g. Lambda, ThunkDef).
The graph is directed acyclic (i.e. DAG) in which edges go from boundVars
down to roots
.
Base class for most predefined operations.
Base class for most predefined operations.
Type descriptor for primitive types.
Type descriptor for primitive types.
There is implicit val
declaration for each primitive type.
Base class for virtualized instances of type companions.
Base class for virtualized instances of type companions. Each virtualized entity type (trait or class) may have virtualized companion class.
Base class for all descriptors of staged companions
Base class for all descriptors of staged companions
Base class for all descriptors of staged classes.
Base class for all descriptors of staged classes.
Base class for all descriptors of staged classes with one type parameter.
Base class for all descriptors of staged classes with one type parameter. Note, it doesn't inherit from ConcreteElem
Default node type for embedding of literal values to graph IR.
Default node type for embedding of literal values to graph IR.
This can be used or those types T
when Elem[T]
is defined,
but Liftable[_,T]
is not, i.e. for non-liftable types.
literal value
type descriptor of IR type T
Descriptor of type constructor of * -> *
kind.
Descriptor of type constructor of * -> *
kind. Type constructor is not a type,
but rather a function from type to type.
It contains methods which abstract relationship between types T
, F[T]
etc.
Immutable data environment used to assign data values to graph nodes.
Immutable data environment used to assign data values to graph nodes.
Base type for all graph nodes (aka computable value definitions).
Base type for all graph nodes (aka computable value definitions). Each graph node or definition represent one operation node of the data flow graph.
Default pass to be used when IR is used without special compiler configuration.
Default pass to be used when IR is used without special compiler configuration.
Type descriptor of staged types, which correspond to source (unstaged) RTypes defined outside of IR cake.
Type descriptor of staged types, which correspond to source (unstaged) RTypes defined outside of IR cake.
the type represented by this descriptor
Elements cache information for each Elem class.
Elements cache information for each Elem class.
Defines syntax available after IF (cond) THEN thenp ELSEIF (cond1)
Defines syntax available after IF (cond) THEN thenp ELSEIF (cond1)
Base class for all descriptors of staged traits.
Base class for all descriptors of staged traits.
See derived classes in impl
packages.
Base class for all descriptors of staged traits with one type parameter.
Base class for all descriptors of staged traits with one type parameter.
Base class for all objects generated for virtualized types to support staged evaluation machinery.
Base class for all objects generated for virtualized types to support
staged evaluation machinery.
Each object contains definitions which can be imported when necessary.
All that objects are registered in entityObjects
hash map,
which is done while IR cake is constructed.
State monad for symbols computed in a data environment.
State monad for symbols computed in a data environment.
DataEnv
is used as the state of the state monad.
Extension methods to construct ApplyBinOp nodes
Extension methods to construct ApplyBinOp nodes
Binary operation representing structural equality between arguments.
Binary operation representing structural equality between arguments.
Type descriptor for A => B
type where descriptors for A
and B
are given as arguments.
Type descriptor for A => B
type where descriptors for A
and B
are given as arguments.
GraphNode is created for each symbol of the AstGraph and represents graph linking structure
GraphNode is created for each symbol of the AstGraph and represents graph linking structure
Defines syntax available after IF (cond)
Defines syntax available after IF (cond)
IR node to represent IF condition with lazy branches.
IR node to represent IF condition with lazy branches.
Exception thrown during MethodCall invocation.
Exception thrown during MethodCall invocation.
Result of MethodCall invocation.
Result of MethodCall invocation.
tryInvoke
Successful MethodCall invocation with the given result.
Successful MethodCall invocation with the given result.
Type descriptor which is computed lazily on demand.
Type descriptor which is computed lazily on demand.
Represent lambda expression as IR node.
Represent lambda expression as IR node.
Concrete and default implementation of Transformer using underlying HashMap.
Concrete and default implementation of Transformer using underlying HashMap.
Graph node to represent invocation of the method of some class.
Graph node to represent invocation of the method of some class.
Base class for mirrors of graph nodes.
Base class for mirrors of graph nodes. Provides default implementations which can be overriden if special logic is required.
Represents invocation of constructor of the class described by eA
.
Represents invocation of constructor of the class described by eA
.
class descriptor for new instance
arguments of class constructor
Base class for all IR nodes/operations/definitions.
Base class for all IR nodes/operations/definitions.
Binary operation representing structural inequality between arguments.
Binary operation representing structural inequality between arguments.
Special graph node to represent accumulation of the operation costs.
Special graph node to represent accumulation of the operation costs.
In general, due to node sharing it is incorrect to just sum up all the args
costs
and add resCost
to that value.
Example:
val x = ..
val y = op1(x)
val z = op2(x)
val res = op3(y, z)
The naive summation will lead to the cost of x is accumulated both into
cost of y
and into
cost of z, so in the
cost of res it is accumulated twice.
To avoid this problem OpCost nodes require special handling in during evaluation.
the variable of the lambda in which scope this node is created. This makes this node belong to the lambda body, even if it doesn't otherwise depend on lambda argument.
The id of the node for which this node represents cost
costs of the arguments, which are here represent dependency information.
operation cost, which should be added to the current scope accumulated cost
Variants of owner
parameter of constructors of nested classes:
1) predefined node classes are owned by IR cake (ScalanOwner)
2) entity classes are owned by enclosing EntityObject
Variants of owner
parameter of constructors of nested classes:
1) predefined node classes are owned by IR cake (ScalanOwner)
2) entity classes are owned by enclosing EntityObject
Deboxed function to obtain usages of a given node.
Deboxed function to obtain usages of a given node.
Represents adjacency matrix of the reversed graph g
.
Type descriptor for (A, B)
type where descriptors for A
and B
are given as arguments.
Type descriptor for (A, B)
type where descriptors for A
and B
are given as arguments.
Turns partial function into rewriter (i.e.
Turns partial function into rewriter (i.e. set of rewriting rules)
Descriptor of a current compiler pass.
Descriptor of a current compiler pass. Compiler can be configured to perform one pass after another. Each pass has name, configuration parameters, finalizaton logic etc.
Configuration parameters of the Pass descriptor.
Configuration parameters of the Pass descriptor.
Symbols may temporary refer to this node until their target node is updated.
Symbols may temporary refer to this node until their target node is updated.
Immutable graph collected from roots
following Ref.node.deps links.
Immutable graph collected from roots
following Ref.node.deps links.
Abstract representation of a computable value.
Abstract representation of a computable value.
Default implementation is a simple lightweight reference to the corresponding definition.
Every Ref have direct access to its Def via node
property.
Every Ref is typed, and the type is avaliable via elem
property.
SingleRep
Type synonim for graph schedules.
Type synonim for graph schedules.
Alternative representation of schedules using node ids.
Alternative representation of schedules using node ids.
A Ref is a symbolic reference used internally to refer to graph nodes.
A Ref is a symbolic reference used internally to refer to graph nodes. Light weight stateless immutable reference to a graph node (Def[T]). Two symbols are equal if they refer to the nodes with the same id, which is due to Def unification means equal symbols refer to the same instance of Def.
Represents calculation of size in bytes of the given value.
Represents calculation of size in bytes of the given value. The descriptor value.elem can be used to decompose value into components.
Type descriptor for A | B
type where descriptors for A
and B
are given as arguments.
Type descriptor for A | B
type where descriptors for A
and B
are given as arguments.
Untyped shortcut sinonim of Ref, which is used as untyped reference to graph nodes (definitions).
Untyped shortcut sinonim of Ref, which is used as untyped reference to graph nodes (definitions). Following a tradition in compiler engineering we call references to definitions as symbols.
Defines syntax available after IF (cond) THEN thenp
Defines syntax available after IF (cond) THEN thenp
Base class for Ref to Ref transformations.
Base class for Ref to Ref transformations. Each transformer keeps a mapping data between references to original nodes and references to the corresponding transformed nodes.
Node class for typed variables.
Node class for typed variables. In particular for lambda-bound variables.
is independent from nodeId, shouldn't be used as node id.
type descriptor of the variable type
Helper methods to throw errors
Helper methods to throw errors
Logical AND between two pattern matches of the save value x
.
Logical AND between two pattern matches of the save value x
.
Can be used to construct patterns like case P1 && P2 => ...
Type descriptor for Any
, cannot be used implicitly.
Type descriptor for Any
, cannot be used implicitly.
Type descriptor for AnyRef
, cannot be used implicitly.
Type descriptor for AnyRef
, cannot be used implicitly.
Matcher for lambdas which don't depend on their arguments (but can close over other expressions, unlike VeryConstantLambda).
Matcher for lambdas which don't depend on their arguments (but can close over other expressions, unlike VeryConstantLambda).
Default Mirror instance which is used in core IR methods.
Default Mirror instance which is used in core IR methods.
Since ListMap is immutable this empty map can be shared by all other maps created from it.
Since ListMap is immutable this empty map can be shared by all other maps created from it.
If c then t else e construction with standard lazy evaluation of branches.
If c then t else e construction with standard lazy evaluation of branches. The representation uses Thunk for each branch
Zero literal node, which is lazily created and can be efficiently reused.
Zero literal node, which is lazily created and can be efficiently reused.
Much faster alternative to (0: Rep[Int])
or toRep(0)
.
Invocation is not possible, e.g.
Invocation is not possible, e.g. when receiver doesn't implemented the method.
Predefined Lazy value saved here to be used in hotspot code.
Predefined Lazy value saved here to be used in hotspot code.
Data type ST
is liftable is there is Liftable[ST, T] instance for some type T
.
Data type ST
is liftable is there is Liftable[ST, T] instance for some type T
.
Liftable typeclass allows to define which types can have values embedded as literals
into graph IR.
Identity rewriter, i.e.
Identity rewriter, i.e. doesn't change the graph when applied.
Matcher for lambdas which return staging-time constants.
Matcher for lambdas which return staging-time constants. VeryConstantLambda(x) should be equivalent to ConstantLambda(Def(Const(x)))
Helper type case method.
Helper type case method.
Helper to type cast node references.
Helper to type cast node references.
Called to setup IR before the new pass is executed.
Called to setup IR before the new pass is executed.
Whether IR type descriptors should be cached.
Whether IR type descriptors should be cached.
Whether Tup instances should be cached.
Whether Tup instances should be cached.
Retrieve an instance of the given Elem class by either looking up in the cache or creating a new one.
Retrieve an instance of the given Elem class by either looking up in the cache or creating a new one. We assume that all Elem instances are uniquely defined by (clazz, args)
arguments of Elem class constructor
Elem class
Method invocation checker.
Method invocation checker.
Composition of two functions (in mathematical notation), where first g
is applied and them f
.
Composition of two functions (in mathematical notation), where first g
is applied and them f
.
Create new definition entry in either given Thunk or in the global hash table.
Create new definition entry in either given Thunk or in the global hash table.
optional thunk scope to put given definition
symbol refering to d
definition node to add to the scope of globally
reference to d
(which is s
)
IR global current Pass, changes when the compier switches from one pass to the next one.
IR global current Pass, changes when the compier switches from one pass to the next one. Should remain constant during the whole pass execution.
Whether to perform extended checks of correctness, expected invariants and data consistency.
Whether to perform extended checks of correctness, expected invariants and data consistency.
NOTE: Since it may add substantial overhead, set it to false
before using in production.
Returns a number of definitions added to this IR context.
Returns a number of definitions added to this IR context.
Called to let this IR context to finalized the given pass.
Called to let this IR context to finalized the given pass.
Lookup definition in this IR context's hash table of definitions.
Lookup definition in this IR context's hash table of definitions.
node reference to an instance stored in hash table, which is equal to d
and null if there is no definition which is equal to d
Lookup d
in the heap of nodes.
Lookup d
in the heap of nodes. If the lookup is successfull, then
its reference is returned. If the node is not found in the heap, then it is added
and d.self
reference is returned.
node to be added to the head of nodes
producer of the reference to be used as the reference to d
node.
return a reference to d
node in the heap
Get next fresh node id
Get next fresh node id
Lookup of create reference to the given definition.
Lookup of create reference to the given definition.
To lookup d.nodeId
is used as the index in the _symbolTable
.
If Ref is not found in _symbolTable
, then new Ref instance is created
and stored in _symbolTable
at d.nodeId
index.
Executes given lambda to construct Lambda node.
Executes given lambda to construct Lambda node. The function f
can be called with any symbol
and has an effect of growing a graph starting from the argument symbol.
If a reference to Variable
node is passed as argument, then the constructed graph nodes
can be collected to Lambda node forming its body and schedule.
function which execution will create body nodes
arguments type descriptor
Returns OwnerKind for the given constructor, using its first parameter.
Returns OwnerKind for the given constructor, using its first parameter.
Lookup node reference by its id.
Lookup node reference by its id. This is simple array access by index O(1) operation.
Constructs IfThenElse node wrapping by-name args into ThunkDef nodes.
Constructs IfThenElse node wrapping by-name args into ThunkDef nodes.
Invoke source type method corresponding to the given MethodCall node.
Invoke source type method corresponding to the given MethodCall node. This method delegated the work to the given element instance.
type descriptor of receiver node
IR node representing method invocation
environment where each symbol of 'mc' has associated data value
data value returned from invoked method
Method invocation enabler.
Method invocation enabler.
true if the given method can be invoked on the given node.
Global flag governing lambda reification in fun
and mkLambda
.
Global flag governing lambda reification in fun
and mkLambda
.
If this flag is true
then original f: Ref[A] => Ref[B]
function is stored in Lambda node.
As a consequence if f
is not stored, then unfoldLambda
is done by mirrorLambda
.
Log warning message to the log.
Log warning message to the log. This is default and simple implementation, which can be overriden.
Creates new MethodCall node and returns its node ref.
Creates new MethodCall node and returns its node ref.
Creates new NewObject node and returns its node ref.
Creates new NewObject node and returns its node ref.
Whether staged modules should be registered when cake is constructed and initialized.
Whether staged modules should be registered when cake is constructed and initialized.
Called during resetContext() operation after the core context state has been reset.
Called during resetContext() operation after the core context state has been reset. Derived classes can override to define application specific initialization. Don't forget to call super method in the beginning of your overriding method.
Perform constant propagation if enabled and both arguments are Const.
Perform constant propagation if enabled and both arguments are Const.
null if propagation is not done
Perform constant propagation if enabled and argument is Const.
Perform constant propagation if enabled and argument is Const.
null if propagation is not done
Called once for each staged module during this cake initialization.
Called once for each staged module during this cake initialization.
Implicit injection of new definition (graph node) into universum of nodes with collapsing semantics.
Implicit injection of new definition (graph node) into universum of
nodes with collapsing semantics. If there exists node n
in this IR
such that obj equals n
, then the value of n.self
is returned, i.e.
the new node obj
is collapsed with already existing one.
This has an effect of Common Subexpression Elimination (CSE) when
an expression tree is transformed to the graph and identical subtrees
are collapsed.
After a reference to the node is obtained, global rewriting rules are
examined and the reference may be replaced with a new one.
Rewrites application of given binary operation to the given arguments.
Rewrites application of given binary operation to the given arguments.
null if no rewriting is defined.
Rewrites given node to another equivalent node and returns its reference.
Rewrites given node to another equivalent node and returns its reference.
node to be matched against rewrite patterns
reference of new node if RW pattern is found and applied null if no rewriting is defined.
This method is called for each MethodCall node which is about to be added to the graph.
This method is called for each MethodCall node which is about to be added to the graph.
This means mc
has been examined by all the rewrite rules, but has not need rewritten.
Now, if this method returns null, then mc will be added to the graph.
However, in this method, mc
can be examined by a second set of RW rules
(kind of lower priority rules). These rules kind of context dependent, because at this
point we know that the first RW set didn't triggered any rewrite.
Rewrites application of given unary operation to the given argument.
Rewrites application of given unary operation to the given argument.
null if no rewriting is defined.
Prettyprint exception message
Prettyprint exception message
Updates the universe of symbols and definitions, then rewrites until fix-point
Updates the universe of symbols and definitions, then rewrites until fix-point
A new graph node to add to the universe
A symbol that will be used if d doesn't exist in the universe
The symbol of the graph which is semantically(up to rewrites) equivalent to d
Lifting of data values to IR nodes.
Lifting of data values to IR nodes.
Transforms this object into new one by applying t
to every Ref inside
its structure.
Transforms this object into new one by applying t
to every Ref inside
its structure. The structure is build out of Seq, Array, Option and Def values.
Other structure items remain unchanged and copied to the new instance.
Turns on/off lambda unfolding using original function f
stored in the Lambda node.
Turns on/off lambda unfolding using original function f
stored in the Lambda node.
If this flag is false
then this function cannot be used even if it is present in the node.
Create delegate instance suitable for method invocation.
Create delegate instance suitable for method invocation.
It is used when T is a class or a trait and the node referred by x doesn't conform to T.
This method returns dynamically constructed instance, which conforms to T.
Whenever a method of T is called on that instance, the call is intercepted and
DelegatedInterceptionHandler.invoke
method is called, then a new MethodCall can
be constructed (which is befavior by default).
Create or find symbol (node Ref) which refers to the given node in the table of all created symbols.
Create or find symbol (node Ref) which refers to the given node in the table of all created symbols. The d.nodeId is the index in the _symbolTable which is DBuffer (backed by Array)
new of existing symbol
Global lambda equality mode used by default.
Global lambda equality mode used by default. It is used in fun
and fun2
lambda builders.
If this flag is true
then Lambda nodes are equal if they are the same up to renaming of symbols. (see Lambda.equals()).
Each Lambda node has independent equality mode flag which is setup in the constructor.
Extract data value from Const node or throw an exception.
Extract data value from Const node or throw an exception.