Absence info at run-time

Andreas Klebinger klebinger.andreas at gmx.at
Wed Apr 13 06:59:06 UTC 2022


W/W should transform such a function into one who takes one less
argument removing any runtime overhead at least for fully applied functions.

I suppose your suggestion is then if we an expression`f x` where bar
takes multiple arguments, but doesn't use the current argument then GHC
should:

* Inspect f, check if the first argument to f is used
* If we can determine it isn't used instead of creating a PAP capturing
`f` and `x` instead only capture `f` and record this in the PAP closure
somehow.
* Once the PAP is fully applied pass a dummy argument instead of `x` to f.

If f is a known call that seems doable, although adding a bitmap to paps
might require us to increase the size of all PAP closures, making this
optimization less useful.

If `f` is a unknown function there is currently no way to get
absent/used info for it's arguments at runtime. And changing that would
be a major change which seems unlikely to pay off.

So I think this would be theoretically possible, but it would rarely pay
off.

Also do you have an example where `(const a) b` leads to stupid thunks?
It seems to me const should always be inlined in such a case, avoiding a
PAP allocation.

Am 12/04/2022 um 23:02 schrieb David Feuer:
> Suppose `f` doesn't use its first argument. When forming the thunk (or
> partial application) `f a`, we don't need to record `a`. What if
> instead of arity, we store a bitmap used/absent arguments, terminated
> by a 1 bit? Could we then get rid of "stupid thunks" like `(const a) b`?
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


More information about the ghc-devs mailing list