[commit: ghc] wip/spj-early-inline: Small changes to expression sizing in CoreUnfold (7188cd1)

git at git.haskell.org git at git.haskell.org
Fri Feb 17 16:28:27 UTC 2017


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

On branch  : wip/spj-early-inline
Link       : http://ghc.haskell.org/trac/ghc/changeset/7188cd13f8e54efa764d52ca016b87b3669b29f5/ghc

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

commit 7188cd13f8e54efa764d52ca016b87b3669b29f5
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Tue Feb 14 14:15:01 2017 +0000

    Small changes to expression sizing in CoreUnfold
    
    The only significant change here is that
    
       case e of {}
    
    should be treated like 'e', rather than like a case expression.
    We don't push a return address, for example, since 'e' is sure to
    diverge.
    
    I forget why I did this; but it will make these empty-case expressions
    (which are only there to satisfy the type checker) cost-free.


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

7188cd13f8e54efa764d52ca016b87b3669b29f5
 compiler/coreSyn/CoreUnfold.hs | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/compiler/coreSyn/CoreUnfold.hs b/compiler/coreSyn/CoreUnfold.hs
index 71c5f0f..3b12234 100644
--- a/compiler/coreSyn/CoreUnfold.hs
+++ b/compiler/coreSyn/CoreUnfold.hs
@@ -534,6 +534,11 @@ sizeExpr dflags bOMB_OUT_SIZE top_args expr
               pairs
 
     size_up (Case e _ _ alts)
+        | null alts
+        = size_up e    -- case e of {} never returns, so take size of scrutinee
+
+    size_up (Case e _ _ alts)
+        -- Now alts is non-empty
         | Just v <- is_top_arg e -- We are scrutinising an argument variable
         = let
             alt_sizes = map size_up_alt alts
@@ -558,8 +563,8 @@ sizeExpr dflags bOMB_OUT_SIZE top_args expr
 
             alts_size tot_size _ = tot_size
           in
-          alts_size (foldr addAltSize sizeZero alt_sizes)
-                    (foldr maxSize    sizeZero alt_sizes)
+          alts_size (foldr1 addAltSize alt_sizes)  -- alts is non-empty
+                    (foldr1 maxSize    alt_sizes)
                 -- Good to inline if an arg is scrutinised, because
                 -- that may eliminate allocation in the caller
                 -- And it eliminates the case itself
@@ -763,6 +768,7 @@ funSize dflags top_args fun n_val_args voids
     res_discount | idArity fun > n_val_args = ufFunAppDiscount dflags
                  | otherwise                = 0
         -- If the function is partially applied, show a result discount
+-- XXX maybe behave like ConSize for eval'd varaible
 
 conSize :: DataCon -> Int -> ExprSize
 conSize dc n_val_args
@@ -774,6 +780,8 @@ conSize dc n_val_args
 -- See Note [Constructor size and result discount]
   | otherwise = SizeIs 10 emptyBag (10 * (1 + n_val_args))
 
+-- XXX still looks to large to me
+
 {-
 Note [Constructor size and result discount]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the ghc-commits mailing list