diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2017-05-08 17:47:19 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-05-08 22:26:41 -0400 |
commit | 372995364c52eef15066132d7d1ea8b6760034e6 (patch) | |
tree | 1b5d39684c0fe65636a43ff67405615abd2ea8c6 /compiler/hsSyn/HsBinds.hs | |
parent | b99bae6d132e083b73283963be85932596341ddd (diff) | |
download | haskell-372995364c52eef15066132d7d1ea8b6760034e6.tar.gz |
Treat banged bindings as FunBinds
This reworks the HsSyn representation to make banged variable patterns
(e.g. !x = e) be represented as FunBinds instead of PatBinds, adding a flag to
FunRhs to record the bang.
Fixes #13594.
Reviewers: austin, goldfire, alanz, simonpj
Reviewed By: simonpj
Subscribers: simonpj, rwbarton, thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D3525
Diffstat (limited to 'compiler/hsSyn/HsBinds.hs')
-rw-r--r-- | compiler/hsSyn/HsBinds.hs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/compiler/hsSyn/HsBinds.hs b/compiler/hsSyn/HsBinds.hs index b39e25a2c7..5fd523f820 100644 --- a/compiler/hsSyn/HsBinds.hs +++ b/compiler/hsSyn/HsBinds.hs @@ -132,12 +132,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'. -- @@ -148,6 +177,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 [Varities 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 @@ -188,7 +221,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 [Varities of binding pattern matches] for details about the + -- relationship between FunBind and PatBind. + -- -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnBang', -- 'ApiAnnotation.AnnEqual','ApiAnnotation.AnnWhere', |