Rehabilitating switch -- a scorecard

Florian Weimer fw at deneb.enyo.de
Sat May 22 12:51:30 UTC 2021


* forax:

> This remember me something, tail call optimization is not the only
> optimization that avoid the stack to grow.
>
> If you have calls like
>   g(a, () -> h(a, () -> f(a)))
>
> with 'a' being the same arguments, you can transform them to
>   r1 = f(a)
>   r2 = h(a, () -> r1)
>   r3 = g(a, () -> r2)
>
> Here the calls can be at any location in the method, but the
> argument should not depend on the values computed by the function.

> Asking for a friend, is this transformation have already a name ?

It looks a bit like strictness analysis.  However it would specialize
h, g to the non-thunk version, and the end result would look like
this:

  r1 = f(a)
  r2 = h(a, r1)
  r3 = g(a, r2)


More information about the amber-spec-observers mailing list