summaryrefslogtreecommitdiff
path: root/compiler/hsSyn/HsBinds.hs
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2017-06-27 10:30:20 -0400
committerBen Gamari <ben@smart-cactus.org>2017-06-27 13:34:05 -0400
commit6567c815135e93f8550d526f81d13f31c0cd92b6 (patch)
treecf842eaf2045f5ae36579b5e64200c61a8fe7b75 /compiler/hsSyn/HsBinds.hs
parent1e471265c1ea9b2c4e9709adc182c36d0635f071 (diff)
downloadhaskell-6567c815135e93f8550d526f81d13f31c0cd92b6.tar.gz
Treat banged bindings as FunBinds
This is another attempt at resolving #13594 by treating strict variable binds as FunBinds instead of PatBinds (as suggested in comment:1). Test Plan: Validate Reviewers: austin, alanz Subscribers: rwbarton, thomie, mpickering GHC Trac Issues: #13594 Differential Revision: https://phabricator.haskell.org/D3670
Diffstat (limited to 'compiler/hsSyn/HsBinds.hs')
-rw-r--r--compiler/hsSyn/HsBinds.hs40
1 files changed, 38 insertions, 2 deletions
diff --git a/compiler/hsSyn/HsBinds.hs b/compiler/hsSyn/HsBinds.hs
index d0c345a9e5..f08a6af700 100644
--- a/compiler/hsSyn/HsBinds.hs
+++ b/compiler/hsSyn/HsBinds.hs
@@ -129,12 +129,41 @@ type LHsBindsLR idL idR = Bag (LHsBindLR idL idR)
-- | Located Haskell Binding with separate Left and Right identifier types
type LHsBindLR idL idR = Located (HsBindLR idL idR)
+{- Note [Varieties of binding pattern matches]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The distinction between FunBind and PatBind is a bit subtle. FunBind covers
+patterns which resemble function bindings and simple variable bindings.
+
+ f x = e
+ f !x = e
+ f = e
+ !x = e -- FunRhs has SrcStrict
+ x `f` y = e -- FunRhs has Infix
+
+The actual patterns and RHSs of a FunBind are encoding in fun_matches.
+The m_ctxt field of Match will be FunRhs and carries two bits of information
+about the match,
+
+ * the mc_strictness field describes whether the match is decorated with a bang
+ (e.g. `!x = e`)
+ * the mc_fixity field describes the fixity of the function binder
+
+By contrast, PatBind represents data constructor patterns, as well as a few
+other interesting cases. Namely,
+
+ Just x = e
+ (x) = e
+ x :: Ty = e
+-}
+
-- | Haskell Binding with separate Left and Right id's
data HsBindLR idL idR
- = -- | Function Binding
+ = -- | Function-like Binding
--
-- FunBind is used for both functions @f x = e@
-- and variables @f = \x -> e@
+ -- and strict variables @!x = x + 1@
--
-- Reason 1: Special case for type inference: see 'TcBinds.tcMonoBinds'.
--
@@ -145,6 +174,10 @@ data HsBindLR idL idR
-- parses as a pattern binding, just like
-- @(f :: a -> a) = ... @
--
+ -- Strict bindings have their strictness recorded in the 'SrcStrictness' of their
+ -- 'MatchContext'. See Note [Varieties of binding pattern matches] for
+ -- details about the relationship between FunBind and PatBind.
+ --
-- 'ApiAnnotation.AnnKeywordId's
--
-- - 'ApiAnnotation.AnnFunId', attached to each element of fun_matches
@@ -185,7 +218,10 @@ data HsBindLR idL idR
-- | Pattern Binding
--
-- The pattern is never a simple variable;
- -- That case is done by FunBind
+ -- That case is done by FunBind.
+ -- See Note [Varieties of binding pattern matches] for details about the
+ -- relationship between FunBind and PatBind.
+
--
-- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnBang',
-- 'ApiAnnotation.AnnEqual','ApiAnnotation.AnnWhere',