[project @ 2001-10-03 13:57:33 by simonpj]
authorsimonpj <unknown>
Wed, 3 Oct 2001 13:57:33 +0000 (13:57 +0000)
committersimonpj <unknown>
Wed, 3 Oct 2001 13:57:33 +0000 (13:57 +0000)
-------------------------------------------
Don't bomb out on inlining big constructors
-------------------------------------------

The unfolder bombs out if the expression get too big; no point in
computing its exact size when it's vast.  But for *constructors*
applied to a lot of args, it's worth keeping going, because we
get a big *disount* too
$fFooInt = :CFoo a1 a2 a3 ... a50

We want to keep the inlining for $fFooInt in interface files, so
that importing guys can do the selection.

Solution: only bomb out when size-discount gets too big.

ghc/compiler/coreSyn/CoreUnfold.lhs

index fe7b8f2..7412f0d 100644 (file)
@@ -58,7 +58,7 @@ import FastTypes
 import Outputable
 
 #if __GLASGOW_HASKELL__ >= 404
-import GlaExts         ( fromInt )
+import GlaExts         ( fromInt, Int# )
 #endif
 \end{code}
 
@@ -132,7 +132,7 @@ calcUnfoldingGuidance bOMB_OUT_SIZE expr
        --   but no more.
 
     in
-    case (sizeExpr bOMB_OUT_SIZE val_binders body) of
+    case (sizeExpr (iUnbox bOMB_OUT_SIZE) val_binders body) of
 
       TooBig 
        | not inline -> UnfoldNever
@@ -176,7 +176,7 @@ calcUnfoldingGuidance bOMB_OUT_SIZE expr
 \end{code}
 
 \begin{code}
-sizeExpr :: Int            -- Bomb out if it gets bigger than this
+sizeExpr :: Int#           -- Bomb out if it gets bigger than this
         -> [Id]            -- Arguments; we're interested in which of these
                            -- get case'd
         -> CoreExpr
@@ -335,35 +335,27 @@ sizeExpr bOMB_OUT_SIZE top_args expr
        -- These addSize things have to be here because
        -- I don't want to give them bOMB_OUT_SIZE as an argument
 
-    addSizeN TooBig          _      = TooBig
-    addSizeN (SizeIs n xs d) m
-      | n_tot ># (iUnbox bOMB_OUT_SIZE) = TooBig
-      | otherwise                  = SizeIs n_tot xs d
-      where
-       n_tot = n +# iUnbox m
+    addSizeN TooBig          _  = TooBig
+    addSizeN (SizeIs n xs d) m         = mkSizeIs bOMB_OUT_SIZE (n +# iUnbox m) xs d
     
-    addSize TooBig _ = TooBig
-    addSize _ TooBig = TooBig
-    addSize (SizeIs n1 xs d1) (SizeIs n2 ys d2)
-      | n_tot ># (iUnbox bOMB_OUT_SIZE) = TooBig
-      | otherwise             = SizeIs n_tot xys d_tot
-      where
-       n_tot = n1 +# n2
-       d_tot = d1 +# d2
-       xys   = xs `unionBags` ys
+    addSize TooBig           _                 = TooBig
+    addSize _                TooBig            = TooBig
+    addSize (SizeIs n1 xs d1) (SizeIs n2 ys d2) 
+       = mkSizeIs bOMB_OUT_SIZE (n1 +# n2) (xs `unionBags` ys) (d1 +# d2)
 \end{code}
 
 Code for manipulating sizes
 
 \begin{code}
-
 data ExprSize = TooBig
              | SizeIs FastInt          -- Size found
                       (Bag (Id,Int))   -- Arguments cased herein, and discount for each such
                       FastInt          -- Size to subtract if result is scrutinised 
                                        -- by a case expression
 
-
+mkSizeIs max n xs d | (n -# d) ># max = TooBig
+                   | otherwise       = SizeIs n xs d
 maxSize TooBig         _                                 = TooBig
 maxSize _              TooBig                            = TooBig
 maxSize s1@(SizeIs n1 _ _) s2@(SizeIs n2 _ _) | n1 ># n2  = s1