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

Commits:

4 changed files:

Changes:

  • compiler/GHC/Builtin/WiredIn/Ids.hs
    ... ... @@ -616,15 +616,15 @@ Here are the moving parts:
    616 616
     * In the Simplifier, see the `isNoInlineId` case of `simplOutId`.
    
    617 617
       When we encounter    noinline (f e1 e2) e3 e4:
    
    618 618
     
    
    619
    -  * We switch off inlining before simplifying `f` (#18995)
    
    619
    +  * (NOI0-a) We switch off inlining before simplifying `f` (#18995)
    
    620 620
         See `GHC.Core.Opt.Simplify.Unils.updModeForNoInline`.
    
    621 621
     
    
    622
    -  * We slide `e3` and `e4` under the `noinline` to give
    
    622
    +  * (NOI0-b) We slide `e3` and `e4` under the `noinline` to give
    
    623 623
              noinline (f e1 e2 e3 e4)
    
    624 624
         See wrinkle (NOI1)
    
    625 625
     
    
    626
    -* In GHC.CoreToStg.Prep.cpe_app, we discard the `noinline`, so that
    
    627
    -  there is no runtime overhead.
    
    626
    +* (NOI0-c)  In GHC.CoreToStg.Prep.cpe_app, we discard the `noinline`,
    
    627
    +  so that there is no runtime overhead.
    
    628 628
     
    
    629 629
     Wrinkles
    
    630 630
     
    
    ... ... @@ -698,6 +698,13 @@ Wrinkles
    698 698
       we just simplify the whole `noinline` argument with inlining switched off,
    
    699 699
       like let/case.
    
    700 700
     
    
    701
    +(NOI8) We must also be careful of
    
    702
    +            noinline (f (case x of (a,b) -> blah))
    
    703
    +  where `f` is strict.  We do not want to get
    
    704
    +            noinline (case x of (a,b) -> f blah)
    
    705
    +  because that doesn't look like a plain call any more.  So we switch off
    
    706
    +  `sm_case_case` when simplifying the function, as well as switching off `sm_inline`.
    
    707
    +
    
    701 708
     Note [nospecId magic]
    
    702 709
     ~~~~~~~~~~~~~~~~~~~~~
    
    703 710
     The 'nospec' magic Id is used to ensure to make a value opaque to the typeclass
    

  • compiler/GHC/Core/Opt/Simplify/Iteration.hs
    ... ... @@ -1821,8 +1821,15 @@ simplArg :: SimplEnvIS -- ^ Used only for its InScopeSet
    1821 1821
                                         --   continuation passed to 'simplExprC'
    
    1822 1822
              -> OutType                 -- ^ Type of the function applied to this arg
    
    1823 1823
              -> StaticEnv -> CoreExpr   -- ^ Expression with its static envt
    
    1824
    -         -> MOutCoercion            -- Wrap this around the result
    
    1824
    +         -> MOutCoercion            -- ^ Wrap this around the result
    
    1825 1825
              -> SimplM OutExpr
    
    1826
    +-- Simplify a function argument
    
    1827
    +--
    
    1828
    +-- DO NOT float anything outside, hence simplExprC. Doing sio is no benefit (unlike
    
    1829
    +-- in a let-binding), and we'd have to be very careful about
    
    1830
    +--     f (let x*=e in b)
    
    1831
    +-- If we floated that let out, and f was lazy, the demand info on `x` would be
    
    1832
    +-- unsound, so (a) we'd have to zap it and (b) it'd be unsound
    
    1826 1833
     simplArg _ _ _ (Simplified {}) arg mco
    
    1827 1834
       = -- See Note [Avoid repeated simplification]
    
    1828 1835
         return (mkCastMCo arg mco)  -- Handles the very common case of mco=MRefl
    
    ... ... @@ -2379,6 +2386,7 @@ simplOutId env noinline_fun cont
    2379 2386
       , ApplyToVal { sc_cont = outer_cont, sc_arg = the_call, sc_cast = call_mco
    
    2380 2387
                    , sc_env = UnSimplified arg_se } <- cont2
    
    2381 2388
       = do { let -- encl_app_cont collects any /arguments/ from `outer_cont`
    
    2389
    +             -- This implements (NOI0-b) in Note [noinlineId magic]
    
    2382 2390
                  (encl_app_cont, new_outer_cont) = splitContArgs outer_cont
    
    2383 2391
                  new_call_ty                     = contHoleType new_outer_cont
    
    2384 2392
     
    
    ... ... @@ -2400,15 +2408,14 @@ simplOutId env noinline_fun cont
    2400 2408
                        do { let call_stop = addCastMCo call_mco (mkBoringStop call_ty)
    
    2401 2409
                           ; return (the_call, call_stop, call_ty, outer_cont) }
    
    2402 2410
     
    
    2403
    -       -- Now simplify the function itself, in call_cont, crucially setting
    
    2404
    -       -- sm_inline = False. The /arguments/ in `call_cont` will be simplified
    
    2405
    -       -- with their own flags, captured in `arg_se`
    
    2411
    +       -- Now simplify the function itself, in call_cont,
    
    2412
    +       --   crucially setting sm_inline=False and sm_case_case=False.
    
    2413
    +       -- The /arguments/ in `call_cont` will be simplified
    
    2414
    +       --   with their own flags, captured in `arg_se`
    
    2406 2415
            ; let call_env = updMode updModeForNoInline $
    
    2407 2416
                             arg_se `setInScopeFromE` env
    
    2408
    -       ; (floats1, call1) <- wrapJoinFloatsX $
    
    2409
    -                             simplExprF call_env inner_fun call_cont
    
    2410
    -             -- wrapJoinFloatsX: any floating join bindings must stay
    
    2411
    -             --                  around the call, not be floated out
    
    2417
    +       ; call1 <- simplExprC call_env inner_fun call_cont
    
    2418
    +             -- simplExprC: don't float anthing out of a `noinline` call
    
    2412 2419
     
    
    2413 2420
            -- Now `rebuild` does the rest, wrapping in final_outer_cont
    
    2414 2421
            ; let (new_noinline_fun, rep) = getNoinlineId final_call_ty
    
    ... ... @@ -2416,9 +2423,8 @@ simplOutId env noinline_fun cont
    2416 2423
                                  `App` Type rep
    
    2417 2424
                                  `App` Type final_call_ty
    
    2418 2425
                                  `App` call1
    
    2419
    -       ; (floats2, res) <- rebuild (env `setInScopeFromF` floats1)
    
    2420
    -                                   noinline_expr final_outer_cont
    
    2421
    -       ; return (floats1 `addFloats` floats2 , res) }
    
    2426
    +       ; rebuild (env `setInScopeFromF` floats1)
    
    2427
    +                 noinline_expr final_outer_cont }
    
    2422 2428
     
    
    2423 2429
       where
    
    2424 2430
         var_at_head :: CoreExpr -> Bool
    
    ... ... @@ -2537,10 +2543,6 @@ rebuildCall env fun_info
    2537 2543
                     -- Note [Shadowing in the Simplifier]
    
    2538 2544
     
    
    2539 2545
       | otherwise      -- Lazy, or already simplified arguments
    
    2540
    -  -- DO NOT float anything outside, hence simplExprC
    
    2541
    -  -- There is no benefit (unlike in a let-binding), and we'd
    
    2542
    -  -- have to be very careful about bogus strictness through
    
    2543
    -  -- floating a demanded let.
    
    2544 2546
       = do  { arg' <- simplArg env (Just fun_info) fun_ty arg_se arg arg_mco
    
    2545 2547
             ; rebuildCall env (addValArgTo fun_info  arg' fun_ty) cont }
    
    2546 2548
     
    

  • compiler/GHC/Core/Opt/Simplify/Utils.hs
    ... ... @@ -1251,7 +1251,8 @@ updModeForRuleRHS rule_act current_mode =
    1251 1251
     
    
    1252 1252
     updModeForNoInline :: SimplMode -> SimplMode
    
    1253 1253
     -- See Note [noinlineId magic] in GHC.Builtin.WiredIn.Ids
    
    1254
    -updModeForNoInline mode = mode { sm_inline = False }
    
    1254
    +updModeForNoInline mode = mode { sm_inline    = False     -- (NOI0-a)
    
    1255
    +                               , sm_case_case = False }   -- (NOI8)
    
    1255 1256
     
    
    1256 1257
     -- | `phaseForRuleOrUnf` computes the phase range to use when
    
    1257 1258
     -- simplifying the RHS of a rule or of a stable unfolding.
    

  • testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
    No preview for this file type