EtaExpansion
Lifter for eta expansion
Attributes
- Graph
-
- Supertypes
- Self type
-
EtaExpansion.type
Members list
Value members
Concrete methods
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 parameters
- 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) _ } whereT1, ..., Tn
are the paremeter types of the expanded method. Ifexpr
has implicit function type, the arguments are passed withgiven
. 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 typexarity
differs from the number of parameters inmt
. Case (1) applies ifmt
is uncurried and its number of parameters equalsxarity
. 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, withes
andexpr
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 theExprType
case in functionprune
in classConstraintHandling
.
Attributes
Inherited methods
The corresponding lifter for pass-by-name arguments
Is lifting performed on erased terms?
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.
Attributes
- Inherited from:
- Lifter
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.
Attributes
- Inherited from:
- Lifter
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
Attributes
- Inherited from:
- Lifter
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.
Attributes
- Inherited from:
- Lifter
The tree of a lifted definition
The flags of a lifted definition
Test indicating expr
does not need lifting