{-# LANGUAGE ScopedTypeVariables, BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
module RnBinds (
rnTopBindsLHS, rnTopBindsBoot, rnValBindsRHS,
rnLocalBindsAndThen, rnLocalValBindsLHS, rnLocalValBindsRHS,
rnMethodBinds, renameSigs,
rnMatchGroup, rnGRHSs, rnGRHS, rnSrcFixityDecl,
makeMiniFixityEnv, MiniFixityEnv,
HsSigCtxt(..)
) where
import GhcPrelude
import {-# SOURCE #-} RnExpr( rnLExpr, rnStmts )
import HsSyn
import TcRnMonad
import RnTypes
import RnPat
import RnNames
import RnEnv
import RnFixity
import RnUtils ( HsDocContext(..), mapFvRn, extendTyVarEnvFVRn
, checkDupRdrNames, warnUnusedLocalBinds
, checkDupAndShadowedNames, bindLocalNamesFV )
import DynFlags
import Module
import Name
import NameEnv
import NameSet
import RdrName ( RdrName, rdrNameOcc )
import SrcLoc
import ListSetOps ( findDupsEq )
import BasicTypes ( RecFlag(..) )
import Digraph ( SCC(..) )
import Bag
import Util
import Outputable
import UniqSet
import Maybes ( orElse )
import qualified GHC.LanguageExtensions as LangExt
import Control.Monad
import Data.Foldable ( toList )
import Data.List ( partition, sort )
import Data.List.NonEmpty ( NonEmpty(..) )
rnTopBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs
-> RnM (HsValBindsLR GhcRn GhcPs)
rnTopBindsLHS :: MiniFixityEnv -> HsValBinds GhcPs -> RnM (HsValBindsLR GhcRn GhcPs)
rnTopBindsLHS fix_env :: MiniFixityEnv
fix_env binds :: HsValBinds GhcPs
binds
= NameMaker -> HsValBinds GhcPs -> RnM (HsValBindsLR GhcRn GhcPs)
rnValBindsLHS (MiniFixityEnv -> NameMaker
topRecNameMaker MiniFixityEnv
fix_env) HsValBinds GhcPs
binds
rnTopBindsBoot :: NameSet -> HsValBindsLR GhcRn GhcPs
-> RnM (HsValBinds GhcRn, DefUses)
rnTopBindsBoot :: NameSet
-> HsValBindsLR GhcRn GhcPs -> RnM (HsValBinds GhcRn, DefUses)
rnTopBindsBoot bound_names :: NameSet
bound_names (ValBinds _ mbinds :: LHsBindsLR GhcRn GhcPs
mbinds sigs :: [LSig GhcPs]
sigs)
= do { Bool -> MsgDoc -> TcRn ()
checkErr (LHsBindsLR GhcRn GhcPs -> Bool
forall idL idR. LHsBindsLR idL idR -> Bool
isEmptyLHsBinds LHsBindsLR GhcRn GhcPs
mbinds) (LHsBindsLR GhcRn GhcPs -> MsgDoc
bindsInHsBootFile LHsBindsLR GhcRn GhcPs
mbinds)
; (sigs' :: [LSig GhcRn]
sigs', fvs :: NameSet
fvs) <- HsSigCtxt -> [LSig GhcPs] -> RnM ([LSig GhcRn], NameSet)
renameSigs (NameSet -> HsSigCtxt
HsBootCtxt NameSet
bound_names) [LSig GhcPs]
sigs
; (HsValBinds GhcRn, DefUses) -> RnM (HsValBinds GhcRn, DefUses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XXValBindsLR GhcRn GhcRn -> HsValBinds GhcRn
forall idL idR. XXValBindsLR idL idR -> HsValBindsLR idL idR
XValBindsLR ([(RecFlag, LHsBinds GhcRn)] -> [LSig GhcRn] -> NHsValBindsLR GhcRn
forall idL.
[(RecFlag, LHsBinds idL)] -> [LSig GhcRn] -> NHsValBindsLR idL
NValBinds [] [LSig GhcRn]
sigs'), NameSet -> DefUses
usesOnly NameSet
fvs) }
rnTopBindsBoot _ b :: HsValBindsLR GhcRn GhcPs
b = String -> MsgDoc -> RnM (HsValBinds GhcRn, DefUses)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnTopBindsBoot" (HsValBindsLR GhcRn GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsValBindsLR GhcRn GhcPs
b)
rnLocalBindsAndThen :: HsLocalBinds GhcPs
-> (HsLocalBinds GhcRn -> FreeVars -> RnM (result, FreeVars))
-> RnM (result, FreeVars)
rnLocalBindsAndThen :: HsLocalBinds GhcPs
-> (HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalBindsAndThen (EmptyLocalBinds x :: XEmptyLocalBinds GhcPs GhcPs
x) thing_inside :: HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside =
HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside (XEmptyLocalBinds GhcRn GhcRn -> HsLocalBinds GhcRn
forall idL idR. XEmptyLocalBinds idL idR -> HsLocalBindsLR idL idR
EmptyLocalBinds XEmptyLocalBinds GhcPs GhcPs
XEmptyLocalBinds GhcRn GhcRn
x) NameSet
emptyNameSet
rnLocalBindsAndThen (HsValBinds x :: XHsValBinds GhcPs GhcPs
x val_binds :: HsValBinds GhcPs
val_binds) thing_inside :: HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside
= HsValBinds GhcPs
-> (HsValBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
forall result.
HsValBinds GhcPs
-> (HsValBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalValBindsAndThen HsValBinds GhcPs
val_binds ((HsValBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet))
-> (HsValBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
forall a b. (a -> b) -> a -> b
$ \ val_binds' :: HsValBinds GhcRn
val_binds' ->
HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside (XHsValBinds GhcRn GhcRn -> HsValBinds GhcRn -> HsLocalBinds GhcRn
forall idL idR.
XHsValBinds idL idR
-> HsValBindsLR idL idR -> HsLocalBindsLR idL idR
HsValBinds XHsValBinds GhcPs GhcPs
XHsValBinds GhcRn GhcRn
x HsValBinds GhcRn
val_binds')
rnLocalBindsAndThen (HsIPBinds x :: XHsIPBinds GhcPs GhcPs
x binds :: HsIPBinds GhcPs
binds) thing_inside :: HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside = do
(binds' :: HsIPBinds GhcRn
binds',fv_binds :: NameSet
fv_binds) <- HsIPBinds GhcPs -> RnM (HsIPBinds GhcRn, NameSet)
rnIPBinds HsIPBinds GhcPs
binds
(thing :: result
thing, fvs_thing :: NameSet
fvs_thing) <- HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside (XHsIPBinds GhcRn GhcRn -> HsIPBinds GhcRn -> HsLocalBinds GhcRn
forall idL idR.
XHsIPBinds idL idR -> HsIPBinds idR -> HsLocalBindsLR idL idR
HsIPBinds XHsIPBinds GhcPs GhcPs
XHsIPBinds GhcRn GhcRn
x HsIPBinds GhcRn
binds') NameSet
fv_binds
(result, NameSet) -> RnM (result, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (result
thing, NameSet
fvs_thing NameSet -> NameSet -> NameSet
`plusFV` NameSet
fv_binds)
rnLocalBindsAndThen (XHsLocalBindsLR _) _ = String -> RnM (result, NameSet)
forall a. String -> a
panic "rnLocalBindsAndThen"
rnIPBinds :: HsIPBinds GhcPs -> RnM (HsIPBinds GhcRn, FreeVars)
rnIPBinds :: HsIPBinds GhcPs -> RnM (HsIPBinds GhcRn, NameSet)
rnIPBinds (IPBinds _ ip_binds :: [LIPBind GhcPs]
ip_binds ) = do
(ip_binds' :: [LIPBind GhcRn]
ip_binds', fvs_s :: [NameSet]
fvs_s) <- (LIPBind GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LIPBind GhcRn, NameSet))
-> [LIPBind GhcPs]
-> IOEnv (Env TcGblEnv TcLclEnv) ([LIPBind GhcRn], [NameSet])
forall (m :: * -> *) a b c.
Applicative m =>
(a -> m (b, c)) -> [a] -> m ([b], [c])
mapAndUnzipM ((SrcSpanLess (LIPBind GhcPs)
-> TcM (SrcSpanLess (LIPBind GhcRn), NameSet))
-> LIPBind GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LIPBind GhcRn, NameSet)
forall a b c.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b, c)) -> a -> TcM (b, c)
wrapLocFstM SrcSpanLess (LIPBind GhcPs)
-> TcM (SrcSpanLess (LIPBind GhcRn), NameSet)
IPBind GhcPs -> RnM (IPBind GhcRn, NameSet)
rnIPBind) [LIPBind GhcPs]
ip_binds
(HsIPBinds GhcRn, NameSet) -> RnM (HsIPBinds GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XIPBinds GhcRn -> [LIPBind GhcRn] -> HsIPBinds GhcRn
forall id. XIPBinds id -> [LIPBind id] -> HsIPBinds id
IPBinds XIPBinds GhcRn
NoExt
noExt [LIPBind GhcRn]
ip_binds', [NameSet] -> NameSet
plusFVs [NameSet]
fvs_s)
rnIPBinds (XHsIPBinds _) = String -> RnM (HsIPBinds GhcRn, NameSet)
forall a. String -> a
panic "rnIPBinds"
rnIPBind :: IPBind GhcPs -> RnM (IPBind GhcRn, FreeVars)
rnIPBind :: IPBind GhcPs -> RnM (IPBind GhcRn, NameSet)
rnIPBind (IPBind _ ~(Left n :: Located HsIPName
n) expr :: LHsExpr GhcPs
expr) = do
(expr' :: LHsExpr GhcRn
expr',fvExpr :: NameSet
fvExpr) <- LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet)
rnLExpr LHsExpr GhcPs
expr
(IPBind GhcRn, NameSet) -> RnM (IPBind GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCIPBind GhcRn
-> Either (Located HsIPName) (IdP GhcRn)
-> LHsExpr GhcRn
-> IPBind GhcRn
forall id.
XCIPBind id
-> Either (Located HsIPName) (IdP id) -> LHsExpr id -> IPBind id
IPBind XCIPBind GhcRn
NoExt
noExt (Located HsIPName -> Either (Located HsIPName) Name
forall a b. a -> Either a b
Left Located HsIPName
n) LHsExpr GhcRn
expr', NameSet
fvExpr)
rnIPBind (XIPBind _) = String -> RnM (IPBind GhcRn, NameSet)
forall a. String -> a
panic "rnIPBind"
rnLocalValBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs
-> RnM ([Name], HsValBindsLR GhcRn GhcPs)
rnLocalValBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs -> RnM ([Name], HsValBindsLR GhcRn GhcPs)
rnLocalValBindsLHS fix_env :: MiniFixityEnv
fix_env binds :: HsValBinds GhcPs
binds
= do { HsValBindsLR GhcRn GhcPs
binds' <- NameMaker -> HsValBinds GhcPs -> RnM (HsValBindsLR GhcRn GhcPs)
rnValBindsLHS (MiniFixityEnv -> NameMaker
localRecNameMaker MiniFixityEnv
fix_env) HsValBinds GhcPs
binds
; let bound_names :: [IdP GhcRn]
bound_names = HsValBindsLR GhcRn GhcPs -> [IdP GhcRn]
forall (idL :: Pass) (idR :: Pass).
HsValBindsLR (GhcPass idL) (GhcPass idR) -> [IdP (GhcPass idL)]
collectHsValBinders HsValBindsLR GhcRn GhcPs
binds'
; (GlobalRdrEnv, LocalRdrEnv)
envs <- TcRn (GlobalRdrEnv, LocalRdrEnv)
getRdrEnvs
; (GlobalRdrEnv, LocalRdrEnv) -> [Name] -> TcRn ()
checkDupAndShadowedNames (GlobalRdrEnv, LocalRdrEnv)
envs [Name]
[IdP GhcRn]
bound_names
; ([Name], HsValBindsLR GhcRn GhcPs)
-> RnM ([Name], HsValBindsLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Name]
[IdP GhcRn]
bound_names, HsValBindsLR GhcRn GhcPs
binds') }
rnValBindsLHS :: NameMaker
-> HsValBinds GhcPs
-> RnM (HsValBindsLR GhcRn GhcPs)
rnValBindsLHS :: NameMaker -> HsValBinds GhcPs -> RnM (HsValBindsLR GhcRn GhcPs)
rnValBindsLHS topP :: NameMaker
topP (ValBinds x :: XValBinds GhcPs GhcPs
x mbinds :: LHsBindsLR GhcPs GhcPs
mbinds sigs :: [LSig GhcPs]
sigs)
= do { LHsBindsLR GhcRn GhcPs
mbinds' <- (LHsBindLR GhcPs GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindLR GhcRn GhcPs))
-> LHsBindsLR GhcPs GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM ((SrcSpanLess (LHsBindLR GhcPs GhcPs)
-> TcM (SrcSpanLess (LHsBindLR GhcRn GhcPs)))
-> LHsBindLR GhcPs GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindLR GhcRn GhcPs)
forall a b.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b)) -> a -> TcM b
wrapLocM (NameMaker -> MsgDoc -> HsBind GhcPs -> RnM (HsBindLR GhcRn GhcPs)
rnBindLHS NameMaker
topP MsgDoc
doc)) LHsBindsLR GhcPs GhcPs
mbinds
; HsValBindsLR GhcRn GhcPs -> RnM (HsValBindsLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsValBindsLR GhcRn GhcPs -> RnM (HsValBindsLR GhcRn GhcPs))
-> HsValBindsLR GhcRn GhcPs -> RnM (HsValBindsLR GhcRn GhcPs)
forall a b. (a -> b) -> a -> b
$ XValBinds GhcRn GhcPs
-> LHsBindsLR GhcRn GhcPs
-> [LSig GhcPs]
-> HsValBindsLR GhcRn GhcPs
forall idL idR.
XValBinds idL idR
-> LHsBindsLR idL idR -> [LSig idR] -> HsValBindsLR idL idR
ValBinds XValBinds GhcPs GhcPs
XValBinds GhcRn GhcPs
x LHsBindsLR GhcRn GhcPs
mbinds' [LSig GhcPs]
sigs }
where
bndrs :: [IdP GhcPs]
bndrs = LHsBindsLR GhcPs GhcPs -> [IdP GhcPs]
forall (p :: Pass) idR.
LHsBindsLR (GhcPass p) idR -> [IdP (GhcPass p)]
collectHsBindsBinders LHsBindsLR GhcPs GhcPs
mbinds
doc :: MsgDoc
doc = String -> MsgDoc
text "In the binding group for:" MsgDoc -> MsgDoc -> MsgDoc
<+> (RdrName -> MsgDoc) -> [RdrName] -> MsgDoc
forall a. (a -> MsgDoc) -> [a] -> MsgDoc
pprWithCommas RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr [RdrName]
[IdP GhcPs]
bndrs
rnValBindsLHS _ b :: HsValBinds GhcPs
b = String -> MsgDoc -> RnM (HsValBindsLR GhcRn GhcPs)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnValBindsLHSFromDoc" (HsValBinds GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsValBinds GhcPs
b)
rnValBindsRHS :: HsSigCtxt
-> HsValBindsLR GhcRn GhcPs
-> RnM (HsValBinds GhcRn, DefUses)
rnValBindsRHS :: HsSigCtxt
-> HsValBindsLR GhcRn GhcPs -> RnM (HsValBinds GhcRn, DefUses)
rnValBindsRHS ctxt :: HsSigCtxt
ctxt (ValBinds _ mbinds :: LHsBindsLR GhcRn GhcPs
mbinds sigs :: [LSig GhcPs]
sigs)
= do { (sigs' :: [LSig GhcRn]
sigs', sig_fvs :: NameSet
sig_fvs) <- HsSigCtxt -> [LSig GhcPs] -> RnM ([LSig GhcRn], NameSet)
renameSigs HsSigCtxt
ctxt [LSig GhcPs]
sigs
; Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus <- (LHsBindLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet))
-> LHsBindsLR GhcRn GhcPs
-> IOEnv
(Env TcGblEnv TcLclEnv) (Bag (LHsBind GhcRn, [Name], NameSet))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM ((Name -> [Name])
-> LHsBindLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
rnLBind ([LSig GhcRn] -> Name -> [Name]
mkScopedTvFn [LSig GhcRn]
sigs')) LHsBindsLR GhcRn GhcPs
mbinds
; let !(anal_binds :: [(RecFlag, LHsBinds GhcRn)]
anal_binds, anal_dus :: DefUses
anal_dus) = Bag (LHsBind GhcRn, [Name], NameSet)
-> ([(RecFlag, LHsBinds GhcRn)], DefUses)
depAnalBinds Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus
; let patsyn_fvs :: NameSet
patsyn_fvs = (PatSynBind GhcRn GhcRn -> NameSet -> NameSet)
-> NameSet -> [PatSynBind GhcRn GhcRn] -> NameSet
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (NameSet -> NameSet -> NameSet
unionNameSet (NameSet -> NameSet -> NameSet)
-> (PatSynBind GhcRn GhcRn -> NameSet)
-> PatSynBind GhcRn GhcRn
-> NameSet
-> NameSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatSynBind GhcRn GhcRn -> NameSet
forall idL idR. PatSynBind idL idR -> XPSB idL idR
psb_ext) NameSet
emptyNameSet ([PatSynBind GhcRn GhcRn] -> NameSet)
-> [PatSynBind GhcRn GhcRn] -> NameSet
forall a b. (a -> b) -> a -> b
$
[(RecFlag, LHsBinds GhcRn)] -> [PatSynBind GhcRn GhcRn]
forall id. [(RecFlag, LHsBinds id)] -> [PatSynBind id id]
getPatSynBinds [(RecFlag, LHsBinds GhcRn)]
anal_binds
valbind'_dus :: DefUses
valbind'_dus = DefUses
anal_dus DefUses -> DefUses -> DefUses
`plusDU` NameSet -> DefUses
usesOnly NameSet
sig_fvs
DefUses -> DefUses -> DefUses
`plusDU` NameSet -> DefUses
usesOnly NameSet
patsyn_fvs
; (HsValBinds GhcRn, DefUses) -> RnM (HsValBinds GhcRn, DefUses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XXValBindsLR GhcRn GhcRn -> HsValBinds GhcRn
forall idL idR. XXValBindsLR idL idR -> HsValBindsLR idL idR
XValBindsLR ([(RecFlag, LHsBinds GhcRn)] -> [LSig GhcRn] -> NHsValBindsLR GhcRn
forall idL.
[(RecFlag, LHsBinds idL)] -> [LSig GhcRn] -> NHsValBindsLR idL
NValBinds [(RecFlag, LHsBinds GhcRn)]
anal_binds [LSig GhcRn]
sigs'), DefUses
valbind'_dus) }
rnValBindsRHS _ b :: HsValBindsLR GhcRn GhcPs
b = String -> MsgDoc -> RnM (HsValBinds GhcRn, DefUses)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnValBindsRHS" (HsValBindsLR GhcRn GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsValBindsLR GhcRn GhcPs
b)
rnLocalValBindsRHS :: NameSet
-> HsValBindsLR GhcRn GhcPs
-> RnM (HsValBinds GhcRn, DefUses)
rnLocalValBindsRHS :: NameSet
-> HsValBindsLR GhcRn GhcPs -> RnM (HsValBinds GhcRn, DefUses)
rnLocalValBindsRHS bound_names :: NameSet
bound_names binds :: HsValBindsLR GhcRn GhcPs
binds
= HsSigCtxt
-> HsValBindsLR GhcRn GhcPs -> RnM (HsValBinds GhcRn, DefUses)
rnValBindsRHS (NameSet -> HsSigCtxt
LocalBindCtxt NameSet
bound_names) HsValBindsLR GhcRn GhcPs
binds
rnLocalValBindsAndThen
:: HsValBinds GhcPs
-> (HsValBinds GhcRn -> FreeVars -> RnM (result, FreeVars))
-> RnM (result, FreeVars)
rnLocalValBindsAndThen :: HsValBinds GhcPs
-> (HsValBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalValBindsAndThen binds :: HsValBinds GhcPs
binds@(ValBinds _ _ sigs :: [LSig GhcPs]
sigs) thing_inside :: HsValBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside
= do {
MiniFixityEnv
new_fixities <- [LFixitySig GhcPs] -> RnM MiniFixityEnv
makeMiniFixityEnv [ SrcSpan -> FixitySig GhcPs -> LFixitySig GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc FixitySig GhcPs
sig
| L loc :: SrcSpan
loc (FixSig _ sig :: FixitySig GhcPs
sig) <- [LSig GhcPs]
sigs]
; (bound_names :: [Name]
bound_names, new_lhs :: HsValBindsLR GhcRn GhcPs
new_lhs) <- MiniFixityEnv
-> HsValBinds GhcPs -> RnM ([Name], HsValBindsLR GhcRn GhcPs)
rnLocalValBindsLHS MiniFixityEnv
new_fixities HsValBinds GhcPs
binds
; [Name] -> RnM (result, NameSet) -> RnM (result, NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindLocalNamesFV [Name]
bound_names (RnM (result, NameSet) -> RnM (result, NameSet))
-> RnM (result, NameSet) -> RnM (result, NameSet)
forall a b. (a -> b) -> a -> b
$
MiniFixityEnv
-> [Name] -> RnM (result, NameSet) -> RnM (result, NameSet)
forall a. MiniFixityEnv -> [Name] -> RnM a -> RnM a
addLocalFixities MiniFixityEnv
new_fixities [Name]
bound_names (RnM (result, NameSet) -> RnM (result, NameSet))
-> RnM (result, NameSet) -> RnM (result, NameSet)
forall a b. (a -> b) -> a -> b
$ do
{
(binds' :: HsValBinds GhcRn
binds', dus :: DefUses
dus) <- NameSet
-> HsValBindsLR GhcRn GhcPs -> RnM (HsValBinds GhcRn, DefUses)
rnLocalValBindsRHS ([Name] -> NameSet
mkNameSet [Name]
bound_names) HsValBindsLR GhcRn GhcPs
new_lhs
; (result :: result
result, result_fvs :: NameSet
result_fvs) <- HsValBinds GhcRn -> NameSet -> RnM (result, NameSet)
thing_inside HsValBinds GhcRn
binds' (DefUses -> NameSet
allUses DefUses
dus)
; let real_uses :: NameSet
real_uses = DefUses -> NameSet -> NameSet
findUses DefUses
dus NameSet
result_fvs
implicit_uses :: NameSet
implicit_uses = HsValBinds GhcRn -> NameSet
forall (idR :: Pass). HsValBindsLR GhcRn (GhcPass idR) -> NameSet
hsValBindsImplicits HsValBinds GhcRn
binds'
; [Name] -> NameSet -> TcRn ()
warnUnusedLocalBinds [Name]
bound_names
(NameSet
real_uses NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
implicit_uses)
; let
all_uses :: NameSet
all_uses = DefUses -> NameSet
allUses DefUses
dus NameSet -> NameSet -> NameSet
`plusFV` NameSet
result_fvs
; (result, NameSet) -> RnM (result, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (result
result, NameSet
all_uses) }}
rnLocalValBindsAndThen bs :: HsValBinds GhcPs
bs _ = String -> MsgDoc -> RnM (result, NameSet)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnLocalValBindsAndThen" (HsValBinds GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsValBinds GhcPs
bs)
rnBindLHS :: NameMaker
-> SDoc
-> HsBind GhcPs
-> RnM (HsBindLR GhcRn GhcPs)
rnBindLHS :: NameMaker -> MsgDoc -> HsBind GhcPs -> RnM (HsBindLR GhcRn GhcPs)
rnBindLHS name_maker :: NameMaker
name_maker _ bind :: HsBind GhcPs
bind@(PatBind { pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat GhcPs
pat })
= do
(pat' :: LPat GhcRn
pat',pat'_fvs :: NameSet
pat'_fvs) <- NameMaker -> LPat GhcPs -> RnM (LPat GhcRn, NameSet)
rnBindPat NameMaker
name_maker LPat GhcPs
pat
HsBindLR GhcRn GhcPs -> RnM (HsBindLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBind GhcPs
bind { pat_lhs :: LPat GhcRn
pat_lhs = LPat GhcRn
pat', pat_ext :: XPatBind GhcRn GhcPs
pat_ext = NameSet
XPatBind GhcRn GhcPs
pat'_fvs })
rnBindLHS name_maker :: NameMaker
name_maker _ bind :: HsBind GhcPs
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = Located (IdP GhcPs)
rdr_name })
= do { Located Name
name <- NameMaker -> Located RdrName -> RnM (Located Name)
applyNameMaker NameMaker
name_maker Located RdrName
Located (IdP GhcPs)
rdr_name
; HsBindLR GhcRn GhcPs -> RnM (HsBindLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBind GhcPs
bind { fun_id :: Located (IdP GhcRn)
fun_id = Located Name
Located (IdP GhcRn)
name
, fun_ext :: XFunBind GhcRn GhcPs
fun_ext = XFunBind GhcRn GhcPs
NoExt
noExt }) }
rnBindLHS name_maker :: NameMaker
name_maker _ (PatSynBind x :: XPatSynBind GhcPs GhcPs
x psb :: PatSynBind GhcPs GhcPs
psb@PSB{ psb_id :: forall idL idR. PatSynBind idL idR -> Located (IdP idL)
psb_id = Located (IdP GhcPs)
rdrname })
| NameMaker -> Bool
isTopRecNameMaker NameMaker
name_maker
= do { (SrcSpanLess (Located RdrName) -> TcRn ())
-> Located RdrName -> TcRn ()
forall a b. HasSrcSpan a => (SrcSpanLess a -> TcM b) -> a -> TcM b
addLocM SrcSpanLess (Located RdrName) -> TcRn ()
RdrName -> TcRn ()
checkConName Located RdrName
Located (IdP GhcPs)
rdrname
; Located Name
name <- Located RdrName -> RnM (Located Name)
lookupLocatedTopBndrRn Located RdrName
Located (IdP GhcPs)
rdrname
; HsBindLR GhcRn GhcPs -> RnM (HsBindLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynBind GhcRn GhcPs
-> PatSynBind GhcRn GhcPs -> HsBindLR GhcRn GhcPs
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind GhcPs GhcPs
XPatSynBind GhcRn GhcPs
x PatSynBind GhcPs GhcPs
psb{ psb_ext :: XPSB GhcRn GhcPs
psb_ext = XPSB GhcRn GhcPs
NoExt
noExt, psb_id :: Located (IdP GhcRn)
psb_id = Located Name
Located (IdP GhcRn)
name }) }
| Bool
otherwise
= do { MsgDoc -> TcRn ()
addErr MsgDoc
localPatternSynonymErr
; Located Name
name <- NameMaker -> Located RdrName -> RnM (Located Name)
applyNameMaker NameMaker
name_maker Located RdrName
Located (IdP GhcPs)
rdrname
; HsBindLR GhcRn GhcPs -> RnM (HsBindLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynBind GhcRn GhcPs
-> PatSynBind GhcRn GhcPs -> HsBindLR GhcRn GhcPs
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind GhcPs GhcPs
XPatSynBind GhcRn GhcPs
x PatSynBind GhcPs GhcPs
psb{ psb_ext :: XPSB GhcRn GhcPs
psb_ext = XPSB GhcRn GhcPs
NoExt
noExt, psb_id :: Located (IdP GhcRn)
psb_id = Located Name
Located (IdP GhcRn)
name }) }
where
localPatternSynonymErr :: SDoc
localPatternSynonymErr :: MsgDoc
localPatternSynonymErr
= MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "Illegal pattern synonym declaration for" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Located RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Located RdrName
Located (IdP GhcPs)
rdrname))
2 (String -> MsgDoc
text "Pattern synonym declarations are only valid at top level")
rnBindLHS _ _ b :: HsBind GhcPs
b = String -> MsgDoc -> RnM (HsBindLR GhcRn GhcPs)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnBindHS" (HsBind GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBind GhcPs
b)
rnLBind :: (Name -> [Name])
-> LHsBindLR GhcRn GhcPs
-> RnM (LHsBind GhcRn, [Name], Uses)
rnLBind :: (Name -> [Name])
-> LHsBindLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
rnLBind sig_fn :: Name -> [Name]
sig_fn (L loc :: SrcSpan
loc bind :: HsBindLR GhcRn GhcPs
bind)
= SrcSpan
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet))
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
forall a b. (a -> b) -> a -> b
$
do { (bind' :: HsBind GhcRn
bind', bndrs :: [Name]
bndrs, dus :: NameSet
dus) <- (Name -> [Name])
-> HsBindLR GhcRn GhcPs -> RnM (HsBind GhcRn, [Name], NameSet)
rnBind Name -> [Name]
sig_fn HsBindLR GhcRn GhcPs
bind
; (LHsBind GhcRn, [Name], NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> HsBind GhcRn -> LHsBind GhcRn
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc HsBind GhcRn
bind', [Name]
bndrs, NameSet
dus) }
rnBind :: (Name -> [Name])
-> HsBindLR GhcRn GhcPs
-> RnM (HsBind GhcRn, [Name], Uses)
rnBind :: (Name -> [Name])
-> HsBindLR GhcRn GhcPs -> RnM (HsBind GhcRn, [Name], NameSet)
rnBind _ bind :: HsBindLR GhcRn GhcPs
bind@(PatBind { pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat GhcRn
pat
, pat_rhs :: forall idL idR. HsBindLR idL idR -> GRHSs idR (LHsExpr idR)
pat_rhs = GRHSs GhcPs (LHsExpr GhcPs)
grhss
, pat_ext :: forall idL idR. HsBindLR idL idR -> XPatBind idL idR
pat_ext = XPatBind GhcRn GhcPs
pat_fvs })
= do { Module
mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; (grhss' :: GRHSs GhcRn (LHsExpr GhcRn)
grhss', rhs_fvs :: NameSet
rhs_fvs) <- HsMatchContext Name
-> (LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet))
-> GRHSs GhcPs (LHsExpr GhcPs)
-> RnM (GRHSs GhcRn (LHsExpr GhcRn), NameSet)
forall (body :: * -> *).
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHSs GhcPs (Located (body GhcPs))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
rnGRHSs HsMatchContext Name
forall id. HsMatchContext id
PatBindRhs LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet)
rnLExpr GRHSs GhcPs (LHsExpr GhcPs)
grhss
; let all_fvs :: NameSet
all_fvs = NameSet
XPatBind GhcRn GhcPs
pat_fvs NameSet -> NameSet -> NameSet
`plusFV` NameSet
rhs_fvs
fvs' :: NameSet
fvs' = (Name -> Bool) -> NameSet -> NameSet
filterNameSet (Module -> Name -> Bool
nameIsLocalOrFrom Module
mod) NameSet
all_fvs
bndrs :: [IdP GhcRn]
bndrs = LPat GhcRn -> [IdP GhcRn]
forall (p :: Pass). LPat (GhcPass p) -> [IdP (GhcPass p)]
collectPatBinders LPat GhcRn
pat
bind' :: HsBind GhcRn
bind' = HsBindLR GhcRn GhcPs
bind { pat_rhs :: GRHSs GhcRn (LHsExpr GhcRn)
pat_rhs = GRHSs GhcRn (LHsExpr GhcRn)
grhss'
, pat_ext :: XPatBind GhcRn GhcRn
pat_ext = NameSet
XPatBind GhcRn GhcRn
fvs' }
ok_nobind_pat :: Bool
ok_nobind_pat
=
case LPat GhcRn -> SrcSpanLess (LPat GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcRn
pat of
WildPat {} -> Bool
True
BangPat {} -> Bool
True
SplicePat {} -> Bool
True
_ -> Bool
False
; WarningFlag -> TcRn () -> TcRn ()
forall gbl lcl.
WarningFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
whenWOptM WarningFlag
Opt_WarnUnusedPatternBinds (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Name] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
[IdP GhcRn]
bndrs Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
ok_nobind_pat) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
WarnReason -> MsgDoc -> TcRn ()
addWarn (WarningFlag -> WarnReason
Reason WarningFlag
Opt_WarnUnusedPatternBinds) (MsgDoc -> TcRn ()) -> MsgDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
HsBind GhcRn -> MsgDoc
unusedPatBindWarn HsBind GhcRn
bind'
; NameSet
fvs' NameSet
-> RnM (HsBind GhcRn, [Name], NameSet)
-> RnM (HsBind GhcRn, [Name], NameSet)
forall a b. a -> b -> b
`seq`
(HsBind GhcRn, [Name], NameSet)
-> RnM (HsBind GhcRn, [Name], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBind GhcRn
bind', [Name]
[IdP GhcRn]
bndrs, NameSet
all_fvs) }
rnBind sig_fn :: Name -> [Name]
sig_fn bind :: HsBindLR GhcRn GhcPs
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = Located (IdP GhcRn)
name
, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup GhcPs (LHsExpr GhcPs)
matches })
= do { let plain_name :: SrcSpanLess (Located Name)
plain_name = Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
Located (IdP GhcRn)
name
; (matches' :: MatchGroup GhcRn (LHsExpr GhcRn)
matches', rhs_fvs :: NameSet
rhs_fvs) <- [Name]
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV (Name -> [Name]
sig_fn Name
SrcSpanLess (Located Name)
plain_name) (RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet))
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
forall a b. (a -> b) -> a -> b
$
HsMatchContext Name
-> (LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet))
-> MatchGroup GhcPs (LHsExpr GhcPs)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
forall (body :: * -> *).
Outputable (body GhcPs) =>
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> MatchGroup GhcPs (Located (body GhcPs))
-> RnM (MatchGroup GhcRn (Located (body GhcRn)), NameSet)
rnMatchGroup (Located Name -> HsMatchContext Name
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs Located Name
Located (IdP GhcRn)
name)
LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet)
rnLExpr MatchGroup GhcPs (LHsExpr GhcPs)
matches
; let is_infix :: Bool
is_infix = HsBindLR GhcRn GhcPs -> Bool
forall id1 id2. HsBindLR id1 id2 -> Bool
isInfixFunBind HsBindLR GhcRn GhcPs
bind
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
is_infix (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ Name -> MatchGroup GhcRn (LHsExpr GhcRn) -> TcRn ()
forall body. Name -> MatchGroup GhcRn body -> TcRn ()
checkPrecMatch Name
SrcSpanLess (Located Name)
plain_name MatchGroup GhcRn (LHsExpr GhcRn)
matches'
; Module
mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; let fvs' :: NameSet
fvs' = (Name -> Bool) -> NameSet -> NameSet
filterNameSet (Module -> Name -> Bool
nameIsLocalOrFrom Module
mod) NameSet
rhs_fvs
; NameSet
fvs' NameSet
-> RnM (HsBind GhcRn, [Name], NameSet)
-> RnM (HsBind GhcRn, [Name], NameSet)
forall a b. a -> b -> b
`seq`
(HsBind GhcRn, [Name], NameSet)
-> RnM (HsBind GhcRn, [Name], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBindLR GhcRn GhcPs
bind { fun_matches :: MatchGroup GhcRn (LHsExpr GhcRn)
fun_matches = MatchGroup GhcRn (LHsExpr GhcRn)
matches'
, fun_ext :: XFunBind GhcRn GhcRn
fun_ext = NameSet
XFunBind GhcRn GhcRn
fvs' },
[Name
SrcSpanLess (Located Name)
plain_name], NameSet
rhs_fvs)
}
rnBind sig_fn :: Name -> [Name]
sig_fn (PatSynBind x :: XPatSynBind GhcRn GhcPs
x bind :: PatSynBind GhcRn GhcPs
bind)
= do { (bind' :: PatSynBind GhcRn GhcRn
bind', name :: [Name]
name, fvs :: NameSet
fvs) <- (Name -> [Name])
-> PatSynBind GhcRn GhcPs
-> RnM (PatSynBind GhcRn GhcRn, [Name], NameSet)
rnPatSynBind Name -> [Name]
sig_fn PatSynBind GhcRn GhcPs
bind
; (HsBind GhcRn, [Name], NameSet)
-> RnM (HsBind GhcRn, [Name], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynBind GhcRn GhcRn -> PatSynBind GhcRn GhcRn -> HsBind GhcRn
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind GhcRn GhcPs
XPatSynBind GhcRn GhcRn
x PatSynBind GhcRn GhcRn
bind', [Name]
name, NameSet
fvs) }
rnBind _ b :: HsBindLR GhcRn GhcPs
b = String -> MsgDoc -> RnM (HsBind GhcRn, [Name], NameSet)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnBind" (HsBindLR GhcRn GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBindLR GhcRn GhcPs
b)
depAnalBinds :: Bag (LHsBind GhcRn, [Name], Uses)
-> ([(RecFlag, LHsBinds GhcRn)], DefUses)
depAnalBinds :: Bag (LHsBind GhcRn, [Name], NameSet)
-> ([(RecFlag, LHsBinds GhcRn)], DefUses)
depAnalBinds binds_w_dus :: Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus
= ((SCC (LHsBind GhcRn, [Name], NameSet) -> (RecFlag, LHsBinds GhcRn))
-> [SCC (LHsBind GhcRn, [Name], NameSet)]
-> [(RecFlag, LHsBinds GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map SCC (LHsBind GhcRn, [Name], NameSet) -> (RecFlag, LHsBinds GhcRn)
forall a b c. SCC (a, b, c) -> (RecFlag, Bag a)
get_binds [SCC (LHsBind GhcRn, [Name], NameSet)]
sccs, (SCC (LHsBind GhcRn, [Name], NameSet) -> (Maybe NameSet, NameSet))
-> [SCC (LHsBind GhcRn, [Name], NameSet)] -> DefUses
forall a b. (a -> b) -> [a] -> [b]
map SCC (LHsBind GhcRn, [Name], NameSet) -> (Maybe NameSet, NameSet)
forall a. SCC (a, [Name], NameSet) -> (Maybe NameSet, NameSet)
get_du [SCC (LHsBind GhcRn, [Name], NameSet)]
sccs)
where
sccs :: [SCC (LHsBind GhcRn, [Name], NameSet)]
sccs = ((LHsBind GhcRn, [Name], NameSet) -> [Name])
-> ((LHsBind GhcRn, [Name], NameSet) -> [Name])
-> [(LHsBind GhcRn, [Name], NameSet)]
-> [SCC (LHsBind GhcRn, [Name], NameSet)]
forall node.
(node -> [Name]) -> (node -> [Name]) -> [node] -> [SCC node]
depAnal (\(_, defs :: [Name]
defs, _) -> [Name]
defs)
(\(_, _, uses :: NameSet
uses) -> NameSet -> [Name]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet NameSet
uses)
(Bag (LHsBind GhcRn, [Name], NameSet)
-> [(LHsBind GhcRn, [Name], NameSet)]
forall a. Bag a -> [a]
bagToList Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus)
get_binds :: SCC (a, b, c) -> (RecFlag, Bag a)
get_binds (AcyclicSCC (bind :: a
bind, _, _)) = (RecFlag
NonRecursive, a -> Bag a
forall a. a -> Bag a
unitBag a
bind)
get_binds (CyclicSCC binds_w_dus :: [(a, b, c)]
binds_w_dus) = (RecFlag
Recursive, [a] -> Bag a
forall a. [a] -> Bag a
listToBag [a
b | (b :: a
b,_,_) <- [(a, b, c)]
binds_w_dus])
get_du :: SCC (a, [Name], NameSet) -> (Maybe NameSet, NameSet)
get_du (AcyclicSCC (_, bndrs :: [Name]
bndrs, uses :: NameSet
uses)) = (NameSet -> Maybe NameSet
forall a. a -> Maybe a
Just ([Name] -> NameSet
mkNameSet [Name]
bndrs), NameSet
uses)
get_du (CyclicSCC binds_w_dus :: [(a, [Name], NameSet)]
binds_w_dus) = (NameSet -> Maybe NameSet
forall a. a -> Maybe a
Just NameSet
defs, NameSet
uses)
where
defs :: NameSet
defs = [Name] -> NameSet
mkNameSet [Name
b | (_,bs :: [Name]
bs,_) <- [(a, [Name], NameSet)]
binds_w_dus, Name
b <- [Name]
bs]
uses :: NameSet
uses = [NameSet] -> NameSet
unionNameSets [NameSet
u | (_,_,u :: NameSet
u) <- [(a, [Name], NameSet)]
binds_w_dus]
mkScopedTvFn :: [LSig GhcRn] -> (Name -> [Name])
mkScopedTvFn :: [LSig GhcRn] -> Name -> [Name]
mkScopedTvFn sigs :: [LSig GhcRn]
sigs = \n :: Name
n -> NameEnv [Name] -> Name -> Maybe [Name]
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv [Name]
env Name
n Maybe [Name] -> [Name] -> [Name]
forall a. Maybe a -> a -> a
`orElse` []
where
env :: NameEnv [Name]
env = (LSig GhcRn -> Maybe ([Located Name], [Name]))
-> [LSig GhcRn] -> NameEnv [Name]
forall a.
(LSig GhcRn -> Maybe ([Located Name], a))
-> [LSig GhcRn] -> NameEnv a
mkHsSigEnv LSig GhcRn -> Maybe ([Located Name], [Name])
get_scoped_tvs [LSig GhcRn]
sigs
get_scoped_tvs :: LSig GhcRn -> Maybe ([Located Name], [Name])
get_scoped_tvs :: LSig GhcRn -> Maybe ([Located Name], [Name])
get_scoped_tvs (L _ (ClassOpSig _ _ names :: [Located (IdP GhcRn)]
names sig_ty :: LHsSigType GhcRn
sig_ty))
= ([Located Name], [Name]) -> Maybe ([Located Name], [Name])
forall a. a -> Maybe a
Just ([Located Name]
[Located (IdP GhcRn)]
names, LHsSigType GhcRn -> [Name]
hsScopedTvs LHsSigType GhcRn
sig_ty)
get_scoped_tvs (L _ (TypeSig _ names :: [Located (IdP GhcRn)]
names sig_ty :: LHsSigWcType GhcRn
sig_ty))
= ([Located Name], [Name]) -> Maybe ([Located Name], [Name])
forall a. a -> Maybe a
Just ([Located Name]
[Located (IdP GhcRn)]
names, LHsSigWcType GhcRn -> [Name]
hsWcScopedTvs LHsSigWcType GhcRn
sig_ty)
get_scoped_tvs (L _ (PatSynSig _ names :: [Located (IdP GhcRn)]
names sig_ty :: LHsSigType GhcRn
sig_ty))
= ([Located Name], [Name]) -> Maybe ([Located Name], [Name])
forall a. a -> Maybe a
Just ([Located Name]
[Located (IdP GhcRn)]
names, LHsSigType GhcRn -> [Name]
hsScopedTvs LHsSigType GhcRn
sig_ty)
get_scoped_tvs _ = Maybe ([Located Name], [Name])
forall a. Maybe a
Nothing
makeMiniFixityEnv :: [LFixitySig GhcPs] -> RnM MiniFixityEnv
makeMiniFixityEnv :: [LFixitySig GhcPs] -> RnM MiniFixityEnv
makeMiniFixityEnv decls :: [LFixitySig GhcPs]
decls = (MiniFixityEnv -> LFixitySig GhcPs -> RnM MiniFixityEnv)
-> MiniFixityEnv -> [LFixitySig GhcPs] -> RnM MiniFixityEnv
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM MiniFixityEnv -> LFixitySig GhcPs -> RnM MiniFixityEnv
forall pass.
(IdP pass ~ RdrName) =>
MiniFixityEnv
-> GenLocated SrcSpan (FixitySig pass) -> RnM MiniFixityEnv
add_one_sig MiniFixityEnv
forall a. FastStringEnv a
emptyFsEnv [LFixitySig GhcPs]
decls
where
add_one_sig :: MiniFixityEnv
-> GenLocated SrcSpan (FixitySig pass) -> RnM MiniFixityEnv
add_one_sig env :: MiniFixityEnv
env (L loc :: SrcSpan
loc (FixitySig _ names :: [Located (IdP pass)]
names fixity :: Fixity
fixity)) =
(MiniFixityEnv
-> (SrcSpan, SrcSpan, RdrName, Fixity) -> RnM MiniFixityEnv)
-> MiniFixityEnv
-> [(SrcSpan, SrcSpan, RdrName, Fixity)]
-> RnM MiniFixityEnv
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM MiniFixityEnv
-> (SrcSpan, SrcSpan, RdrName, Fixity) -> RnM MiniFixityEnv
forall e.
FastStringEnv (GenLocated SrcSpan e)
-> (SrcSpan, SrcSpan, RdrName, e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
add_one MiniFixityEnv
env [ (SrcSpan
loc,SrcSpan
name_loc,RdrName
name,Fixity
fixity)
| L name_loc :: SrcSpan
name_loc name :: RdrName
name <- [Located RdrName]
[Located (IdP pass)]
names ]
add_one_sig _ (L _ (XFixitySig _)) = String -> RnM MiniFixityEnv
forall a. String -> a
panic "makeMiniFixityEnv"
add_one :: FastStringEnv (GenLocated SrcSpan e)
-> (SrcSpan, SrcSpan, RdrName, e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
add_one env :: FastStringEnv (GenLocated SrcSpan e)
env (loc :: SrcSpan
loc, name_loc :: SrcSpan
name_loc, name :: RdrName
name,fixity :: e
fixity) = do
{
let { fs :: FastString
fs = OccName -> FastString
occNameFS (RdrName -> OccName
rdrNameOcc RdrName
name)
; fix_item :: GenLocated SrcSpan e
fix_item = SrcSpan -> e -> GenLocated SrcSpan e
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc e
fixity };
case FastStringEnv (GenLocated SrcSpan e)
-> FastString -> Maybe (GenLocated SrcSpan e)
forall a. FastStringEnv a -> FastString -> Maybe a
lookupFsEnv FastStringEnv (GenLocated SrcSpan e)
env FastString
fs of
Nothing -> FastStringEnv (GenLocated SrcSpan e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
forall (m :: * -> *) a. Monad m => a -> m a
return (FastStringEnv (GenLocated SrcSpan e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e)))
-> FastStringEnv (GenLocated SrcSpan e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
forall a b. (a -> b) -> a -> b
$ FastStringEnv (GenLocated SrcSpan e)
-> FastString
-> GenLocated SrcSpan e
-> FastStringEnv (GenLocated SrcSpan e)
forall a. FastStringEnv a -> FastString -> a -> FastStringEnv a
extendFsEnv FastStringEnv (GenLocated SrcSpan e)
env FastString
fs GenLocated SrcSpan e
fix_item
Just (L loc' :: SrcSpan
loc' _) -> do
{ SrcSpan -> TcRn () -> TcRn ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
SrcSpan -> MsgDoc -> TcRn ()
addErrAt SrcSpan
name_loc (SrcSpan -> RdrName -> MsgDoc
dupFixityDecl SrcSpan
loc' RdrName
name)
; FastStringEnv (GenLocated SrcSpan e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
forall (m :: * -> *) a. Monad m => a -> m a
return FastStringEnv (GenLocated SrcSpan e)
env}
}
dupFixityDecl :: SrcSpan -> RdrName -> SDoc
dupFixityDecl :: SrcSpan -> RdrName -> MsgDoc
dupFixityDecl loc :: SrcSpan
loc rdr_name :: RdrName
rdr_name
= [MsgDoc] -> MsgDoc
vcat [String -> MsgDoc
text "Multiple fixity declarations for" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr RdrName
rdr_name),
String -> MsgDoc
text "also at " MsgDoc -> MsgDoc -> MsgDoc
<+> SrcSpan -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr SrcSpan
loc]
rnPatSynBind :: (Name -> [Name])
-> PatSynBind GhcRn GhcPs
-> RnM (PatSynBind GhcRn GhcRn, [Name], Uses)
rnPatSynBind :: (Name -> [Name])
-> PatSynBind GhcRn GhcPs
-> RnM (PatSynBind GhcRn GhcRn, [Name], NameSet)
rnPatSynBind sig_fn :: Name -> [Name]
sig_fn bind :: PatSynBind GhcRn GhcPs
bind@(PSB { psb_id :: forall idL idR. PatSynBind idL idR -> Located (IdP idL)
psb_id = L l :: SrcSpan
l name :: IdP GhcRn
name
, psb_args :: forall idL idR.
PatSynBind idL idR -> HsPatSynDetails (Located (IdP idR))
psb_args = HsPatSynDetails (Located (IdP GhcPs))
details
, psb_def :: forall idL idR. PatSynBind idL idR -> LPat idR
psb_def = LPat GhcPs
pat
, psb_dir :: forall idL idR. PatSynBind idL idR -> HsPatSynDir idR
psb_dir = HsPatSynDir GhcPs
dir })
= do { Bool
pattern_synonym_ok <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PatternSynonyms
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
pattern_synonym_ok (MsgDoc -> TcRn ()
addErr MsgDoc
patternSynonymErr)
; let scoped_tvs :: [Name]
scoped_tvs = Name -> [Name]
sig_fn Name
IdP GhcRn
name
; ((pat' :: LPat GhcRn
pat', details' :: HsConDetails (Located Name) [RecordPatSynField (Located Name)]
details'), fvs1 :: NameSet
fvs1) <- [Name]
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV [Name]
scoped_tvs (RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet))
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall a b. (a -> b) -> a -> b
$
HsMatchContext Name
-> LPat GhcPs
-> (LPat GhcRn
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet))
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall a.
HsMatchContext Name
-> LPat GhcPs
-> (LPat GhcRn -> RnM (a, NameSet))
-> RnM (a, NameSet)
rnPat HsMatchContext Name
forall id. HsMatchContext id
PatSyn LPat GhcPs
pat ((LPat GhcRn
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet))
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet))
-> (LPat GhcRn
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet))
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall a b. (a -> b) -> a -> b
$ \pat' :: LPat GhcRn
pat' ->
case HsPatSynDetails (Located (IdP GhcPs))
details of
PrefixCon vars :: [Located (IdP GhcPs)]
vars ->
do { [Located RdrName] -> TcRn ()
checkDupRdrNames [Located RdrName]
[Located (IdP GhcPs)]
vars
; [Located Name]
names <- (Located RdrName -> RnM (Located Name))
-> [Located RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Located RdrName -> RnM (Located Name)
lookupPatSynBndr [Located RdrName]
[Located (IdP GhcPs)]
vars
; ((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return ( (LPat GhcRn
pat', [Located Name]
-> HsConDetails (Located Name) [RecordPatSynField (Located Name)]
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon [Located Name]
names)
, [Name] -> NameSet
mkFVs ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located Name]
names)) }
InfixCon var1 :: Located (IdP GhcPs)
var1 var2 :: Located (IdP GhcPs)
var2 ->
do { [Located RdrName] -> TcRn ()
checkDupRdrNames [Located RdrName
Located (IdP GhcPs)
var1, Located RdrName
Located (IdP GhcPs)
var2]
; Located Name
name1 <- Located RdrName -> RnM (Located Name)
lookupPatSynBndr Located RdrName
Located (IdP GhcPs)
var1
; Located Name
name2 <- Located RdrName -> RnM (Located Name)
lookupPatSynBndr Located RdrName
Located (IdP GhcPs)
var2
; ((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return ( (LPat GhcRn
pat', Located Name
-> Located Name
-> HsConDetails (Located Name) [RecordPatSynField (Located Name)]
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon Located Name
name1 Located Name
name2)
, [Name] -> NameSet
mkFVs ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located Name
name1, Located Name
name2])) }
RecCon vars :: [RecordPatSynField (Located (IdP GhcPs))]
vars ->
do { [Located RdrName] -> TcRn ()
checkDupRdrNames ((RecordPatSynField (Located RdrName) -> Located RdrName)
-> [RecordPatSynField (Located RdrName)] -> [Located RdrName]
forall a b. (a -> b) -> [a] -> [b]
map RecordPatSynField (Located RdrName) -> Located RdrName
forall a. RecordPatSynField a -> a
recordPatSynSelectorId [RecordPatSynField (Located RdrName)]
[RecordPatSynField (Located (IdP GhcPs))]
vars)
; let rnRecordPatSynField :: RecordPatSynField (Located RdrName)
-> IOEnv (Env TcGblEnv TcLclEnv) (RecordPatSynField (Located Name))
rnRecordPatSynField
(RecordPatSynField { recordPatSynSelectorId :: forall a. RecordPatSynField a -> a
recordPatSynSelectorId = Located RdrName
visible
, recordPatSynPatVar :: forall a. RecordPatSynField a -> a
recordPatSynPatVar = Located RdrName
hidden })
= do { Located Name
visible' <- Located RdrName -> RnM (Located Name)
lookupLocatedTopBndrRn Located RdrName
visible
; Located Name
hidden' <- Located RdrName -> RnM (Located Name)
lookupPatSynBndr Located RdrName
hidden
; RecordPatSynField (Located Name)
-> IOEnv (Env TcGblEnv TcLclEnv) (RecordPatSynField (Located Name))
forall (m :: * -> *) a. Monad m => a -> m a
return (RecordPatSynField (Located Name)
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (Located Name)))
-> RecordPatSynField (Located Name)
-> IOEnv (Env TcGblEnv TcLclEnv) (RecordPatSynField (Located Name))
forall a b. (a -> b) -> a -> b
$ RecordPatSynField :: forall a. a -> a -> RecordPatSynField a
RecordPatSynField { recordPatSynSelectorId :: Located Name
recordPatSynSelectorId = Located Name
visible'
, recordPatSynPatVar :: Located Name
recordPatSynPatVar = Located Name
hidden' } }
; [RecordPatSynField (Located Name)]
names <- (RecordPatSynField (Located RdrName)
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (Located Name)))
-> [RecordPatSynField (Located RdrName)]
-> IOEnv (Env TcGblEnv TcLclEnv) [RecordPatSynField (Located Name)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RecordPatSynField (Located RdrName)
-> IOEnv (Env TcGblEnv TcLclEnv) (RecordPatSynField (Located Name))
rnRecordPatSynField [RecordPatSynField (Located RdrName)]
[RecordPatSynField (Located (IdP GhcPs))]
vars
; ((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
-> RnM
((LPat GhcRn,
HsConDetails (Located Name) [RecordPatSynField (Located Name)]),
NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return ( (LPat GhcRn
pat', [RecordPatSynField (Located Name)]
-> HsConDetails (Located Name) [RecordPatSynField (Located Name)]
forall arg rec. rec -> HsConDetails arg rec
RecCon [RecordPatSynField (Located Name)]
names)
, [Name] -> NameSet
mkFVs ((RecordPatSynField (Located Name) -> Name)
-> [RecordPatSynField (Located Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located Name -> Name)
-> (RecordPatSynField (Located Name) -> Located Name)
-> RecordPatSynField (Located Name)
-> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField (Located Name) -> Located Name
forall a. RecordPatSynField a -> a
recordPatSynPatVar) [RecordPatSynField (Located Name)]
names)) }
; (dir' :: HsPatSynDir GhcRn
dir', fvs2 :: NameSet
fvs2) <- case HsPatSynDir GhcPs
dir of
Unidirectional -> (HsPatSynDir GhcRn, NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsPatSynDir GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsPatSynDir GhcRn
forall id. HsPatSynDir id
Unidirectional, NameSet
emptyFVs)
ImplicitBidirectional -> (HsPatSynDir GhcRn, NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsPatSynDir GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsPatSynDir GhcRn
forall id. HsPatSynDir id
ImplicitBidirectional, NameSet
emptyFVs)
ExplicitBidirectional mg :: MatchGroup GhcPs (LHsExpr GhcPs)
mg ->
do { (mg' :: MatchGroup GhcRn (LHsExpr GhcRn)
mg', fvs :: NameSet
fvs) <- [Name]
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV [Name]
scoped_tvs (RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet))
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
forall a b. (a -> b) -> a -> b
$
HsMatchContext Name
-> (LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet))
-> MatchGroup GhcPs (LHsExpr GhcPs)
-> RnM (MatchGroup GhcRn (LHsExpr GhcRn), NameSet)
forall (body :: * -> *).
Outputable (body GhcPs) =>
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> MatchGroup GhcPs (Located (body GhcPs))
-> RnM (MatchGroup GhcRn (Located (body GhcRn)), NameSet)
rnMatchGroup (Located Name -> HsMatchContext Name
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs (SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
l Name
IdP GhcRn
name))
LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet)
rnLExpr MatchGroup GhcPs (LHsExpr GhcPs)
mg
; (HsPatSynDir GhcRn, NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsPatSynDir GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (MatchGroup GhcRn (LHsExpr GhcRn) -> HsPatSynDir GhcRn
forall id. MatchGroup id (LHsExpr id) -> HsPatSynDir id
ExplicitBidirectional MatchGroup GhcRn (LHsExpr GhcRn)
mg', NameSet
fvs) }
; Module
mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; let fvs :: NameSet
fvs = NameSet
fvs1 NameSet -> NameSet -> NameSet
`plusFV` NameSet
fvs2
fvs' :: NameSet
fvs' = (Name -> Bool) -> NameSet -> NameSet
filterNameSet (Module -> Name -> Bool
nameIsLocalOrFrom Module
mod) NameSet
fvs
bind' :: PatSynBind GhcRn GhcRn
bind' = PatSynBind GhcRn GhcPs
bind{ psb_args :: HsPatSynDetails (Located (IdP GhcRn))
psb_args = HsConDetails (Located Name) [RecordPatSynField (Located Name)]
HsPatSynDetails (Located (IdP GhcRn))
details'
, psb_def :: LPat GhcRn
psb_def = LPat GhcRn
pat'
, psb_dir :: HsPatSynDir GhcRn
psb_dir = HsPatSynDir GhcRn
dir'
, psb_ext :: XPSB GhcRn GhcRn
psb_ext = NameSet
XPSB GhcRn GhcRn
fvs' }
selector_names :: [Name]
selector_names = case HsConDetails (Located Name) [RecordPatSynField (Located Name)]
details' of
RecCon names :: [RecordPatSynField (Located Name)]
names ->
(RecordPatSynField (Located Name) -> Name)
-> [RecordPatSynField (Located Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located Name -> Name)
-> (RecordPatSynField (Located Name) -> Located Name)
-> RecordPatSynField (Located Name)
-> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField (Located Name) -> Located Name
forall a. RecordPatSynField a -> a
recordPatSynSelectorId) [RecordPatSynField (Located Name)]
names
_ -> []
; NameSet
fvs' NameSet
-> RnM (PatSynBind GhcRn GhcRn, [Name], NameSet)
-> RnM (PatSynBind GhcRn GhcRn, [Name], NameSet)
forall a b. a -> b -> b
`seq`
(PatSynBind GhcRn GhcRn, [Name], NameSet)
-> RnM (PatSynBind GhcRn GhcRn, [Name], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (PatSynBind GhcRn GhcRn
bind', Name
IdP GhcRn
name Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: [Name]
selector_names , NameSet
fvs1)
}
where
lookupPatSynBndr :: Located RdrName -> RnM (Located Name)
lookupPatSynBndr = (SrcSpanLess (Located RdrName) -> TcM (SrcSpanLess (Located Name)))
-> Located RdrName -> RnM (Located Name)
forall a b.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b)) -> a -> TcM b
wrapLocM SrcSpanLess (Located RdrName) -> TcM (SrcSpanLess (Located Name))
RdrName -> RnM Name
lookupLocalOccRn
patternSynonymErr :: SDoc
patternSynonymErr :: MsgDoc
patternSynonymErr
= MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "Illegal pattern synonym declaration")
2 (String -> MsgDoc
text "Use -XPatternSynonyms to enable this extension")
rnPatSynBind _ (XPatSynBind _) = String -> RnM (PatSynBind GhcRn GhcRn, [Name], NameSet)
forall a. String -> a
panic "rnPatSynBind"
rnMethodBinds :: Bool
-> Name
-> [Name]
-> LHsBinds GhcPs
-> [LSig GhcPs]
-> RnM (LHsBinds GhcRn, [LSig GhcRn], FreeVars)
rnMethodBinds :: Bool
-> Name
-> [Name]
-> LHsBindsLR GhcPs GhcPs
-> [LSig GhcPs]
-> RnM (LHsBinds GhcRn, [LSig GhcRn], NameSet)
rnMethodBinds is_cls_decl :: Bool
is_cls_decl cls :: Name
cls ktv_names :: [Name]
ktv_names binds :: LHsBindsLR GhcPs GhcPs
binds sigs :: [LSig GhcPs]
sigs
= do { [Located RdrName] -> TcRn ()
checkDupRdrNames (LHsBindsLR GhcPs GhcPs -> [Located (IdP GhcPs)]
forall idL idR. LHsBindsLR idL idR -> [Located (IdP idL)]
collectMethodBinders LHsBindsLR GhcPs GhcPs
binds)
; LHsBindsLR GhcRn GhcPs
binds' <- (LHsBindLR GhcPs GhcPs
-> LHsBindsLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs))
-> LHsBindsLR GhcRn GhcPs
-> LHsBindsLR GhcPs GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m b) -> b -> Bag a -> m b
foldrBagM (Bool
-> Name
-> LHsBindLR GhcPs GhcPs
-> LHsBindsLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
rnMethodBindLHS Bool
is_cls_decl Name
cls) LHsBindsLR GhcRn GhcPs
forall a. Bag a
emptyBag LHsBindsLR GhcPs GhcPs
binds
; let (spec_inst_prags :: [LSig GhcPs]
spec_inst_prags, other_sigs :: [LSig GhcPs]
other_sigs) = (LSig GhcPs -> Bool)
-> [LSig GhcPs] -> ([LSig GhcPs], [LSig GhcPs])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition LSig GhcPs -> Bool
forall name. LSig name -> Bool
isSpecInstLSig [LSig GhcPs]
sigs
bound_nms :: NameSet
bound_nms = [Name] -> NameSet
mkNameSet (LHsBindsLR GhcRn GhcPs -> [IdP GhcRn]
forall (p :: Pass) idR.
LHsBindsLR (GhcPass p) idR -> [IdP (GhcPass p)]
collectHsBindsBinders LHsBindsLR GhcRn GhcPs
binds')
sig_ctxt :: HsSigCtxt
sig_ctxt | Bool
is_cls_decl = Name -> HsSigCtxt
ClsDeclCtxt Name
cls
| Bool
otherwise = NameSet -> HsSigCtxt
InstDeclCtxt NameSet
bound_nms
; (spec_inst_prags' :: [LSig GhcRn]
spec_inst_prags', sip_fvs :: NameSet
sip_fvs) <- HsSigCtxt -> [LSig GhcPs] -> RnM ([LSig GhcRn], NameSet)
renameSigs HsSigCtxt
sig_ctxt [LSig GhcPs]
spec_inst_prags
; (other_sigs' :: [LSig GhcRn]
other_sigs', sig_fvs :: NameSet
sig_fvs) <- [Name]
-> RnM ([LSig GhcRn], NameSet) -> RnM ([LSig GhcRn], NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
extendTyVarEnvFVRn [Name]
ktv_names (RnM ([LSig GhcRn], NameSet) -> RnM ([LSig GhcRn], NameSet))
-> RnM ([LSig GhcRn], NameSet) -> RnM ([LSig GhcRn], NameSet)
forall a b. (a -> b) -> a -> b
$
HsSigCtxt -> [LSig GhcPs] -> RnM ([LSig GhcRn], NameSet)
renameSigs HsSigCtxt
sig_ctxt [LSig GhcPs]
other_sigs
; Bool
scoped_tvs <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.ScopedTypeVariables
; (binds'' :: LHsBinds GhcRn
binds'', bind_fvs :: NameSet
bind_fvs) <- Bool
-> RnM (LHsBinds GhcRn, NameSet) -> RnM (LHsBinds GhcRn, NameSet)
maybe_extend_tyvar_env Bool
scoped_tvs (RnM (LHsBinds GhcRn, NameSet) -> RnM (LHsBinds GhcRn, NameSet))
-> RnM (LHsBinds GhcRn, NameSet) -> RnM (LHsBinds GhcRn, NameSet)
forall a b. (a -> b) -> a -> b
$
do { Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus <- (LHsBindLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet))
-> LHsBindsLR GhcRn GhcPs
-> IOEnv
(Env TcGblEnv TcLclEnv) (Bag (LHsBind GhcRn, [Name], NameSet))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM ((Name -> [Name])
-> LHsBindLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcRn, [Name], NameSet)
rnLBind ([LSig GhcRn] -> Name -> [Name]
mkScopedTvFn [LSig GhcRn]
other_sigs')) LHsBindsLR GhcRn GhcPs
binds'
; let bind_fvs :: NameSet
bind_fvs = ((LHsBind GhcRn, [Name], NameSet) -> NameSet -> NameSet)
-> NameSet -> Bag (LHsBind GhcRn, [Name], NameSet) -> NameSet
forall a r. (a -> r -> r) -> r -> Bag a -> r
foldrBag (\(_,_,fv1 :: NameSet
fv1) fv2 :: NameSet
fv2 -> NameSet
fv1 NameSet -> NameSet -> NameSet
`plusFV` NameSet
fv2)
NameSet
emptyFVs Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus
; (LHsBinds GhcRn, NameSet) -> RnM (LHsBinds GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (((LHsBind GhcRn, [Name], NameSet) -> LHsBind GhcRn)
-> Bag (LHsBind GhcRn, [Name], NameSet) -> LHsBinds GhcRn
forall a b. (a -> b) -> Bag a -> Bag b
mapBag (LHsBind GhcRn, [Name], NameSet) -> LHsBind GhcRn
forall a b c. (a, b, c) -> a
fstOf3 Bag (LHsBind GhcRn, [Name], NameSet)
binds_w_dus, NameSet
bind_fvs) }
; (LHsBinds GhcRn, [LSig GhcRn], NameSet)
-> RnM (LHsBinds GhcRn, [LSig GhcRn], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return ( LHsBinds GhcRn
binds'', [LSig GhcRn]
spec_inst_prags' [LSig GhcRn] -> [LSig GhcRn] -> [LSig GhcRn]
forall a. [a] -> [a] -> [a]
++ [LSig GhcRn]
other_sigs'
, NameSet
sig_fvs NameSet -> NameSet -> NameSet
`plusFV` NameSet
sip_fvs NameSet -> NameSet -> NameSet
`plusFV` NameSet
bind_fvs) }
where
maybe_extend_tyvar_env :: Bool
-> RnM (LHsBinds GhcRn, NameSet) -> RnM (LHsBinds GhcRn, NameSet)
maybe_extend_tyvar_env scoped_tvs :: Bool
scoped_tvs thing_inside :: RnM (LHsBinds GhcRn, NameSet)
thing_inside
| Bool
scoped_tvs = [Name]
-> RnM (LHsBinds GhcRn, NameSet) -> RnM (LHsBinds GhcRn, NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
extendTyVarEnvFVRn [Name]
ktv_names RnM (LHsBinds GhcRn, NameSet)
thing_inside
| Bool
otherwise = RnM (LHsBinds GhcRn, NameSet)
thing_inside
rnMethodBindLHS :: Bool -> Name
-> LHsBindLR GhcPs GhcPs
-> LHsBindsLR GhcRn GhcPs
-> RnM (LHsBindsLR GhcRn GhcPs)
rnMethodBindLHS :: Bool
-> Name
-> LHsBindLR GhcPs GhcPs
-> LHsBindsLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
rnMethodBindLHS _ cls :: Name
cls (L loc :: SrcSpan
loc bind :: HsBind GhcPs
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = Located (IdP GhcPs)
name })) rest :: LHsBindsLR GhcRn GhcPs
rest
= SrcSpan
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs))
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
forall a b. (a -> b) -> a -> b
$ do
do { Located Name
sel_name <- (SrcSpanLess (Located RdrName) -> TcM (SrcSpanLess (Located Name)))
-> Located RdrName -> RnM (Located Name)
forall a b.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b)) -> a -> TcM b
wrapLocM (Name -> MsgDoc -> RdrName -> RnM Name
lookupInstDeclBndr Name
cls (String -> MsgDoc
text "method")) Located RdrName
Located (IdP GhcPs)
name
; let bind' :: HsBindLR GhcRn GhcPs
bind' = HsBind GhcPs
bind { fun_id :: Located (IdP GhcRn)
fun_id = Located Name
Located (IdP GhcRn)
sel_name, fun_ext :: XFunBind GhcRn GhcPs
fun_ext = XFunBind GhcRn GhcPs
NoExt
noExt }
; LHsBindsLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> HsBindLR GhcRn GhcPs -> LHsBindLR GhcRn GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc HsBindLR GhcRn GhcPs
bind' LHsBindLR GhcRn GhcPs
-> LHsBindsLR GhcRn GhcPs -> LHsBindsLR GhcRn GhcPs
forall a. a -> Bag a -> Bag a
`consBag` LHsBindsLR GhcRn GhcPs
rest ) }
rnMethodBindLHS is_cls_decl :: Bool
is_cls_decl _ (L loc :: SrcSpan
loc bind :: HsBind GhcPs
bind) rest :: LHsBindsLR GhcRn GhcPs
rest
= do { SrcSpan -> MsgDoc -> TcRn ()
addErrAt SrcSpan
loc (MsgDoc -> TcRn ()) -> MsgDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ MsgDoc
what MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text "not allowed in" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
decl_sort
, Int -> MsgDoc -> MsgDoc
nest 2 (HsBind GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBind GhcPs
bind) ]
; LHsBindsLR GhcRn GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBindsLR GhcRn GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return LHsBindsLR GhcRn GhcPs
rest }
where
decl_sort :: MsgDoc
decl_sort | Bool
is_cls_decl = String -> MsgDoc
text "class declaration:"
| Bool
otherwise = String -> MsgDoc
text "instance declaration:"
what :: MsgDoc
what = case HsBind GhcPs
bind of
PatBind {} -> String -> MsgDoc
text "Pattern bindings (except simple variables)"
PatSynBind {} -> String -> MsgDoc
text "Pattern synonyms"
_ -> String -> MsgDoc -> MsgDoc
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic "rnMethodBind" (HsBind GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBind GhcPs
bind)
renameSigs :: HsSigCtxt
-> [LSig GhcPs]
-> RnM ([LSig GhcRn], FreeVars)
renameSigs :: HsSigCtxt -> [LSig GhcPs] -> RnM ([LSig GhcRn], NameSet)
renameSigs ctxt :: HsSigCtxt
ctxt sigs :: [LSig GhcPs]
sigs
= do { (NonEmpty (Located RdrName, Sig GhcPs) -> TcRn ())
-> [NonEmpty (Located RdrName, Sig GhcPs)] -> TcRn ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ NonEmpty (Located RdrName, Sig GhcPs) -> TcRn ()
dupSigDeclErr ([LSig GhcPs] -> [NonEmpty (Located RdrName, Sig GhcPs)]
findDupSigs [LSig GhcPs]
sigs)
; [LSig GhcPs] -> TcRn ()
checkDupMinimalSigs [LSig GhcPs]
sigs
; (sigs' :: [LSig GhcRn]
sigs', sig_fvs :: NameSet
sig_fvs) <- (LSig GhcPs -> RnM (LSig GhcRn, NameSet))
-> [LSig GhcPs] -> RnM ([LSig GhcRn], NameSet)
forall a b. (a -> RnM (b, NameSet)) -> [a] -> RnM ([b], NameSet)
mapFvRn ((SrcSpanLess (LSig GhcPs)
-> TcM (SrcSpanLess (LSig GhcRn), NameSet))
-> LSig GhcPs -> RnM (LSig GhcRn, NameSet)
forall a b c.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b, c)) -> a -> TcM (b, c)
wrapLocFstM (HsSigCtxt -> Sig GhcPs -> RnM (Sig GhcRn, NameSet)
renameSig HsSigCtxt
ctxt)) [LSig GhcPs]
sigs
; let (good_sigs :: [LSig GhcRn]
good_sigs, bad_sigs :: [LSig GhcRn]
bad_sigs) = (LSig GhcRn -> Bool)
-> [LSig GhcRn] -> ([LSig GhcRn], [LSig GhcRn])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (HsSigCtxt -> LSig GhcRn -> Bool
forall a. HsSigCtxt -> LSig a -> Bool
okHsSig HsSigCtxt
ctxt) [LSig GhcRn]
sigs'
; (LSig GhcRn -> TcRn ()) -> [LSig GhcRn] -> TcRn ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LSig GhcRn -> TcRn ()
misplacedSigErr [LSig GhcRn]
bad_sigs
; ([LSig GhcRn], NameSet) -> RnM ([LSig GhcRn], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LSig GhcRn]
good_sigs, NameSet
sig_fvs) }
renameSig :: HsSigCtxt -> Sig GhcPs -> RnM (Sig GhcRn, FreeVars)
renameSig :: HsSigCtxt -> Sig GhcPs -> RnM (Sig GhcRn, NameSet)
renameSig _ (IdSig _ x :: Id
x)
= (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XIdSig GhcRn -> Id -> Sig GhcRn
forall pass. XIdSig pass -> Id -> Sig pass
IdSig XIdSig GhcRn
NoExt
noExt Id
x, NameSet
emptyFVs)
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(TypeSig _ vs :: [Located (IdP GhcPs)]
vs ty :: LHsSigWcType GhcPs
ty)
= do { [Located Name]
new_vs <- (Located RdrName -> RnM (Located Name))
-> [Located RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig) [Located RdrName]
[Located (IdP GhcPs)]
vs
; let doc :: HsDocContext
doc = MsgDoc -> HsDocContext
TypeSigCtx ([Located RdrName] -> MsgDoc
ppr_sig_bndrs [Located RdrName]
[Located (IdP GhcPs)]
vs)
; (new_ty :: LHsSigWcType GhcRn
new_ty, fvs :: NameSet
fvs) <- HsSigWcTypeScoping
-> HsDocContext
-> LHsSigWcType GhcPs
-> RnM (LHsSigWcType GhcRn, NameSet)
rnHsSigWcType HsSigWcTypeScoping
BindUnlessForall HsDocContext
doc LHsSigWcType GhcPs
ty
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XTypeSig GhcRn
-> [Located (IdP GhcRn)] -> LHsSigWcType GhcRn -> Sig GhcRn
forall pass.
XTypeSig pass
-> [Located (IdP pass)] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig GhcRn
NoExt
noExt [Located Name]
[Located (IdP GhcRn)]
new_vs LHsSigWcType GhcRn
new_ty, NameSet
fvs) }
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(ClassOpSig _ is_deflt :: Bool
is_deflt vs :: [Located (IdP GhcPs)]
vs ty :: LHsSigType GhcPs
ty)
= do { Bool
defaultSigs_on <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.DefaultSignatures
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
is_deflt Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
defaultSigs_on) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
MsgDoc -> TcRn ()
addErr (Sig GhcPs -> MsgDoc
defaultSigErr Sig GhcPs
sig)
; [Located Name]
new_v <- (Located RdrName -> RnM (Located Name))
-> [Located RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig) [Located RdrName]
[Located (IdP GhcPs)]
vs
; (new_ty :: LHsSigType GhcRn
new_ty, fvs :: NameSet
fvs) <- HsDocContext -> LHsSigType GhcPs -> RnM (LHsSigType GhcRn, NameSet)
rnHsSigType HsDocContext
ty_ctxt LHsSigType GhcPs
ty
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XClassOpSig GhcRn
-> Bool -> [Located (IdP GhcRn)] -> LHsSigType GhcRn -> Sig GhcRn
forall pass.
XClassOpSig pass
-> Bool -> [Located (IdP pass)] -> LHsSigType pass -> Sig pass
ClassOpSig XClassOpSig GhcRn
NoExt
noExt Bool
is_deflt [Located Name]
[Located (IdP GhcRn)]
new_v LHsSigType GhcRn
new_ty, NameSet
fvs) }
where
(v1 :: Located RdrName
v1:_) = [Located RdrName]
[Located (IdP GhcPs)]
vs
ty_ctxt :: HsDocContext
ty_ctxt = MsgDoc -> HsDocContext
GenericCtx (String -> MsgDoc
text "a class method signature for"
MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Located RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Located RdrName
v1))
renameSig _ (SpecInstSig _ src :: SourceText
src ty :: LHsSigType GhcPs
ty)
= do { (new_ty :: LHsSigType GhcRn
new_ty, fvs :: NameSet
fvs) <- HsDocContext -> LHsSigType GhcPs -> RnM (LHsSigType GhcRn, NameSet)
rnHsSigType HsDocContext
SpecInstSigCtx LHsSigType GhcPs
ty
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSpecInstSig GhcRn -> SourceText -> LHsSigType GhcRn -> Sig GhcRn
forall pass.
XSpecInstSig pass -> SourceText -> LHsSigType pass -> Sig pass
SpecInstSig XSpecInstSig GhcRn
NoExt
noExt SourceText
src LHsSigType GhcRn
new_ty,NameSet
fvs) }
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(SpecSig _ v :: Located (IdP GhcPs)
v tys :: [LHsSigType GhcPs]
tys inl :: InlinePragma
inl)
= do { Located Name
new_v <- case HsSigCtxt
ctxt of
TopSigCtxt {} -> Located RdrName -> RnM (Located Name)
lookupLocatedOccRn Located RdrName
Located (IdP GhcPs)
v
_ -> HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig Located RdrName
Located (IdP GhcPs)
v
; (new_ty :: [LHsSigType GhcRn]
new_ty, fvs :: NameSet
fvs) <- (([LHsSigType GhcRn], NameSet)
-> LHsSigType GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) ([LHsSigType GhcRn], NameSet))
-> ([LHsSigType GhcRn], NameSet)
-> [LHsSigType GhcPs]
-> IOEnv (Env TcGblEnv TcLclEnv) ([LHsSigType GhcRn], NameSet)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM ([LHsSigType GhcRn], NameSet)
-> LHsSigType GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) ([LHsSigType GhcRn], NameSet)
do_one ([],NameSet
emptyFVs) [LHsSigType GhcPs]
tys
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSpecSig GhcRn
-> Located (IdP GhcRn)
-> [LHsSigType GhcRn]
-> InlinePragma
-> Sig GhcRn
forall pass.
XSpecSig pass
-> Located (IdP pass)
-> [LHsSigType pass]
-> InlinePragma
-> Sig pass
SpecSig XSpecSig GhcRn
NoExt
noExt Located Name
Located (IdP GhcRn)
new_v [LHsSigType GhcRn]
new_ty InlinePragma
inl, NameSet
fvs) }
where
ty_ctxt :: HsDocContext
ty_ctxt = MsgDoc -> HsDocContext
GenericCtx (String -> MsgDoc
text "a SPECIALISE signature for"
MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Located RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Located RdrName
Located (IdP GhcPs)
v))
do_one :: ([LHsSigType GhcRn], NameSet)
-> LHsSigType GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) ([LHsSigType GhcRn], NameSet)
do_one (tys :: [LHsSigType GhcRn]
tys,fvs :: NameSet
fvs) ty :: LHsSigType GhcPs
ty
= do { (new_ty :: LHsSigType GhcRn
new_ty, fvs_ty :: NameSet
fvs_ty) <- HsDocContext -> LHsSigType GhcPs -> RnM (LHsSigType GhcRn, NameSet)
rnHsSigType HsDocContext
ty_ctxt LHsSigType GhcPs
ty
; ([LHsSigType GhcRn], NameSet)
-> IOEnv (Env TcGblEnv TcLclEnv) ([LHsSigType GhcRn], NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return ( LHsSigType GhcRn
new_tyLHsSigType GhcRn -> [LHsSigType GhcRn] -> [LHsSigType GhcRn]
forall a. a -> [a] -> [a]
:[LHsSigType GhcRn]
tys, NameSet
fvs_ty NameSet -> NameSet -> NameSet
`plusFV` NameSet
fvs) }
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(InlineSig _ v :: Located (IdP GhcPs)
v s :: InlinePragma
s)
= do { Located Name
new_v <- HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig Located RdrName
Located (IdP GhcPs)
v
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XInlineSig GhcRn
-> Located (IdP GhcRn) -> InlinePragma -> Sig GhcRn
forall pass.
XInlineSig pass -> Located (IdP pass) -> InlinePragma -> Sig pass
InlineSig XInlineSig GhcRn
NoExt
noExt Located Name
Located (IdP GhcRn)
new_v InlinePragma
s, NameSet
emptyFVs) }
renameSig ctxt :: HsSigCtxt
ctxt (FixSig _ fsig :: FixitySig GhcPs
fsig)
= do { FixitySig GhcRn
new_fsig <- HsSigCtxt -> FixitySig GhcPs -> RnM (FixitySig GhcRn)
rnSrcFixityDecl HsSigCtxt
ctxt FixitySig GhcPs
fsig
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XFixSig GhcRn -> FixitySig GhcRn -> Sig GhcRn
forall pass. XFixSig pass -> FixitySig pass -> Sig pass
FixSig XFixSig GhcRn
NoExt
noExt FixitySig GhcRn
new_fsig, NameSet
emptyFVs) }
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(MinimalSig _ s :: SourceText
s (L l :: SrcSpan
l bf :: BooleanFormula (Located (IdP GhcPs))
bf))
= do BooleanFormula (Located Name)
new_bf <- (Located RdrName -> RnM (Located Name))
-> BooleanFormula (Located RdrName)
-> IOEnv (Env TcGblEnv TcLclEnv) (BooleanFormula (Located Name))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig) BooleanFormula (Located RdrName)
BooleanFormula (Located (IdP GhcPs))
bf
(Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XMinimalSig GhcRn
-> SourceText -> LBooleanFormula (Located (IdP GhcRn)) -> Sig GhcRn
forall pass.
XMinimalSig pass
-> SourceText -> LBooleanFormula (Located (IdP pass)) -> Sig pass
MinimalSig XMinimalSig GhcRn
NoExt
noExt SourceText
s (SrcSpan
-> BooleanFormula (Located Name)
-> GenLocated SrcSpan (BooleanFormula (Located Name))
forall l e. l -> e -> GenLocated l e
L SrcSpan
l BooleanFormula (Located Name)
new_bf), NameSet
emptyFVs)
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(PatSynSig _ vs :: [Located (IdP GhcPs)]
vs ty :: LHsSigType GhcPs
ty)
= do { [Located Name]
new_vs <- (Located RdrName -> RnM (Located Name))
-> [Located RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig) [Located RdrName]
[Located (IdP GhcPs)]
vs
; (ty' :: LHsSigType GhcRn
ty', fvs :: NameSet
fvs) <- HsDocContext -> LHsSigType GhcPs -> RnM (LHsSigType GhcRn, NameSet)
rnHsSigType HsDocContext
ty_ctxt LHsSigType GhcPs
ty
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynSig GhcRn
-> [Located (IdP GhcRn)] -> LHsSigType GhcRn -> Sig GhcRn
forall pass.
XPatSynSig pass
-> [Located (IdP pass)] -> LHsSigType pass -> Sig pass
PatSynSig XPatSynSig GhcRn
NoExt
noExt [Located Name]
[Located (IdP GhcRn)]
new_vs LHsSigType GhcRn
ty', NameSet
fvs) }
where
ty_ctxt :: HsDocContext
ty_ctxt = MsgDoc -> HsDocContext
GenericCtx (String -> MsgDoc
text "a pattern synonym signature for"
MsgDoc -> MsgDoc -> MsgDoc
<+> [Located RdrName] -> MsgDoc
ppr_sig_bndrs [Located RdrName]
[Located (IdP GhcPs)]
vs)
renameSig ctxt :: HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(SCCFunSig _ st :: SourceText
st v :: Located (IdP GhcPs)
v s :: Maybe (Located StringLiteral)
s)
= do { Located Name
new_v <- HsSigCtxt -> Sig GhcPs -> Located RdrName -> RnM (Located Name)
lookupSigOccRn HsSigCtxt
ctxt Sig GhcPs
sig Located RdrName
Located (IdP GhcPs)
v
; (Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSCCFunSig GhcRn
-> SourceText
-> Located (IdP GhcRn)
-> Maybe (Located StringLiteral)
-> Sig GhcRn
forall pass.
XSCCFunSig pass
-> SourceText
-> Located (IdP pass)
-> Maybe (Located StringLiteral)
-> Sig pass
SCCFunSig XSCCFunSig GhcRn
NoExt
noExt SourceText
st Located Name
Located (IdP GhcRn)
new_v Maybe (Located StringLiteral)
s, NameSet
emptyFVs) }
renameSig _ctxt :: HsSigCtxt
_ctxt sig :: Sig GhcPs
sig@(CompleteMatchSig _ s :: SourceText
s (L l :: SrcSpan
l bf :: [Located (IdP GhcPs)]
bf) mty :: Maybe (Located (IdP GhcPs))
mty)
= do [Located Name]
new_bf <- (Located RdrName -> RnM (Located Name))
-> [Located RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Located RdrName -> RnM (Located Name)
lookupLocatedOccRn [Located RdrName]
[Located (IdP GhcPs)]
bf
Maybe (Located Name)
new_mty <- (Located RdrName -> RnM (Located Name))
-> Maybe (Located RdrName)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Located Name))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Located RdrName -> RnM (Located Name)
lookupLocatedOccRn Maybe (Located RdrName)
Maybe (Located (IdP GhcPs))
mty
Module
this_mod <- (TcGblEnv -> Module)
-> IOEnv (Env TcGblEnv TcLclEnv) TcGblEnv
-> IOEnv (Env TcGblEnv TcLclEnv) Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TcGblEnv -> Module
tcg_mod IOEnv (Env TcGblEnv TcLclEnv) TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((Located Name -> Bool) -> [Located Name] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Module -> Name -> Bool
nameIsLocalOrFrom Module
this_mod (Name -> Bool) -> (Located Name -> Name) -> Located Name -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [Located Name]
new_bf) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ do
MsgDoc -> TcRn () -> TcRn ()
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (String -> MsgDoc
text "In" MsgDoc -> MsgDoc -> MsgDoc
<+> Sig GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Sig GhcPs
sig) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ MsgDoc -> TcRn ()
forall a. MsgDoc -> TcM a
failWithTc MsgDoc
orphanError
(Sig GhcRn, NameSet) -> RnM (Sig GhcRn, NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCompleteMatchSig GhcRn
-> SourceText
-> Located [Located (IdP GhcRn)]
-> Maybe (Located (IdP GhcRn))
-> Sig GhcRn
forall pass.
XCompleteMatchSig pass
-> SourceText
-> Located [Located (IdP pass)]
-> Maybe (Located (IdP pass))
-> Sig pass
CompleteMatchSig XCompleteMatchSig GhcRn
NoExt
noExt SourceText
s (SrcSpan -> [Located Name] -> GenLocated SrcSpan [Located Name]
forall l e. l -> e -> GenLocated l e
L SrcSpan
l [Located Name]
new_bf) Maybe (Located Name)
Maybe (Located (IdP GhcRn))
new_mty, NameSet
emptyFVs)
where
orphanError :: SDoc
orphanError :: MsgDoc
orphanError =
String -> MsgDoc
text "Orphan COMPLETE pragmas not supported" MsgDoc -> MsgDoc -> MsgDoc
$$
String -> MsgDoc
text "A COMPLETE pragma must mention at least one data constructor" MsgDoc -> MsgDoc -> MsgDoc
$$
String -> MsgDoc
text "or pattern synonym defined in the same module."
renameSig _ (XSig _) = String -> RnM (Sig GhcRn, NameSet)
forall a. String -> a
panic "renameSig"
ppr_sig_bndrs :: [Located RdrName] -> SDoc
ppr_sig_bndrs :: [Located RdrName] -> MsgDoc
ppr_sig_bndrs bs :: [Located RdrName]
bs = MsgDoc -> MsgDoc
quotes ((Located RdrName -> MsgDoc) -> [Located RdrName] -> MsgDoc
forall a. (a -> MsgDoc) -> [a] -> MsgDoc
pprWithCommas Located RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr [Located RdrName]
bs)
okHsSig :: HsSigCtxt -> LSig a -> Bool
okHsSig :: HsSigCtxt -> LSig a -> Bool
okHsSig ctxt :: HsSigCtxt
ctxt (L _ sig :: Sig a
sig)
= case (Sig a
sig, HsSigCtxt
ctxt) of
(ClassOpSig {}, ClsDeclCtxt {}) -> Bool
True
(ClassOpSig {}, InstDeclCtxt {}) -> Bool
True
(ClassOpSig {}, _) -> Bool
False
(TypeSig {}, ClsDeclCtxt {}) -> Bool
False
(TypeSig {}, InstDeclCtxt {}) -> Bool
False
(TypeSig {}, _) -> Bool
True
(PatSynSig {}, TopSigCtxt{}) -> Bool
True
(PatSynSig {}, _) -> Bool
False
(FixSig {}, InstDeclCtxt {}) -> Bool
False
(FixSig {}, _) -> Bool
True
(IdSig {}, TopSigCtxt {}) -> Bool
True
(IdSig {}, InstDeclCtxt {}) -> Bool
True
(IdSig {}, _) -> Bool
False
(InlineSig {}, HsBootCtxt {}) -> Bool
False
(InlineSig {}, _) -> Bool
True
(SpecSig {}, TopSigCtxt {}) -> Bool
True
(SpecSig {}, LocalBindCtxt {}) -> Bool
True
(SpecSig {}, InstDeclCtxt {}) -> Bool
True
(SpecSig {}, _) -> Bool
False
(SpecInstSig {}, InstDeclCtxt {}) -> Bool
True
(SpecInstSig {}, _) -> Bool
False
(MinimalSig {}, ClsDeclCtxt {}) -> Bool
True
(MinimalSig {}, _) -> Bool
False
(SCCFunSig {}, HsBootCtxt {}) -> Bool
False
(SCCFunSig {}, _) -> Bool
True
(CompleteMatchSig {}, TopSigCtxt {} ) -> Bool
True
(CompleteMatchSig {}, _) -> Bool
False
(XSig _, _) -> String -> Bool
forall a. String -> a
panic "okHsSig"
findDupSigs :: [LSig GhcPs] -> [NonEmpty (Located RdrName, Sig GhcPs)]
findDupSigs :: [LSig GhcPs] -> [NonEmpty (Located RdrName, Sig GhcPs)]
findDupSigs sigs :: [LSig GhcPs]
sigs
= ((Located RdrName, Sig GhcPs)
-> (Located RdrName, Sig GhcPs) -> Bool)
-> [(Located RdrName, Sig GhcPs)]
-> [NonEmpty (Located RdrName, Sig GhcPs)]
forall a. (a -> a -> Bool) -> [a] -> [NonEmpty a]
findDupsEq (Located RdrName, Sig GhcPs)
-> (Located RdrName, Sig GhcPs) -> Bool
forall a l pass l pass.
Eq a =>
(GenLocated l a, Sig pass) -> (GenLocated l a, Sig pass) -> Bool
matching_sig ((LSig GhcPs -> [(Located RdrName, Sig GhcPs)])
-> [LSig GhcPs] -> [(Located RdrName, Sig GhcPs)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Sig GhcPs -> [(Located RdrName, Sig GhcPs)]
forall pass. Sig pass -> [(Located (IdP pass), Sig pass)]
expand_sig (Sig GhcPs -> [(Located RdrName, Sig GhcPs)])
-> (LSig GhcPs -> Sig GhcPs)
-> LSig GhcPs
-> [(Located RdrName, Sig GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LSig GhcPs -> Sig GhcPs
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LSig GhcPs]
sigs)
where
expand_sig :: Sig pass -> [(Located (IdP pass), Sig pass)]
expand_sig sig :: Sig pass
sig@(FixSig _ (FixitySig _ ns :: [Located (IdP pass)]
ns _)) = [Located (IdP pass)]
-> [Sig pass] -> [(Located (IdP pass), Sig pass)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Located (IdP pass)]
ns (Sig pass -> [Sig pass]
forall a. a -> [a]
repeat Sig pass
sig)
expand_sig sig :: Sig pass
sig@(InlineSig _ n :: Located (IdP pass)
n _) = [(Located (IdP pass)
n,Sig pass
sig)]
expand_sig sig :: Sig pass
sig@(TypeSig _ ns :: [Located (IdP pass)]
ns _) = [(Located (IdP pass)
n,Sig pass
sig) | Located (IdP pass)
n <- [Located (IdP pass)]
ns]
expand_sig sig :: Sig pass
sig@(ClassOpSig _ _ ns :: [Located (IdP pass)]
ns _) = [(Located (IdP pass)
n,Sig pass
sig) | Located (IdP pass)
n <- [Located (IdP pass)]
ns]
expand_sig sig :: Sig pass
sig@(PatSynSig _ ns :: [Located (IdP pass)]
ns _ ) = [(Located (IdP pass)
n,Sig pass
sig) | Located (IdP pass)
n <- [Located (IdP pass)]
ns]
expand_sig sig :: Sig pass
sig@(SCCFunSig _ _ n :: Located (IdP pass)
n _) = [(Located (IdP pass)
n,Sig pass
sig)]
expand_sig _ = []
matching_sig :: (GenLocated l a, Sig pass) -> (GenLocated l a, Sig pass) -> Bool
matching_sig (L _ n1 :: a
n1,sig1 :: Sig pass
sig1) (L _ n2 :: a
n2,sig2 :: Sig pass
sig2) = a
n1 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
n2 Bool -> Bool -> Bool
&& Sig pass -> Sig pass -> Bool
forall pass pass. Sig pass -> Sig pass -> Bool
mtch Sig pass
sig1 Sig pass
sig2
mtch :: Sig pass -> Sig pass -> Bool
mtch (FixSig {}) (FixSig {}) = Bool
True
mtch (InlineSig {}) (InlineSig {}) = Bool
True
mtch (TypeSig {}) (TypeSig {}) = Bool
True
mtch (ClassOpSig _ d1 :: Bool
d1 _ _) (ClassOpSig _ d2 :: Bool
d2 _ _) = Bool
d1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
d2
mtch (PatSynSig _ _ _) (PatSynSig _ _ _) = Bool
True
mtch (SCCFunSig{}) (SCCFunSig{}) = Bool
True
mtch _ _ = Bool
False
checkDupMinimalSigs :: [LSig GhcPs] -> RnM ()
checkDupMinimalSigs :: [LSig GhcPs] -> TcRn ()
checkDupMinimalSigs sigs :: [LSig GhcPs]
sigs
= case (LSig GhcPs -> Bool) -> [LSig GhcPs] -> [LSig GhcPs]
forall a. (a -> Bool) -> [a] -> [a]
filter LSig GhcPs -> Bool
forall name. LSig name -> Bool
isMinimalLSig [LSig GhcPs]
sigs of
minSigs :: [LSig GhcPs]
minSigs@(_:_:_) -> [LSig GhcPs] -> TcRn ()
dupMinimalSigErr [LSig GhcPs]
minSigs
_ -> () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
rnMatchGroup :: Outputable (body GhcPs) => HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), FreeVars))
-> MatchGroup GhcPs (Located (body GhcPs))
-> RnM (MatchGroup GhcRn (Located (body GhcRn)), FreeVars)
rnMatchGroup :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> MatchGroup GhcPs (Located (body GhcPs))
-> RnM (MatchGroup GhcRn (Located (body GhcRn)), NameSet)
rnMatchGroup ctxt :: HsMatchContext Name
ctxt rnBody :: Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody (MG { mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = L _ ms :: [LMatch GhcPs (Located (body GhcPs))]
ms, mg_origin :: forall p body. MatchGroup p body -> Origin
mg_origin = Origin
origin })
= do { Bool
empty_case_ok <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.EmptyCase
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([LMatch GhcPs (Located (body GhcPs))] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LMatch GhcPs (Located (body GhcPs))]
ms Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
empty_case_ok) (MsgDoc -> TcRn ()
addErr (HsMatchContext Name -> MsgDoc
emptyCaseErr HsMatchContext Name
ctxt))
; (new_ms :: [LMatch GhcRn (Located (body GhcRn))]
new_ms, ms_fvs :: NameSet
ms_fvs) <- (LMatch GhcPs (Located (body GhcPs))
-> RnM (LMatch GhcRn (Located (body GhcRn)), NameSet))
-> [LMatch GhcPs (Located (body GhcPs))]
-> RnM ([LMatch GhcRn (Located (body GhcRn))], NameSet)
forall a b. (a -> RnM (b, NameSet)) -> [a] -> RnM ([b], NameSet)
mapFvRn (HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> LMatch GhcPs (Located (body GhcPs))
-> RnM (LMatch GhcRn (Located (body GhcRn)), NameSet)
forall (body :: * -> *).
Outputable (body GhcPs) =>
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> LMatch GhcPs (Located (body GhcPs))
-> RnM (LMatch GhcRn (Located (body GhcRn)), NameSet)
rnMatch HsMatchContext Name
ctxt Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody) [LMatch GhcPs (Located (body GhcPs))]
ms
; (MatchGroup GhcRn (Located (body GhcRn)), NameSet)
-> RnM (MatchGroup GhcRn (Located (body GhcRn)), NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (Origin
-> [LMatch GhcRn (Located (body GhcRn))]
-> MatchGroup GhcRn (Located (body GhcRn))
forall name (body :: * -> *).
(XMG name (Located (body name)) ~ NoExt) =>
Origin
-> [LMatch name (Located (body name))]
-> MatchGroup name (Located (body name))
mkMatchGroup Origin
origin [LMatch GhcRn (Located (body GhcRn))]
new_ms, NameSet
ms_fvs) }
rnMatchGroup _ _ (XMatchGroup {}) = String -> RnM (MatchGroup GhcRn (Located (body GhcRn)), NameSet)
forall a. String -> a
panic "rnMatchGroup"
rnMatch :: Outputable (body GhcPs) => HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), FreeVars))
-> LMatch GhcPs (Located (body GhcPs))
-> RnM (LMatch GhcRn (Located (body GhcRn)), FreeVars)
rnMatch :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> LMatch GhcPs (Located (body GhcPs))
-> RnM (LMatch GhcRn (Located (body GhcRn)), NameSet)
rnMatch ctxt :: HsMatchContext Name
ctxt rnBody :: Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody = (SrcSpanLess (LMatch GhcPs (Located (body GhcPs)))
-> TcM
(SrcSpanLess (LMatch GhcRn (Located (body GhcRn))), NameSet))
-> LMatch GhcPs (Located (body GhcPs))
-> RnM (LMatch GhcRn (Located (body GhcRn)), NameSet)
forall a b c.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b, c)) -> a -> TcM (b, c)
wrapLocFstM (HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> Match GhcPs (Located (body GhcPs))
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
forall (body :: * -> *).
Outputable (body GhcPs) =>
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> Match GhcPs (Located (body GhcPs))
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
rnMatch' HsMatchContext Name
ctxt Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody)
rnMatch' :: Outputable (body GhcPs) => HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), FreeVars))
-> Match GhcPs (Located (body GhcPs))
-> RnM (Match GhcRn (Located (body GhcRn)), FreeVars)
rnMatch' :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> Match GhcPs (Located (body GhcPs))
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
rnMatch' ctxt :: HsMatchContext Name
ctxt rnBody :: Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody (Match { m_ctxt :: forall p body.
Match p body -> HsMatchContext (NameOrRdrName (IdP p))
m_ctxt = HsMatchContext (NameOrRdrName (IdP GhcPs))
mf, m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat GhcPs]
pats, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs GhcPs (Located (body GhcPs))
grhss })
= do {
; HsMatchContext Name
-> [LPat GhcPs]
-> ([LPat GhcRn]
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet))
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
forall a.
HsMatchContext Name
-> [LPat GhcPs]
-> ([LPat GhcRn] -> RnM (a, NameSet))
-> RnM (a, NameSet)
rnPats HsMatchContext Name
ctxt [LPat GhcPs]
pats (([LPat GhcRn]
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet))
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet))
-> ([LPat GhcRn]
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet))
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
forall a b. (a -> b) -> a -> b
$ \ pats' :: [LPat GhcRn]
pats' -> do
{ (grhss' :: GRHSs GhcRn (Located (body GhcRn))
grhss', grhss_fvs :: NameSet
grhss_fvs) <- HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHSs GhcPs (Located (body GhcPs))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
forall (body :: * -> *).
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHSs GhcPs (Located (body GhcPs))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
rnGRHSs HsMatchContext Name
ctxt Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody GRHSs GhcPs (Located (body GhcPs))
grhss
; let mf' :: HsMatchContext Name
mf' = case (HsMatchContext Name
ctxt, HsMatchContext RdrName
HsMatchContext (NameOrRdrName (IdP GhcPs))
mf) of
(FunRhs { mc_fun :: forall id. HsMatchContext id -> Located id
mc_fun = L _ funid :: Name
funid }, FunRhs { mc_fun :: forall id. HsMatchContext id -> Located id
mc_fun = L lf :: SrcSpan
lf _ })
-> HsMatchContext RdrName
HsMatchContext (NameOrRdrName (IdP GhcPs))
mf { mc_fun :: Located Name
mc_fun = SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
lf Name
funid }
_ -> HsMatchContext Name
ctxt
; (Match GhcRn (Located (body GhcRn)), NameSet)
-> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (Match :: forall p body.
XCMatch p body
-> HsMatchContext (NameOrRdrName (IdP p))
-> [LPat p]
-> GRHSs p body
-> Match p body
Match { m_ext :: XCMatch GhcRn (Located (body GhcRn))
m_ext = XCMatch GhcRn (Located (body GhcRn))
NoExt
noExt, m_ctxt :: HsMatchContext (NameOrRdrName (IdP GhcRn))
m_ctxt = HsMatchContext Name
HsMatchContext (NameOrRdrName (IdP GhcRn))
mf', m_pats :: [LPat GhcRn]
m_pats = [LPat GhcRn]
pats'
, m_grhss :: GRHSs GhcRn (Located (body GhcRn))
m_grhss = GRHSs GhcRn (Located (body GhcRn))
grhss'}, NameSet
grhss_fvs ) }}
rnMatch' _ _ (XMatch _) = String -> RnM (Match GhcRn (Located (body GhcRn)), NameSet)
forall a. String -> a
panic "rnMatch'"
emptyCaseErr :: HsMatchContext Name -> SDoc
emptyCaseErr :: HsMatchContext Name -> MsgDoc
emptyCaseErr ctxt :: HsMatchContext Name
ctxt = MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "Empty list of alternatives in" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
pp_ctxt)
2 (String -> MsgDoc
text "Use EmptyCase to allow this")
where
pp_ctxt :: MsgDoc
pp_ctxt = case HsMatchContext Name
ctxt of
CaseAlt -> String -> MsgDoc
text "case expression"
LambdaExpr -> String -> MsgDoc
text "\\case expression"
_ -> String -> MsgDoc
text "(unexpected)" MsgDoc -> MsgDoc -> MsgDoc
<+> HsMatchContext Name -> MsgDoc
forall id.
(Outputable (NameOrRdrName id), Outputable id) =>
HsMatchContext id -> MsgDoc
pprMatchContextNoun HsMatchContext Name
ctxt
rnGRHSs :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), FreeVars))
-> GRHSs GhcPs (Located (body GhcPs))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), FreeVars)
rnGRHSs :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHSs GhcPs (Located (body GhcPs))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
rnGRHSs ctxt :: HsMatchContext Name
ctxt rnBody :: Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody (GRHSs _ grhss :: [LGRHS GhcPs (Located (body GhcPs))]
grhss (L l :: SrcSpan
l binds :: HsLocalBinds GhcPs
binds))
= HsLocalBinds GhcPs
-> (HsLocalBinds GhcRn
-> NameSet -> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
forall result.
HsLocalBinds GhcPs
-> (HsLocalBinds GhcRn -> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalBindsAndThen HsLocalBinds GhcPs
binds ((HsLocalBinds GhcRn
-> NameSet -> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet))
-> (HsLocalBinds GhcRn
-> NameSet -> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet))
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
forall a b. (a -> b) -> a -> b
$ \ binds' :: HsLocalBinds GhcRn
binds' _ -> do
(grhss' :: [LGRHS GhcRn (Located (body GhcRn))]
grhss', fvGRHSs :: NameSet
fvGRHSs) <- (LGRHS GhcPs (Located (body GhcPs))
-> RnM (LGRHS GhcRn (Located (body GhcRn)), NameSet))
-> [LGRHS GhcPs (Located (body GhcPs))]
-> RnM ([LGRHS GhcRn (Located (body GhcRn))], NameSet)
forall a b. (a -> RnM (b, NameSet)) -> [a] -> RnM ([b], NameSet)
mapFvRn (HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> LGRHS GhcPs (Located (body GhcPs))
-> RnM (LGRHS GhcRn (Located (body GhcRn)), NameSet)
forall (body :: * -> *).
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> LGRHS GhcPs (Located (body GhcPs))
-> RnM (LGRHS GhcRn (Located (body GhcRn)), NameSet)
rnGRHS HsMatchContext Name
ctxt Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody) [LGRHS GhcPs (Located (body GhcPs))]
grhss
(GRHSs GhcRn (Located (body GhcRn)), NameSet)
-> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCGRHSs GhcRn (Located (body GhcRn))
-> [LGRHS GhcRn (Located (body GhcRn))]
-> LHsLocalBinds GhcRn
-> GRHSs GhcRn (Located (body GhcRn))
forall p body.
XCGRHSs p body -> [LGRHS p body] -> LHsLocalBinds p -> GRHSs p body
GRHSs XCGRHSs GhcRn (Located (body GhcRn))
NoExt
noExt [LGRHS GhcRn (Located (body GhcRn))]
grhss' (SrcSpan -> HsLocalBinds GhcRn -> LHsLocalBinds GhcRn
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsLocalBinds GhcRn
binds'), NameSet
fvGRHSs)
rnGRHSs _ _ (XGRHSs _) = String -> RnM (GRHSs GhcRn (Located (body GhcRn)), NameSet)
forall a. String -> a
panic "rnGRHSs"
rnGRHS :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), FreeVars))
-> LGRHS GhcPs (Located (body GhcPs))
-> RnM (LGRHS GhcRn (Located (body GhcRn)), FreeVars)
rnGRHS :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> LGRHS GhcPs (Located (body GhcPs))
-> RnM (LGRHS GhcRn (Located (body GhcRn)), NameSet)
rnGRHS ctxt :: HsMatchContext Name
ctxt rnBody :: Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody = (SrcSpanLess (LGRHS GhcPs (Located (body GhcPs)))
-> TcM (SrcSpanLess (LGRHS GhcRn (Located (body GhcRn))), NameSet))
-> LGRHS GhcPs (Located (body GhcPs))
-> RnM (LGRHS GhcRn (Located (body GhcRn)), NameSet)
forall a b c.
(HasSrcSpan a, HasSrcSpan b) =>
(SrcSpanLess a -> TcM (SrcSpanLess b, c)) -> a -> TcM (b, c)
wrapLocFstM (HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHS GhcPs (Located (body GhcPs))
-> RnM (GRHS GhcRn (Located (body GhcRn)), NameSet)
forall (body :: * -> *).
HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHS GhcPs (Located (body GhcPs))
-> RnM (GRHS GhcRn (Located (body GhcRn)), NameSet)
rnGRHS' HsMatchContext Name
ctxt Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody)
rnGRHS' :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), FreeVars))
-> GRHS GhcPs (Located (body GhcPs))
-> RnM (GRHS GhcRn (Located (body GhcRn)), FreeVars)
rnGRHS' :: HsMatchContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> GRHS GhcPs (Located (body GhcPs))
-> RnM (GRHS GhcRn (Located (body GhcRn)), NameSet)
rnGRHS' ctxt :: HsMatchContext Name
ctxt rnBody :: Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody (GRHS _ guards :: [GuardLStmt GhcPs]
guards rhs :: Located (body GhcPs)
rhs)
= do { Bool
pattern_guards_allowed <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PatternGuards
; ((guards' :: [LStmt GhcRn (LHsExpr GhcRn)]
guards', rhs' :: Located (body GhcRn)
rhs'), fvs :: NameSet
fvs) <- HsStmtContext Name
-> (LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet))
-> [GuardLStmt GhcPs]
-> ([Name] -> RnM (Located (body GhcRn), NameSet))
-> RnM
(([LStmt GhcRn (LHsExpr GhcRn)], Located (body GhcRn)), NameSet)
forall (body :: * -> *) thing.
Outputable (body GhcPs) =>
HsStmtContext Name
-> (Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet))
-> [LStmt GhcPs (Located (body GhcPs))]
-> ([Name] -> RnM (thing, NameSet))
-> RnM (([LStmt GhcRn (Located (body GhcRn))], thing), NameSet)
rnStmts (HsMatchContext Name -> HsStmtContext Name
forall id. HsMatchContext id -> HsStmtContext id
PatGuard HsMatchContext Name
ctxt) LHsExpr GhcPs -> RnM (LHsExpr GhcRn, NameSet)
rnLExpr [GuardLStmt GhcPs]
guards (([Name] -> RnM (Located (body GhcRn), NameSet))
-> RnM
(([LStmt GhcRn (LHsExpr GhcRn)], Located (body GhcRn)), NameSet))
-> ([Name] -> RnM (Located (body GhcRn), NameSet))
-> RnM
(([LStmt GhcRn (LHsExpr GhcRn)], Located (body GhcRn)), NameSet)
forall a b. (a -> b) -> a -> b
$ \ _ ->
Located (body GhcPs) -> RnM (Located (body GhcRn), NameSet)
rnBody Located (body GhcPs)
rhs
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
pattern_guards_allowed Bool -> Bool -> Bool
|| [LStmt GhcRn (LHsExpr GhcRn)] -> Bool
forall l idL idR body. [GenLocated l (StmtLR idL idR body)] -> Bool
is_standard_guard [LStmt GhcRn (LHsExpr GhcRn)]
guards')
(WarnReason -> MsgDoc -> TcRn ()
addWarn WarnReason
NoReason ([LStmt GhcRn (LHsExpr GhcRn)] -> MsgDoc
forall body.
Outputable body =>
[LStmtLR GhcRn GhcRn body] -> MsgDoc
nonStdGuardErr [LStmt GhcRn (LHsExpr GhcRn)]
guards'))
; (GRHS GhcRn (Located (body GhcRn)), NameSet)
-> RnM (GRHS GhcRn (Located (body GhcRn)), NameSet)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCGRHS GhcRn (Located (body GhcRn))
-> [LStmt GhcRn (LHsExpr GhcRn)]
-> Located (body GhcRn)
-> GRHS GhcRn (Located (body GhcRn))
forall p body.
XCGRHS p body -> [GuardLStmt p] -> body -> GRHS p body
GRHS XCGRHS GhcRn (Located (body GhcRn))
NoExt
noExt [LStmt GhcRn (LHsExpr GhcRn)]
guards' Located (body GhcRn)
rhs', NameSet
fvs) }
where
is_standard_guard :: [GenLocated l (StmtLR idL idR body)] -> Bool
is_standard_guard [] = Bool
True
is_standard_guard [L _ (BodyStmt {})] = Bool
True
is_standard_guard _ = Bool
False
rnGRHS' _ _ (XGRHS _) = String -> RnM (GRHS GhcRn (Located (body GhcRn)), NameSet)
forall a. String -> a
panic "rnGRHS'"
rnSrcFixityDecl :: HsSigCtxt -> FixitySig GhcPs -> RnM (FixitySig GhcRn)
rnSrcFixityDecl :: HsSigCtxt -> FixitySig GhcPs -> RnM (FixitySig GhcRn)
rnSrcFixityDecl sig_ctxt :: HsSigCtxt
sig_ctxt = FixitySig GhcPs -> RnM (FixitySig GhcRn)
rn_decl
where
rn_decl :: FixitySig GhcPs -> RnM (FixitySig GhcRn)
rn_decl :: FixitySig GhcPs -> RnM (FixitySig GhcRn)
rn_decl (FixitySig _ fnames :: [Located (IdP GhcPs)]
fnames fixity :: Fixity
fixity)
= do [Located Name]
names <- (Located RdrName -> IOEnv (Env TcGblEnv TcLclEnv) [Located Name])
-> [Located RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM Located RdrName -> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
lookup_one [Located RdrName]
[Located (IdP GhcPs)]
fnames
FixitySig GhcRn -> RnM (FixitySig GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return (XFixitySig GhcRn
-> [Located (IdP GhcRn)] -> Fixity -> FixitySig GhcRn
forall pass.
XFixitySig pass -> [Located (IdP pass)] -> Fixity -> FixitySig pass
FixitySig XFixitySig GhcRn
NoExt
noExt [Located Name]
[Located (IdP GhcRn)]
names Fixity
fixity)
rn_decl (XFixitySig _) = String -> RnM (FixitySig GhcRn)
forall a. String -> a
panic "rnSrcFixityDecl"
lookup_one :: Located RdrName -> RnM [Located Name]
lookup_one :: Located RdrName -> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
lookup_one (L name_loc :: SrcSpan
name_loc rdr_name :: RdrName
rdr_name)
= SrcSpan
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
name_loc (IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name])
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall a b. (a -> b) -> a -> b
$
do [(RdrName, Name)]
names <- HsSigCtxt -> MsgDoc -> RdrName -> RnM [(RdrName, Name)]
lookupLocalTcNames HsSigCtxt
sig_ctxt MsgDoc
what RdrName
rdr_name
[Located Name] -> IOEnv (Env TcGblEnv TcLclEnv) [Located Name]
forall (m :: * -> *) a. Monad m => a -> m a
return [ SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
name_loc Name
name | (_, name :: Name
name) <- [(RdrName, Name)]
names ]
what :: MsgDoc
what = String -> MsgDoc
text "fixity signature"
dupSigDeclErr :: NonEmpty (Located RdrName, Sig GhcPs) -> RnM ()
dupSigDeclErr :: NonEmpty (Located RdrName, Sig GhcPs) -> TcRn ()
dupSigDeclErr pairs :: NonEmpty (Located RdrName, Sig GhcPs)
pairs@((L loc :: SrcSpan
loc name :: RdrName
name, sig :: Sig GhcPs
sig) :| _)
= SrcSpan -> MsgDoc -> TcRn ()
addErrAt SrcSpan
loc (MsgDoc -> TcRn ()) -> MsgDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ String -> MsgDoc
text "Duplicate" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
what_it_is
MsgDoc -> MsgDoc -> MsgDoc
<> String -> MsgDoc
text "s for" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (RdrName -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr RdrName
name)
, String -> MsgDoc
text "at" MsgDoc -> MsgDoc -> MsgDoc
<+> [MsgDoc] -> MsgDoc
vcat ((SrcSpan -> MsgDoc) -> [SrcSpan] -> [MsgDoc]
forall a b. (a -> b) -> [a] -> [b]
map SrcSpan -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ([SrcSpan] -> [MsgDoc]) -> [SrcSpan] -> [MsgDoc]
forall a b. (a -> b) -> a -> b
$ [SrcSpan] -> [SrcSpan]
forall a. Ord a => [a] -> [a]
sort
([SrcSpan] -> [SrcSpan]) -> [SrcSpan] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ ((Located RdrName, Sig GhcPs) -> SrcSpan)
-> [(Located RdrName, Sig GhcPs)] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map (Located RdrName -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc (Located RdrName -> SrcSpan)
-> ((Located RdrName, Sig GhcPs) -> Located RdrName)
-> (Located RdrName, Sig GhcPs)
-> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located RdrName, Sig GhcPs) -> Located RdrName
forall a b. (a, b) -> a
fst)
([(Located RdrName, Sig GhcPs)] -> [SrcSpan])
-> [(Located RdrName, Sig GhcPs)] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ NonEmpty (Located RdrName, Sig GhcPs)
-> [(Located RdrName, Sig GhcPs)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (Located RdrName, Sig GhcPs)
pairs)
]
where
what_it_is :: MsgDoc
what_it_is = Sig GhcPs -> MsgDoc
forall name. Sig name -> MsgDoc
hsSigDoc Sig GhcPs
sig
misplacedSigErr :: LSig GhcRn -> RnM ()
misplacedSigErr :: LSig GhcRn -> TcRn ()
misplacedSigErr (L loc :: SrcSpan
loc sig :: Sig GhcRn
sig)
= SrcSpan -> MsgDoc -> TcRn ()
addErrAt SrcSpan
loc (MsgDoc -> TcRn ()) -> MsgDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
sep [String -> MsgDoc
text "Misplaced" MsgDoc -> MsgDoc -> MsgDoc
<+> Sig GhcRn -> MsgDoc
forall name. Sig name -> MsgDoc
hsSigDoc Sig GhcRn
sig MsgDoc -> MsgDoc -> MsgDoc
<> MsgDoc
colon, Sig GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Sig GhcRn
sig]
defaultSigErr :: Sig GhcPs -> SDoc
defaultSigErr :: Sig GhcPs -> MsgDoc
defaultSigErr sig :: Sig GhcPs
sig = [MsgDoc] -> MsgDoc
vcat [ MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "Unexpected default signature:")
2 (Sig GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Sig GhcPs
sig)
, String -> MsgDoc
text "Use DefaultSignatures to enable default signatures" ]
bindsInHsBootFile :: LHsBindsLR GhcRn GhcPs -> SDoc
bindsInHsBootFile :: LHsBindsLR GhcRn GhcPs -> MsgDoc
bindsInHsBootFile mbinds :: LHsBindsLR GhcRn GhcPs
mbinds
= MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "Bindings in hs-boot files are not allowed")
2 (LHsBindsLR GhcRn GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr LHsBindsLR GhcRn GhcPs
mbinds)
nonStdGuardErr :: Outputable body => [LStmtLR GhcRn GhcRn body] -> SDoc
nonStdGuardErr :: [LStmtLR GhcRn GhcRn body] -> MsgDoc
nonStdGuardErr guards :: [LStmtLR GhcRn GhcRn body]
guards
= MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "accepting non-standard pattern guards (use PatternGuards to suppress this message)")
4 ([LStmtLR GhcRn GhcRn body] -> MsgDoc
forall a. Outputable a => [a] -> MsgDoc
interpp'SP [LStmtLR GhcRn GhcRn body]
guards)
unusedPatBindWarn :: HsBind GhcRn -> SDoc
unusedPatBindWarn :: HsBind GhcRn -> MsgDoc
unusedPatBindWarn bind :: HsBind GhcRn
bind
= MsgDoc -> Int -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text "This pattern-binding binds no variables:")
2 (HsBind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBind GhcRn
bind)
dupMinimalSigErr :: [LSig GhcPs] -> RnM ()
dupMinimalSigErr :: [LSig GhcPs] -> TcRn ()
dupMinimalSigErr sigs :: [LSig GhcPs]
sigs@(L loc :: SrcSpan
loc _ : _)
= SrcSpan -> MsgDoc -> TcRn ()
addErrAt SrcSpan
loc (MsgDoc -> TcRn ()) -> MsgDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ String -> MsgDoc
text "Multiple minimal complete definitions"
, String -> MsgDoc
text "at" MsgDoc -> MsgDoc -> MsgDoc
<+> [MsgDoc] -> MsgDoc
vcat ((SrcSpan -> MsgDoc) -> [SrcSpan] -> [MsgDoc]
forall a b. (a -> b) -> [a] -> [b]
map SrcSpan -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ([SrcSpan] -> [MsgDoc]) -> [SrcSpan] -> [MsgDoc]
forall a b. (a -> b) -> a -> b
$ [SrcSpan] -> [SrcSpan]
forall a. Ord a => [a] -> [a]
sort ([SrcSpan] -> [SrcSpan]) -> [SrcSpan] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ (LSig GhcPs -> SrcSpan) -> [LSig GhcPs] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map LSig GhcPs -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc [LSig GhcPs]
sigs)
, String -> MsgDoc
text "Combine alternative minimal complete definitions with `|'" ]
dupMinimalSigErr [] = String -> TcRn ()
forall a. String -> a
panic "dupMinimalSigErr"