Simon Peyton Jones pushed to branch wip/T26425 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Core/Opt/Simplify/Iteration.hs
    ... ... @@ -4598,13 +4598,21 @@ mkLetUnfolding :: SimplEnv -> TopLevelFlag -> UnfoldingSource
    4598 4598
                    -> InId -> Bool    -- True <=> this is a join point
    
    4599 4599
                    -> OutExpr -> SimplM Unfolding
    
    4600 4600
     mkLetUnfolding env top_lvl src id is_join new_rhs
    
    4601
    -  = return (mkUnfolding uf_opts src is_top_lvl is_bottoming is_join new_rhs Nothing)
    
    4602
    -            -- We make an  unfolding *even for loop-breakers*.
    
    4603
    -            -- Reason: (a) It might be useful to know that they are WHNF
    
    4604
    -            --         (b) In GHC.Iface.Tidy we currently assume that, if we want to
    
    4605
    -            --             expose the unfolding then indeed we *have* an unfolding
    
    4606
    -            --             to expose.  (We could instead use the RHS, but currently
    
    4607
    -            --             we don't.)  The simple thing is always to have one.
    
    4601
    +  | is_join
    
    4602
    +  , UnfNever <- guidance
    
    4603
    +  = -- For large join points, don't keep an unfolding at all if it is large
    
    4604
    +    -- This is just an attempt to keep residency under control in
    
    4605
    +    -- deeply-nested join-point such as those arising in #26425
    
    4606
    +    return NoUnfolding
    
    4607
    +
    
    4608
    +  | otherwise
    
    4609
    +  = return (mkCoreUnfolding src is_top_lvl new_rhs Nothing guidance)
    
    4610
    +    -- We make an  unfolding *even for loop-breakers*.
    
    4611
    +    -- Reason: (a) It might be useful to know that they are WHNF
    
    4612
    +    --         (b) In GHC.Iface.Tidy we currently assume that, if we want to
    
    4613
    +    --             expose the unfolding then indeed we *have* an unfolding
    
    4614
    +    --             to expose.  (We could instead use the RHS, but currently
    
    4615
    +    --             we don't.)  The simple thing is always to have one.
    
    4608 4616
       where
    
    4609 4617
         -- !opts: otherwise, we end up retaining all the SimpleEnv
    
    4610 4618
         !uf_opts = seUnfoldingOpts env
    
    ... ... @@ -4615,6 +4623,9 @@ mkLetUnfolding env top_lvl src id is_join new_rhs
    4615 4623
         -- See Note [Force bottoming field]
    
    4616 4624
         !is_bottoming = isDeadEndId id
    
    4617 4625
     
    
    4626
    +    is_top_bottoming = is_top_lvl && is_bottoming
    
    4627
    +    guidance         = calcUnfoldingGuidance uf_opts is_top_bottoming is_join new_rhs
    
    4628
    +
    
    4618 4629
     -------------------
    
    4619 4630
     simplStableUnfolding :: SimplEnv -> BindContext
    
    4620 4631
                          -> InId
    

  • compiler/GHC/Core/Unfold/Make.hs
    ... ... @@ -354,14 +354,6 @@ mkCoreUnfolding :: UnfoldingSource -> Bool -> CoreExpr
    354 354
                     -> Maybe UnfoldingCache -> UnfoldingGuidance -> Unfolding
    
    355 355
     -- Occurrence-analyses the expression before capturing it
    
    356 356
     mkCoreUnfolding src top_lvl expr precomputed_cache guidance
    
    357
    -  | UnfNever <- guidance
    
    358
    -  , not top_lvl
    
    359
    -  = -- For large, non-top-level bindings, don't keep an unfolding at all if it is large
    
    360
    -    -- Keep top-level ones in case of -fexpose-all-unfoldings
    
    361
    -    -- Just an attempt to keep residency under control in deeply-nested let bindings
    
    362
    -    NoUnfolding
    
    363
    -
    
    364
    -  | otherwise
    
    365 357
       = CoreUnfolding { uf_tmpl = cache `seq`
    
    366 358
                                   occurAnalyseExpr expr
    
    367 359
           -- occAnalyseExpr: see Note [OccInfo in unfoldings and rules] in GHC.Core