[commit: ghc] wip/all-inlinable: Always expose unfoldings for overloaded functions. (e408eab)

git at git.haskell.org git at git.haskell.org
Fri Jan 6 16:34:40 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/all-inlinable
Link       : http://ghc.haskell.org/trac/ghc/changeset/e408eab02db3592f04397714ef8bf44a6a2ace50/ghc

>---------------------------------------------------------------

commit e408eab02db3592f04397714ef8bf44a6a2ace50
Author: Matthew Pickering <matthewtpickering at gmail.com>
Date:   Fri Jan 6 12:55:07 2017 +0000

    Always expose unfoldings for overloaded functions.
    
    Summary:
    Users expect their overloaded functions to be specialised at call sites,
    however, this is only the case if they are either lucky and GHC chooses to
    include the unfolding or they mark their definition with an INLINABLE pragma.
    This leads to library authors marking all their functions with `INLINABLE` (or
    more accurately `INLINE`) so they ensure that downstream consumers pay no cost
    for their abstraction.
    
    A more sensible default is to do this job for the library author and give more
    predictable guarantees about specialisation.
    
    Empirically, I compiled a selection of 1150 packages with (a similar) patch applied. The total size of the interface files before the patch was 519mb and after 634mb. On modern machines, I think this increase is justified for the result.
    
    Reviewers: simonpj, austin, bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2929


>---------------------------------------------------------------

e408eab02db3592f04397714ef8bf44a6a2ace50
 compiler/deSugar/DsBinds.hs | 5 -----
 compiler/main/TidyPgm.hs    | 4 +++-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/compiler/deSugar/DsBinds.hs b/compiler/deSugar/DsBinds.hs
index bb15c95..6ebfc59 100644
--- a/compiler/deSugar/DsBinds.hs
+++ b/compiler/deSugar/DsBinds.hs
@@ -361,11 +361,6 @@ makeCorePair :: DynFlags -> Id -> Bool -> Arity -> CoreExpr -> (Id, CoreExpr)
 makeCorePair dflags gbl_id is_default_method dict_arity rhs
   | is_default_method                 -- Default methods are *always* inlined
   = (gbl_id `setIdUnfolding` mkCompulsoryUnfolding rhs, rhs)
-  | (isId gbl_id) &&
-    (isEmptyInlineSpec inline_spec) &&
-      (isOverloadedTy (idType gbl_id))
-  = (gbl_id `setIdUnfolding` inlinable_unf, rhs)
-    -- Expose unfolding of overloaded function if we know no better
   | otherwise
   = case inlinePragmaSpec inline_prag of
           EmptyInlineSpec -> (gbl_id, rhs)
diff --git a/compiler/main/TidyPgm.hs b/compiler/main/TidyPgm.hs
index 52137a4..5896bb0 100644
--- a/compiler/main/TidyPgm.hs
+++ b/compiler/main/TidyPgm.hs
@@ -738,6 +738,7 @@ addExternal expose_all id = (new_needed_ids, show_unfold)
     never_active   = isNeverActive (inlinePragmaActivation (inlinePragInfo idinfo))
     loop_breaker   = isStrongLoopBreaker (occInfo idinfo)
     bottoming_fn   = isBottomingSig (strictnessInfo idinfo)
+    is_overloaded  = isOverloadedTy (idType id)
 
         -- Stuff to do with the Id's unfolding
         -- We leave the unfolding there even if there is a worker
@@ -749,7 +750,8 @@ addExternal expose_all id = (new_needed_ids, show_unfold)
 
        || isStableSource src     -- Always expose things whose
                                  -- source is an inline rule
-
+       || is_overloaded          -- Always expose overloaded things so that
+                                 -- they can be specialised at call sites.
        || not (bottoming_fn      -- No need to inline bottom functions
            || never_active       -- Or ones that say not to
            || loop_breaker       -- Or that are loop breakers



More information about the ghc-commits mailing list