summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
authorAdam Sandberg Eriksson <adam@sandbergericsson.se>2019-11-01 22:54:04 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-08 10:15:38 -0500
commit588acb99bc3cb377ceb76447dd60656b4a11de5a (patch)
tree598a83c392cca6ed977046685469038d661f831c /compiler/GHC
parent7c1228511f2dd4d262c04edb8539174a7de810b2 (diff)
downloadhaskell-588acb99bc3cb377ceb76447dd60656b4a11de5a.tar.gz
slightly better named cost-centres for simple pattern bindings #17006
``` main = do print $ g [1..100] a where g xs x = map (`mod` x) xs a :: Int = 324 ``` The above program previously attributed the cost of computing 324 to a cost centre named `(...)`, with this change the cost is attributed to `a` instead. This change only affects simple pattern bindings (decorated variables: type signatures, parens, ~ annotations and ! annotations).
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/Hs/Pat.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/GHC/Hs/Pat.hs b/compiler/GHC/Hs/Pat.hs
index 945c2c195f..9812fe2c44 100644
--- a/compiler/GHC/Hs/Pat.hs
+++ b/compiler/GHC/Hs/Pat.hs
@@ -31,6 +31,7 @@ module GHC.Hs.Pat (
mkPrefixConPat, mkCharLitPat, mkNilPat,
+ isSimplePat,
looksLazyPatBind,
isBangedLPat,
patNeedsParens, parenthesizePat,
@@ -274,6 +275,7 @@ data Pat p
| XPat
(XXPat p)
+
-- ---------------------------------------------------------------------
data ListPatTc
@@ -730,6 +732,23 @@ isIrrefutableHsPat
go (XPat {}) = False
+-- | Is the pattern any of combination of:
+--
+-- - (pat)
+-- - pat :: Type
+-- - ~pat
+-- - !pat
+-- - x (variable)
+isSimplePat :: LPat (GhcPass x) -> Maybe (IdP (GhcPass x))
+isSimplePat p = case unLoc p of
+ ParPat _ x -> isSimplePat x
+ SigPat _ x _ -> isSimplePat x
+ LazyPat _ x -> isSimplePat x
+ BangPat _ x -> isSimplePat x
+ VarPat _ x -> Just (unLoc x)
+ _ -> Nothing
+
+
{- Note [Unboxed sum patterns aren't irrefutable]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unlike unboxed tuples, unboxed sums are *not* irrefutable when used as