[Git][ghc/ghc][wip/T27724] More wibbles [skip ci]
Simon Peyton Jones pushed to branch wip/T27724 at Glasgow Haskell Compiler / GHC Commits: 0b32f133 by Simon Peyton Jones at 2026-11-23T15:40:53+00:00 More wibbles [skip ci] - - - - - 4 changed files: - compiler/GHC/Builtin/WiredIn/Ids.hs - compiler/GHC/Core/Opt/Simplify/Iteration.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs Changes: ===================================== compiler/GHC/Builtin/WiredIn/Ids.hs ===================================== @@ -616,15 +616,15 @@ Here are the moving parts: * In the Simplifier, see the `isNoInlineId` case of `simplOutId`. When we encounter noinline (f e1 e2) e3 e4: - * We switch off inlining before simplifying `f` (#18995) + * (NOI0-a) We switch off inlining before simplifying `f` (#18995) See `GHC.Core.Opt.Simplify.Unils.updModeForNoInline`. - * We slide `e3` and `e4` under the `noinline` to give + * (NOI0-b) We slide `e3` and `e4` under the `noinline` to give noinline (f e1 e2 e3 e4) See wrinkle (NOI1) -* In GHC.CoreToStg.Prep.cpe_app, we discard the `noinline`, so that - there is no runtime overhead. +* (NOI0-c) In GHC.CoreToStg.Prep.cpe_app, we discard the `noinline`, + so that there is no runtime overhead. Wrinkles @@ -698,6 +698,13 @@ Wrinkles we just simplify the whole `noinline` argument with inlining switched off, like let/case. +(NOI8) We must also be careful of + noinline (f (case x of (a,b) -> blah)) + where `f` is strict. We do not want to get + noinline (case x of (a,b) -> f blah) + because that doesn't look like a plain call any more. So we switch off + `sm_case_case` when simplifying the function, as well as switching off `sm_inline`. + Note [nospecId magic] ~~~~~~~~~~~~~~~~~~~~~ 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 -- continuation passed to 'simplExprC' -> OutType -- ^ Type of the function applied to this arg -> StaticEnv -> CoreExpr -- ^ Expression with its static envt - -> MOutCoercion -- Wrap this around the result + -> MOutCoercion -- ^ Wrap this around the result -> SimplM OutExpr +-- Simplify a function argument +-- +-- DO NOT float anything outside, hence simplExprC. Doing sio is no benefit (unlike +-- in a let-binding), and we'd have to be very careful about +-- f (let x*=e in b) +-- If we floated that let out, and f was lazy, the demand info on `x` would be +-- unsound, so (a) we'd have to zap it and (b) it'd be unsound simplArg _ _ _ (Simplified {}) arg mco = -- See Note [Avoid repeated simplification] return (mkCastMCo arg mco) -- Handles the very common case of mco=MRefl @@ -2379,6 +2386,7 @@ simplOutId env noinline_fun cont , ApplyToVal { sc_cont = outer_cont, sc_arg = the_call, sc_cast = call_mco , sc_env = UnSimplified arg_se } <- cont2 = do { let -- encl_app_cont collects any /arguments/ from `outer_cont` + -- This implements (NOI0-b) in Note [noinlineId magic] (encl_app_cont, new_outer_cont) = splitContArgs outer_cont new_call_ty = contHoleType new_outer_cont @@ -2400,15 +2408,14 @@ simplOutId env noinline_fun cont do { let call_stop = addCastMCo call_mco (mkBoringStop call_ty) ; return (the_call, call_stop, call_ty, outer_cont) } - -- Now simplify the function itself, in call_cont, crucially setting - -- sm_inline = False. The /arguments/ in `call_cont` will be simplified - -- with their own flags, captured in `arg_se` + -- Now simplify the function itself, in call_cont, + -- crucially setting sm_inline=False and sm_case_case=False. + -- The /arguments/ in `call_cont` will be simplified + -- with their own flags, captured in `arg_se` ; let call_env = updMode updModeForNoInline $ arg_se `setInScopeFromE` env - ; (floats1, call1) <- wrapJoinFloatsX $ - simplExprF call_env inner_fun call_cont - -- wrapJoinFloatsX: any floating join bindings must stay - -- around the call, not be floated out + ; call1 <- simplExprC call_env inner_fun call_cont + -- simplExprC: don't float anthing out of a `noinline` call -- Now `rebuild` does the rest, wrapping in final_outer_cont ; let (new_noinline_fun, rep) = getNoinlineId final_call_ty @@ -2416,9 +2423,8 @@ simplOutId env noinline_fun cont `App` Type rep `App` Type final_call_ty `App` call1 - ; (floats2, res) <- rebuild (env `setInScopeFromF` floats1) - noinline_expr final_outer_cont - ; return (floats1 `addFloats` floats2 , res) } + ; rebuild (env `setInScopeFromF` floats1) + noinline_expr final_outer_cont } where var_at_head :: CoreExpr -> Bool @@ -2537,10 +2543,6 @@ rebuildCall env fun_info -- Note [Shadowing in the Simplifier] | otherwise -- Lazy, or already simplified arguments - -- DO NOT float anything outside, hence simplExprC - -- There is no benefit (unlike in a let-binding), and we'd - -- have to be very careful about bogus strictness through - -- floating a demanded let. = do { arg' <- simplArg env (Just fun_info) fun_ty arg_se arg arg_mco ; rebuildCall env (addValArgTo fun_info arg' fun_ty) cont } ===================================== compiler/GHC/Core/Opt/Simplify/Utils.hs ===================================== @@ -1251,7 +1251,8 @@ updModeForRuleRHS rule_act current_mode = updModeForNoInline :: SimplMode -> SimplMode -- See Note [noinlineId magic] in GHC.Builtin.WiredIn.Ids -updModeForNoInline mode = mode { sm_inline = False } +updModeForNoInline mode = mode { sm_inline = False -- (NOI0-a) + , sm_case_case = False } -- (NOI8) -- | `phaseForRuleOrUnf` computes the phase range to use when -- simplifying the RHS of a rule or of a stable unfolding. ===================================== testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs ===================================== @@ -4281,7 +4281,7 @@ module GHC.Base where newSmallArray# :: forall {l :: Levity} (a :: TYPE (BoxedRep l)) d. Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #) newTVar# :: forall {l :: Levity} (a :: TYPE (BoxedRep l)) d. a -> State# d -> (# State# d, TVar# d a #) noDuplicate# :: forall d. State# d -> State# d - noinline :: forall a. a -> a + noinline :: forall {q :: RuntimeRep} (a :: TYPE q). a -> a not :: Bool -> Bool not# :: Word# -> Word# not64# :: Word64# -> Word64# @@ -6324,7 +6324,7 @@ module GHC.Exts where newSmallArray# :: forall {l :: Levity} (a :: TYPE (BoxedRep l)) d. Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #) newTVar# :: forall {l :: Levity} (a :: TYPE (BoxedRep l)) d. a -> State# d -> (# State# d, TVar# d a #) noDuplicate# :: forall d. State# d -> State# d - noinline :: forall a. a -> a + noinline :: forall {q :: RuntimeRep} (a :: TYPE q). a -> a not# :: Word# -> Word# not64# :: Word64# -> Word64# notI# :: Int# -> Int# View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0b32f133436a46c5dceecece06989c3e... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0b32f133436a46c5dceecece06989c3e... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Simon Peyton Jones (@simonpj)