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

Simon Peyton Jones simonpj at microsoft.com
Mon Sep 21 07:41:43 UTC 2020


|  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?

Simon


|  -----Original Message-----
|  From: Evan Laforge <qdunkan at gmail.com>
|  Sent: 21 September 2020 01:27
|  To: Simon Peyton Jones <simonpj at microsoft.com>
|  Cc: Isaac Elliott <isaace71295 at gmail.com>; Olaf Klinke <olf at aatal-
|  apotheke.de>; Haskell Cafe <haskell-cafe at haskell.org>
|  Subject: Re: [Haskell-cafe] Are explicit exports and local imports
|  desirable in a production application?
|  
|  On Fri, Sep 18, 2020 at 12:48 AM Simon Peyton Jones
|  <simonpj at microsoft.com> wrote:
|  >
|  > |  For explicit exports, I often leave them off for convenience
|  during
|  > |  development, but put them in when it settles down.  I don't think
|  it
|  > |  unlocks any optimization in code generation
|  >
|  > Actually, it does make a difference to optimisation.  If a function
|  is known not to be exported, then GHC knows every one of its call
|  sites.  Eg so
|  
|  I stand corrected!
|  
|  I recall reading somewhere that, for the purposes of inlining, all
|  symbols inside the module are fully visible, so the only difference
|  the export makes is whether or not the non-inlined/specialized version
|  is also kept around for possible external callers.  So maybe that's
|  just wrong, or I made it up somehow, or maybe it's right but just for
|  inlining and not for those other things?
|  
|  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.


More information about the Haskell-Cafe mailing list