summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2020-03-09 10:32:23 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-03-14 05:29:55 -0400
commit88f7a76208b0fcf41ca0e16d18a71523f0601ee5 (patch)
treed1af4b334038872ea16ab9c28e40b51ef749cb03 /compiler/GHC
parent2f8c77673f1faf0d8fed6df2bdd1ca15d696a010 (diff)
downloadhaskell-88f7a76208b0fcf41ca0e16d18a71523f0601ee5.tar.gz
Improve CSE.combineAlts
This patch improves the way that CSE combines identical alternatives. See #17901. I'm still not happy about the duplication between CSE.combineAlts and GHC.Core.Utils.combineIdenticalAlts; see the Notes with those functions. But this patch is a step forward. Metric Decrease: T12425 T5642
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/Core/Utils.hs25
1 files changed, 21 insertions, 4 deletions
diff --git a/compiler/GHC/Core/Utils.hs b/compiler/GHC/Core/Utils.hs
index c846d2ac2e..82d920a58e 100644
--- a/compiler/GHC/Core/Utils.hs
+++ b/compiler/GHC/Core/Utils.hs
@@ -864,10 +864,27 @@ This gave rise to a horrible sequence of cases
and similarly in cascade for all the join points!
-NB: it's important that all this is done in [InAlt], *before* we work
-on the alternatives themselves, because Simplify.simplAlt may zap the
-occurrence info on the binders in the alternatives, which in turn
-defeats combineIdenticalAlts (see #7360).
+Note [Combine identical alternatives: wrinkles]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* It's important that we try to combine alternatives *before*
+ simplifying them, rather than after. Reason: because
+ Simplify.simplAlt may zap the occurrence info on the binders in the
+ alternatives, which in turn defeats combineIdenticalAlts use of
+ isDeadBinder (see #7360).
+
+ You can see this in the call to combineIdenticalAlts in
+ SimplUtils.prepareAlts. Here the alternatives have type InAlt
+ (the "In" meaning input) rather than OutAlt.
+
+* combineIdenticalAlts does not work well for nullary constructors
+ case x of y
+ [] -> f []
+ (_:_) -> f y
+ Here we won't see that [] and y are the same. Sigh! This problem
+ is solved in CSE, in CSE.combineAlts, which does a better version of
+ combineIdenticalAlts. But sadly it doesn't have the occurrence info
+ we have here. See Note [Combine case alts: awkward corner] in CSE).
Note [Care with impossible-constructors when combining alternatives]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~