[project @ 1999-07-07 15:27:27 by simonmar]
authorsimonmar <unknown>
Wed, 7 Jul 1999 15:27:27 +0000 (15:27 +0000)
committersimonmar <unknown>
Wed, 7 Jul 1999 15:27:27 +0000 (15:27 +0000)
- charge 1 for a case expression

- give a discount of opt_UF_ScrutConDiscount each time a constructor
  is scrutinised

(previously a case expression was not charged for at all, and the
discount for a scrutinised constructor was (opt_UF_ScrutConDiscount *
tyconFamilySize).  In 4.02, a case expression was also charged
tyconFamilySize to balance the discount, but this had the disadvantage
of charging for alternatives which may not be present in the actual
case expression).

ghc/compiler/coreSyn/CoreUnfold.lhs

index f27289e..0c8e6e1 100644 (file)
@@ -205,7 +205,7 @@ calcUnfoldingGuidance bOMB_OUT_SIZE expr
            discount_for b 
                | num_cases == 0 = 0
                | is_fun_ty      = num_cases * opt_UF_FunAppDiscount
-               | is_data_ty     = num_cases * tyConFamilySize tycon * opt_UF_ScrutConDiscount
+               | is_data_ty     = num_cases * opt_UF_ScrutConDiscount
                | otherwise      = num_cases * opt_UF_PrimArgDiscount
                where
                  num_cases           = foldlBag (\n b' -> if b==b' then n+1 else n) 0 cased_args
@@ -267,6 +267,7 @@ sizeExpr (I# bOMB_OUT_SIZE) args expr
       = nukeScrutDiscount (size_up scrut)              `addSize`
        arg_discount scrut                              `addSize`
        foldr (addSize . size_up_alt) sizeZero alts     
+         `addSizeN` 1  -- charge one for the case itself.
 
 -- Just charge for the alts that exist, not the ones that might exist
 --     `addSizeN`