[Haskell-cafe] Are explicit exports and local imports desirable in a production application?

Evan Laforge qdunkan at gmail.com
Mon Sep 21 10:29:49 UTC 2020


On Mon, Sep 21, 2020 at 12:41 AM Simon Peyton Jones
<simonpj at microsoft.com> wrote:
>
> |  I suppose it could theoretically have been right if GHC were willing
> |  to duplicate all exported functions and perhaps analyze them twice,
> |  but perhaps it's not willing to do that?  I'm not saying it should,
> |  especially if it would hurt compile time, just curious.
>
> For non-exported functions, GHC inlines one regardless of size (and discards the definition) if it has exactly one occurrence, because that doesn't duplicate.   For all other functions (local and exported) GHC will inline (and hence duplicate) small ones, and not inline (thereby avoiding duplicating) big ones.
>
> There are flags to control what "big" means.
>
> Does that answer your question?

Yes I think it does, to rephrase, we could say the distinction is not
so much exported or not, but 1 caller vs. >1 caller.  But of course it
happens that exported forces you to assume >1 caller.

I was thinking GHC could theoretically be willing to duplicate an
exported oversized function if it only occurs once within the module,
because this is a max of 1 additional copy, not an unbounded number.
But perhaps it makes sense that it refuses to copy at all if it's over
the size limit, because who's to say how far over the limit it is!
Inlining something with exactly 1 caller is guaranteed safe.  It also
makes it worry-free to extract an expression to a where, or promote a
where to the toplevel, so long as it remains called only once.  This
is as it should be, but it's nice to know for sure!


More information about the Haskell-Cafe mailing list