Simon Peyton Jones pushed to branch wip/T26989 at Glasgow Haskell Compiler / GHC
Commits:
-
1100029e
by Simon Peyton Jones at 2026-04-13T00:09:18+01:00
3 changed files:
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Ppr.hs
Changes:
| ... | ... | @@ -283,7 +283,7 @@ simplRecOrTopPair :: SimplEnv |
| 283 | 283 | |
| 284 | 284 | simplRecOrTopPair env bind_cxt old_bndr new_bndr rhs
|
| 285 | 285 | | Just env' <- preInlineUnconditionally env (bindContextLevel bind_cxt)
|
| 286 | - old_bndr rhs env
|
|
| 286 | + old_bndr NoDup rhs env
|
|
| 287 | 287 | = {-#SCC "simplRecOrTopPair-pre-inline-uncond" #-}
|
| 288 | 288 | simplTrace "SimplBindr:inline-uncond1" (ppr old_bndr) $
|
| 289 | 289 | do { tick (PreInlineUnconditionally old_bndr)
|
| ... | ... | @@ -1298,7 +1298,7 @@ simplExprF1 env (Let (NonRec bndr rhs) body) cont |
| 1298 | 1298 | do { ty' <- simplType env ty
|
| 1299 | 1299 | ; simplExprF (extendTvSubst env bndr ty') body cont }
|
| 1300 | 1300 | |
| 1301 | - | Just env' <- preInlineUnconditionally env NotTopLevel bndr rhs env
|
|
| 1301 | + | Just env' <- preInlineUnconditionally env NotTopLevel bndr NoDup rhs env
|
|
| 1302 | 1302 | -- Because of the let-can-float invariant, it's ok to
|
| 1303 | 1303 | -- inline freely, or to drop the binding if it is dead.
|
| 1304 | 1304 | = do { simplTrace "SimplBindr:inline-uncond2" (ppr bndr) $
|
| ... | ... | @@ -1869,7 +1869,7 @@ simpl_lam env bndr body (ApplyToVal { sc_arg = arg, sc_env = arg_se |
| 1869 | 1869 | -- It's wrong to err in either direction
|
| 1870 | 1870 | -- But fun_ty is an OutType, so is fully substituted
|
| 1871 | 1871 | |
| 1872 | - ; if | Just env' <- preInlineUnconditionally env NotTopLevel bndr arg arg_se
|
|
| 1872 | + ; if | Just env' <- preInlineUnconditionally env NotTopLevel bndr dup arg arg_se
|
|
| 1873 | 1873 | , not (needsCaseBindingL arg_levity arg)
|
| 1874 | 1874 | -- Ok to test arg::InExpr in needsCaseBinding because
|
| 1875 | 1875 | -- exprOkForSpeculation is stable under simplification
|
| ... | ... | @@ -2686,10 +2686,9 @@ tryRules env rules fn args |
| 2686 | 2686 | | Just rule_match <- lookupRule ropts in_scope_env
|
| 2687 | 2687 | act_fun fn args rules
|
| 2688 | 2688 | -- Fire a rule for the function
|
| 2689 | - = do { let the_rule = rm_rule rule_match
|
|
| 2690 | - ; logger <- getLogger
|
|
| 2691 | - ; checkedTick (RuleFired (ruleName the_rule))
|
|
| 2692 | - ; dump logger the_rule (rm_rhs rule_match)
|
|
| 2689 | + = do { logger <- getLogger
|
|
| 2690 | + ; checkedTick (RuleFired (ruleName (rm_rule rule_match)))
|
|
| 2691 | + ; dump logger rule_match
|
|
| 2693 | 2692 | ; return (Just rule_match) }
|
| 2694 | 2693 | |
| 2695 | 2694 | | otherwise -- No rule fires
|
| ... | ... | @@ -2707,7 +2706,7 @@ tryRules env rules fn args |
| 2707 | 2706 | (pprModuleName . moduleName)
|
| 2708 | 2707 | (ruleModule rule))
|
| 2709 | 2708 | |
| 2710 | - dump logger rule rule_rhs
|
|
| 2709 | + dump logger (RM { rm_rule = rule, rm_rhs = rhs, rm_args = rule_args })
|
|
| 2711 | 2710 | | logHasDumpFlag logger Opt_D_dump_rule_rewrites
|
| 2712 | 2711 | = log_rule Opt_D_dump_rule_rewrites "Rule fired" $ vcat
|
| 2713 | 2712 | [ text "Rule:" <+> ftext (ruleName rule)
|
| ... | ... | @@ -2716,7 +2715,8 @@ tryRules env rules fn args |
| 2716 | 2715 | --, text "Rule activation:" <+> ppr (ruleActivation rule)
|
| 2717 | 2716 | , text "Full arity:" <+> ppr (ruleArity rule)
|
| 2718 | 2717 | , text "Before:" <+> hang (ppr fn) 2 (sep (map ppr args))
|
| 2719 | - , text "After: " <+> pprCoreExpr rule_rhs ]
|
|
| 2718 | + , text "After:" <+> pprCoreExpr (mkApps rhs rule_args)
|
|
| 2719 | + ]
|
|
| 2720 | 2720 | |
| 2721 | 2721 | | logHasDumpFlag logger Opt_D_dump_rule_firings
|
| 2722 | 2722 | = log_rule Opt_D_dump_rule_firings "Rule fired:" $
|
| ... | ... | @@ -3838,7 +3838,7 @@ knownCon env scrut dc dc_args case_bndr alt_bndrs rhs cont |
| 3838 | 3838 | return ( emptyFloats env
|
| 3839 | 3839 | , extendIdSubst env case_bndr (DoneEx scrut NotJoinPoint))
|
| 3840 | 3840 | |
| 3841 | - | Just env' <- preInlineUnconditionally env NotTopLevel case_bndr con_app env
|
|
| 3841 | + | Just env' <- preInlineUnconditionally env NotTopLevel case_bndr NoDup con_app env
|
|
| 3842 | 3842 | = return (emptyFloats env', env')
|
| 3843 | 3843 | |
| 3844 | 3844 | | otherwise
|
| ... | ... | @@ -1565,13 +1565,13 @@ the former. |
| 1565 | 1565 | |
| 1566 | 1566 | preInlineUnconditionally
|
| 1567 | 1567 | :: SimplEnv -> TopLevelFlag -> InId
|
| 1568 | - -> InExpr -> StaticEnv -- These two go together
|
|
| 1568 | + -> DupFlag -> InExpr -> StaticEnv -- These three go together
|
|
| 1569 | 1569 | -> Maybe SimplEnv -- Returned env has extended substitution
|
| 1570 | 1570 | -- Precondition: rhs satisfies the let-can-float invariant
|
| 1571 | 1571 | -- See Note [Core let-can-float invariant] in GHC.Core
|
| 1572 | 1572 | -- Reason: we don't want to inline single uses, or discard dead bindings,
|
| 1573 | 1573 | -- for unlifted, side-effect-ful bindings
|
| 1574 | -preInlineUnconditionally env top_lvl bndr rhs rhs_env
|
|
| 1574 | +preInlineUnconditionally env top_lvl bndr dup rhs rhs_env
|
|
| 1575 | 1575 | | not pre_inline_unconditionally = Nothing
|
| 1576 | 1576 | | not active = Nothing
|
| 1577 | 1577 | | isTopLevel top_lvl && isDeadEndId bndr = Nothing -- Note [Top-level bottoming Ids]
|
| ... | ... | @@ -1584,10 +1584,17 @@ preInlineUnconditionally env top_lvl bndr rhs rhs_env |
| 1584 | 1584 | -- See Note [Stable unfoldings and preInlineUnconditionally]
|
| 1585 | 1585 | | not (isInlinePragma inline_prag)
|
| 1586 | 1586 | , Just inl <- maybeUnfoldingTemplate unf = Just $! (extend_subst_with inl)
|
| 1587 | + |
|
| 1587 | 1588 | | otherwise = Nothing
|
| 1588 | 1589 | where
|
| 1589 | 1590 | unf = idUnfolding bndr
|
| 1590 | - extend_subst_with inl_rhs = extendIdSubst env bndr $! (mkContEx rhs_env inl_rhs)
|
|
| 1591 | + |
|
| 1592 | + -- If the rhs is already simplified, then extend the envt with DoneEx;
|
|
| 1593 | + -- If not then ContEx
|
|
| 1594 | + -- ToDo: flesh this note out
|
|
| 1595 | + extend_subst_with inl_rhs
|
|
| 1596 | + | isSimplified dup = extendIdSubst env bndr $! DoneEx inl_rhs NotJoinPoint
|
|
| 1597 | + | otherwise = extendIdSubst env bndr $! mkContEx rhs_env inl_rhs
|
|
| 1591 | 1598 | |
| 1592 | 1599 | one_occ IAmDead = True -- Happens in ((\x.1) v)
|
| 1593 | 1600 | one_occ OneOcc{ occ_n_br = 1
|
| ... | ... | @@ -430,19 +430,20 @@ pprTypedLamBinder bind_site debug_on var |
| 430 | 430 | = sdocOption sdocSuppressTypeSignatures $ \suppress_sigs ->
|
| 431 | 431 | case () of
|
| 432 | 432 | _
|
| 433 | - | not debug_on -- Show case-bound wild binders only if debug is on
|
|
| 433 | + -- Show case-bound wild binders only if debug is on
|
|
| 434 | + | not debug_on
|
|
| 434 | 435 | , CaseBind <- bind_site
|
| 435 | - , isDeadBinder var -> empty
|
|
| 436 | + -> if isDeadBinder var
|
|
| 437 | + then empty
|
|
| 438 | + else pprUntypedBinder var
|
|
| 436 | 439 | |
| 440 | + -- Show binders as "_" in case patterns
|
|
| 441 | + -- (but not in RULES or let)
|
|
| 437 | 442 | | not debug_on -- Even dead binders can be one-shot
|
| 438 | - , isDeadBinder var -> char '_' <+> ppWhen (isId var)
|
|
| 439 | - (pprIdBndrInfo (idInfo var))
|
|
| 440 | - |
|
| 441 | - | not debug_on -- No parens, no kind info
|
|
| 442 | - , CaseBind <- bind_site -> pprUntypedBinder var
|
|
| 443 | - |
|
| 444 | - | not debug_on
|
|
| 445 | - , CasePatBind <- bind_site -> pprUntypedBinder var
|
|
| 443 | + , CasePatBind <- bind_site
|
|
| 444 | + -> if (isDeadBinder var)
|
|
| 445 | + then char '_' <+> ppWhen (isId var) (pprIdBndrInfo (idInfo var))
|
|
| 446 | + else pprUntypedBinder var
|
|
| 446 | 447 | |
| 447 | 448 | | suppress_sigs -> pprUntypedBinder var
|
| 448 | 449 |