EtaExpansion

object EtaExpansion extends LiftImpure

Lifter for eta expansion

class Lifter
class Object
trait Matchable
class Any

Value members

Concrete methods

def etaExpand(tree: Tree, mt: MethodType, xarity: Int)(using Context): Tree

Eta-expanding a tree means converting a method reference to a function value.

Eta-expanding a tree means converting a method reference to a function value.

Value Params
mt

The type of the method reference

tree

The tree to expand

xarity

The arity of the expected function type and assume the lifted application of tree (@see liftApp) is { val xs = es; expr } The result of the eta-expansion is either (1) { val xs = es; (x1, ..., xn) => expr(x1, ..., xn) } or (2) { val xs = es; (x1: T1, ..., xn: Tn) => expr(x1, ..., xn) } or (3) { val xs = es; (x1: T1, ..., xn: Tn) => expr(x1, ..., xn) _ } where T1, ..., Tn are the paremeter types of the expanded method. If expr has implicit function type, the arguments are passed with given. E.g. for (1): { val xs = es; (x1, ..., xn) => expr(using x1, ..., xn) } Case (3) applies if the method is curried, i.e. its result type is again a method type. Case (2) applies if the expected arity of the function type xarity differs from the number of parameters in mt. Case (1) applies if mt is uncurried and its number of parameters equals xarity. In this case we can always infer the parameter types later from the callee even if parameter types could not be inferred from the expected type. Hence, we lose nothing by omitting parameter types in the eta expansion. On the other hand omitting these parameters keeps the possibility open that different parameters are inferred from the expected type, so we keep more options open. In each case, the result is an untyped tree, with es and expr as typed splices. FV ==> (x => F[X]) Note: We allow eta expanding a method with a call by name parameter like def m(x: => T): T to a value of type (=> T) => T. This type cannot be written in source, since by-name types => T are not legal argument types. It would be simpler to not allow to eta expand by-name methods. That was the rule initially, but at some point, the rule was dropped. Enforcing the restriction again now would break existing code. Allowing by-name parameters in function types seems to be OK. After elimByName they are all converted to regular function types anyway. But see comment on the ExprType case in function prune in class ConstraintHandling.

Inherited methods

protected def exprLifter: Lifter

The corresponding lifter for pass-by-name arguments

The corresponding lifter for pass-by-name arguments

Inherited from
Lifter
protected def isErased: Boolean

Is lifting performed on erased terms?

Is lifting performed on erased terms?

Inherited from
Lifter
def liftApp(defs: ListBuffer[Tree], tree: Tree)(using Context): Tree

Lift out function prefix and all arguments from application

Lift out function prefix and all arguments from application

pre.f(arg1, ..., argN) becomes

val x0 = pre val x1 = arg1 ... val xN = argN x0.f(x1, ..., xN)

But leave pure expressions alone.

Inherited from
Lifter
def liftArgs(defs: ListBuffer[Tree], methRef: Type, args: List[Tree])(using Context): List[Tree]

Lift arguments that are not-idempotent into ValDefs in buffer defs and replace by the idents of so created ValDefs.

Lift arguments that are not-idempotent into ValDefs in buffer defs and replace by the idents of so created ValDefs.

Inherited from
Lifter
def liftAssigned(defs: ListBuffer[Tree], tree: Tree)(using Context): Tree

Lift out common part of lhs tree taking part in an operator assignment such as

Lift out common part of lhs tree taking part in an operator assignment such as

lhs += expr

Inherited from
Lifter
def liftPrefix(defs: ListBuffer[Tree], tree: Tree)(using Context): Tree

Lift prefix pre of an application pre.f(...) to

Lift prefix pre of an application pre.f(...) to

val x0 = pre x0.f(...)

unless pre is idempotent.

Inherited from
Lifter
protected def liftedDef(sym: TermSymbol, rhs: Tree)(using Context): MemberDef

The tree of a lifted definition

The tree of a lifted definition

Inherited from
Lifter
protected def liftedFlags: FlagSet

The flags of a lifted definition

The flags of a lifted definition

Inherited from
Lifter
def noLift(expr: Tree)(using Context): Boolean
Inherited from
LiftImpure