Skip to content

-flate-prof: Push ccs into casts/ticks to reduce overhead.

Andreas Klebinger requested to merge wip/andreask/late_casts into master
-flate-prof: Push ccs into casts/ticks to reduce overhead.

If we see a RHS like `foo = <TickOrCast> (\x y -> ...)` make sure to
look through the cast/tick in order to ensure the cost centre ends up
under any lambdas in the rhs (if there are any).

This is important because if `foo` has an arity of `n` we must
eta-expand it to n value lambdas. To give a concrete example for the
function: `foo = Cast (\x y -> ...) co` we now produce:

    foo = Cast (\x y -> Tick <lateCC> ...)

If we don't push the tick into the cast (or lambda for that matter) we
end up with:

    foo = Tick <lateCC> (Cast (\x y -> ...))

But then code gen would eta-expand foo again to match it's arity giving
us:

    foo = \x1 y1 -> (Tick <lateCC> (Cast (\x y -> ...))) x1 y1

Which is a bit silly.

Merge request reports