diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2022-10-06 10:59:29 +0200 |
---|---|---|
committer | Sebastian Graf <sebastian.graf@kit.edu> | 2022-10-12 13:15:31 +0200 |
commit | f4bfd14be676e75c6b126721251097524fd83d46 (patch) | |
tree | d5e1546d858ea59d69ef4ae7e12a569f62982a48 /compiler/GHC/Core.hs | |
parent | ed4b5885bdac7b986655bb40f8c9ece2f8735c98 (diff) | |
download | haskell-wip/T22277.tar.gz |
Denest NonRecs in SpecConstr for more specialisation (#22277)wip/T22277
See Note [Denesting non-recursive let bindings].
Fixes #22277. It is also related to #14951 and #14844 in that it
fixes a very specific case of looking through a non-recursive let binding in
SpecConstr.
Diffstat (limited to 'compiler/GHC/Core.hs')
-rw-r--r-- | compiler/GHC/Core.hs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/GHC/Core.hs b/compiler/GHC/Core.hs index c1ed8d741d..ef856d76c9 100644 --- a/compiler/GHC/Core.hs +++ b/compiler/GHC/Core.hs @@ -41,7 +41,7 @@ module GHC.Core ( isId, cmpAltCon, cmpAlt, ltAlt, -- ** Simple 'Expr' access functions and predicates - bindersOf, bindersOfBinds, rhssOfBind, rhssOfAlts, + bindersOf, bindersOfBinds, rhssOfBind, rhssOfAlts, collectLets, collectBinders, collectTyBinders, collectTyAndValBinders, collectNBinders, collectNValBinders_maybe, collectArgs, stripNArgs, collectArgsTicks, flattenBinds, @@ -1940,6 +1940,15 @@ flattenBinds (NonRec b r : binds) = (b,r) : flattenBinds binds flattenBinds (Rec prs1 : binds) = prs1 ++ flattenBinds binds flattenBinds [] = [] +-- | We often want to strip off leading 'Let's before getting down to +-- business. The inverse of 'mkLets'. +collectLets :: Expr b -> ([Bind b], Expr b) +collectLets expr + = go [] expr + where + go bs (Let b e) = go (b:bs) e + go bs e = (reverse bs, e) + -- | We often want to strip off leading lambdas before getting down to -- business. Variants are 'collectTyBinders', 'collectValBinders', -- and 'collectTyAndValBinders' @@ -1957,7 +1966,7 @@ collectBinders expr = go [] expr where go bs (Lam b e) = go (b:bs) e - go bs e = (reverse bs, e) + go bs e = (reverse bs, e) collectTyBinders expr = go [] expr |