diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2021-11-01 20:44:52 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-11-07 12:54:30 -0500 |
commit | 0d8a883e4b880453e044af3a69a96a648496926f (patch) | |
tree | c7ef1596759dca46fbe27ff84213e26e480f82ed | |
parent | 7045b7831cae974ed3a96aa8246ec93846aa868b (diff) | |
download | haskell-0d8a883e4b880453e044af3a69a96a648496926f.tar.gz |
Don't undersaturate join points through eta-reduction.
In #20599 I ran into an issue where the unfolding for a join point was
eta-reduced removing the required lambdas.
This patch adds guards that should prevent this from happening going
forward.
-rw-r--r-- | compiler/GHC/Core/Utils.hs | 7 | ||||
-rw-r--r-- | compiler/GHC/CoreToStg/Prep.hs | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/compiler/GHC/Core/Utils.hs b/compiler/GHC/Core/Utils.hs index 6b7eb3bf11..271380557d 100644 --- a/compiler/GHC/Core/Utils.hs +++ b/compiler/GHC/Core/Utils.hs @@ -2460,7 +2460,12 @@ tryEtaReduce bndrs body ok_fun _fun = False --------------- - ok_fun_id fun = fun_arity fun >= incoming_arity + ok_fun_id fun = -- There are arguments to reduce + fun_arity fun >= incoming_arity && + -- We always want args for join points so + -- we should never eta-reduce to a trivial expression. + -- See Note [Invariants on join points] in GHC.Core, and #20599 + not (isJoinId fun) --------------- fun_arity fun -- See Note [Arity care] diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs index 675ef7776c..bc12ec2b63 100644 --- a/compiler/GHC/CoreToStg/Prep.hs +++ b/compiler/GHC/CoreToStg/Prep.hs @@ -1527,7 +1527,13 @@ tryEtaReducePrep bndrs expr@(App _ _) ok _ _ = False -- We can't eta reduce something which must be saturated. - ok_to_eta_reduce (Var f) = not (hasNoBinding f) && not (isLinearType (idType f)) + ok_to_eta_reduce (Var f) = not (hasNoBinding f) && + not (isLinearType (idType f)) && -- Unsure why this is unsafe. + (not (isJoinId f) || idJoinArity f <= n_remaining) + -- Don't undersaturate join points. + -- See Note [Invariants on join points] in GHC.Core, and #20599 + + ok_to_eta_reduce _ = False -- Safe. ToDo: generalise |