Skip to content

Note [exprIsCheap] says it decides whether to inline at more than one place

Currently, Note [exprIsCheap] says

By ``cheap'' we mean a computation we're willing to:
        push inside a lambda, or
        inline at more than one place
That might mean it gets evaluated more than once, instead of being
shared.

I think that inline at more than one place is wrong. Git blame reveals that line is from 2011, in which case it probably wasn't updated after May 2012, when Note [exprIsWorkFree] was written, which says:

exprIsWorkFree is used when deciding whether to inline something; we
don't inline it if doing so might duplicate work, by peeling off a
complete copy of the expression.  Here we do not want even to
duplicate a primop (#5623):
   eg   let x = a #+ b in x +# x
   we do not want to inline/duplicate x

Previously we were a bit more liberal, which led to the primop-duplicating
problem.  However, being more conservative did lead to a big regression in
one nofib benchmark, wheel-sieve1.

In general, I'd like to see a chart where we compare the various exprIs{Cheap,WorkFree,HNF,Trivial,OkForSpeculation,...} and maybe state some implications, like "exprIsWorkFree e implicates exprIsCheap e". And if two such functions don't imply each other, provide an example.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information