[Git][ghc/ghc][wip/T27484] Some changes on my laptop
Simon Peyton Jones pushed to branch wip/T27484 at Glasgow Haskell Compiler / GHC Commits: dab4ff84 by Simon Peyton Jones at 2026-08-11T22:26:43+01:00 Some changes on my laptop I'm not sure if they are /good/ changes! - - - - - 3 changed files: - compiler/GHC/Core/Opt/OccurAnal.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Types/Basic.hs Changes: ===================================== compiler/GHC/Core/Opt/OccurAnal.hs ===================================== @@ -3061,10 +3061,45 @@ OccEncl is used to control whether to inline into constructor arguments. The OccRhs just tells occAnalApp to mark occurrences in constructor args -* OccInteresting: consider (case x of ...). Here we want to give `x` OneOcc - with "interesting context" field int_cxt = True. The OccInteresting tells - occAnalApp (which deals with lone variables too) when to set this field - to True. +* OccInteresting: see Note [Interesting occurrences] + +Note [Interesting function occurrences] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have a binding + f = \x. blah +that occurs exactly once, but under a lambda. Should we substitute `f` at its +unique occurrence site? (Since there is ony one occurrence, there is no code bloat +to worry about.) Consider these cases: + + (a) \y. h f2 + Do not substitute. If we did, each time we call this lambda we'd have to + allocate a \x.blah closure. + + (b) \y. h (\z. f) + Do substitute. The \x will join with the \z, so there will be no new allocation. + + (c) \y. f 3 y + Do substitute: the function is applied. + +We only want to inline-single-use-under-lambda where the thing to be inlined is +itself a /lambda/, or a PAP, but not for other HNFs. In particualr, for data +constructors we get all the goodness without inlining. E.g. + let x = (p,q) in \y. ...(case x of (a,b) -> rhs)... +We don't need to inline `x` to eliminate the case. + +To accomplish this: + + * Occurrence analysis uses the `occ_encl` field of the `OccEnv` to set + `occ_int_cxt` to `IsInteresting`, for variables that are applied (e.g. (c) above) + or are the immediate body of a lambda (b). + + `occ_int_cxt` is only used for interesting /function/ occurences. + + * The `uf_is_vlam` field of the `UnfoldingCache` of an unfolding records if the + unfolding is a manifest lambda; that is (manifestArity > 0). + + * `preInlineUnconditionally` and `postInlineUnconditionally` both use `occ_int_cxt` + and `uf_is_vlam` (via `isValueLamUnfolding`). -} data OccEncl -- See Note [OccEncl] ===================================== compiler/GHC/Core/Opt/Simplify/Utils.hs ===================================== @@ -1863,9 +1863,8 @@ postInlineUnconditionally env bind_cxt old_bndr bndr rhs -- the uses in C1, C2 are not 'interesting' -- An example that gets worse if you add int_cxt here is 'clausify' - -- InsideLam: check for acceptable work duplication, using isCheapUnfoldign - -- int_cxt to prevent us inlining inside a lambda without some - -- good reason. See the notes on int_cxt in preInlineUnconditionally + -- InsideLam: isValueLamUnfolding checks that the function is a manifest lambda + -- See Note [Interesting function occurrences] in GHC.Core.Opt.OccurAnal -- is_unlifted = isUnliftedType (idType bndr) is_demanded = isStrUsedDmd (idDemandInfo bndr) ===================================== compiler/GHC/Types/Basic.hs ===================================== @@ -845,7 +845,6 @@ means that it is /used/ only once. It might occur syntactically many times. For example, in (case x of A -> y; B -> y; C -> True), * `y` is used only once * but it occurs syntactically twice - -} -- | identifier Occurrence Information @@ -909,11 +908,9 @@ seqOccInfo occ = occ `seq` () ----------------- -- | Interesting Context +-- See Note [Interesting occurrences] in GHC.Core.Opt.Occ data InterestingCxt - = IsInteresting - -- ^ Function: is applied - -- Data value: scrutinised by a case with at least one non-DEFAULT branch - | NotInteresting + = IsInteresting | NotInteresting deriving (Eq) -- | If there is any 'interesting' identifier occurrence, then the View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dab4ff84d8146030e38061a30ed69034... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dab4ff84d8146030e38061a30ed69034... 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)