reducer

object reducer

A utility object offering methods for rewriting inlined code

class Object
trait Matchable
class Any

Type members

Types

The result type of reducing a match. It consists optionally of a list of bindings for the pattern-bound variables and the RHS of the selected case. Returns None if no case was selected.

The result type of reducing a match. It consists optionally of a list of bindings for the pattern-bound variables and the RHS of the selected case. Returns None if no case was selected.

Value members

Concrete methods

def betaReduce(tree: Tree)(using Context): Tree

Rewrite an application

Rewrite an application

((x1, ..., xn) => b)(e1, ..., en)

to

val/def x1 = e1; ...; val/def xn = en; b

where def is used for call-by-name parameters. However, we shortcut any NoPrefix refs among the ei's directly without creating an intermediate binding.

If this is a value binding:

If this is a value binding:

  • reduce its rhs if it is a projection and adjust its type accordingly,
  • record symbol -> rhs in the InlineBindings context propery.
def reduceInlineMatch(scrutinee: Tree, scrutType: Type, cases: List[CaseDef], typer: Typer)(using Context): MatchRedux

Reduce an inline match

Reduce an inline match

Value Params
mtch

the match tree

scrutType

its fully defined type, or ImplicitScrutineeTypeRef for a summonFrom

scrutinee

the scrutinee expression, assumed to be pure, or EmptyTree for a summonFrom

typer

The current inline typer

Returns

optionally, if match can be reduced to a matching case: A pair of bindings for all pattern-bound variables and the RHS of the case.

def reduceProjection(tree: Tree)(using Context): Tree

If tree is equivalent to new C(args).x where class C does not have initialization code and x is a parameter corresponding to one of the arguments args, the corresponding argument, otherwise tree itself. Side effects of original arguments need to be preserved.

If tree is equivalent to new C(args).x where class C does not have initialization code and x is a parameter corresponding to one of the arguments args, the corresponding argument, otherwise tree itself. Side effects of original arguments need to be preserved.

def tryInlineArg(tree: Tree)(using Context): Tree