summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2018-04-02 21:32:33 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2018-04-02 23:38:47 +0200
commit5593b3692eee0dbcaaf277938d485531836efa11 (patch)
tree0131eae56d5b2140024a7d6c72097536f0c59056
parent83a628592ad8071ff62ce8cdaee5a45d99c32805 (diff)
downloadhaskell-5593b3692eee0dbcaaf277938d485531836efa11.tar.gz
Add TTG to HsBinds
-rw-r--r--compiler/deSugar/Coverage.hs1
-rw-r--r--compiler/deSugar/DsBinds.hs1
-rw-r--r--compiler/deSugar/DsMeta.hs12
-rw-r--r--compiler/hsSyn/Convert.hs4
-rw-r--r--compiler/hsSyn/HsBinds.hs43
-rw-r--r--compiler/hsSyn/HsExtension.hs24
-rw-r--r--compiler/hsSyn/HsInstances.hs18
-rw-r--r--compiler/hsSyn/HsUtils.hs20
-rw-r--r--compiler/parser/Parser.y8
-rw-r--r--compiler/parser/RdrHsSyn.hs11
-rw-r--r--compiler/rename/RnBinds.hs26
-rw-r--r--compiler/rename/RnSource.hs6
-rw-r--r--compiler/typecheck/TcBinds.hs34
-rw-r--r--compiler/typecheck/TcClassDcl.hs3
-rw-r--r--compiler/typecheck/TcHsSyn.hs22
-rw-r--r--compiler/typecheck/TcInstDcls.hs11
-rw-r--r--compiler/typecheck/TcPatSyn.hs8
-rw-r--r--compiler/typecheck/TcRnDriver.hs2
-rw-r--r--testsuite/tests/parser/should_compile/DumpParsedAst.stderr2
-rw-r--r--testsuite/tests/parser/should_compile/DumpRenamedAst.stderr4
-rw-r--r--testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr11
-rw-r--r--utils/ghctags/Main.hs3
m---------utils/haddock0
23 files changed, 177 insertions, 97 deletions
diff --git a/compiler/deSugar/Coverage.hs b/compiler/deSugar/Coverage.hs
index 59abbc74b4..431acddbc9 100644
--- a/compiler/deSugar/Coverage.hs
+++ b/compiler/deSugar/Coverage.hs
@@ -351,6 +351,7 @@ addTickLHsBind (L pos (pat@(PatBind { pat_lhs = lhs, pat_rhs = rhs }))) = do
-- Only internal stuff, not from source, uses VarBind, so we ignore it.
addTickLHsBind var_bind@(L _ (VarBind {})) = return var_bind
addTickLHsBind patsyn_bind@(L _ (PatSynBind {})) = return patsyn_bind
+addTickLHsBind bind@(L _ (XHsBindsLR {})) = return bind
bindTick
diff --git a/compiler/deSugar/DsBinds.hs b/compiler/deSugar/DsBinds.hs
index 3a736a5e6c..5028d04de7 100644
--- a/compiler/deSugar/DsBinds.hs
+++ b/compiler/deSugar/DsBinds.hs
@@ -192,6 +192,7 @@ dsHsBind dflags (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dicts
; dsAbsBinds dflags tyvars dicts exports ds_ev_binds ds_binds has_sig }
dsHsBind _ (PatSynBind{}) = panic "dsHsBind: PatSynBind"
+dsHsBind _ (XHsBindsLR{}) = panic "dsHsBind: XHsBindsLR"
-----------------------
diff --git a/compiler/deSugar/DsMeta.hs b/compiler/deSugar/DsMeta.hs
index e579f7dbf4..afdc1b835d 100644
--- a/compiler/deSugar/DsMeta.hs
+++ b/compiler/deSugar/DsMeta.hs
@@ -1522,11 +1522,11 @@ rep_bind (L _ (VarBind { var_id = v, var_rhs = e}))
; return (srcLocSpan (getSrcLoc v), ans) }
rep_bind (L _ (AbsBinds {})) = panic "rep_bind: AbsBinds"
-rep_bind (L loc (PatSynBind (PSB { psb_id = syn
- , psb_fvs = _fvs
- , psb_args = args
- , psb_def = pat
- , psb_dir = dir })))
+rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn
+ , psb_fvs = _fvs
+ , psb_args = args
+ , psb_def = pat
+ , psb_dir = dir })))
= do { syn' <- lookupLBinder syn
; dir' <- repPatSynDir dir
; ss <- mkGenArgSyms args
@@ -1561,6 +1561,8 @@ rep_bind (L loc (PatSynBind (PSB { psb_id = syn
wrapGenArgSyms (RecCon _) _ dec = return dec
wrapGenArgSyms _ ss dec = wrapGenSyms ss dec
+rep_bind (L _ (XHsBindsLR {})) = panic "rep_bind: XHsBindsLR"
+
repPatSynD :: Core TH.Name
-> Core TH.PatSynArgsQ
-> Core TH.PatSynDirQ
diff --git a/compiler/hsSyn/Convert.hs b/compiler/hsSyn/Convert.hs
index 7fcfb6020e..c3eed53fc0 100644
--- a/compiler/hsSyn/Convert.hs
+++ b/compiler/hsSyn/Convert.hs
@@ -153,7 +153,7 @@ cvtDec (TH.ValD pat body ds)
; ds' <- cvtLocalDecs (text "a where clause") ds
; returnJustL $ Hs.ValD $
PatBind { pat_lhs = pat', pat_rhs = GRHSs body' (noLoc ds')
- , pat_rhs_ty = placeHolderType, bind_fvs = placeHolderNames
+ , pat_rhs_ty = placeHolderType, pat_ext = noExt
, pat_ticks = ([],[]) } }
cvtDec (TH.FunD nm cls)
@@ -365,7 +365,7 @@ cvtDec (TH.PatSynD nm args dir pat)
; args' <- cvtArgs args
; dir' <- cvtDir nm' dir
; pat' <- cvtPat pat
- ; returnJustL $ Hs.ValD $ PatSynBind $
+ ; returnJustL $ Hs.ValD $ PatSynBind noExt $
PSB nm' placeHolderType args' pat' dir' }
where
cvtArgs (TH.PrefixPatSyn args) = Hs.PrefixCon <$> mapM vNameL args
diff --git a/compiler/hsSyn/HsBinds.hs b/compiler/hsSyn/HsBinds.hs
index 554a9addcd..164c0a4a1e 100644
--- a/compiler/hsSyn/HsBinds.hs
+++ b/compiler/hsSyn/HsBinds.hs
@@ -196,7 +196,6 @@ other interesting cases. Namely,
-- | Haskell Binding with separate Left and Right id's
data HsBindLR idL idR
- -- AZ:TODO TTG HsBindLR
= -- | Function-like Binding
--
-- FunBind is used for both functions @f x = e@
@@ -226,6 +225,11 @@ data HsBindLR idL idR
-- For details on above see note [Api annotations] in ApiAnnotation
FunBind {
+ fun_ext :: XFunBind idL idR, -- ^ After the renamer, this contains
+ -- the locally-bound
+ -- free variables of this defn.
+ -- See Note [Bind free vars]
+
fun_id :: Located (IdP idL), -- Note [fun_id in Match] in HsExpr
fun_matches :: MatchGroup idR (LHsExpr idR), -- ^ The payload
@@ -244,10 +248,10 @@ data HsBindLR idL idR
-- type Int -> forall a'. a' -> a'
-- Notice that the coercion captures the free a'.
- bind_fvs :: PostRn idL NameSet, -- ^ After the renamer, this contains
- -- the locally-bound
- -- free variables of this defn.
- -- See Note [Bind free vars]
+ -- bind_fvs :: PostRn idL NameSet, -- ^ After the renamer, this contains
+ -- -- the locally-bound
+ -- -- free variables of this defn.
+ -- -- See Note [Bind free vars]
fun_tick :: [Tickish Id] -- ^ Ticks to put on the rhs, if any
@@ -267,10 +271,12 @@ data HsBindLR idL idR
-- For details on above see note [Api annotations] in ApiAnnotation
| PatBind {
+ pat_ext :: XPatBind idL idR, -- ^ See Note [Bind free vars]
pat_lhs :: LPat idL,
pat_rhs :: GRHSs idR (LHsExpr idR),
+ -- AZ:TODO: put this into TTG extension too
pat_rhs_ty :: PostTc idR Type, -- ^ Type of the GRHSs
- bind_fvs :: PostRn idL NameSet, -- ^ See Note [Bind free vars]
+ -- bind_fvs :: PostRn idL NameSet, -- ^ See Note [Bind free vars]
pat_ticks :: ([Tickish Id], [[Tickish Id]])
-- ^ Ticks to put on the rhs, if any, and ticks to put on
-- the bound variables.
@@ -281,6 +287,7 @@ data HsBindLR idL idR
-- Dictionary binding and suchlike.
-- All VarBinds are introduced by the type checker
| VarBind {
+ var_ext :: XVarBind idL idR,
var_id :: IdP idL,
var_rhs :: LHsExpr idR, -- ^ Located only for consistency
var_inline :: Bool -- ^ True <=> inline this binding regardless
@@ -289,6 +296,7 @@ data HsBindLR idL idR
-- | Abstraction Bindings
| AbsBinds { -- Binds abstraction; TRANSLATION
+ abs_ext :: XAbsBinds idL idR,
abs_tvs :: [TyVar],
abs_ev_vars :: [EvVar], -- ^ Includes equality constraints
@@ -309,7 +317,9 @@ data HsBindLR idL idR
}
-- | Patterns Synonym Binding
- | PatSynBind (PatSynBind idL idR)
+ | PatSynBind
+ (XPatSynBind idL idR)
+ (PatSynBind idL idR)
-- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnPattern',
-- 'ApiAnnotation.AnnLarrow','ApiAnnotation.AnnEqual',
-- 'ApiAnnotation.AnnWhere'
@@ -317,8 +327,24 @@ data HsBindLR idL idR
-- For details on above see note [Api annotations] in ApiAnnotation
+ | XHsBindsLR (XXHsBindsLR idL idR)
+
-- deriving instance (DataIdLR idL idR) => Data (HsBindLR idL idR)
+type instance XFunBind (GhcPass pL) GhcPs = PlaceHolder
+type instance XFunBind (GhcPass pL) GhcRn = NameSet -- Free variables
+type instance XFunBind (GhcPass pL) GhcTc = NameSet -- Free variables
+
+type instance XPatBind GhcPs (GhcPass pR) = PlaceHolder
+type instance XPatBind GhcRn (GhcPass pR) = NameSet -- Free variables
+type instance XPatBind GhcTc (GhcPass pR) = NameSet -- Free variables
+
+type instance XVarBind (GhcPass pL) (GhcPass pR) = PlaceHolder
+type instance XAbsBinds (GhcPass pL) (GhcPass pR) = PlaceHolder
+type instance XPatSynBind (GhcPass pL) (GhcPass pR) = PlaceHolder
+type instance XXHsBindsLR (GhcPass pL) (GhcPass pR) = PlaceHolder
+
+
-- Consider (AbsBinds tvs ds [(ftvs, poly_f, mono_f) binds]
--
-- Creates bindings for (polymorphic, overloaded) poly_f
@@ -716,7 +742,7 @@ ppr_monobind (FunBind { fun_id = fun,
$$ whenPprDebug (pprBndr LetBind (unLoc fun))
$$ pprFunBind matches
$$ whenPprDebug (ppr wrap)
-ppr_monobind (PatSynBind psb) = ppr psb
+ppr_monobind (PatSynBind _ psb) = ppr psb
ppr_monobind (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dictvars
, abs_exports = exports, abs_binds = val_binds
, abs_ev_binds = ev_binds })
@@ -734,6 +760,7 @@ ppr_monobind (AbsBinds { abs_tvs = tyvars, abs_ev_vars = dictvars
, text "Evidence:" <+> ppr ev_binds ]
else
pprLHsBinds val_binds
+ppr_monobind (XHsBindsLR x) = ppr x
instance (OutputableBndrId p) => Outputable (ABExport p) where
ppr (ABE { abe_wrap = wrap, abe_poly = gbl, abe_mono = lcl, abe_prags = prags })
diff --git a/compiler/hsSyn/HsExtension.hs b/compiler/hsSyn/HsExtension.hs
index 5ca5bc4db7..b5ffdfbe28 100644
--- a/compiler/hsSyn/HsExtension.hs
+++ b/compiler/hsSyn/HsExtension.hs
@@ -106,14 +106,12 @@ type LIdP p = Located (IdP p)
type family XHsValBinds x x'
type family XHsIPBinds x x'
type family XEmptyLocalBinds x x'
--- type family XHsLocalBindsLR x x'
type family XXHsLocalBindsLR x x'
type ForallXHsLocalBindsLR (c :: * -> Constraint) (x :: *) (x' :: *) =
( c (XHsValBinds x x')
, c (XHsIPBinds x x')
, c (XEmptyLocalBinds x x')
- -- , c (XHsLocalBindsLR x x')
, c (XXHsLocalBindsLR x x')
)
@@ -127,6 +125,23 @@ type ForallXValBindsLR (c :: * -> Constraint) (x :: *) (x' :: *) =
)
+-- HsBindsLR type families
+type family XFunBind x x'
+type family XPatBind x x'
+type family XVarBind x x'
+type family XAbsBinds x x'
+type family XPatSynBind x x'
+type family XXHsBindsLR x x'
+
+type ForallXHsBindsLR (c :: * -> Constraint) (x :: *) (x' :: *) =
+ ( c (XFunBind x x')
+ , c (XPatBind x x')
+ , c (XVarBind x x')
+ , c (XAbsBinds x x')
+ , c (XPatSynBind x x')
+ , c (XXHsBindsLR x x')
+ )
+
-- =====================================================================
-- Type families for the HsDecls extension points
@@ -663,9 +678,14 @@ type DataIdLR pL pR =
, ForallXValBindsLR Data pL pL
, ForallXValBindsLR Data pR pR
+ , ForallXHsBindsLR Data pL pR
+ , ForallXHsBindsLR Data pL pL
+ , ForallXHsBindsLR Data pR pR
+
, ForallXParStmtBlock Data pL pR
, ForallXParStmtBlock Data pL pL
, ForallXParStmtBlock Data pR pR
+
, ForallXParStmtBlock Data GhcRn GhcRn
)
diff --git a/compiler/hsSyn/HsInstances.hs b/compiler/hsSyn/HsInstances.hs
index 1aafacecdb..eb173262af 100644
--- a/compiler/hsSyn/HsInstances.hs
+++ b/compiler/hsSyn/HsInstances.hs
@@ -97,22 +97,22 @@ deriving instance Data PendingTcSplice
deriving instance (DataId p) => Data (HsLit p)
deriving instance (DataIdLR p p) => Data (HsOverLit p)
+-- Data derivations from HsPat -----------------------------------------
+
+deriving instance (DataIdLR p p) => Data (Pat p)
+deriving instance (DataIdLR p p, Data body) => Data (HsRecFields p body)
+
-- Data derivations from HsTypes ---------------------------------------
-deriving instance (DataIdLR p p) => Data (LHsQTyVars p)
+deriving instance (DataIdLR p p) => Data (LHsQTyVars p)
deriving instance (DataIdLR p p, Data thing) => Data (HsImplicitBndrs p thing)
deriving instance (DataIdLR p p, Data thing) => Data (HsWildCardBndrs p thing)
deriving instance (DataIdLR p p) => Data (HsTyVarBndr p)
deriving instance (DataIdLR p p) => Data (HsType p)
-deriving instance (DataId p) => Data (HsWildCardInfo p)
+deriving instance (DataId p) => Data (HsWildCardInfo p)
deriving instance (DataIdLR p p) => Data (HsAppType p)
deriving instance (DataIdLR p p) => Data (ConDeclField p)
-deriving instance (DataId p) => Data (FieldOcc p)
-deriving instance DataId p => Data (AmbiguousFieldOcc p)
-
--- Data derivations from HsPat -----------------------------------------
-
-deriving instance (DataIdLR p p) => Data (Pat p)
-deriving instance (DataIdLR p p, Data body) => Data (HsRecFields p body)
+deriving instance (DataId p) => Data (FieldOcc p)
+deriving instance DataId p => Data (AmbiguousFieldOcc p)
-- ---------------------------------------------------------------------
diff --git a/compiler/hsSyn/HsUtils.hs b/compiler/hsSyn/HsUtils.hs
index 6420a3c070..cbd1c2cc48 100644
--- a/compiler/hsSyn/HsUtils.hs
+++ b/compiler/hsSyn/HsUtils.hs
@@ -790,7 +790,7 @@ mkFunBind :: Origin -> Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)]
mkFunBind origin fn ms = FunBind { fun_id = fn
, fun_matches = mkMatchGroup origin ms
, fun_co_fn = idHsWrapper
- , bind_fvs = placeHolderNames
+ , fun_ext = PlaceHolder
, fun_tick = [] }
mkTopFunBind :: Origin -> Located Name -> [LMatch GhcRn (LHsExpr GhcRn)]
@@ -799,20 +799,21 @@ mkTopFunBind :: Origin -> Located Name -> [LMatch GhcRn (LHsExpr GhcRn)]
mkTopFunBind origin fn ms = FunBind { fun_id = fn
, fun_matches = mkMatchGroup origin ms
, fun_co_fn = idHsWrapper
- , bind_fvs = emptyNameSet -- NB: closed
+ , fun_ext = emptyNameSet -- NB: closed
-- binding
, fun_tick = [] }
mkHsVarBind :: SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind loc var rhs = mk_easy_FunBind loc var [] rhs
-mkVarBind :: IdP p -> LHsExpr p -> LHsBind p
+mkVarBind :: IdP (GhcPass p) -> LHsExpr (GhcPass p) -> LHsBind (GhcPass p)
mkVarBind var rhs = L (getLoc rhs) $
- VarBind { var_id = var, var_rhs = rhs, var_inline = False }
+ VarBind { var_ext = noExt,
+ var_id = var, var_rhs = rhs, var_inline = False }
mkPatSynBind :: Located RdrName -> HsPatSynDetails (Located RdrName)
-> LPat GhcPs -> HsPatSynDir GhcPs -> HsBind GhcPs
-mkPatSynBind name details lpat dir = PatSynBind psb
+mkPatSynBind name details lpat dir = PatSynBind noExt psb
where
psb = PSB{ psb_id = name
, psb_args = details
@@ -823,7 +824,7 @@ mkPatSynBind name details lpat dir = PatSynBind psb
-- |If any of the matches in the 'FunBind' are infix, the 'FunBind' is
-- considered infix.
isInfixFunBind :: HsBindLR id1 id2 -> Bool
-isInfixFunBind (FunBind _ (MG matches _ _ _) _ _ _)
+isInfixFunBind (FunBind _ _ (MG matches _ _ _) _ _)
= any (isInfixMatch . unLoc) (unLoc matches)
isInfixFunBind _ = False
@@ -986,9 +987,10 @@ collect_bind _ (AbsBinds { abs_exports = dbinds }) acc = map abe_poly dbinds ++
-- I don't think we want the binders from the abe_binds
-- binding (hence see AbsBinds) is in zonking in TcHsSyn
-collect_bind omitPatSyn (PatSynBind (PSB { psb_id = L _ ps })) acc
+collect_bind omitPatSyn (PatSynBind _ (PSB { psb_id = L _ ps })) acc
| omitPatSyn = acc
| otherwise = ps : acc
+collect_bind _ (XHsBindsLR _) acc = acc
collectMethodBinders :: LHsBindsLR GhcPs idR -> [Located RdrName]
-- Used exclusively for the bindings of an instance decl which are all FunBinds
@@ -1156,14 +1158,14 @@ hsPatSynSelectors (XValBindsLR (NValBinds binds _))
addPatSynSelector:: LHsBind p -> [IdP p] -> [IdP p]
addPatSynSelector bind sels
- | L _ (PatSynBind (PSB { psb_args = RecCon as })) <- bind
+ | L _ (PatSynBind _ (PSB { psb_args = RecCon as })) <- bind
= map (unLoc . recordPatSynSelectorId) as ++ sels
| otherwise = sels
getPatSynBinds :: [(RecFlag, LHsBinds id)] -> [PatSynBind id id]
getPatSynBinds binds
= [ psb | (_, lbinds) <- binds
- , L _ (PatSynBind psb) <- bagToList lbinds ]
+ , L _ (PatSynBind _ psb) <- bagToList lbinds ]
-------------------
hsLInstDeclBinders :: LInstDecl pass
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index b218be88ae..45835940b9 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -2281,9 +2281,9 @@ decl_no_th :: { LHsDecl GhcPs }
-- a FunBind or PatBind back from checkValDef. See Note
-- [FunBind vs PatBind]
case r of {
- (FunBind n _ _ _ _) ->
+ (FunBind _ n _ _ _) ->
ams (L l ()) [mj AnnFunId n] >> return () ;
- (PatBind (L lh _lhs) _rhs _ _ _) ->
+ (PatBind _ (L lh _lhs) _rhs _ _) ->
ams (L lh ()) [] >> return () } ;
_ <- ams (L l ()) (ann ++ fst (unLoc $3) ++ [mj AnnBang $1]) ;
@@ -2295,9 +2295,9 @@ decl_no_th :: { LHsDecl GhcPs }
-- a FunBind or PatBind back from checkValDef. See Note
-- [FunBind vs PatBind]
case r of {
- (FunBind n _ _ _ _) ->
+ (FunBind _ n _ _ _) ->
ams (L l ()) (mj AnnFunId n:(fst $2)) >> return () ;
- (PatBind (L lh _lhs) _rhs _ _ _) ->
+ (PatBind _ (L lh _lhs) _rhs _ _) ->
ams (L lh ()) (fst $2) >> return () } ;
_ <- ams (L l ()) (ann ++ (fst $ unLoc $3));
return $! (sL l $ ValD r) } }
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs
index 68d152e62e..f5278fc9fd 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -100,6 +100,7 @@ import FastString
import Maybes
import Util
import ApiAnnotation
+import HsExtension ( noExt )
import Data.List
import qualified GHC.LanguageExtensions as LangExt
import MonadUtils
@@ -560,7 +561,9 @@ mkPatSynMatchGroup (L loc patsyn_name) (L _ decls) =
; when (null matches) (wrongNumberErr loc)
; return $ mkMatchGroup FromSource matches }
where
- fromDecl (L loc decl@(ValD (PatBind pat@(L _ (ConPatIn ln@(L _ name) details)) rhs _ _ _))) =
+ fromDecl (L loc decl@(ValD (PatBind _
+ pat@(L _ (ConPatIn ln@(L _ name) details))
+ rhs _ _))) =
do { unless (name == patsyn_name) $
wrongNameBindingErr loc decl
; match <- case details of
@@ -1090,10 +1093,10 @@ makeFunBind :: Origin -> Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)]
-> HsBind GhcPs
-- Like HsUtils.mkFunBind, but we need to be able to set the fixity too
makeFunBind origin fn ms
- = FunBind { fun_id = fn,
+ = FunBind { fun_ext = noExt,
+ fun_id = fn,
fun_matches = mkMatchGroup origin ms,
fun_co_fn = idHsWrapper,
- bind_fvs = placeHolderNames,
fun_tick = [] }
checkPatBind :: SDoc
@@ -1102,7 +1105,7 @@ checkPatBind :: SDoc
-> P ([AddAnn],HsBind GhcPs)
checkPatBind msg lhs (L _ (_,grhss))
= do { lhs <- checkPattern msg lhs
- ; return ([],PatBind lhs grhss placeHolderType placeHolderNames
+ ; return ([],PatBind noExt lhs grhss placeHolderType
([],[])) }
checkValSigLhs :: LHsExpr GhcPs -> P (Located RdrName)
diff --git a/compiler/rename/RnBinds.hs b/compiler/rename/RnBinds.hs
index dee89cacd3..4b4aad7c00 100644
--- a/compiler/rename/RnBinds.hs
+++ b/compiler/rename/RnBinds.hs
@@ -407,27 +407,27 @@ rnBindLHS name_maker _ bind@(PatBind { pat_lhs = pat })
= do
-- we don't actually use the FV processing of rnPatsAndThen here
(pat',pat'_fvs) <- rnBindPat name_maker pat
- return (bind { pat_lhs = pat', bind_fvs = pat'_fvs })
+ return (bind { pat_lhs = pat', pat_ext = pat'_fvs })
-- We temporarily store the pat's FVs in bind_fvs;
-- gets updated to the FVs of the whole bind
-- when doing the RHS below
rnBindLHS name_maker _ bind@(FunBind { fun_id = rdr_name })
= do { name <- applyNameMaker name_maker rdr_name
- ; return (bind { fun_id = name
- , bind_fvs = placeHolderNamesTc }) }
+ ; return (bind { fun_id = name
+ , fun_ext = noExt }) }
-rnBindLHS name_maker _ (PatSynBind psb@PSB{ psb_id = rdrname })
+rnBindLHS name_maker _ (PatSynBind x psb@PSB{ psb_id = rdrname })
| isTopRecNameMaker name_maker
= do { addLocM checkConName rdrname
; name <- lookupLocatedTopBndrRn rdrname -- Should be in scope already
- ; return (PatSynBind psb{ psb_id = name }) }
+ ; return (PatSynBind x psb{ psb_id = name }) }
| otherwise -- Pattern synonym, not at top level
= do { addErr localPatternSynonymErr -- Complain, but make up a fake
-- name so that we can carry on
; name <- applyNameMaker name_maker rdrname
- ; return (PatSynBind psb{ psb_id = name }) }
+ ; return (PatSynBind x psb{ psb_id = name }) }
where
localPatternSynonymErr :: SDoc
localPatternSynonymErr
@@ -452,7 +452,7 @@ rnBind _ bind@(PatBind { pat_lhs = pat
, pat_rhs = grhss
-- pat fvs were stored in bind_fvs
-- after processing the LHS
- , bind_fvs = pat_fvs })
+ , pat_ext = pat_fvs })
= do { mod <- getModule
; (grhss', rhs_fvs) <- rnGRHSs PatBindRhs rnLExpr grhss
@@ -464,7 +464,7 @@ rnBind _ bind@(PatBind { pat_lhs = pat
-- MonoLocalBinds test in TcBinds.decideGeneralisationPlan
bndrs = collectPatBinders pat
bind' = bind { pat_rhs = grhss'
- , pat_rhs_ty = placeHolderType, bind_fvs = fvs' }
+ , pat_rhs_ty = placeHolderType, pat_ext = fvs' }
ok_nobind_pat
= -- See Note [Pattern bindings that bind no variables]
@@ -503,13 +503,13 @@ rnBind sig_fn bind@(FunBind { fun_id = name
; fvs' `seq` -- See Note [Free-variable space leak]
return (bind { fun_matches = matches'
- , bind_fvs = fvs' },
+ , fun_ext = fvs' },
[plain_name], rhs_fvs)
}
-rnBind sig_fn (PatSynBind bind)
+rnBind sig_fn (PatSynBind x bind)
= do { (bind', name, fvs) <- rnPatSynBind sig_fn bind
- ; return (PatSynBind bind', name, fvs) }
+ ; return (PatSynBind x bind', name, fvs) }
rnBind _ b = pprPanic "rnBind" (ppr b)
@@ -878,9 +878,7 @@ rnMethodBindLHS _ cls (L loc bind@(FunBind { fun_id = name })) rest
= setSrcSpan loc $ do
do { sel_name <- wrapLocM (lookupInstDeclBndr cls (text "method")) name
-- We use the selector name as the binder
- ; let bind' = bind { fun_id = sel_name
- , bind_fvs = placeHolderNamesTc }
-
+ ; let bind' = bind { fun_id = sel_name, fun_ext = noExt }
; return (L loc bind' `consBag` rest ) }
-- Report error for all other forms of bindings
diff --git a/compiler/rename/RnSource.hs b/compiler/rename/RnSource.hs
index 3e992fa4a3..6881575c0b 100644
--- a/compiler/rename/RnSource.hs
+++ b/compiler/rename/RnSource.hs
@@ -2011,8 +2011,8 @@ extendPatSynEnv val_decls local_fix_env thing = do {
-> [(Name, [FieldLabel])]
-> TcM [(Name, [FieldLabel])]
new_ps' bind names
- | L bind_loc (PatSynBind (PSB { psb_id = L _ n
- , psb_args = RecCon as })) <- bind
+ | L bind_loc (PatSynBind _ (PSB { psb_id = L _ n
+ , psb_args = RecCon as })) <- bind
= do
bnd_name <- newTopSrcBinder (L bind_loc n)
let rnames = map recordPatSynSelectorId as
@@ -2021,7 +2021,7 @@ extendPatSynEnv val_decls local_fix_env thing = do {
field_occs = map mkFieldOcc rnames
flds <- mapM (newRecordSelector False [bnd_name]) field_occs
return ((bnd_name, flds): names)
- | L bind_loc (PatSynBind (PSB { psb_id = L _ n})) <- bind
+ | L bind_loc (PatSynBind _ (PSB { psb_id = L _ n})) <- bind
= do
bnd_name <- newTopSrcBinder (L bind_loc n)
return ((bnd_name, []): names)
diff --git a/compiler/typecheck/TcBinds.hs b/compiler/typecheck/TcBinds.hs
index 88358582c1..893b18b51c 100644
--- a/compiler/typecheck/TcBinds.hs
+++ b/compiler/typecheck/TcBinds.hs
@@ -533,7 +533,7 @@ tc_single :: forall thing.
-> LHsBind GhcRn -> IsGroupClosed -> TcM thing
-> TcM (LHsBinds GhcTcId, thing)
tc_single _top_lvl sig_fn _prag_fn
- (L _ (PatSynBind psb@PSB{ psb_id = L _ name }))
+ (L _ (PatSynBind _ psb@PSB{ psb_id = L _ name }))
_ thing_inside
= do { (aux_binds, tcg_env) <- tc_pat_syn_decl
; thing <- setGblEnv tcg_env thing_inside
@@ -568,6 +568,10 @@ mkEdges sig_fn binds
-- is still deterministic even if the edges are in nondeterministic order
-- as explained in Note [Deterministic SCC] in Digraph.
where
+ bind_fvs (FunBind { fun_ext = fvs }) = fvs
+ bind_fvs (PatBind { pat_ext = fvs }) = fvs
+ bind_fvs _ = emptyNameSet
+
no_sig :: Name -> Bool
no_sig n = not (hasCompleteSig sig_fn n)
@@ -719,7 +723,7 @@ tcPolyCheck prag_fn
; let bind' = FunBind { fun_id = L nm_loc mono_id
, fun_matches = matches'
, fun_co_fn = co_fn
- , bind_fvs = placeHolderNamesTc
+ , fun_ext = placeHolderNamesTc
, fun_tick = tick }
export = ABE { abe_wrap = idHsWrapper
@@ -728,7 +732,8 @@ tcPolyCheck prag_fn
, abe_prags = SpecPrags spec_prags }
abs_bind = L loc $
- AbsBinds { abs_tvs = skol_tvs
+ AbsBinds { abs_ext = noExt
+ , abs_tvs = skol_tvs
, abs_ev_vars = ev_vars
, abs_ev_binds = [ev_binds]
, abs_exports = [export]
@@ -809,7 +814,8 @@ tcPolyInfer rec_tc prag_fn tc_sig_fn mono bind_list
; loc <- getSrcSpanM
; let poly_ids = map abe_poly exports
abs_bind = L loc $
- AbsBinds { abs_tvs = qtvs
+ AbsBinds { abs_ext = noExt
+ , abs_tvs = qtvs
, abs_ev_vars = givens, abs_ev_binds = [ev_binds]
, abs_exports = exports, abs_binds = binds'
, abs_sig = False }
@@ -1320,7 +1326,7 @@ tcMonoBinds :: RecFlag -- Whether the binding is recursive for typechecking pur
-> TcM (LHsBinds GhcTcId, [MonoBindInfo])
tcMonoBinds is_rec sig_fn no_gen
[ L b_loc (FunBind { fun_id = L nm_loc name,
- fun_matches = matches, bind_fvs = fvs })]
+ fun_matches = matches, fun_ext = fvs })]
-- Single function binding,
| NonRecursive <- is_rec -- ...binder isn't mentioned in RHS
, Nothing <- sig_fn name -- ...with no type signature
@@ -1345,7 +1351,7 @@ tcMonoBinds is_rec sig_fn no_gen
; mono_id <- newLetBndr no_gen name rhs_ty
; return (unitBag $ L b_loc $
FunBind { fun_id = L nm_loc mono_id,
- fun_matches = matches', bind_fvs = fvs,
+ fun_matches = matches', fun_ext = fvs,
fun_co_fn = co_fn, fun_tick = [] },
[MBI { mbi_poly_name = name
, mbi_sig = Nothing
@@ -1493,7 +1499,7 @@ tcRhs (TcFunBind info@(MBI { mbi_sig = mb_sig, mbi_mono_id = mono_id })
; return ( FunBind { fun_id = L loc mono_id
, fun_matches = matches'
, fun_co_fn = co_fn
- , bind_fvs = placeHolderNamesTc
+ , fun_ext = placeHolderNamesTc
, fun_tick = [] } ) }
tcRhs (TcPatBind infos pat' grhss pat_ty)
@@ -1507,7 +1513,7 @@ tcRhs (TcPatBind infos pat' grhss pat_ty)
tcGRHSsPat grhss pat_ty
; return ( PatBind { pat_lhs = pat', pat_rhs = grhss'
, pat_rhs_ty = pat_ty
- , bind_fvs = placeHolderNamesTc
+ , pat_ext = placeHolderNamesTc
, pat_ticks = ([],[]) } )}
tcExtendTyVarEnvForRhs :: Maybe TcIdSigInst -> TcM a -> TcM a
@@ -1746,16 +1752,18 @@ isClosedBndrGroup type_env binds
fv_env :: NameEnv NameSet
fv_env = mkNameEnv $ concatMap (bindFvs . unLoc) binds
- bindFvs :: HsBindLR GhcRn idR -> [(Name, NameSet)]
- bindFvs (FunBind { fun_id = L _ f, bind_fvs = fvs })
- = let open_fvs = filterNameSet (not . is_closed) fvs
+ bindFvs :: HsBindLR GhcRn GhcRn -> [(Name, NameSet)]
+ bindFvs (FunBind { fun_id = L _ f, fun_ext = fvs })
+ = let open_fvs = get_open_fvs fvs
in [(f, open_fvs)]
- bindFvs (PatBind { pat_lhs = pat, bind_fvs = fvs })
- = let open_fvs = filterNameSet (not . is_closed) fvs
+ bindFvs (PatBind { pat_lhs = pat, pat_ext = fvs })
+ = let open_fvs = get_open_fvs fvs
in [(b, open_fvs) | b <- collectPatBinders pat]
bindFvs _
= []
+ get_open_fvs fvs = filterNameSet (not . is_closed) fvs
+
is_closed :: Name -> ClosedTypeId
is_closed name
| Just thing <- lookupNameEnv type_env name
diff --git a/compiler/typecheck/TcClassDcl.hs b/compiler/typecheck/TcClassDcl.hs
index 250319742c..70f3f9e8f0 100644
--- a/compiler/typecheck/TcClassDcl.hs
+++ b/compiler/typecheck/TcClassDcl.hs
@@ -284,7 +284,8 @@ tcDefMeth clas tyvars this_dict binds_in hs_sig_fn prag_fn
, abe_mono = local_dm_id
, abe_wrap = idHsWrapper
, abe_prags = IsDefaultMethod }
- full_bind = AbsBinds { abs_tvs = tyvars
+ full_bind = AbsBinds { abs_ext = noExt
+ , abs_tvs = tyvars
, abs_ev_vars = [this_dict]
, abs_exports = [export]
, abs_ev_binds = [ev_binds]
diff --git a/compiler/typecheck/TcHsSyn.hs b/compiler/typecheck/TcHsSyn.hs
index f1caecd12c..1ce29ea551 100644
--- a/compiler/typecheck/TcHsSyn.hs
+++ b/compiler/typecheck/TcHsSyn.hs
@@ -455,10 +455,14 @@ zonk_bind env bind@(PatBind { pat_lhs = pat, pat_rhs = grhss, pat_rhs_ty = ty})
; new_ty <- zonkTcTypeToType env ty
; return (bind { pat_lhs = new_pat, pat_rhs = new_grhss, pat_rhs_ty = new_ty }) }
-zonk_bind env (VarBind { var_id = var, var_rhs = expr, var_inline = inl })
+zonk_bind env (VarBind { var_ext = x
+ , var_id = var, var_rhs = expr, var_inline = inl })
= do { new_var <- zonkIdBndr env var
; new_expr <- zonkLExpr env expr
- ; return (VarBind { var_id = new_var, var_rhs = new_expr, var_inline = inl }) }
+ ; return (VarBind { var_ext = x
+ , var_id = new_var
+ , var_rhs = new_expr
+ , var_inline = inl }) }
zonk_bind env bind@(FunBind { fun_id = L loc var, fun_matches = ms
, fun_co_fn = co_fn })
@@ -483,7 +487,8 @@ zonk_bind env (AbsBinds { abs_tvs = tyvars, abs_ev_vars = evs
; new_val_binds <- mapBagM (zonk_val_bind env3) val_binds
; new_exports <- mapM (zonk_export env3) exports
; return (new_val_binds, new_exports) }
- ; return (AbsBinds { abs_tvs = new_tyvars, abs_ev_vars = new_evs
+ ; return (AbsBinds { abs_ext = noExt
+ , abs_tvs = new_tyvars, abs_ev_vars = new_evs
, abs_ev_binds = new_ev_binds
, abs_exports = new_exports, abs_binds = new_val_bind
, abs_sig = has_sig }) }
@@ -517,19 +522,20 @@ zonk_bind env (AbsBinds { abs_tvs = tyvars, abs_ev_vars = evs
, abe_mono = zonkIdOcc env mono_id
, abe_prags = new_prags })
-zonk_bind env (PatSynBind bind@(PSB { psb_id = L loc id
- , psb_args = details
- , psb_def = lpat
- , psb_dir = dir }))
+zonk_bind env (PatSynBind x bind@(PSB { psb_id = L loc id
+ , psb_args = details
+ , psb_def = lpat
+ , psb_dir = dir }))
= do { id' <- zonkIdBndr env id
; (env1, lpat') <- zonkPat env lpat
; let details' = zonkPatSynDetails env1 details
; (_env2, dir') <- zonkPatSynDir env1 dir
- ; return $ PatSynBind $
+ ; return $ PatSynBind x $
bind { psb_id = L loc id'
, psb_args = details'
, psb_def = lpat'
, psb_dir = dir' } }
+zonk_bind _ (XHsBindsLR _) = panic "zonk_bind"
zonkPatSynDetails :: ZonkEnv
-> HsPatSynDetails (Located TcId)
diff --git a/compiler/typecheck/TcInstDcls.hs b/compiler/typecheck/TcInstDcls.hs
index 78615d9f44..8e201045c1 100644
--- a/compiler/typecheck/TcInstDcls.hs
+++ b/compiler/typecheck/TcInstDcls.hs
@@ -895,7 +895,8 @@ tcInstDecl2 (InstInfo { iSpec = ispec, iBinds = ibinds })
, abe_mono = self_dict
, abe_prags = dfun_spec_prags }
-- NB: see Note [SPECIALISE instance pragmas]
- main_bind = AbsBinds { abs_tvs = inst_tyvars
+ main_bind = AbsBinds { abs_ext = noExt
+ , abs_tvs = inst_tyvars
, abs_ev_vars = dfun_ev_vars
, abs_exports = [export]
, abs_ev_binds = []
@@ -1044,7 +1045,8 @@ tcSuperClasses dfun_id cls tyvars dfun_evs inst_tys dfun_ev_binds sc_theta
, abe_mono = sc_ev_id
, abe_prags = noSpecPrags }
local_ev_binds = TcEvBinds ev_binds_var
- bind = AbsBinds { abs_tvs = tyvars
+ bind = AbsBinds { abs_ext = noExt
+ , abs_tvs = tyvars
, abs_ev_vars = dfun_evs
, abs_exports = [export]
, abs_ev_binds = [dfun_ev_binds, local_ev_binds]
@@ -1386,7 +1388,8 @@ tcMethodBody clas tyvars dfun_ev_vars inst_tys
, abe_prags = specs }
local_ev_binds = TcEvBinds ev_binds_var
- full_bind = AbsBinds { abs_tvs = tyvars
+ full_bind = AbsBinds { abs_ext = noExt
+ , abs_tvs = tyvars
, abs_ev_vars = dfun_ev_vars
, abs_exports = [export]
, abs_ev_binds = [dfun_ev_binds, local_ev_binds]
@@ -1434,7 +1437,7 @@ tcMethodBodyHelp hs_sig_fn sel_id local_meth_id meth_bind
, abe_prags = noSpecPrags }
; return (unitBag $ L (getLoc meth_bind) $
- AbsBinds { abs_tvs = [], abs_ev_vars = []
+ AbsBinds { abs_ext = noExt, abs_tvs = [], abs_ev_vars = []
, abs_exports = [export]
, abs_binds = tc_bind, abs_ev_binds = []
, abs_sig = True }) }
diff --git a/compiler/typecheck/TcPatSyn.hs b/compiler/typecheck/TcPatSyn.hs
index 0c50dd3313..7f8187cf78 100644
--- a/compiler/typecheck/TcPatSyn.hs
+++ b/compiler/typecheck/TcPatSyn.hs
@@ -695,10 +695,10 @@ tcPatSynMatcher (L loc name) lpat
, mg_origin = Generated
}
- ; let bind = FunBind{ fun_id = L loc matcher_id
+ ; let bind = FunBind{ fun_ext = emptyNameSet
+ , fun_id = L loc matcher_id
, fun_matches = mg
, fun_co_fn = idHsWrapper
- , bind_fvs = emptyNameSet
, fun_tick = [] }
matcher_bind = unitBag (noLoc bind)
@@ -780,10 +780,10 @@ tcPatSynBuilderBind (PSB { psb_id = L loc name, psb_def = lpat
match_group' | need_dummy_arg = add_dummy_arg match_group
| otherwise = match_group
- bind = FunBind { fun_id = L loc (idName builder_id)
+ bind = FunBind { fun_ext = placeHolderNamesTc
+ , fun_id = L loc (idName builder_id)
, fun_matches = match_group'
, fun_co_fn = idHsWrapper
- , bind_fvs = placeHolderNamesTc
, fun_tick = [] }
sig = completeSigFromId (PatSynCtxt name) builder_id
diff --git a/compiler/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs
index 3307189692..c0884dd68c 100644
--- a/compiler/typecheck/TcRnDriver.hs
+++ b/compiler/typecheck/TcRnDriver.hs
@@ -1988,7 +1988,7 @@ tcUserStmt (L loc (BodyStmt expr _ _ _))
matches = [mkMatch (mkPrefixFunRhs (L loc fresh_it)) [] rn_expr
(noLoc emptyLocalBinds)]
-- [it = expr]
- the_bind = L loc $ (mkTopFunBind FromSource (L loc fresh_it) matches) { bind_fvs = fvs }
+ the_bind = L loc $ (mkTopFunBind FromSource (L loc fresh_it) matches) { fun_ext = fvs }
-- Care here! In GHCi the expression might have
-- free variables, and they in turn may have free type variables
-- (if we are at a breakpoint, say). We must put those free vars
diff --git a/testsuite/tests/parser/should_compile/DumpParsedAst.stderr b/testsuite/tests/parser/should_compile/DumpParsedAst.stderr
index 6bc0895f1a..100b420227 100644
--- a/testsuite/tests/parser/should_compile/DumpParsedAst.stderr
+++ b/testsuite/tests/parser/should_compile/DumpParsedAst.stderr
@@ -203,6 +203,7 @@
,({ DumpParsedAst.hs:11:1-23 }
(ValD
(FunBind
+ (PlaceHolder)
({ DumpParsedAst.hs:11:1-4 }
(Unqual
{OccName: main}))
@@ -244,7 +245,6 @@
(PlaceHolder)
(FromSource))
(WpHole)
- (PlaceHolder)
[])))]
(Nothing)
(Nothing)))
diff --git a/testsuite/tests/parser/should_compile/DumpRenamedAst.stderr b/testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
index aff54a805f..cd6bd9823b 100644
--- a/testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
+++ b/testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
@@ -11,6 +11,8 @@
{Bag(Located (HsBind Name)):
[({ DumpRenamedAst.hs:18:1-23 }
(FunBind
+ {NameSet:
+ []}
({ DumpRenamedAst.hs:18:1-4 }
{Name: DumpRenamedAst.main})
(MG
@@ -49,8 +51,6 @@
(PlaceHolder)
(FromSource))
(WpHole)
- {NameSet:
- []}
[]))]})]
[]))
[]
diff --git a/testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr b/testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr
index 75cc7722b4..bf5ceaf1da 100644
--- a/testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr
+++ b/testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr
@@ -4,6 +4,7 @@
{Bag(Located (HsBind Var)):
[({ <no location info> }
(VarBind
+ (PlaceHolder)
{Var: DumpTypecheckedAst.$tcPeano}
({ <no location info> }
(HsApp
@@ -69,6 +70,7 @@
(False)))
,({ <no location info> }
(VarBind
+ (PlaceHolder)
{Var: DumpTypecheckedAst.$tc'Zero}
({ <no location info> }
(HsApp
@@ -134,6 +136,7 @@
(False)))
,({ <no location info> }
(VarBind
+ (PlaceHolder)
{Var: DumpTypecheckedAst.$tc'Succ}
({ <no location info> }
(HsApp
@@ -199,6 +202,7 @@
(False)))
,({ <no location info> }
(VarBind
+ (PlaceHolder)
{Var: $krep}
({ <no location info> }
(HsApp
@@ -223,6 +227,7 @@
(False)))
,({ <no location info> }
(VarBind
+ (PlaceHolder)
{Var: $krep}
({ <no location info> }
(HsApp
@@ -252,6 +257,7 @@
(False)))
,({ <no location info> }
(VarBind
+ (PlaceHolder)
{Var: DumpTypecheckedAst.$trModule}
({ <no location info> }
(HsApp
@@ -298,6 +304,7 @@
(False)))
,({ DumpTypecheckedAst.hs:11:1-23 }
(AbsBinds
+ (PlaceHolder)
[]
[]
[(ABE
@@ -310,6 +317,8 @@
{Bag(Located (HsBind Var)):
[({ DumpTypecheckedAst.hs:11:1-23 }
(FunBind
+ {NameSet:
+ []}
({ DumpTypecheckedAst.hs:11:1-4 }
{Var: main})
(MG
@@ -352,8 +361,6 @@
[])])
(FromSource))
(WpHole)
- {NameSet:
- []}
[]))]}
(False)))]}
diff --git a/utils/ghctags/Main.hs b/utils/ghctags/Main.hs
index 059692622e..7949f1679b 100644
--- a/utils/ghctags/Main.hs
+++ b/utils/ghctags/Main.hs
@@ -284,7 +284,8 @@ boundThings modname lbinding =
PatBind { pat_lhs = lhs } -> patThings lhs []
VarBind { var_id = id } -> [FoundThing modname (getOccString id) (startOfLocated lbinding)]
AbsBinds { } -> [] -- nothing interesting in a type abstraction
- PatSynBind PSB{ psb_id = id } -> [thing id]
+ PatSynBind _ PSB{ psb_id = id } -> [thing id]
+ XHsBindsLR _ -> []
where thing = foundOfLName modname
patThings lpat tl =
let loc = startOfLocated lpat
diff --git a/utils/haddock b/utils/haddock
-Subproject 73fa32d2a0f9867fc6aa85f9995b02607507578
+Subproject efd05f6960f0a5c5f24f8f7540ffdef006fd0a7