{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ScopedTypeVariables, BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Rename.Bind (
rnTopBindsLHS, rnTopBindsLHSBoot, rnTopBindsBoot, rnValBindsRHS,
rnLocalBindsAndThen, rnLocalValBindsLHS, rnLocalValBindsRHS,
rnMethodBinds, renameSigs,
rnMatchGroup, rnGRHSs, rnGRHS, rnSrcFixityDecl,
makeMiniFixityEnv, MiniFixityEnv,
HsSigCtxt(..)
) where
import GHC.Prelude
import {-# SOURCE #-} GHC.Rename.Expr( rnExpr, rnLExpr, rnStmts )
import GHC.Hs
import GHC.Tc.Errors.Types
import GHC.Tc.Utils.Monad
import GHC.Rename.HsType
import GHC.Rename.Pat
import GHC.Rename.Names
import GHC.Rename.Env
import GHC.Rename.Fixity
import GHC.Rename.Utils ( mapFvRn
, checkDupRdrNames, checkDupRdrNamesN
, warnUnusedLocalBinds
, warnForallIdentifier
, checkUnusedRecordWildcard
, checkDupAndShadowedNames, bindLocalNamesFV
, addNoNestedForallsContextsErr, checkInferredVars )
import GHC.Driver.Session
import GHC.Unit.Module
import GHC.Types.Error
import GHC.Types.FieldLabel
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Name.Set
import GHC.Types.Name.Reader ( RdrName, rdrNameOcc )
import GHC.Types.SrcLoc as SrcLoc
import GHC.Data.List.SetOps ( findDupsEq )
import GHC.Types.Basic ( RecFlag(..), TypeOrKind(..) )
import GHC.Data.Graph.Directed ( SCC(..) )
import GHC.Data.Bag
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Types.Unique.Set
import GHC.Data.Maybe ( orElse )
import GHC.Data.OrdList
import qualified GHC.LanguageExtensions as LangExt
import Language.Haskell.Syntax.Basic (FieldLabelString(..))
import Control.Monad
import Data.Foldable ( toList )
import Data.List ( partition, sortBy )
import Data.List.NonEmpty ( NonEmpty(..) )
rnTopBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs
-> RnM (HsValBindsLR GhcRn GhcPs)
rnTopBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnTopBindsLHS MiniFixityEnv
fix_env HsValBinds GhcPs
binds
= NameMaker
-> HsValBinds GhcPs -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnValBindsLHS (MiniFixityEnv -> NameMaker
topRecNameMaker MiniFixityEnv
fix_env) HsValBinds GhcPs
binds
rnTopBindsLHSBoot :: MiniFixityEnv
-> HsValBinds GhcPs
-> RnM (HsValBindsLR GhcRn GhcPs)
rnTopBindsLHSBoot :: MiniFixityEnv
-> HsValBinds GhcPs -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnTopBindsLHSBoot MiniFixityEnv
fix_env HsValBinds GhcPs
binds
= do { HsValBindsLR (GhcPass 'Renamed) GhcPs
topBinds <- MiniFixityEnv
-> HsValBinds GhcPs -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnTopBindsLHS MiniFixityEnv
fix_env HsValBinds GhcPs
binds
; case HsValBindsLR (GhcPass 'Renamed) GhcPs
topBinds of
ValBinds XValBinds (GhcPass 'Renamed) GhcPs
x LHsBindsLR (GhcPass 'Renamed) GhcPs
mbinds [LSig GhcPs]
sigs ->
do { (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsBindLR (GhcPass 'Renamed) GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) ()
GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) ()
bindInHsBootFileErr LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
mbinds
; HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (XValBinds (GhcPass 'Renamed) GhcPs
-> LHsBindsLR (GhcPass 'Renamed) GhcPs
-> [LSig GhcPs]
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
forall idL idR.
XValBinds idL idR
-> LHsBindsLR idL idR -> [LSig idR] -> HsValBindsLR idL idR
ValBinds XValBinds (GhcPass 'Renamed) GhcPs
x LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
forall a. Bag a
emptyBag [LSig GhcPs]
sigs) }
HsValBindsLR (GhcPass 'Renamed) GhcPs
_ -> String -> SDoc -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnTopBindsLHSBoot" (HsValBindsLR (GhcPass 'Renamed) GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsValBindsLR (GhcPass 'Renamed) GhcPs
topBinds) }
rnTopBindsBoot :: NameSet -> HsValBindsLR GhcRn GhcPs
-> RnM (HsValBinds GhcRn, DefUses)
rnTopBindsBoot :: NameSet
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
rnTopBindsBoot NameSet
bound_names (ValBinds XValBinds (GhcPass 'Renamed) GhcPs
_ LHsBindsLR (GhcPass 'Renamed) GhcPs
_ [LSig GhcPs]
sigs)
= do { ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs', NameSet
fvs) <- HsSigCtxt
-> [LSig GhcPs] -> RnM ([LSig (GhcPass 'Renamed)], NameSet)
renameSigs (NameSet -> HsSigCtxt
HsBootCtxt NameSet
bound_names) [LSig GhcPs]
sigs
; (HsValBinds (GhcPass 'Renamed), DefUses)
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XXValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
-> HsValBinds (GhcPass 'Renamed)
forall idL idR. XXValBindsLR idL idR -> HsValBindsLR idL idR
XValBindsLR ([(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> [LSig (GhcPass 'Renamed)] -> NHsValBindsLR (GhcPass 'Renamed)
forall idL.
[(RecFlag, LHsBinds idL)]
-> [LSig (GhcPass 'Renamed)] -> NHsValBindsLR idL
NValBinds [] [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs'), NameSet -> DefUses
usesOnly NameSet
fvs) }
rnTopBindsBoot NameSet
_ HsValBindsLR (GhcPass 'Renamed) GhcPs
b = String -> SDoc -> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnTopBindsBoot" (HsValBindsLR (GhcPass 'Renamed) GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsValBindsLR (GhcPass 'Renamed) GhcPs
b)
rnLocalBindsAndThen :: HsLocalBinds GhcPs
-> (HsLocalBinds GhcRn -> FreeVars -> RnM (result, FreeVars))
-> RnM (result, FreeVars)
rnLocalBindsAndThen :: forall result.
HsLocalBinds GhcPs
-> (HsLocalBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalBindsAndThen (EmptyLocalBinds XEmptyLocalBinds GhcPs GhcPs
x) HsLocalBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside =
HsLocalBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside (XEmptyLocalBinds (GhcPass 'Renamed) (GhcPass 'Renamed)
-> HsLocalBinds (GhcPass 'Renamed)
forall idL idR. XEmptyLocalBinds idL idR -> HsLocalBindsLR idL idR
EmptyLocalBinds XEmptyLocalBinds GhcPs GhcPs
XEmptyLocalBinds (GhcPass 'Renamed) (GhcPass 'Renamed)
x) NameSet
emptyNameSet
rnLocalBindsAndThen (HsValBinds XHsValBinds GhcPs GhcPs
x HsValBinds GhcPs
val_binds) HsLocalBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside
= HsValBinds GhcPs
-> (HsValBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
forall result.
HsValBinds GhcPs
-> (HsValBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalValBindsAndThen HsValBinds GhcPs
val_binds ((HsValBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet))
-> (HsValBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
forall a b. (a -> b) -> a -> b
$ \ HsValBinds (GhcPass 'Renamed)
val_binds' ->
HsLocalBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside (XHsValBinds (GhcPass 'Renamed) (GhcPass 'Renamed)
-> HsValBinds (GhcPass 'Renamed) -> HsLocalBinds (GhcPass 'Renamed)
forall idL idR.
XHsValBinds idL idR
-> HsValBindsLR idL idR -> HsLocalBindsLR idL idR
HsValBinds XHsValBinds GhcPs GhcPs
XHsValBinds (GhcPass 'Renamed) (GhcPass 'Renamed)
x HsValBinds (GhcPass 'Renamed)
val_binds')
rnLocalBindsAndThen (HsIPBinds XHsIPBinds GhcPs GhcPs
x HsIPBinds GhcPs
binds) HsLocalBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside = do
(HsIPBinds (GhcPass 'Renamed)
binds',NameSet
fv_binds) <- HsIPBinds GhcPs -> RnM (HsIPBinds (GhcPass 'Renamed), NameSet)
rnIPBinds HsIPBinds GhcPs
binds
(result
thing, NameSet
fvs_thing) <- HsLocalBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside (XHsIPBinds (GhcPass 'Renamed) (GhcPass 'Renamed)
-> HsIPBinds (GhcPass 'Renamed) -> HsLocalBinds (GhcPass 'Renamed)
forall idL idR.
XHsIPBinds idL idR -> HsIPBinds idR -> HsLocalBindsLR idL idR
HsIPBinds XHsIPBinds GhcPs GhcPs
XHsIPBinds (GhcPass 'Renamed) (GhcPass 'Renamed)
x HsIPBinds (GhcPass 'Renamed)
binds') NameSet
fv_binds
(result, NameSet) -> RnM (result, NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (result
thing, NameSet
fvs_thing NameSet -> NameSet -> NameSet
`plusFV` NameSet
fv_binds)
rnIPBinds :: HsIPBinds GhcPs -> RnM (HsIPBinds GhcRn, FreeVars)
rnIPBinds :: HsIPBinds GhcPs -> RnM (HsIPBinds (GhcPass 'Renamed), NameSet)
rnIPBinds (IPBinds XIPBinds GhcPs
_ [LIPBind GhcPs]
ip_binds ) = do
([GenLocated SrcSpanAnnA (IPBind (GhcPass 'Renamed))]
ip_binds', [NameSet]
fvs_s) <- (GenLocated SrcSpanAnnA (IPBind GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (IPBind (GhcPass 'Renamed)), NameSet))
-> [GenLocated SrcSpanAnnA (IPBind GhcPs)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (IPBind (GhcPass 'Renamed))], [NameSet])
forall (m :: * -> *) a b c.
Applicative m =>
(a -> m (b, c)) -> [a] -> m ([b], [c])
mapAndUnzipM ((IPBind GhcPs -> TcM (IPBind (GhcPass 'Renamed), NameSet))
-> GenLocated SrcSpanAnnA (IPBind GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (IPBind (GhcPass 'Renamed)), NameSet)
forall a b c ann.
(a -> TcM (b, c))
-> GenLocated (SrcSpanAnn' ann) a
-> TcM (GenLocated (SrcSpanAnn' ann) b, c)
wrapLocFstMA IPBind GhcPs -> TcM (IPBind (GhcPass 'Renamed), NameSet)
rnIPBind) [LIPBind GhcPs]
[GenLocated SrcSpanAnnA (IPBind GhcPs)]
ip_binds
(HsIPBinds (GhcPass 'Renamed), NameSet)
-> RnM (HsIPBinds (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XIPBinds (GhcPass 'Renamed)
-> [LIPBind (GhcPass 'Renamed)] -> HsIPBinds (GhcPass 'Renamed)
forall id. XIPBinds id -> [LIPBind id] -> HsIPBinds id
IPBinds XIPBinds (GhcPass 'Renamed)
NoExtField
noExtField [LIPBind (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (IPBind (GhcPass 'Renamed))]
ip_binds', [NameSet] -> NameSet
plusFVs [NameSet]
fvs_s)
rnIPBind :: IPBind GhcPs -> RnM (IPBind GhcRn, FreeVars)
rnIPBind :: IPBind GhcPs -> TcM (IPBind (GhcPass 'Renamed), NameSet)
rnIPBind (IPBind XCIPBind GhcPs
_ XRec GhcPs HsIPName
n LHsExpr GhcPs
expr) = do
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
expr',NameSet
fvExpr) <- LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), NameSet)
rnLExpr LHsExpr GhcPs
expr
(IPBind (GhcPass 'Renamed), NameSet)
-> TcM (IPBind (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XCIPBind (GhcPass 'Renamed)
-> XRec (GhcPass 'Renamed) HsIPName
-> LHsExpr (GhcPass 'Renamed)
-> IPBind (GhcPass 'Renamed)
forall id.
XCIPBind id -> XRec id HsIPName -> LHsExpr id -> IPBind id
IPBind XCIPBind (GhcPass 'Renamed)
NoExtField
noExtField XRec GhcPs HsIPName
XRec (GhcPass 'Renamed) HsIPName
n LHsExpr (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
expr', NameSet
fvExpr)
rnLocalValBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs
-> RnM ([Name], HsValBindsLR GhcRn GhcPs)
rnLocalValBindsLHS :: MiniFixityEnv
-> HsValBinds GhcPs
-> RnM ([Name], HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnLocalValBindsLHS MiniFixityEnv
fix_env HsValBinds GhcPs
binds
= do { HsValBindsLR (GhcPass 'Renamed) GhcPs
binds' <- NameMaker
-> HsValBinds GhcPs -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnValBindsLHS (MiniFixityEnv -> NameMaker
localRecNameMaker MiniFixityEnv
fix_env) HsValBinds GhcPs
binds
; let bound_names :: [IdP (GhcPass 'Renamed)]
bound_names = CollectFlag (GhcPass 'Renamed)
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> [IdP (GhcPass 'Renamed)]
forall (idL :: Pass) idR.
CollectPass (GhcPass idL) =>
CollectFlag (GhcPass idL)
-> HsValBindsLR (GhcPass idL) idR -> [IdP (GhcPass idL)]
collectHsValBinders CollectFlag (GhcPass 'Renamed)
forall p. CollectFlag p
CollNoDictBinders HsValBindsLR (GhcPass 'Renamed) GhcPs
binds'
; (GlobalRdrEnv, LocalRdrEnv)
envs <- TcRn (GlobalRdrEnv, LocalRdrEnv)
getRdrEnvs
; (GlobalRdrEnv, LocalRdrEnv)
-> [Name] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupAndShadowedNames (GlobalRdrEnv, LocalRdrEnv)
envs [IdP (GhcPass 'Renamed)]
[Name]
bound_names
; ([Name], HsValBindsLR (GhcPass 'Renamed) GhcPs)
-> RnM ([Name], HsValBindsLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([IdP (GhcPass 'Renamed)]
[Name]
bound_names, HsValBindsLR (GhcPass 'Renamed) GhcPs
binds') }
rnValBindsLHS :: NameMaker
-> HsValBinds GhcPs
-> RnM (HsValBindsLR GhcRn GhcPs)
rnValBindsLHS :: NameMaker
-> HsValBinds GhcPs -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
rnValBindsLHS NameMaker
topP (ValBinds XValBinds GhcPs GhcPs
x LHsBindsLR GhcPs GhcPs
mbinds [LSig GhcPs]
sigs)
= do { Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
mbinds' <- (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM ((HsBindLR GhcPs GhcPs -> TcM (HsBindLR (GhcPass 'Renamed) GhcPs))
-> GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
forall a b ann.
(a -> TcM b)
-> GenLocated (SrcSpanAnn' ann) a
-> TcRn (GenLocated (SrcSpanAnn' ann) b)
wrapLocMA (NameMaker
-> SDoc
-> HsBindLR GhcPs GhcPs
-> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
rnBindLHS NameMaker
topP SDoc
doc)) LHsBindsLR GhcPs GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
mbinds
; HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs))
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
forall a b. (a -> b) -> a -> b
$ XValBinds (GhcPass 'Renamed) GhcPs
-> LHsBindsLR (GhcPass 'Renamed) GhcPs
-> [LSig GhcPs]
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
forall idL idR.
XValBinds idL idR
-> LHsBindsLR idL idR -> [LSig idR] -> HsValBindsLR idL idR
ValBinds XValBinds GhcPs GhcPs
XValBinds (GhcPass 'Renamed) GhcPs
x LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
mbinds' [LSig GhcPs]
sigs }
where
bndrs :: [IdP GhcPs]
bndrs = CollectFlag GhcPs -> LHsBindsLR GhcPs GhcPs -> [IdP GhcPs]
forall p idR.
CollectPass p =>
CollectFlag p -> LHsBindsLR p idR -> [IdP p]
collectHsBindsBinders CollectFlag GhcPs
forall p. CollectFlag p
CollNoDictBinders LHsBindsLR GhcPs GhcPs
mbinds
doc :: SDoc
doc = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the binding group for:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (RdrName -> SDoc) -> [RdrName] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [IdP GhcPs]
[RdrName]
bndrs
rnValBindsLHS NameMaker
_ HsValBinds GhcPs
b = String -> SDoc -> RnM (HsValBindsLR (GhcPass 'Renamed) GhcPs)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnValBindsLHSFromDoc" (HsValBinds GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsValBinds GhcPs
b)
rnValBindsRHS :: HsSigCtxt
-> HsValBindsLR GhcRn GhcPs
-> RnM (HsValBinds GhcRn, DefUses)
rnValBindsRHS :: HsSigCtxt
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
rnValBindsRHS HsSigCtxt
ctxt (ValBinds XValBinds (GhcPass 'Renamed) GhcPs
_ LHsBindsLR (GhcPass 'Renamed) GhcPs
mbinds [LSig GhcPs]
sigs)
= do { ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs', NameSet
sig_fvs) <- HsSigCtxt
-> [LSig GhcPs] -> RnM ([LSig (GhcPass 'Renamed)], NameSet)
renameSigs HsSigCtxt
ctxt [LSig GhcPs]
sigs
; Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
binds_w_dus <- (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM ((Name -> [Name])
-> LHsBindLR (GhcPass 'Renamed) GhcPs
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
rnLBind ([LSig (GhcPass 'Renamed)] -> Name -> [Name]
mkScopedTvFn [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs')) LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
mbinds
; let !([(RecFlag, LHsBinds (GhcPass 'Renamed))]
anal_binds, DefUses
anal_dus) = Bag (LHsBind (GhcPass 'Renamed), [Name], NameSet)
-> ([(RecFlag, LHsBinds (GhcPass 'Renamed))], DefUses)
depAnalBinds Bag (LHsBind (GhcPass 'Renamed), [Name], NameSet)
Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
binds_w_dus
; let patsyn_fvs :: NameSet
patsyn_fvs = (PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
-> NameSet -> NameSet)
-> NameSet
-> [PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)]
-> NameSet
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (NameSet -> NameSet -> NameSet
unionNameSet (NameSet -> NameSet -> NameSet)
-> (PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed) -> NameSet)
-> PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
-> NameSet
-> NameSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
-> XPSB (GhcPass 'Renamed) (GhcPass 'Renamed)
PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed) -> NameSet
forall idL idR. PatSynBind idL idR -> XPSB idL idR
psb_ext) NameSet
emptyNameSet ([PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)] -> NameSet)
-> [PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)] -> NameSet
forall a b. (a -> b) -> a -> b
$
[(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> [PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)]
forall id.
UnXRec id =>
[(RecFlag, LHsBinds id)] -> [PatSynBind id id]
getPatSynBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
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 (GhcPass 'Renamed), DefUses)
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XXValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
-> HsValBinds (GhcPass 'Renamed)
forall idL idR. XXValBindsLR idL idR -> HsValBindsLR idL idR
XValBindsLR ([(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> [LSig (GhcPass 'Renamed)] -> NHsValBindsLR (GhcPass 'Renamed)
forall idL.
[(RecFlag, LHsBinds idL)]
-> [LSig (GhcPass 'Renamed)] -> NHsValBindsLR idL
NValBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
anal_binds [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs'), DefUses
valbind'_dus) }
rnValBindsRHS HsSigCtxt
_ HsValBindsLR (GhcPass 'Renamed) GhcPs
b = String -> SDoc -> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnValBindsRHS" (HsValBindsLR (GhcPass 'Renamed) GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsValBindsLR (GhcPass 'Renamed) GhcPs
b)
rnLocalValBindsRHS :: NameSet
-> HsValBindsLR GhcRn GhcPs
-> RnM (HsValBinds GhcRn, DefUses)
rnLocalValBindsRHS :: NameSet
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
rnLocalValBindsRHS NameSet
bound_names HsValBindsLR (GhcPass 'Renamed) GhcPs
binds
= HsSigCtxt
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
rnValBindsRHS (NameSet -> HsSigCtxt
LocalBindCtxt NameSet
bound_names) HsValBindsLR (GhcPass 'Renamed) GhcPs
binds
rnLocalValBindsAndThen
:: HsValBinds GhcPs
-> (HsValBinds GhcRn -> FreeVars -> RnM (result, FreeVars))
-> RnM (result, FreeVars)
rnLocalValBindsAndThen :: forall result.
HsValBinds GhcPs
-> (HsValBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalValBindsAndThen binds :: HsValBinds GhcPs
binds@(ValBinds XValBinds GhcPs GhcPs
_ LHsBindsLR GhcPs GhcPs
_ [LSig GhcPs]
sigs) HsValBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside
= do {
MiniFixityEnv
new_fixities <- [LFixitySig GhcPs] -> RnM MiniFixityEnv
makeMiniFixityEnv [ SrcSpanAnnA
-> FixitySig GhcPs -> GenLocated SrcSpanAnnA (FixitySig GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc FixitySig GhcPs
sig
| L SrcSpanAnnA
loc (FixSig XFixSig GhcPs
_ FixitySig GhcPs
sig) <- [LSig GhcPs]
[GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs]
; ([Name]
bound_names, HsValBindsLR (GhcPass 'Renamed) GhcPs
new_lhs) <- MiniFixityEnv
-> HsValBinds GhcPs
-> RnM ([Name], HsValBindsLR (GhcPass 'Renamed) 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
{
(HsValBinds (GhcPass 'Renamed)
binds', DefUses
dus) <- NameSet
-> HsValBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (HsValBinds (GhcPass 'Renamed), DefUses)
rnLocalValBindsRHS ([Name] -> NameSet
mkNameSet [Name]
bound_names) HsValBindsLR (GhcPass 'Renamed) GhcPs
new_lhs
; (result
result, NameSet
result_fvs) <- HsValBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
thing_inside HsValBinds (GhcPass 'Renamed)
binds' (DefUses -> NameSet
allUses DefUses
dus)
; let real_uses :: NameSet
real_uses = DefUses -> NameSet -> NameSet
findUses DefUses
dus NameSet
result_fvs
rec_uses :: [(SrcSpan, [Name])]
rec_uses = HsValBinds (GhcPass 'Renamed) -> [(SrcSpan, [Name])]
forall (idR :: Pass).
HsValBindsLR (GhcPass 'Renamed) (GhcPass idR)
-> [(SrcSpan, [Name])]
hsValBindsImplicits HsValBinds (GhcPass 'Renamed)
binds'
implicit_uses :: NameSet
implicit_uses = [Name] -> NameSet
mkNameSet ([Name] -> NameSet) -> [Name] -> NameSet
forall a b. (a -> b) -> a -> b
$ ((SrcSpan, [Name]) -> [Name]) -> [(SrcSpan, [Name])] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (SrcSpan, [Name]) -> [Name]
forall a b. (a, b) -> b
snd
([(SrcSpan, [Name])] -> [Name]) -> [(SrcSpan, [Name])] -> [Name]
forall a b. (a -> b) -> a -> b
$ [(SrcSpan, [Name])]
rec_uses
; ((SrcSpan, [Name]) -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> [(SrcSpan, [Name])] -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\(SrcSpan
loc, [Name]
ns) ->
SrcSpan
-> NameSet -> Maybe [Name] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkUnusedRecordWildcard SrcSpan
loc NameSet
real_uses ([Name] -> Maybe [Name]
forall a. a -> Maybe a
Just [Name]
ns))
[(SrcSpan, [Name])]
rec_uses
; [Name] -> NameSet -> IOEnv (Env TcGblEnv TcLclEnv) ()
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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (result
result, NameSet
all_uses) }}
rnLocalValBindsAndThen HsValBinds GhcPs
bs HsValBinds (GhcPass 'Renamed) -> NameSet -> RnM (result, NameSet)
_ = String -> SDoc -> RnM (result, NameSet)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnLocalValBindsAndThen" (HsValBinds GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsValBinds GhcPs
bs)
rnBindLHS :: NameMaker
-> SDoc
-> HsBind GhcPs
-> RnM (HsBindLR GhcRn GhcPs)
rnBindLHS :: NameMaker
-> SDoc
-> HsBindLR GhcPs GhcPs
-> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
rnBindLHS NameMaker
name_maker SDoc
_ bind :: HsBindLR GhcPs GhcPs
bind@(PatBind { pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat GhcPs
pat })
= do
(GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
pat',NameSet
pat'_fvs) <- NameMaker -> LPat GhcPs -> RnM (LPat (GhcPass 'Renamed), NameSet)
rnBindPat NameMaker
name_maker LPat GhcPs
pat
HsBindLR (GhcPass 'Renamed) GhcPs
-> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBindLR GhcPs GhcPs
bind { pat_lhs = pat', pat_ext = pat'_fvs })
rnBindLHS NameMaker
name_maker SDoc
_ bind :: HsBindLR GhcPs GhcPs
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP GhcPs
rdr_name })
= do { GenLocated SrcSpanAnnN Name
name <- NameMaker -> LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
applyNameMaker NameMaker
name_maker LIdP GhcPs
LocatedN RdrName
rdr_name
; HsBindLR (GhcPass 'Renamed) GhcPs
-> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBindLR GhcPs GhcPs
bind { fun_id = name
, fun_ext = noExtField }) }
rnBindLHS NameMaker
name_maker SDoc
_ (PatSynBind XPatSynBind GhcPs GhcPs
x psb :: PatSynBind GhcPs GhcPs
psb@PSB{ psb_id :: forall idL idR. PatSynBind idL idR -> LIdP idL
psb_id = LIdP GhcPs
rdrname })
| NameMaker -> Bool
isTopRecNameMaker NameMaker
name_maker
= do { (RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> LocatedN RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b ann.
(a -> TcM b) -> GenLocated (SrcSpanAnn' ann) a -> TcM b
addLocMA RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkConName LIdP GhcPs
LocatedN RdrName
rdrname
; GenLocated SrcSpanAnnN Name
name <-
LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
lookupLocatedTopConstructorRnN LIdP GhcPs
LocatedN RdrName
rdrname
; HsBindLR (GhcPass 'Renamed) GhcPs
-> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynBind (GhcPass 'Renamed) GhcPs
-> PatSynBind (GhcPass 'Renamed) GhcPs
-> HsBindLR (GhcPass 'Renamed) GhcPs
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind GhcPs GhcPs
XPatSynBind (GhcPass 'Renamed) GhcPs
x PatSynBind GhcPs GhcPs
psb{ psb_ext = noAnn, psb_id = name }) }
| Bool
otherwise
= do { TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr TcRnMessage
localPatternSynonymErr
; GenLocated SrcSpanAnnN Name
name <- NameMaker -> LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
applyNameMaker NameMaker
name_maker LIdP GhcPs
LocatedN RdrName
rdrname
; HsBindLR (GhcPass 'Renamed) GhcPs
-> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynBind (GhcPass 'Renamed) GhcPs
-> PatSynBind (GhcPass 'Renamed) GhcPs
-> HsBindLR (GhcPass 'Renamed) GhcPs
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind GhcPs GhcPs
XPatSynBind (GhcPass 'Renamed) GhcPs
x PatSynBind GhcPs GhcPs
psb{ psb_ext = noAnn, psb_id = name }) }
where
localPatternSynonymErr :: TcRnMessage
localPatternSynonymErr :: TcRnMessage
localPatternSynonymErr = LIdP GhcPs -> TcRnMessage
TcRnIllegalPatSynDecl LIdP GhcPs
rdrname
rnBindLHS NameMaker
_ SDoc
_ HsBindLR GhcPs GhcPs
b = String -> SDoc -> TcM (HsBindLR (GhcPass 'Renamed) GhcPs)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnBindHS" (HsBindLR GhcPs GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsBindLR GhcPs GhcPs
b)
rnLBind :: (Name -> [Name])
-> LHsBindLR GhcRn GhcPs
-> RnM (LHsBind GhcRn, [Name], Uses)
rnLBind :: (Name -> [Name])
-> LHsBindLR (GhcPass 'Renamed) GhcPs
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
rnLBind Name -> [Name]
sig_fn (L SrcSpanAnnA
loc HsBindLR (GhcPass 'Renamed) GhcPs
bind)
= SrcSpanAnnA
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet))
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
forall a b. (a -> b) -> a -> b
$
do { (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
bind', [Name]
bndrs, NameSet
dus) <- (Name -> [Name])
-> HsBindLR (GhcPass 'Renamed) GhcPs
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
rnBind Name -> [Name]
sig_fn HsBindLR (GhcPass 'Renamed) GhcPs
bind
; (GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
-> GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
bind', [Name]
bndrs, NameSet
dus) }
rnBind :: (Name -> [Name])
-> HsBindLR GhcRn GhcPs
-> RnM (HsBind GhcRn, [Name], Uses)
rnBind :: (Name -> [Name])
-> HsBindLR (GhcPass 'Renamed) GhcPs
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
rnBind Name -> [Name]
_ bind :: HsBindLR (GhcPass 'Renamed) GhcPs
bind@(PatBind { pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat (GhcPass 'Renamed)
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 (GhcPass 'Renamed) GhcPs
pat_fvs })
= do { Module
mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; (GRHSs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
grhss', NameSet
rhs_fvs) <- HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (HsExpr GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)), NameSet))
-> GRHSs GhcPs (LocatedA (HsExpr GhcPs))
-> RnM
(GRHSs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHSs GhcPs (LocatedA (body GhcPs))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHSs HsMatchContext (GhcPass 'Renamed)
forall p. HsMatchContext p
PatBindRhs LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), NameSet)
LocatedA (HsExpr GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)), NameSet)
rnLExpr GRHSs GhcPs (LHsExpr GhcPs)
GRHSs GhcPs (LocatedA (HsExpr GhcPs))
grhss
; let all_fvs :: NameSet
all_fvs = XPatBind (GhcPass 'Renamed) GhcPs
NameSet
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 (GhcPass 'Renamed)]
bndrs = CollectFlag (GhcPass 'Renamed)
-> LPat (GhcPass 'Renamed) -> [IdP (GhcPass 'Renamed)]
forall p. CollectPass p => CollectFlag p -> LPat p -> [IdP p]
collectPatBinders CollectFlag (GhcPass 'Renamed)
forall p. CollectFlag p
CollNoDictBinders LPat (GhcPass 'Renamed)
pat
bind' :: HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
bind' = HsBindLR (GhcPass 'Renamed) GhcPs
bind { pat_rhs = grhss'
, pat_ext = fvs' }
; WarningFlag
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall gbl lcl.
WarningFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
whenWOptM WarningFlag
Opt_WarnUnusedPatternBinds (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Name] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [IdP (GhcPass 'Renamed)]
[Name]
bndrs Bool -> Bool -> Bool
&& Bool -> Bool
not (LPat (GhcPass 'Renamed) -> Bool
isOkNoBindPattern LPat (GhcPass 'Renamed)
pat)) (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addTcRnDiagnostic (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed) -> TcRnMessage
TcRnUnusedPatternBinds HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
bind')
; NameSet
fvs' NameSet
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a b. a -> b -> b
`seq`
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
bind', [IdP (GhcPass 'Renamed)]
[Name]
bndrs, NameSet
all_fvs) }
rnBind Name -> [Name]
sig_fn bind :: HsBindLR (GhcPass 'Renamed) GhcPs
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
name
, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup GhcPs (LHsExpr GhcPs)
matches })
= do { let plain_name :: Name
plain_name = GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
GenLocated SrcSpanAnnN Name
name
; (MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
matches', NameSet
rhs_fvs) <- [Name]
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV (Name -> [Name]
sig_fn Name
plain_name) (RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet))
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall a b. (a -> b) -> a -> b
$
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (HsExpr GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)), NameSet))
-> MatchGroup GhcPs (LocatedA (HsExpr GhcPs))
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
(Outputable (body GhcPs), AnnoBody body) =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> MatchGroup GhcPs (LocatedA (body GhcPs))
-> RnM
(MatchGroup
(GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatchGroup (XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
-> HsMatchContext (GhcPass 'Renamed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
name)
LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), NameSet)
LocatedA (HsExpr GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)), NameSet)
rnLExpr MatchGroup GhcPs (LHsExpr GhcPs)
MatchGroup GhcPs (LocatedA (HsExpr GhcPs))
matches
; let is_infix :: Bool
is_infix = HsBindLR (GhcPass 'Renamed) GhcPs -> Bool
forall id1 id2. UnXRec id2 => HsBindLR id1 id2 -> Bool
isInfixFunBind HsBindLR (GhcPass 'Renamed) GhcPs
bind
; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
is_infix (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ Name
-> MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall body.
Name
-> MatchGroup (GhcPass 'Renamed) body
-> IOEnv (Env TcGblEnv TcLclEnv) ()
checkPrecMatch Name
plain_name MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
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
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a b. a -> b -> b
`seq`
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBindLR (GhcPass 'Renamed) GhcPs
bind { fun_matches = matches'
, fun_ext = fvs' },
[Name
plain_name], NameSet
rhs_fvs)
}
rnBind Name -> [Name]
sig_fn (PatSynBind XPatSynBind (GhcPass 'Renamed) GhcPs
x PatSynBind (GhcPass 'Renamed) GhcPs
bind)
= do { (PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
bind', [Name]
name, NameSet
fvs) <- (Name -> [Name])
-> PatSynBind (GhcPass 'Renamed) GhcPs
-> RnM
(PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
rnPatSynBind Name -> [Name]
sig_fn PatSynBind (GhcPass 'Renamed) GhcPs
bind
; (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
-> PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
-> HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind (GhcPass 'Renamed) GhcPs
XPatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
x PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
bind', [Name]
name, NameSet
fvs) }
rnBind Name -> [Name]
_ HsBindLR (GhcPass 'Renamed) GhcPs
b = String
-> SDoc
-> RnM
(HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnBind" (HsBindLR (GhcPass 'Renamed) GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsBindLR (GhcPass 'Renamed) GhcPs
b)
isOkNoBindPattern :: LPat GhcRn -> Bool
isOkNoBindPattern :: LPat (GhcPass 'Renamed) -> Bool
isOkNoBindPattern (L SrcSpanAnnA
_ Pat (GhcPass 'Renamed)
pat) =
case Pat (GhcPass 'Renamed)
pat of
WildPat{} -> Bool
True
BangPat {} -> Bool
True
Pat (GhcPass 'Renamed)
p -> Pat (GhcPass 'Renamed) -> Bool
patternContainsSplice Pat (GhcPass 'Renamed)
p
where
lpatternContainsSplice :: LPat GhcRn -> Bool
lpatternContainsSplice :: LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice (L SrcSpanAnnA
_ Pat (GhcPass 'Renamed)
p) = Pat (GhcPass 'Renamed) -> Bool
patternContainsSplice Pat (GhcPass 'Renamed)
p
patternContainsSplice :: Pat GhcRn -> Bool
patternContainsSplice :: Pat (GhcPass 'Renamed) -> Bool
patternContainsSplice Pat (GhcPass 'Renamed)
p =
case Pat (GhcPass 'Renamed)
p of
SplicePat (HsUntypedSpliceTop ThModFinalizers
_ Pat (GhcPass 'Renamed)
p) HsUntypedSplice (GhcPass 'Renamed)
_ -> Pat (GhcPass 'Renamed) -> Bool
patternContainsSplice Pat (GhcPass 'Renamed)
p
SplicePat (HsUntypedSpliceNested {}) HsUntypedSplice (GhcPass 'Renamed)
_ -> Bool
True
VarPat {} -> Bool
False
WildPat {} -> Bool
False
LitPat {} -> Bool
False
NPat {} -> Bool
False
NPlusKPat {} -> Bool
False
BangPat XBangPat (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
LazyPat XLazyPat (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
AsPat XAsPat (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
_ LHsToken "@" (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
ParPat XParPat (GhcPass 'Renamed)
_ LHsToken "(" (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp LHsToken ")" (GhcPass 'Renamed)
_ -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
ViewPat XViewPat (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
SigPat XSigPat (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp HsPatSigType (NoGhcTc (GhcPass 'Renamed))
_ -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
ListPat XListPat (GhcPass 'Renamed)
_ [LPat (GhcPass 'Renamed)]
lps -> (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)) -> Bool)
-> [GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any LPat (GhcPass 'Renamed) -> Bool
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)) -> Bool
lpatternContainsSplice [LPat (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))]
lps
TuplePat XTuplePat (GhcPass 'Renamed)
_ [LPat (GhcPass 'Renamed)]
lps Boxity
_ -> (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)) -> Bool)
-> [GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any LPat (GhcPass 'Renamed) -> Bool
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)) -> Bool
lpatternContainsSplice [LPat (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))]
lps
SumPat XSumPat (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
lp ConTag
_ ConTag
_ -> LPat (GhcPass 'Renamed) -> Bool
lpatternContainsSplice LPat (GhcPass 'Renamed)
lp
ConPat XConPat (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) (ConLikeP (GhcPass 'Renamed))
_ HsConPatDetails (GhcPass 'Renamed)
cpd -> (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)) -> Bool)
-> [GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any LPat (GhcPass 'Renamed) -> Bool
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)) -> Bool
lpatternContainsSplice (HsConPatDetails (GhcPass 'Renamed) -> [LPat (GhcPass 'Renamed)]
forall p. UnXRec p => HsConPatDetails p -> [LPat p]
hsConPatArgs HsConPatDetails (GhcPass 'Renamed)
cpd)
XPat (HsPatExpanded Pat (GhcPass 'Renamed)
_orig Pat (GhcPass 'Renamed)
new) -> Pat (GhcPass 'Renamed) -> Bool
patternContainsSplice Pat (GhcPass 'Renamed)
new
depAnalBinds :: Bag (LHsBind GhcRn, [Name], Uses)
-> ([(RecFlag, LHsBinds GhcRn)], DefUses)
depAnalBinds :: Bag (LHsBind (GhcPass 'Renamed), [Name], NameSet)
-> ([(RecFlag, LHsBinds (GhcPass 'Renamed))], DefUses)
depAnalBinds Bag (LHsBind (GhcPass 'Renamed), [Name], NameSet)
binds_w_dus
= ((SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> (RecFlag,
Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)))))
-> [SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
-> [(RecFlag,
Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))))]
forall a b. (a -> b) -> [a] -> [b]
map SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> (RecFlag,
Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))))
forall {a} {b} {c}. SCC (a, b, c) -> (RecFlag, Bag a)
get_binds [SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
sccs, [DefUse] -> DefUses
forall a. [a] -> OrdList a
toOL ([DefUse] -> DefUses) -> [DefUse] -> DefUses
forall a b. (a -> b) -> a -> b
$ (SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> DefUse)
-> [SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
-> [DefUse]
forall a b. (a -> b) -> [a] -> [b]
map SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> DefUse
forall {a}. SCC (a, [Name], NameSet) -> DefUse
get_du [SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
sccs)
where
sccs :: [SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
sccs = ((GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> [Name])
-> ((GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> [Name])
-> [(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
-> [SCC
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
forall node.
(node -> [Name]) -> (node -> [Name]) -> [node] -> [SCC node]
depAnal (\(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
_, [Name]
defs, NameSet
_) -> [Name]
defs)
(\(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
_, [Name]
_, NameSet
uses) -> NameSet -> [Name]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet NameSet
uses)
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> [(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)]
forall a. Bag a -> [a]
bagToList Bag (LHsBind (GhcPass 'Renamed), [Name], NameSet)
Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
binds_w_dus)
get_binds :: SCC (a, b, c) -> (RecFlag, Bag a)
get_binds (AcyclicSCC (a
bind, b
_, c
_)) = (RecFlag
NonRecursive, a -> Bag a
forall a. a -> Bag a
unitBag a
bind)
get_binds (CyclicSCC [(a, b, c)]
binds_w_dus) = (RecFlag
Recursive, [a] -> Bag a
forall a. [a] -> Bag a
listToBag [a
b | (a
b,b
_,c
_) <- [(a, b, c)]
binds_w_dus])
get_du :: SCC (a, [Name], NameSet) -> DefUse
get_du (AcyclicSCC (a
_, [Name]
bndrs, NameSet
uses)) = (NameSet -> Maybe NameSet
forall a. a -> Maybe a
Just ([Name] -> NameSet
mkNameSet [Name]
bndrs), NameSet
uses)
get_du (CyclicSCC [(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 | (a
_,[Name]
bs,NameSet
_) <- [(a, [Name], NameSet)]
binds_w_dus, Name
b <- [Name]
bs]
uses :: NameSet
uses = [NameSet] -> NameSet
unionNameSets [NameSet
u | (a
_,[Name]
_,NameSet
u) <- [(a, [Name], NameSet)]
binds_w_dus]
mkScopedTvFn :: [LSig GhcRn] -> (Name -> [Name])
mkScopedTvFn :: [LSig (GhcPass 'Renamed)] -> Name -> [Name]
mkScopedTvFn [LSig (GhcPass 'Renamed)]
sigs = \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 (GhcPass 'Renamed)
-> Maybe ([GenLocated SrcSpanAnnN Name], [Name]))
-> [LSig (GhcPass 'Renamed)] -> NameEnv [Name]
forall a.
(LSig (GhcPass 'Renamed)
-> Maybe ([GenLocated SrcSpanAnnN Name], a))
-> [LSig (GhcPass 'Renamed)] -> NameEnv a
mkHsSigEnv LSig (GhcPass 'Renamed)
-> Maybe ([GenLocated SrcSpanAnnN Name], [Name])
get_scoped_tvs [LSig (GhcPass 'Renamed)]
sigs
get_scoped_tvs :: LSig GhcRn -> Maybe ([LocatedN Name], [Name])
get_scoped_tvs :: LSig (GhcPass 'Renamed)
-> Maybe ([GenLocated SrcSpanAnnN Name], [Name])
get_scoped_tvs (L SrcSpanAnnA
_ (ClassOpSig XClassOpSig (GhcPass 'Renamed)
_ Bool
_ [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
names LHsSigType (GhcPass 'Renamed)
sig_ty))
= ([GenLocated SrcSpanAnnN Name], [Name])
-> Maybe ([GenLocated SrcSpanAnnN Name], [Name])
forall a. a -> Maybe a
Just ([XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
names, LHsSigType (GhcPass 'Renamed) -> [Name]
hsScopedTvs LHsSigType (GhcPass 'Renamed)
sig_ty)
get_scoped_tvs (L SrcSpanAnnA
_ (TypeSig XTypeSig (GhcPass 'Renamed)
_ [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
names LHsSigWcType (GhcPass 'Renamed)
sig_ty))
= ([GenLocated SrcSpanAnnN Name], [Name])
-> Maybe ([GenLocated SrcSpanAnnN Name], [Name])
forall a. a -> Maybe a
Just ([XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
names, LHsSigWcType (GhcPass 'Renamed) -> [Name]
hsWcScopedTvs LHsSigWcType (GhcPass 'Renamed)
sig_ty)
get_scoped_tvs (L SrcSpanAnnA
_ (PatSynSig XPatSynSig (GhcPass 'Renamed)
_ [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
names LHsSigType (GhcPass 'Renamed)
sig_ty))
= ([GenLocated SrcSpanAnnN Name], [Name])
-> Maybe ([GenLocated SrcSpanAnnN Name], [Name])
forall a. a -> Maybe a
Just ([XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
names, LHsSigType (GhcPass 'Renamed) -> [Name]
hsScopedTvs LHsSigType (GhcPass 'Renamed)
sig_ty)
get_scoped_tvs LSig (GhcPass 'Renamed)
_ = Maybe ([GenLocated SrcSpanAnnN Name], [Name])
forall a. Maybe a
Nothing
makeMiniFixityEnv :: [LFixitySig GhcPs] -> RnM MiniFixityEnv
makeMiniFixityEnv :: [LFixitySig GhcPs] -> RnM MiniFixityEnv
makeMiniFixityEnv [LFixitySig GhcPs]
decls = (MiniFixityEnv
-> GenLocated SrcSpanAnnA (FixitySig GhcPs) -> RnM MiniFixityEnv)
-> MiniFixityEnv
-> [GenLocated SrcSpanAnnA (FixitySig GhcPs)]
-> RnM MiniFixityEnv
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM MiniFixityEnv -> LFixitySig GhcPs -> RnM MiniFixityEnv
MiniFixityEnv
-> GenLocated SrcSpanAnnA (FixitySig GhcPs) -> RnM MiniFixityEnv
add_one_sig MiniFixityEnv
forall a. FastStringEnv a
emptyFsEnv [LFixitySig GhcPs]
[GenLocated SrcSpanAnnA (FixitySig GhcPs)]
decls
where
add_one_sig :: MiniFixityEnv -> LFixitySig GhcPs -> RnM MiniFixityEnv
add_one_sig :: MiniFixityEnv -> LFixitySig GhcPs -> RnM MiniFixityEnv
add_one_sig MiniFixityEnv
env (L SrcSpanAnnA
loc (FixitySig XFixitySig GhcPs
_ [LIdP GhcPs]
names Fixity
fixity)) =
(MiniFixityEnv
-> (SrcSpan, SrcSpan, RdrName, Fixity) -> RnM MiniFixityEnv)
-> MiniFixityEnv
-> [(SrcSpan, SrcSpan, RdrName, Fixity)]
-> RnM MiniFixityEnv
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
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 [ (SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc,SrcSpanAnnN -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
name_loc,RdrName
name,Fixity
fixity)
| L SrcSpanAnnN
name_loc RdrName
name <- [LIdP GhcPs]
[LocatedN RdrName]
names ]
add_one :: FastStringEnv (GenLocated SrcSpan e)
-> (SrcSpan, SrcSpan, RdrName, e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
add_one FastStringEnv (GenLocated SrcSpan e)
env (SrcSpan
loc, SrcSpan
name_loc, RdrName
name,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
Maybe (GenLocated SrcSpan e)
Nothing -> FastStringEnv (GenLocated SrcSpan e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 SrcSpan
loc' e
_) -> do
{ SrcSpan
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
SrcSpan -> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErrAt SrcSpan
name_loc (SrcSpan -> RdrName -> TcRnMessage
dupFixityDecl SrcSpan
loc' RdrName
name)
; FastStringEnv (GenLocated SrcSpan e)
-> IOEnv
(Env TcGblEnv TcLclEnv) (FastStringEnv (GenLocated SrcSpan e))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return FastStringEnv (GenLocated SrcSpan e)
env}
}
dupFixityDecl :: SrcSpan -> RdrName -> TcRnMessage
dupFixityDecl :: SrcSpan -> RdrName -> TcRnMessage
dupFixityDecl SrcSpan
loc RdrName
rdr_name
= DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Multiple fixity declarations for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name),
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"also at " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr SrcSpan
loc]
rnPatSynBind :: (Name -> [Name])
-> PatSynBind GhcRn GhcPs
-> RnM (PatSynBind GhcRn GhcRn, [Name], Uses)
rnPatSynBind :: (Name -> [Name])
-> PatSynBind (GhcPass 'Renamed) GhcPs
-> RnM
(PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
rnPatSynBind Name -> [Name]
sig_fn bind :: PatSynBind (GhcPass 'Renamed) GhcPs
bind@(PSB { psb_id :: forall idL idR. PatSynBind idL idR -> LIdP idL
psb_id = L SrcSpanAnnN
l Name
name
, psb_args :: forall idL idR. PatSynBind idL idR -> HsPatSynDetails idR
psb_args = HsPatSynDetails 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
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
pattern_synonym_ok (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr TcRnMessage
patternSynonymErr)
; let scoped_tvs :: [Name]
scoped_tvs = Name -> [Name]
sig_fn Name
name
; ((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
pat', HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]
details'), NameSet
fvs1) <- [Name]
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV [Name]
scoped_tvs (RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet))
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a b. (a -> b) -> a -> b
$
HsMatchContext (GhcPass 'Renamed)
-> LPat GhcPs
-> (LPat (GhcPass 'Renamed)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet))
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a.
HsMatchContext (GhcPass 'Renamed)
-> LPat GhcPs
-> (LPat (GhcPass 'Renamed) -> RnM (a, NameSet))
-> RnM (a, NameSet)
rnPat HsMatchContext (GhcPass 'Renamed)
forall p. HsMatchContext p
PatSyn LPat GhcPs
pat ((LPat (GhcPass 'Renamed)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet))
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet))
-> (LPat (GhcPass 'Renamed)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet))
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a b. (a -> b) -> a -> b
$ \LPat (GhcPass 'Renamed)
pat' ->
case HsPatSynDetails GhcPs
details of
PrefixCon [Void]
_ [LIdP GhcPs]
vars ->
do { [LocatedN RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupRdrNamesN [LIdP GhcPs]
[LocatedN RdrName]
vars
; [GenLocated SrcSpanAnnN Name]
names <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> [LocatedN RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupPatSynBndr [LIdP GhcPs]
[LocatedN RdrName]
vars
; ((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( (LPat (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
pat', [Void]
-> [GenLocated SrcSpanAnnN Name]
-> HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [Void]
noTypeArgs [GenLocated SrcSpanAnnN Name]
names)
, [Name] -> NameSet
mkFVs ((GenLocated SrcSpanAnnN Name -> Name)
-> [GenLocated SrcSpanAnnN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc [GenLocated SrcSpanAnnN Name]
names)) }
InfixCon LIdP GhcPs
var1 LIdP GhcPs
var2 ->
do { [LocatedN RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupRdrNames [LIdP GhcPs
LocatedN RdrName
var1, LIdP GhcPs
LocatedN RdrName
var2]
; GenLocated SrcSpanAnnN Name
name1 <- LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupPatSynBndr LIdP GhcPs
LocatedN RdrName
var1
; GenLocated SrcSpanAnnN Name
name2 <- LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupPatSynBndr LIdP GhcPs
LocatedN RdrName
var2
; ((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( (LPat (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
pat', GenLocated SrcSpanAnnN Name
-> GenLocated SrcSpanAnnN Name
-> HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]
forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon GenLocated SrcSpanAnnN Name
name1 GenLocated SrcSpanAnnN Name
name2)
, [Name] -> NameSet
mkFVs ((GenLocated SrcSpanAnnN Name -> Name)
-> [GenLocated SrcSpanAnnN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc [GenLocated SrcSpanAnnN Name
name1, GenLocated SrcSpanAnnN Name
name2])) }
RecCon [RecordPatSynField GhcPs]
vars ->
do { [LocatedN RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupRdrNames ((RecordPatSynField GhcPs -> LocatedN RdrName)
-> [RecordPatSynField GhcPs] -> [LocatedN RdrName]
forall a b. (a -> b) -> [a] -> [b]
map (FieldOcc GhcPs -> XRec GhcPs RdrName
FieldOcc GhcPs -> LocatedN RdrName
forall pass. FieldOcc pass -> XRec pass RdrName
foLabel (FieldOcc GhcPs -> LocatedN RdrName)
-> (RecordPatSynField GhcPs -> FieldOcc GhcPs)
-> RecordPatSynField GhcPs
-> LocatedN RdrName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField GhcPs -> FieldOcc GhcPs
forall pass. RecordPatSynField pass -> FieldOcc pass
recordPatSynField) [RecordPatSynField GhcPs]
vars)
; [FieldLabel]
fls <- Name -> RnM [FieldLabel]
lookupConstructorFields Name
name
; let fld_env :: FastStringEnv FieldLabel
fld_env = [(FastString, FieldLabel)] -> FastStringEnv FieldLabel
forall a. [(FastString, a)] -> FastStringEnv a
mkFsEnv [ (FieldLabelString -> FastString
field_label (FieldLabelString -> FastString) -> FieldLabelString -> FastString
forall a b. (a -> b) -> a -> b
$ FieldLabel -> FieldLabelString
flLabel FieldLabel
fl, FieldLabel
fl) | FieldLabel
fl <- [FieldLabel]
fls ]
; let rnRecordPatSynField :: RecordPatSynField GhcPs
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (GhcPass 'Renamed))
rnRecordPatSynField
(RecordPatSynField { recordPatSynField :: forall pass. RecordPatSynField pass -> FieldOcc pass
recordPatSynField = FieldOcc GhcPs
visible
, recordPatSynPatVar :: forall pass. RecordPatSynField pass -> LIdP pass
recordPatSynPatVar = LIdP GhcPs
hidden })
= do { let visible' :: FieldOcc (GhcPass 'Renamed)
visible' = FastStringEnv FieldLabel
-> FieldOcc GhcPs -> FieldOcc (GhcPass 'Renamed)
lookupField FastStringEnv FieldLabel
fld_env FieldOcc GhcPs
visible
; GenLocated SrcSpanAnnN Name
hidden' <- LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupPatSynBndr LIdP GhcPs
LocatedN RdrName
hidden
; RecordPatSynField (GhcPass 'Renamed)
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (RecordPatSynField (GhcPass 'Renamed)
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (GhcPass 'Renamed)))
-> RecordPatSynField (GhcPass 'Renamed)
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ RecordPatSynField { recordPatSynField :: FieldOcc (GhcPass 'Renamed)
recordPatSynField = FieldOcc (GhcPass 'Renamed)
visible'
, recordPatSynPatVar :: XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
recordPatSynPatVar = XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
GenLocated SrcSpanAnnN Name
hidden' } }
; [RecordPatSynField (GhcPass 'Renamed)]
names <- (RecordPatSynField GhcPs
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (GhcPass 'Renamed)))
-> [RecordPatSynField GhcPs]
-> IOEnv
(Env TcGblEnv TcLclEnv) [RecordPatSynField (GhcPass 'Renamed)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM RecordPatSynField GhcPs
-> IOEnv
(Env TcGblEnv TcLclEnv) (RecordPatSynField (GhcPass 'Renamed))
rnRecordPatSynField [RecordPatSynField GhcPs]
vars
; ((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
-> RnM
((GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)),
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( (LPat (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
pat', [RecordPatSynField (GhcPass 'Renamed)]
-> HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]
forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon [RecordPatSynField (GhcPass 'Renamed)]
names)
, [Name] -> NameSet
mkFVs ((RecordPatSynField (GhcPass 'Renamed) -> Name)
-> [RecordPatSynField (GhcPass 'Renamed)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnN Name -> Name)
-> (RecordPatSynField (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnN Name)
-> RecordPatSynField (GhcPass 'Renamed)
-> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField (GhcPass 'Renamed)
-> XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
RecordPatSynField (GhcPass 'Renamed) -> GenLocated SrcSpanAnnN Name
forall pass. RecordPatSynField pass -> LIdP pass
recordPatSynPatVar) [RecordPatSynField (GhcPass 'Renamed)]
names)) }
; (HsPatSynDir (GhcPass 'Renamed)
dir', NameSet
fvs2) <- case HsPatSynDir GhcPs
dir of
HsPatSynDir GhcPs
Unidirectional -> (HsPatSynDir (GhcPass 'Renamed), NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsPatSynDir (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsPatSynDir (GhcPass 'Renamed)
forall id. HsPatSynDir id
Unidirectional, NameSet
emptyFVs)
HsPatSynDir GhcPs
ImplicitBidirectional -> (HsPatSynDir (GhcPass 'Renamed), NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsPatSynDir (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsPatSynDir (GhcPass 'Renamed)
forall id. HsPatSynDir id
ImplicitBidirectional, NameSet
emptyFVs)
ExplicitBidirectional MatchGroup GhcPs (LHsExpr GhcPs)
mg ->
do { (MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
mg', NameSet
fvs) <- [Name]
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV [Name]
scoped_tvs (RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet))
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall a b. (a -> b) -> a -> b
$
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (HsExpr GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)), NameSet))
-> MatchGroup GhcPs (LocatedA (HsExpr GhcPs))
-> RnM
(MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
(Outputable (body GhcPs), AnnoBody body) =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> MatchGroup GhcPs (LocatedA (body GhcPs))
-> RnM
(MatchGroup
(GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatchGroup (XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
-> HsMatchContext (GhcPass 'Renamed)
forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs (SrcSpanAnnN -> Name -> GenLocated SrcSpanAnnN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
name))
LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), NameSet)
LocatedA (HsExpr GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)), NameSet)
rnLExpr MatchGroup GhcPs (LHsExpr GhcPs)
MatchGroup GhcPs (LocatedA (HsExpr GhcPs))
mg
; (HsPatSynDir (GhcPass 'Renamed), NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv) (HsPatSynDir (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MatchGroup (GhcPass 'Renamed) (LHsExpr (GhcPass 'Renamed))
-> HsPatSynDir (GhcPass 'Renamed)
forall id. MatchGroup id (LHsExpr id) -> HsPatSynDir id
ExplicitBidirectional MatchGroup (GhcPass 'Renamed) (LHsExpr (GhcPass 'Renamed))
MatchGroup
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
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 (GhcPass 'Renamed) (GhcPass 'Renamed)
bind' = PatSynBind (GhcPass 'Renamed) GhcPs
bind{ psb_args = details'
, psb_def = pat'
, psb_dir = dir'
, psb_ext = fvs' }
selector_names :: [Name]
selector_names = case HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]
details' of
RecCon [RecordPatSynField (GhcPass 'Renamed)]
names ->
(RecordPatSynField (GhcPass 'Renamed) -> Name)
-> [RecordPatSynField (GhcPass 'Renamed)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (FieldOcc (GhcPass 'Renamed) -> XCFieldOcc (GhcPass 'Renamed)
FieldOcc (GhcPass 'Renamed) -> Name
forall pass. FieldOcc pass -> XCFieldOcc pass
foExt (FieldOcc (GhcPass 'Renamed) -> Name)
-> (RecordPatSynField (GhcPass 'Renamed)
-> FieldOcc (GhcPass 'Renamed))
-> RecordPatSynField (GhcPass 'Renamed)
-> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField (GhcPass 'Renamed) -> FieldOcc (GhcPass 'Renamed)
forall pass. RecordPatSynField pass -> FieldOcc pass
recordPatSynField) [RecordPatSynField (GhcPass 'Renamed)]
names
HsConDetails
Void
(GenLocated SrcSpanAnnN Name)
[RecordPatSynField (GhcPass 'Renamed)]
_ -> []
; NameSet
fvs' NameSet
-> RnM
(PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a b. a -> b -> b
`seq`
(PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
-> RnM
(PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed), [Name], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)
bind', Name
name Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: [Name]
selector_names , NameSet
fvs1)
}
where
lookupPatSynBndr :: GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupPatSynBndr = (RdrName -> TcM Name)
-> GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
forall a b ann.
(a -> TcM b)
-> GenLocated (SrcSpanAnn' ann) a
-> TcRn (GenLocated (SrcSpanAnn' ann) b)
wrapLocMA RdrName -> TcM Name
lookupLocalOccRn
patternSynonymErr :: TcRnMessage
patternSynonymErr :: TcRnMessage
patternSynonymErr
= DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
SDoc -> ConTag -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Illegal pattern synonym declaration")
ConTag
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use -XPatternSynonyms to enable this extension")
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 (GhcPass 'Renamed), [LSig (GhcPass 'Renamed)], NameSet)
rnMethodBinds Bool
is_cls_decl Name
cls [Name]
ktv_names LHsBindsLR GhcPs GhcPs
binds [LSig GhcPs]
sigs
= do { [LocatedN RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupRdrNamesN (LHsBindsLR GhcPs GhcPs -> [LIdP GhcPs]
forall idL idR. UnXRec idL => LHsBindsLR idL idR -> [LIdP idL]
collectMethodBinders LHsBindsLR GhcPs GhcPs
binds)
; Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
binds' <- (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)))
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> b -> m b) -> b -> t a -> m b
foldrM (Bool
-> Name
-> LHsBindLR GhcPs GhcPs
-> LHsBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
rnMethodBindLHS Bool
is_cls_decl Name
cls) Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
forall a. Bag a
emptyBag LHsBindsLR GhcPs GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
binds
; let ([LSig GhcPs]
spec_inst_prags, [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 p. UnXRec p => LSig p -> Bool
isSpecInstLSig [LSig GhcPs]
sigs
bound_nms :: NameSet
bound_nms = [Name] -> NameSet
mkNameSet (CollectFlag (GhcPass 'Renamed)
-> LHsBindsLR (GhcPass 'Renamed) GhcPs -> [IdP (GhcPass 'Renamed)]
forall p idR.
CollectPass p =>
CollectFlag p -> LHsBindsLR p idR -> [IdP p]
collectHsBindsBinders CollectFlag (GhcPass 'Renamed)
forall p. CollectFlag p
CollNoDictBinders LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
binds')
sig_ctxt :: HsSigCtxt
sig_ctxt | Bool
is_cls_decl = Name -> HsSigCtxt
ClsDeclCtxt Name
cls
| Bool
otherwise = NameSet -> HsSigCtxt
InstDeclCtxt NameSet
bound_nms
; ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
spec_inst_prags', NameSet
sip_fvs) <- HsSigCtxt
-> [LSig GhcPs] -> RnM ([LSig (GhcPass 'Renamed)], NameSet)
renameSigs HsSigCtxt
sig_ctxt [LSig GhcPs]
spec_inst_prags
; ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
other_sigs', NameSet
sig_fvs) <- [Name]
-> RnM ([LSig (GhcPass 'Renamed)], NameSet)
-> RnM ([LSig (GhcPass 'Renamed)], NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindLocalNamesFV [Name]
ktv_names (RnM ([LSig (GhcPass 'Renamed)], NameSet)
-> RnM ([LSig (GhcPass 'Renamed)], NameSet))
-> RnM ([LSig (GhcPass 'Renamed)], NameSet)
-> RnM ([LSig (GhcPass 'Renamed)], NameSet)
forall a b. (a -> b) -> a -> b
$
HsSigCtxt
-> [LSig GhcPs] -> RnM ([LSig (GhcPass 'Renamed)], NameSet)
renameSigs HsSigCtxt
sig_ctxt [LSig GhcPs]
other_sigs
; (Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)))
binds'', NameSet
bind_fvs) <- [Name]
-> RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
-> RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
forall a. [Name] -> RnM (a, NameSet) -> RnM (a, NameSet)
bindSigTyVarsFV [Name]
ktv_names (RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
-> RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet))
-> RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
-> RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
forall a b. (a -> b) -> a -> b
$
do { Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
binds_w_dus <- (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM ((Name -> [Name])
-> LHsBindLR (GhcPass 'Renamed) GhcPs
-> RnM (LHsBind (GhcPass 'Renamed), [Name], NameSet)
rnLBind ([LSig (GhcPass 'Renamed)] -> Name -> [Name]
mkScopedTvFn [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
other_sigs')) Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
binds'
; let bind_fvs :: NameSet
bind_fvs = ((GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> NameSet -> NameSet)
-> NameSet
-> Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> NameSet
forall a b. (a -> b -> b) -> b -> Bag a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
_,[Name]
_,NameSet
fv1) NameSet
fv2 -> NameSet
fv1 NameSet -> NameSet -> NameSet
`plusFV` NameSet
fv2)
NameSet
emptyFVs Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
binds_w_dus
; (Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
-> RnM
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (((GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)))
-> Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)))
forall a b. (a -> b) -> Bag a -> Bag b
mapBag (GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
-> GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
forall a b c. (a, b, c) -> a
fstOf3 Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)),
[Name], NameSet)
binds_w_dus, NameSet
bind_fvs) }
; (Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))], NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))),
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( Bag
(GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)))
binds'', [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
spec_inst_prags' [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
other_sigs'
, NameSet
sig_fvs NameSet -> NameSet -> NameSet
`plusFV` NameSet
sip_fvs NameSet -> NameSet -> NameSet
`plusFV` NameSet
bind_fvs) }
rnMethodBindLHS :: Bool -> Name
-> LHsBindLR GhcPs GhcPs
-> LHsBindsLR GhcRn GhcPs
-> RnM (LHsBindsLR GhcRn GhcPs)
rnMethodBindLHS :: Bool
-> Name
-> LHsBindLR GhcPs GhcPs
-> LHsBindsLR (GhcPass 'Renamed) GhcPs
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
rnMethodBindLHS Bool
_ Name
cls (L SrcSpanAnnA
loc bind :: HsBindLR GhcPs GhcPs
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP GhcPs
name })) LHsBindsLR (GhcPass 'Renamed) GhcPs
rest
= SrcSpanAnnA
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs))
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
-> RnM (LHsBindsLR (GhcPass 'Renamed) GhcPs)
forall a b. (a -> b) -> a -> b
$ do
do { GenLocated SrcSpanAnnN Name
sel_name <- (RdrName -> TcM Name)
-> LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall a b ann.
(a -> TcM b)
-> GenLocated (SrcSpanAnn' ann) a
-> TcRn (GenLocated (SrcSpanAnn' ann) b)
wrapLocMA (Name -> SDoc -> RdrName -> TcM Name
lookupInstDeclBndr Name
cls (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"method")) LIdP GhcPs
LocatedN RdrName
name
; let bind' :: HsBindLR (GhcPass 'Renamed) GhcPs
bind' = HsBindLR GhcPs GhcPs
bind { fun_id = sel_name, fun_ext = noExtField }
; Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> HsBindLR (GhcPass 'Renamed) GhcPs
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc HsBindLR (GhcPass 'Renamed) GhcPs
bind' GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
forall a. a -> Bag a -> Bag a
`consBag` LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
rest ) }
rnMethodBindLHS Bool
is_cls_decl Name
_ (L SrcSpanAnnA
loc HsBindLR GhcPs GhcPs
bind) LHsBindsLR (GhcPass 'Renamed) GhcPs
rest
= do { SrcSpan -> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErrAt (SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc
what SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"not allowed in" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
decl_sort
, ConTag -> SDoc -> SDoc
nest ConTag
2 (HsBindLR GhcPs GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsBindLR GhcPs GhcPs
bind) ]
; Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return LHsBindsLR (GhcPass 'Renamed) GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) GhcPs))
rest }
where
decl_sort :: SDoc
decl_sort | Bool
is_cls_decl = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"class declaration:"
| Bool
otherwise = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instance declaration:"
what :: SDoc
what = case HsBindLR GhcPs GhcPs
bind of
PatBind {} -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Pattern bindings (except simple variables)"
PatSynBind {} -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Pattern synonyms"
HsBindLR GhcPs GhcPs
_ -> String -> SDoc -> SDoc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"rnMethodBind" (HsBindLR GhcPs GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsBindLR GhcPs GhcPs
bind)
renameSigs :: HsSigCtxt
-> [LSig GhcPs]
-> RnM ([LSig GhcRn], FreeVars)
renameSigs :: HsSigCtxt
-> [LSig GhcPs] -> RnM ([LSig (GhcPass 'Renamed)], NameSet)
renameSigs HsSigCtxt
ctxt [LSig GhcPs]
sigs
= do { (NonEmpty (LocatedN RdrName, Sig GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> [NonEmpty (LocatedN RdrName, Sig GhcPs)]
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ NonEmpty (LocatedN RdrName, Sig GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) ()
dupSigDeclErr ([LSig GhcPs] -> [NonEmpty (LocatedN RdrName, Sig GhcPs)]
findDupSigs [LSig GhcPs]
sigs)
; [LSig GhcPs] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupMinimalSigs [LSig GhcPs]
sigs
; ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs', NameSet
sig_fvs) <- (GenLocated SrcSpanAnnA (Sig GhcPs)
-> RnM (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)), NameSet))
-> [GenLocated SrcSpanAnnA (Sig GhcPs)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))], NameSet)
forall (f :: * -> *) a b.
Traversable f =>
(a -> RnM (b, NameSet)) -> f a -> RnM (f b, NameSet)
mapFvRn ((Sig GhcPs -> TcM (Sig (GhcPass 'Renamed), NameSet))
-> GenLocated SrcSpanAnnA (Sig GhcPs)
-> RnM (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)), NameSet)
forall a b c ann.
(a -> TcM (b, c))
-> GenLocated (SrcSpanAnn' ann) a
-> TcM (GenLocated (SrcSpanAnn' ann) b, c)
wrapLocFstMA (HsSigCtxt -> Sig GhcPs -> TcM (Sig (GhcPass 'Renamed), NameSet)
renameSig HsSigCtxt
ctxt)) [LSig GhcPs]
[GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs
; let ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
good_sigs, [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
bad_sigs) = (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)) -> Bool)
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))],
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (HsSigCtxt -> LSig (GhcPass 'Renamed) -> Bool
forall (a :: Pass). HsSigCtxt -> LSig (GhcPass a) -> Bool
okHsSig HsSigCtxt
ctxt) [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs'
; (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LSig (GhcPass 'Renamed) -> IOEnv (Env TcGblEnv TcLclEnv) ()
GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> IOEnv (Env TcGblEnv TcLclEnv) ()
misplacedSigErr [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
bad_sigs
; ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))], NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
good_sigs, NameSet
sig_fvs) }
renameSig :: HsSigCtxt -> Sig GhcPs -> RnM (Sig GhcRn, FreeVars)
renameSig :: HsSigCtxt -> Sig GhcPs -> TcM (Sig (GhcPass 'Renamed), NameSet)
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(TypeSig XTypeSig GhcPs
_ [LIdP GhcPs]
vs LHsSigWcType GhcPs
ty)
= do { [GenLocated SrcSpanAnnN Name]
new_vs <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> [LocatedN RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig) [LIdP GhcPs]
[LocatedN RdrName]
vs
; let doc :: HsDocContext
doc = SDoc -> HsDocContext
TypeSigCtx ([LocatedN RdrName] -> SDoc
ppr_sig_bndrs [LIdP GhcPs]
[LocatedN RdrName]
vs)
; (HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
new_ty, NameSet
fvs) <- HsDocContext
-> LHsSigWcType GhcPs
-> RnM (LHsSigWcType (GhcPass 'Renamed), NameSet)
rnHsSigWcType HsDocContext
doc LHsSigWcType GhcPs
ty
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XTypeSig (GhcPass 'Renamed)
-> [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
-> LHsSigWcType (GhcPass 'Renamed)
-> Sig (GhcPass 'Renamed)
forall pass.
XTypeSig pass -> [LIdP pass] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig (GhcPass 'Renamed)
EpAnn AnnSig
forall a. EpAnn a
noAnn [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
new_vs LHsSigWcType (GhcPass 'Renamed)
HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
new_ty, NameSet
fvs) }
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(ClassOpSig XClassOpSig GhcPs
_ Bool
is_deflt [LIdP GhcPs]
vs 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
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
is_deflt Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
defaultSigs_on) (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr (Sig GhcPs -> TcRnMessage
defaultSigErr Sig GhcPs
sig)
; (LocatedN RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> [LocatedN RdrName] -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LocatedN RdrName -> IOEnv (Env TcGblEnv TcLclEnv) ()
warnForallIdentifier [LIdP GhcPs]
[LocatedN RdrName]
vs
; [GenLocated SrcSpanAnnN Name]
new_v <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> [LocatedN RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig) [LIdP GhcPs]
[LocatedN RdrName]
vs
; (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_ty, NameSet
fvs) <- HsDocContext
-> TypeOrKind
-> LHsSigType GhcPs
-> RnM (LHsSigType (GhcPass 'Renamed), NameSet)
rnHsSigType HsDocContext
ty_ctxt TypeOrKind
TypeLevel LHsSigType GhcPs
ty
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XClassOpSig (GhcPass 'Renamed)
-> Bool
-> [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
-> LHsSigType (GhcPass 'Renamed)
-> Sig (GhcPass 'Renamed)
forall pass.
XClassOpSig pass
-> Bool -> [LIdP pass] -> LHsSigType pass -> Sig pass
ClassOpSig XClassOpSig (GhcPass 'Renamed)
EpAnn AnnSig
forall a. EpAnn a
noAnn Bool
is_deflt [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
new_v LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_ty, NameSet
fvs) }
where
(LIdP GhcPs
v1:[LIdP GhcPs]
_) = [LIdP GhcPs]
vs
ty_ctxt :: HsDocContext
ty_ctxt = SDoc -> HsDocContext
GenericCtx (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"a class method signature for"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (LocatedN RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr LIdP GhcPs
LocatedN RdrName
v1))
renameSig HsSigCtxt
_ (SpecInstSig (EpAnn [AddEpAnn]
_, SourceText
src) LHsSigType GhcPs
ty)
= do { HsDocContext
-> Maybe SDoc
-> LHsSigType GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) ()
checkInferredVars HsDocContext
doc Maybe SDoc
inf_msg LHsSigType GhcPs
ty
; (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_ty, NameSet
fvs) <- HsDocContext
-> TypeOrKind
-> LHsSigType GhcPs
-> RnM (LHsSigType (GhcPass 'Renamed), NameSet)
rnHsSigType HsDocContext
doc TypeOrKind
TypeLevel LHsSigType GhcPs
ty
; HsDocContext
-> SDoc
-> LHsType (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) ()
addNoNestedForallsContextsErr HsDocContext
doc (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"SPECIALISE instance type")
(LHsSigType (GhcPass 'Renamed) -> LHsType (GhcPass 'Renamed)
forall (p :: Pass). LHsSigType (GhcPass p) -> LHsType (GhcPass p)
getLHsInstDeclHead LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_ty)
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XSpecInstSig (GhcPass 'Renamed)
-> LHsSigType (GhcPass 'Renamed) -> Sig (GhcPass 'Renamed)
forall pass. XSpecInstSig pass -> LHsSigType pass -> Sig pass
SpecInstSig (EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn, SourceText
src) LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_ty,NameSet
fvs) }
where
doc :: HsDocContext
doc = HsDocContext
SpecInstSigCtx
inf_msg :: Maybe SDoc
inf_msg = SDoc -> Maybe SDoc
forall a. a -> Maybe a
Just (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Inferred type variables are not allowed")
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(SpecSig XSpecSig GhcPs
_ LIdP GhcPs
v [LHsSigType GhcPs]
tys InlinePragma
inl)
= do { GenLocated SrcSpanAnnN Name
new_v <- case HsSigCtxt
ctxt of
TopSigCtxt {} -> LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupLocatedOccRn LIdP GhcPs
LocatedN RdrName
v
HsSigCtxt
_ -> HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig LIdP GhcPs
LocatedN RdrName
v
; ([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
new_ty, NameSet
fvs) <- (([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
-> GenLocated SrcSpanAnnA (HsSigType GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet))
-> ([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))],
NameSet)
-> [GenLocated SrcSpanAnnA (HsSigType GhcPs)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM ([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
-> GenLocated SrcSpanAnnA (HsSigType GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
do_one ([],NameSet
emptyFVs) [LHsSigType GhcPs]
[GenLocated SrcSpanAnnA (HsSigType GhcPs)]
tys
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XSpecSig (GhcPass 'Renamed)
-> XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
-> [LHsSigType (GhcPass 'Renamed)]
-> InlinePragma
-> Sig (GhcPass 'Renamed)
forall pass.
XSpecSig pass
-> LIdP pass -> [LHsSigType pass] -> InlinePragma -> Sig pass
SpecSig XSpecSig (GhcPass 'Renamed)
EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
GenLocated SrcSpanAnnN Name
new_v [LHsSigType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
new_ty InlinePragma
inl, NameSet
fvs) }
where
ty_ctxt :: HsDocContext
ty_ctxt = SDoc -> HsDocContext
GenericCtx (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"a SPECIALISE signature for"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (LocatedN RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr LIdP GhcPs
LocatedN RdrName
v))
do_one :: ([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
-> GenLocated SrcSpanAnnA (HsSigType GhcPs)
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
do_one ([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
tys,NameSet
fvs) GenLocated SrcSpanAnnA (HsSigType GhcPs)
ty
= do { (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_ty, NameSet
fvs_ty) <- HsDocContext
-> TypeOrKind
-> LHsSigType GhcPs
-> RnM (LHsSigType (GhcPass 'Renamed), NameSet)
rnHsSigType HsDocContext
ty_ctxt TypeOrKind
TypeLevel LHsSigType GhcPs
GenLocated SrcSpanAnnA (HsSigType GhcPs)
ty
; ([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))], NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
new_tyGenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> [GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
-> [GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
forall a. a -> [a] -> [a]
:[GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
tys, NameSet
fvs_ty NameSet -> NameSet -> NameSet
`plusFV` NameSet
fvs) }
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(InlineSig XInlineSig GhcPs
_ LIdP GhcPs
v InlinePragma
s)
= do { GenLocated SrcSpanAnnN Name
new_v <- HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig LIdP GhcPs
LocatedN RdrName
v
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XInlineSig (GhcPass 'Renamed)
-> XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
-> InlinePragma
-> Sig (GhcPass 'Renamed)
forall pass.
XInlineSig pass -> LIdP pass -> InlinePragma -> Sig pass
InlineSig XInlineSig (GhcPass 'Renamed)
EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
GenLocated SrcSpanAnnN Name
new_v InlinePragma
s, NameSet
emptyFVs) }
renameSig HsSigCtxt
ctxt (FixSig XFixSig GhcPs
_ FixitySig GhcPs
fsig)
= do { FixitySig (GhcPass 'Renamed)
new_fsig <- HsSigCtxt -> FixitySig GhcPs -> RnM (FixitySig (GhcPass 'Renamed))
rnSrcFixityDecl HsSigCtxt
ctxt FixitySig GhcPs
fsig
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XFixSig (GhcPass 'Renamed)
-> FixitySig (GhcPass 'Renamed) -> Sig (GhcPass 'Renamed)
forall pass. XFixSig pass -> FixitySig pass -> Sig pass
FixSig XFixSig (GhcPass 'Renamed)
EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn FixitySig (GhcPass 'Renamed)
new_fsig, NameSet
emptyFVs) }
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(MinimalSig (EpAnn [AddEpAnn]
_, SourceText
s) (L SrcSpanAnnL
l BooleanFormula (LIdP GhcPs)
bf))
= do BooleanFormula (GenLocated SrcSpanAnnN Name)
new_bf <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> BooleanFormula (LocatedN RdrName)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(BooleanFormula (GenLocated SrcSpanAnnN Name))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> BooleanFormula a -> f (BooleanFormula b)
traverse (HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig) BooleanFormula (LIdP GhcPs)
BooleanFormula (LocatedN RdrName)
bf
(Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XMinimalSig (GhcPass 'Renamed)
-> LBooleanFormula
(XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed)))
-> Sig (GhcPass 'Renamed)
forall pass.
XMinimalSig pass -> LBooleanFormula (LIdP pass) -> Sig pass
MinimalSig (EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn, SourceText
s) (SrcSpanAnnL
-> BooleanFormula (GenLocated SrcSpanAnnN Name)
-> GenLocated
SrcSpanAnnL (BooleanFormula (GenLocated SrcSpanAnnN Name))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
l BooleanFormula (GenLocated SrcSpanAnnN Name)
new_bf), NameSet
emptyFVs)
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(PatSynSig XPatSynSig GhcPs
_ [LIdP GhcPs]
vs LHsSigType GhcPs
ty)
= do { [GenLocated SrcSpanAnnN Name]
new_vs <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> [LocatedN RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig) [LIdP GhcPs]
[LocatedN RdrName]
vs
; (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
ty', NameSet
fvs) <- HsDocContext
-> TypeOrKind
-> LHsSigType GhcPs
-> RnM (LHsSigType (GhcPass 'Renamed), NameSet)
rnHsSigType HsDocContext
ty_ctxt TypeOrKind
TypeLevel LHsSigType GhcPs
ty
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatSynSig (GhcPass 'Renamed)
-> [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
-> LHsSigType (GhcPass 'Renamed)
-> Sig (GhcPass 'Renamed)
forall pass.
XPatSynSig pass -> [LIdP pass] -> LHsSigType pass -> Sig pass
PatSynSig XPatSynSig (GhcPass 'Renamed)
EpAnn AnnSig
forall a. EpAnn a
noAnn [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
new_vs LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
ty', NameSet
fvs) }
where
ty_ctxt :: HsDocContext
ty_ctxt = SDoc -> HsDocContext
GenericCtx (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"a pattern synonym signature for"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [LocatedN RdrName] -> SDoc
ppr_sig_bndrs [LIdP GhcPs]
[LocatedN RdrName]
vs)
renameSig HsSigCtxt
ctxt sig :: Sig GhcPs
sig@(SCCFunSig (EpAnn [AddEpAnn]
_, SourceText
st) LIdP GhcPs
v Maybe (XRec GhcPs StringLiteral)
s)
= do { GenLocated SrcSpanAnnN Name
new_v <- HsSigCtxt
-> Sig GhcPs
-> LocatedN RdrName
-> RnM (GenLocated SrcSpanAnnN Name)
lookupSigOccRnN HsSigCtxt
ctxt Sig GhcPs
sig LIdP GhcPs
LocatedN RdrName
v
; (Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XSCCFunSig (GhcPass 'Renamed)
-> XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
-> Maybe (XRec (GhcPass 'Renamed) StringLiteral)
-> Sig (GhcPass 'Renamed)
forall pass.
XSCCFunSig pass
-> LIdP pass -> Maybe (XRec pass StringLiteral) -> Sig pass
SCCFunSig (EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn, SourceText
st) XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))
GenLocated SrcSpanAnnN Name
new_v Maybe (XRec GhcPs StringLiteral)
Maybe (XRec (GhcPass 'Renamed) StringLiteral)
s, NameSet
emptyFVs) }
renameSig HsSigCtxt
_ctxt sig :: Sig GhcPs
sig@(CompleteMatchSig (EpAnn [AddEpAnn]
_, SourceText
s) (L SrcSpan
l [LocatedN RdrName]
bf) Maybe (LIdP GhcPs)
mty)
= do [GenLocated SrcSpanAnnN Name]
new_bf <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> [LocatedN RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupLocatedOccRn [LocatedN RdrName]
bf
Maybe (GenLocated SrcSpanAnnN Name)
new_mty <- (LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name))
-> Maybe (LocatedN RdrName)
-> IOEnv
(Env TcGblEnv TcLclEnv) (Maybe (GenLocated SrcSpanAnnN Name))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse LocatedN RdrName -> RnM (GenLocated SrcSpanAnnN Name)
forall {ann}.
GenLocated (SrcSpanAnn' ann) RdrName
-> TcRn (GenLocated (SrcSpanAnn' ann) Name)
lookupLocatedOccRn Maybe (LIdP GhcPs)
Maybe (LocatedN RdrName)
mty
Module
this_mod <- (TcGblEnv -> Module)
-> IOEnv (Env TcGblEnv TcLclEnv) TcGblEnv
-> IOEnv (Env TcGblEnv TcLclEnv) Module
forall a b.
(a -> b)
-> IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) b
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
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((GenLocated SrcSpanAnnN Name -> Bool)
-> [GenLocated SrcSpanAnnN Name] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Module -> Name -> Bool
nameIsLocalOrFrom Module
this_mod (Name -> Bool)
-> (GenLocated SrcSpanAnnN Name -> Name)
-> GenLocated SrcSpanAnnN Name
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc) [GenLocated SrcSpanAnnN Name]
new_bf) (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
SDoc
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. SDoc -> TcM a -> TcM a
addErrCtxt (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Sig GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr Sig GhcPs
sig) (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. TcRnMessage -> TcM a
failWithTc TcRnMessage
orphanError
(Sig (GhcPass 'Renamed), NameSet)
-> TcM (Sig (GhcPass 'Renamed), NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XCompleteMatchSig (GhcPass 'Renamed)
-> XRec
(GhcPass 'Renamed)
[XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
-> Maybe (XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed)))
-> Sig (GhcPass 'Renamed)
forall pass.
XCompleteMatchSig pass
-> XRec pass [LIdP pass] -> Maybe (LIdP pass) -> Sig pass
CompleteMatchSig (EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn, SourceText
s) (SrcSpan
-> [GenLocated SrcSpanAnnN Name]
-> GenLocated SrcSpan [GenLocated SrcSpanAnnN Name]
forall l e. l -> e -> GenLocated l e
L SrcSpan
l [GenLocated SrcSpanAnnN Name]
new_bf) Maybe (XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed)))
Maybe (GenLocated SrcSpanAnnN Name)
new_mty, NameSet
emptyFVs)
where
orphanError :: TcRnMessage
orphanError :: TcRnMessage
orphanError = DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Orphan COMPLETE pragmas not supported" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"A COMPLETE pragma must mention at least one data constructor" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or pattern synonym defined in the same module."
ppr_sig_bndrs :: [LocatedN RdrName] -> SDoc
ppr_sig_bndrs :: [LocatedN RdrName] -> SDoc
ppr_sig_bndrs [LocatedN RdrName]
bs = SDoc -> SDoc
quotes ((LocatedN RdrName -> SDoc) -> [LocatedN RdrName] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas LocatedN RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LocatedN RdrName]
bs)
okHsSig :: HsSigCtxt -> LSig (GhcPass a) -> Bool
okHsSig :: forall (a :: Pass). HsSigCtxt -> LSig (GhcPass a) -> Bool
okHsSig HsSigCtxt
ctxt (L SrcSpanAnnA
_ Sig (GhcPass a)
sig)
= case (Sig (GhcPass a)
sig, HsSigCtxt
ctxt) of
(ClassOpSig {}, ClsDeclCtxt {}) -> Bool
True
(ClassOpSig {}, InstDeclCtxt {}) -> Bool
True
(ClassOpSig {}, HsSigCtxt
_) -> Bool
False
(TypeSig {}, ClsDeclCtxt {}) -> Bool
False
(TypeSig {}, InstDeclCtxt {}) -> Bool
False
(TypeSig {}, HsSigCtxt
_) -> Bool
True
(PatSynSig {}, TopSigCtxt{}) -> Bool
True
(PatSynSig {}, HsSigCtxt
_) -> Bool
False
(FixSig {}, InstDeclCtxt {}) -> Bool
False
(FixSig {}, HsSigCtxt
_) -> Bool
True
(InlineSig {}, HsBootCtxt {}) -> Bool
False
(InlineSig {}, HsSigCtxt
_) -> Bool
True
(SpecSig {}, TopSigCtxt {}) -> Bool
True
(SpecSig {}, LocalBindCtxt {}) -> Bool
True
(SpecSig {}, InstDeclCtxt {}) -> Bool
True
(SpecSig {}, HsSigCtxt
_) -> Bool
False
(SpecInstSig {}, InstDeclCtxt {}) -> Bool
True
(SpecInstSig {}, HsSigCtxt
_) -> Bool
False
(MinimalSig {}, ClsDeclCtxt {}) -> Bool
True
(MinimalSig {}, HsSigCtxt
_) -> Bool
False
(SCCFunSig {}, HsBootCtxt {}) -> Bool
False
(SCCFunSig {}, HsSigCtxt
_) -> Bool
True
(CompleteMatchSig {}, TopSigCtxt {} ) -> Bool
True
(CompleteMatchSig {}, HsSigCtxt
_) -> Bool
False
(XSig {}, TopSigCtxt {}) -> Bool
True
(XSig {}, InstDeclCtxt {}) -> Bool
True
(XSig {}, HsSigCtxt
_) -> Bool
False
findDupSigs :: [LSig GhcPs] -> [NonEmpty (LocatedN RdrName, Sig GhcPs)]
findDupSigs :: [LSig GhcPs] -> [NonEmpty (LocatedN RdrName, Sig GhcPs)]
findDupSigs [LSig GhcPs]
sigs
= ((LocatedN RdrName, Sig GhcPs)
-> (LocatedN RdrName, Sig GhcPs) -> Bool)
-> [(LocatedN RdrName, Sig GhcPs)]
-> [NonEmpty (LocatedN RdrName, Sig GhcPs)]
forall a. (a -> a -> Bool) -> [a] -> [NonEmpty a]
findDupsEq (LocatedN RdrName, Sig GhcPs)
-> (LocatedN RdrName, Sig GhcPs) -> Bool
matching_sig ((GenLocated SrcSpanAnnA (Sig GhcPs)
-> [(LocatedN RdrName, Sig GhcPs)])
-> [GenLocated SrcSpanAnnA (Sig GhcPs)]
-> [(LocatedN RdrName, Sig GhcPs)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Sig GhcPs -> [(LocatedN RdrName, Sig GhcPs)]
expand_sig (Sig GhcPs -> [(LocatedN RdrName, Sig GhcPs)])
-> (GenLocated SrcSpanAnnA (Sig GhcPs) -> Sig GhcPs)
-> GenLocated SrcSpanAnnA (Sig GhcPs)
-> [(LocatedN RdrName, Sig GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Sig GhcPs) -> Sig GhcPs
forall l e. GenLocated l e -> e
unLoc) [LSig GhcPs]
[GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs)
where
expand_sig :: Sig GhcPs -> [(LocatedN RdrName, Sig GhcPs)]
expand_sig :: Sig GhcPs -> [(LocatedN RdrName, Sig GhcPs)]
expand_sig sig :: Sig GhcPs
sig@(FixSig XFixSig GhcPs
_ (FixitySig XFixitySig GhcPs
_ [LIdP GhcPs]
ns Fixity
_)) = [LocatedN RdrName]
-> [Sig GhcPs] -> [(LocatedN RdrName, Sig GhcPs)]
forall a b. [a] -> [b] -> [(a, b)]
zip [LIdP GhcPs]
[LocatedN RdrName]
ns (Sig GhcPs -> [Sig GhcPs]
forall a. a -> [a]
repeat Sig GhcPs
sig)
expand_sig sig :: Sig GhcPs
sig@(InlineSig XInlineSig GhcPs
_ LIdP GhcPs
n InlinePragma
_) = [(LIdP GhcPs
LocatedN RdrName
n,Sig GhcPs
sig)]
expand_sig sig :: Sig GhcPs
sig@(TypeSig XTypeSig GhcPs
_ [LIdP GhcPs]
ns LHsSigWcType GhcPs
_) = [(LocatedN RdrName
n,Sig GhcPs
sig) | LocatedN RdrName
n <- [LIdP GhcPs]
[LocatedN RdrName]
ns]
expand_sig sig :: Sig GhcPs
sig@(ClassOpSig XClassOpSig GhcPs
_ Bool
_ [LIdP GhcPs]
ns LHsSigType GhcPs
_) = [(LocatedN RdrName
n,Sig GhcPs
sig) | LocatedN RdrName
n <- [LIdP GhcPs]
[LocatedN RdrName]
ns]
expand_sig sig :: Sig GhcPs
sig@(PatSynSig XPatSynSig GhcPs
_ [LIdP GhcPs]
ns LHsSigType GhcPs
_ ) = [(LocatedN RdrName
n,Sig GhcPs
sig) | LocatedN RdrName
n <- [LIdP GhcPs]
[LocatedN RdrName]
ns]
expand_sig sig :: Sig GhcPs
sig@(SCCFunSig (EpAnn [AddEpAnn]
_, SourceText
_) LIdP GhcPs
n Maybe (XRec GhcPs StringLiteral)
_) = [(LIdP GhcPs
LocatedN RdrName
n,Sig GhcPs
sig)]
expand_sig Sig GhcPs
_ = []
matching_sig :: (LocatedN RdrName, Sig GhcPs) -> (LocatedN RdrName, Sig GhcPs) -> Bool
matching_sig :: (LocatedN RdrName, Sig GhcPs)
-> (LocatedN RdrName, Sig GhcPs) -> Bool
matching_sig (L SrcSpanAnnN
_ RdrName
n1,Sig GhcPs
sig1) (L SrcSpanAnnN
_ RdrName
n2,Sig GhcPs
sig2) = RdrName
n1 RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
== RdrName
n2 Bool -> Bool -> Bool
&& Sig GhcPs -> Sig GhcPs -> Bool
forall {pass} {pass}. Sig pass -> Sig pass -> Bool
mtch Sig GhcPs
sig1 Sig GhcPs
sig2
mtch :: Sig pass -> Sig pass -> Bool
mtch (FixSig {}) (FixSig {}) = Bool
True
mtch (InlineSig {}) (InlineSig {}) = Bool
True
mtch (TypeSig {}) (TypeSig {}) = Bool
True
mtch (ClassOpSig XClassOpSig pass
_ Bool
d1 [LIdP pass]
_ LHsSigType pass
_) (ClassOpSig XClassOpSig pass
_ Bool
d2 [LIdP pass]
_ LHsSigType pass
_) = Bool
d1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
d2
mtch (PatSynSig XPatSynSig pass
_ [LIdP pass]
_ LHsSigType pass
_) (PatSynSig XPatSynSig pass
_ [LIdP pass]
_ LHsSigType pass
_) = Bool
True
mtch (SCCFunSig{}) (SCCFunSig{}) = Bool
True
mtch Sig pass
_ Sig pass
_ = Bool
False
checkDupMinimalSigs :: [LSig GhcPs] -> RnM ()
checkDupMinimalSigs :: [LSig GhcPs] -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkDupMinimalSigs [LSig GhcPs]
sigs
= case (LSig GhcPs -> Bool) -> [LSig GhcPs] -> [LSig GhcPs]
forall a. (a -> Bool) -> [a] -> [a]
filter LSig GhcPs -> Bool
forall p. UnXRec p => LSig p -> Bool
isMinimalLSig [LSig GhcPs]
sigs of
minSigs :: [LSig GhcPs]
minSigs@(LSig GhcPs
_:LSig GhcPs
_:[LSig GhcPs]
_) -> [LSig GhcPs] -> IOEnv (Env TcGblEnv TcLclEnv) ()
dupMinimalSigErr [LSig GhcPs]
minSigs
[LSig GhcPs]
_ -> () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
type AnnoBody body
= ( Anno [LocatedA (Match GhcRn (LocatedA (body GhcRn)))] ~ SrcSpanAnnL
, Anno [LocatedA (Match GhcPs (LocatedA (body GhcPs)))] ~ SrcSpanAnnL
, Anno (Match GhcRn (LocatedA (body GhcRn))) ~ SrcSpanAnnA
, Anno (Match GhcPs (LocatedA (body GhcPs))) ~ SrcSpanAnnA
, Anno (GRHS GhcRn (LocatedA (body GhcRn))) ~ SrcAnn NoEpAnns
, Anno (GRHS GhcPs (LocatedA (body GhcPs))) ~ SrcAnn NoEpAnns
, Outputable (body GhcPs)
)
rnMatchGroup :: (Outputable (body GhcPs), AnnoBody body) => HsMatchContext GhcRn
-> (LocatedA (body GhcPs) -> RnM (LocatedA (body GhcRn), FreeVars))
-> MatchGroup GhcPs (LocatedA (body GhcPs))
-> RnM (MatchGroup GhcRn (LocatedA (body GhcRn)), FreeVars)
rnMatchGroup :: forall (body :: * -> *).
(Outputable (body GhcPs), AnnoBody body) =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> MatchGroup GhcPs (LocatedA (body GhcPs))
-> RnM
(MatchGroup
(GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatchGroup HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody (MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = L SrcSpanAnnL
lm [LocatedA (Match GhcPs (LocatedA (body GhcPs)))]
ms, mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG GhcPs (LocatedA (body GhcPs))
origin })
= do { TcRnIf TcGblEnv TcLclEnv Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (([LocatedA (Match GhcPs (LocatedA (body GhcPs)))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LocatedA (Match GhcPs (LocatedA (body GhcPs)))]
ms Bool -> Bool -> Bool
&&) (Bool -> Bool)
-> TcRnIf TcGblEnv TcLclEnv Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcRnIf TcGblEnv TcLclEnv Bool
mustn't_be_empty) (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErr (HsMatchContext (GhcPass 'Renamed) -> TcRnMessage
emptyCaseErr HsMatchContext (GhcPass 'Renamed)
ctxt))
; ([LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
new_ms, NameSet
ms_fvs) <- (LocatedA (Match GhcPs (LocatedA (body GhcPs)))
-> RnM
(LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))),
NameSet))
-> [LocatedA (Match GhcPs (LocatedA (body GhcPs)))]
-> RnM
([LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))],
NameSet)
forall (f :: * -> *) a b.
Traversable f =>
(a -> RnM (b, NameSet)) -> f a -> RnM (f b, NameSet)
mapFvRn (HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> LMatch GhcPs (LocatedA (body GhcPs))
-> RnM
(LMatch (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> LMatch GhcPs (LocatedA (body GhcPs))
-> RnM
(LMatch (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatch HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody) [LocatedA (Match GhcPs (LocatedA (body GhcPs)))]
ms
; (MatchGroup
(GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
-> RnM
(MatchGroup
(GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Origin
-> LocatedL
[LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
-> MatchGroup
(GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkMatchGroup XMG GhcPs (LocatedA (body GhcPs))
Origin
origin (SrcSpanAnnL
-> [LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
-> LocatedL
[LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
lm [LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
new_ms), NameSet
ms_fvs) }
where
mustn't_be_empty :: TcRnIf TcGblEnv TcLclEnv Bool
mustn't_be_empty = case HsMatchContext (GhcPass 'Renamed)
ctxt of
LamCaseAlt LamCaseVariant
LamCases -> Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
ArrowMatchCtxt (ArrowLamCaseAlt LamCaseVariant
LamCases) -> Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
HsMatchContext (GhcPass 'Renamed)
_ -> Bool -> Bool
not (Bool -> Bool)
-> TcRnIf TcGblEnv TcLclEnv Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.EmptyCase
rnMatch :: AnnoBody body
=> HsMatchContext GhcRn
-> (LocatedA (body GhcPs) -> RnM (LocatedA (body GhcRn), FreeVars))
-> LMatch GhcPs (LocatedA (body GhcPs))
-> RnM (LMatch GhcRn (LocatedA (body GhcRn)), FreeVars)
rnMatch :: forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> LMatch GhcPs (LocatedA (body GhcPs))
-> RnM
(LMatch (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatch HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody = (Match GhcPs (LocatedA (body GhcPs))
-> TcM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> LocatedA (Match GhcPs (LocatedA (body GhcPs)))
-> TcM
(LocatedA
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))),
NameSet)
forall a b c ann.
(a -> TcM (b, c))
-> GenLocated (SrcSpanAnn' ann) a
-> TcM (GenLocated (SrcSpanAnn' ann) b, c)
wrapLocFstMA (HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> Match GhcPs (LocatedA (body GhcPs))
-> TcM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> Match GhcPs (LocatedA (body GhcPs))
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatch' HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody)
rnMatch' :: (AnnoBody body)
=> HsMatchContext GhcRn
-> (LocatedA (body GhcPs) -> RnM (LocatedA (body GhcRn), FreeVars))
-> Match GhcPs (LocatedA (body GhcPs))
-> RnM (Match GhcRn (LocatedA (body GhcRn)), FreeVars)
rnMatch' :: forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> Match GhcPs (LocatedA (body GhcPs))
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnMatch' HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody (Match { m_ctxt :: forall p body. Match p body -> HsMatchContext p
m_ctxt = HsMatchContext 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 (LocatedA (body GhcPs))
grhss })
= HsMatchContext (GhcPass 'Renamed)
-> [LPat GhcPs]
-> ([LPat (GhcPass 'Renamed)]
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (f :: * -> *) a.
Traversable f =>
HsMatchContext (GhcPass 'Renamed)
-> f (LPat GhcPs)
-> (f (LPat (GhcPass 'Renamed)) -> RnM (a, NameSet))
-> RnM (a, NameSet)
rnPats HsMatchContext (GhcPass 'Renamed)
ctxt [LPat GhcPs]
pats (([LPat (GhcPass 'Renamed)]
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> ([LPat (GhcPass 'Renamed)]
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a b. (a -> b) -> a -> b
$ \ [LPat (GhcPass 'Renamed)]
pats' -> do
{ (GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
grhss', NameSet
grhss_fvs) <- HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHSs GhcPs (LocatedA (body GhcPs))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHSs GhcPs (LocatedA (body GhcPs))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHSs HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody GRHSs GhcPs (LocatedA (body GhcPs))
grhss
; let mf' :: HsMatchContext (GhcPass 'Renamed)
mf' = case (HsMatchContext (GhcPass 'Renamed)
ctxt, HsMatchContext GhcPs
mf) of
(FunRhs { mc_fun :: forall p. HsMatchContext p -> LIdP p
mc_fun = L SrcSpanAnnN
_ Name
funid }, FunRhs { mc_fun :: forall p. HsMatchContext p -> LIdP p
mc_fun = L SrcSpanAnnN
lf RdrName
_ })
-> HsMatchContext GhcPs
mf { mc_fun = L lf funid }
(HsMatchContext (GhcPass 'Renamed), HsMatchContext GhcPs)
_ -> HsMatchContext (GhcPass 'Renamed)
ctxt
; (Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
-> RnM
(Match (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Match { m_ext :: XCMatch (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
m_ext = XCMatch (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
EpAnn [AddEpAnn]
forall a. EpAnn a
noAnn, m_ctxt :: HsMatchContext (GhcPass 'Renamed)
m_ctxt = HsMatchContext (GhcPass 'Renamed)
mf', m_pats :: [LPat (GhcPass 'Renamed)]
m_pats = [LPat (GhcPass 'Renamed)]
pats'
, m_grhss :: GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
m_grhss = GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
grhss'}, NameSet
grhss_fvs ) }
emptyCaseErr :: HsMatchContext GhcRn -> TcRnMessage
emptyCaseErr :: HsMatchContext (GhcPass 'Renamed) -> TcRnMessage
emptyCaseErr HsMatchContext (GhcPass 'Renamed)
ctxt = DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$ HsMatchContext (GhcPass 'Renamed) -> SDoc
message HsMatchContext (GhcPass 'Renamed)
ctxt
where
pp_ctxt :: HsMatchContext GhcRn -> SDoc
pp_ctxt :: HsMatchContext (GhcPass 'Renamed) -> SDoc
pp_ctxt HsMatchContext (GhcPass 'Renamed)
c = case HsMatchContext (GhcPass 'Renamed)
c of
HsMatchContext (GhcPass 'Renamed)
CaseAlt -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"case expression"
LamCaseAlt LamCaseVariant
LamCase -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"\\case expression"
ArrowMatchCtxt (ArrowLamCaseAlt LamCaseVariant
LamCase) -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"\\case command"
ArrowMatchCtxt HsArrowMatchContext
ArrowCaseAlt -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"case command"
ArrowMatchCtxt HsArrowMatchContext
KappaExpr -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"kappa abstraction"
HsMatchContext (GhcPass 'Renamed)
_ -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(unexpected)"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsMatchContext (GhcPass 'Renamed) -> SDoc
forall p.
(Outputable (IdP p), UnXRec p) =>
HsMatchContext p -> SDoc
pprMatchContextNoun HsMatchContext (GhcPass 'Renamed)
c
message :: HsMatchContext GhcRn -> SDoc
message :: HsMatchContext (GhcPass 'Renamed) -> SDoc
message (LamCaseAlt LamCaseVariant
LamCases) = SDoc
lcases_msg SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"expression"
message (ArrowMatchCtxt (ArrowLamCaseAlt LamCaseVariant
LamCases)) =
SDoc
lcases_msg SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"command"
message HsMatchContext (GhcPass 'Renamed)
ctxt =
SDoc -> ConTag -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Empty list of alternatives in" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsMatchContext (GhcPass 'Renamed) -> SDoc
pp_ctxt HsMatchContext (GhcPass 'Renamed)
ctxt)
ConTag
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use EmptyCase to allow this")
lcases_msg :: SDoc
lcases_msg =
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Empty list of alternatives is not allowed in \\cases"
rnGRHSs :: AnnoBody body
=> HsMatchContext GhcRn
-> (LocatedA (body GhcPs) -> RnM (LocatedA (body GhcRn), FreeVars))
-> GRHSs GhcPs (LocatedA (body GhcPs))
-> RnM (GRHSs GhcRn (LocatedA (body GhcRn)), FreeVars)
rnGRHSs :: forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHSs GhcPs (LocatedA (body GhcPs))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHSs HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody (GRHSs XCGRHSs GhcPs (LocatedA (body GhcPs))
_ [LGRHS GhcPs (LocatedA (body GhcPs))]
grhss HsLocalBinds GhcPs
binds)
= HsLocalBinds GhcPs
-> (HsLocalBinds (GhcPass 'Renamed)
-> NameSet
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall result.
HsLocalBinds GhcPs
-> (HsLocalBinds (GhcPass 'Renamed)
-> NameSet -> RnM (result, NameSet))
-> RnM (result, NameSet)
rnLocalBindsAndThen HsLocalBinds GhcPs
binds ((HsLocalBinds (GhcPass 'Renamed)
-> NameSet
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> (HsLocalBinds (GhcPass 'Renamed)
-> NameSet
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a b. (a -> b) -> a -> b
$ \ HsLocalBinds (GhcPass 'Renamed)
binds' NameSet
_ -> do
([GenLocated
(SrcAnn NoEpAnns)
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
grhss', NameSet
fvGRHSs) <- (GenLocated (SrcAnn NoEpAnns) (GRHS GhcPs (LocatedA (body GhcPs)))
-> RnM
(GenLocated
(SrcAnn NoEpAnns)
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))),
NameSet))
-> [GenLocated
(SrcAnn NoEpAnns) (GRHS GhcPs (LocatedA (body GhcPs)))]
-> RnM
([GenLocated
(SrcAnn NoEpAnns)
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))],
NameSet)
forall (f :: * -> *) a b.
Traversable f =>
(a -> RnM (b, NameSet)) -> f a -> RnM (f b, NameSet)
mapFvRn (HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> LGRHS GhcPs (LocatedA (body GhcPs))
-> RnM
(LGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> LGRHS GhcPs (LocatedA (body GhcPs))
-> RnM
(LGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHS HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody) [LGRHS GhcPs (LocatedA (body GhcPs))]
[GenLocated (SrcAnn NoEpAnns) (GRHS GhcPs (LocatedA (body GhcPs)))]
grhss
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
-> RnM
(GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XCGRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
-> [LGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))]
-> HsLocalBinds (GhcPass 'Renamed)
-> GRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
forall p body.
XCGRHSs p body -> [LGRHS p body] -> HsLocalBinds p -> GRHSs p body
GRHSs XCGRHSs (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
EpAnnComments
emptyComments [LGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))]
[GenLocated
(SrcAnn NoEpAnns)
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))))]
grhss' HsLocalBinds (GhcPass 'Renamed)
binds', NameSet
fvGRHSs)
rnGRHS :: AnnoBody body
=> HsMatchContext GhcRn
-> (LocatedA (body GhcPs) -> RnM (LocatedA (body GhcRn), FreeVars))
-> LGRHS GhcPs (LocatedA (body GhcPs))
-> RnM (LGRHS GhcRn (LocatedA (body GhcRn)), FreeVars)
rnGRHS :: forall (body :: * -> *).
AnnoBody body =>
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> LGRHS GhcPs (LocatedA (body GhcPs))
-> RnM
(LGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHS HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody = (GRHS GhcPs (LocatedA (body GhcPs))
-> TcM
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> GenLocated
(SrcAnn NoEpAnns) (GRHS GhcPs (LocatedA (body GhcPs)))
-> TcM
(GenLocated
(SrcAnn NoEpAnns)
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))),
NameSet)
forall a b c ann.
(a -> TcM (b, c))
-> GenLocated (SrcSpanAnn' ann) a
-> TcM (GenLocated (SrcSpanAnn' ann) b, c)
wrapLocFstMA (HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHS GhcPs (LocatedA (body GhcPs))
-> TcM
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *).
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHS GhcPs (LocatedA (body GhcPs))
-> RnM
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHS' HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody)
rnGRHS' :: HsMatchContext GhcRn
-> (LocatedA (body GhcPs) -> RnM (LocatedA (body GhcRn), FreeVars))
-> GRHS GhcPs (LocatedA (body GhcPs))
-> RnM (GRHS GhcRn (LocatedA (body GhcRn)), FreeVars)
rnGRHS' :: forall (body :: * -> *).
HsMatchContext (GhcPass 'Renamed)
-> (LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> GRHS GhcPs (LocatedA (body GhcPs))
-> RnM
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
rnGRHS' HsMatchContext (GhcPass 'Renamed)
ctxt LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody (GRHS XCGRHS GhcPs (LocatedA (body GhcPs))
_ [GuardLStmt GhcPs]
guards LocatedA (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
; (([GenLocated
SrcSpanAnnA
(Stmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
guards', LocatedA (body (GhcPass 'Renamed))
rhs'), NameSet
fvs) <- HsStmtContext (GhcPass 'Renamed)
-> (HsExpr GhcPs -> RnM (HsExpr (GhcPass 'Renamed), NameSet))
-> [LStmt GhcPs (LocatedA (HsExpr GhcPs))]
-> ([Name] -> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> RnM
(([LStmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))],
LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall (body :: * -> *) thing.
AnnoBody body =>
HsStmtContext (GhcPass 'Renamed)
-> (body GhcPs -> RnM (body (GhcPass 'Renamed), NameSet))
-> [LStmt GhcPs (LocatedA (body GhcPs))]
-> ([Name] -> RnM (thing, NameSet))
-> RnM
(([LStmt (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))],
thing),
NameSet)
rnStmts (HsMatchContext (GhcPass 'Renamed)
-> HsStmtContext (GhcPass 'Renamed)
forall p. HsMatchContext p -> HsStmtContext p
PatGuard HsMatchContext (GhcPass 'Renamed)
ctxt) HsExpr GhcPs -> RnM (HsExpr (GhcPass 'Renamed), NameSet)
rnExpr [GuardLStmt GhcPs]
[LStmt GhcPs (LocatedA (HsExpr GhcPs))]
guards (([Name] -> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> RnM
(([LStmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))],
LocatedA (body (GhcPass 'Renamed))),
NameSet))
-> ([Name] -> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet))
-> RnM
(([LStmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))],
LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a b. (a -> b) -> a -> b
$ \ [Name]
_ ->
LocatedA (body GhcPs)
-> RnM (LocatedA (body (GhcPass 'Renamed)), NameSet)
rnBody LocatedA (body GhcPs)
rhs
; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
pattern_guards_allowed Bool -> Bool -> Bool
|| [GenLocated
SrcSpanAnnA
(Stmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
-> Bool
forall {l} {idL} {idR} {body}.
[GenLocated l (StmtLR idL idR body)] -> Bool
is_standard_guard [GenLocated
SrcSpanAnnA
(Stmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
guards') (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
let diag :: TcRnMessage
diag = DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$
DiagnosticReason -> [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainDiagnostic DiagnosticReason
WarningWithoutFlag [GhcHint]
noHints ([LStmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))]
-> SDoc
forall body.
(Outputable body,
Anno (Stmt (GhcPass 'Renamed) body) ~ SrcSpanAnnA) =>
[LStmtLR (GhcPass 'Renamed) (GhcPass 'Renamed) body] -> SDoc
nonStdGuardErr [LStmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))]
[GenLocated
SrcSpanAnnA
(Stmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
guards')
in TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addDiagnostic TcRnMessage
diag
; (GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
-> RnM
(GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed))),
NameSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XCGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
-> [GuardLStmt (GhcPass 'Renamed)]
-> LocatedA (body (GhcPass 'Renamed))
-> GRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
forall p body.
XCGRHS p body -> [GuardLStmt p] -> body -> GRHS p body
GRHS XCGRHS (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))
EpAnn GrhsAnn
forall a. EpAnn a
noAnn [GuardLStmt (GhcPass 'Renamed)]
[GenLocated
SrcSpanAnnA
(Stmt
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
guards' LocatedA (body (GhcPass 'Renamed))
rhs', NameSet
fvs) }
where
is_standard_guard :: [GenLocated l (StmtLR idL idR body)] -> Bool
is_standard_guard [] = Bool
True
is_standard_guard [L l
_ (BodyStmt {})] = Bool
True
is_standard_guard [GenLocated l (StmtLR idL idR body)]
_ = Bool
False
rnSrcFixityDecl :: HsSigCtxt -> FixitySig GhcPs -> RnM (FixitySig GhcRn)
rnSrcFixityDecl :: HsSigCtxt -> FixitySig GhcPs -> RnM (FixitySig (GhcPass 'Renamed))
rnSrcFixityDecl HsSigCtxt
sig_ctxt = FixitySig GhcPs -> RnM (FixitySig (GhcPass 'Renamed))
rn_decl
where
rn_decl :: FixitySig GhcPs -> RnM (FixitySig GhcRn)
rn_decl :: FixitySig GhcPs -> RnM (FixitySig (GhcPass 'Renamed))
rn_decl (FixitySig XFixitySig GhcPs
_ [LIdP GhcPs]
fnames Fixity
fixity)
= do [GenLocated SrcSpanAnnN Name]
names <- (LocatedN RdrName
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name])
-> [LocatedN RdrName]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM LocatedN RdrName
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
lookup_one [LIdP GhcPs]
[LocatedN RdrName]
fnames
FixitySig (GhcPass 'Renamed) -> RnM (FixitySig (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (XFixitySig (GhcPass 'Renamed)
-> [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
-> Fixity
-> FixitySig (GhcPass 'Renamed)
forall pass.
XFixitySig pass -> [LIdP pass] -> Fixity -> FixitySig pass
FixitySig XFixitySig (GhcPass 'Renamed)
NoExtField
noExtField [XRec (GhcPass 'Renamed) (IdP (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnN Name]
names Fixity
fixity)
lookup_one :: LocatedN RdrName -> RnM [LocatedN Name]
lookup_one :: LocatedN RdrName
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
lookup_one (L SrcSpanAnnN
name_loc RdrName
rdr_name)
= SrcSpanAnnN
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
name_loc (IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name])
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall a b. (a -> b) -> a -> b
$
do [(RdrName, Name)]
names <- HsSigCtxt -> SDoc -> RdrName -> RnM [(RdrName, Name)]
lookupLocalTcNames HsSigCtxt
sig_ctxt SDoc
what RdrName
rdr_name
[GenLocated SrcSpanAnnN Name]
-> IOEnv (Env TcGblEnv TcLclEnv) [GenLocated SrcSpanAnnN Name]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [ SrcSpanAnnN -> Name -> GenLocated SrcSpanAnnN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
name_loc Name
name | (RdrName
_, Name
name) <- [(RdrName, Name)]
names ]
what :: SDoc
what = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fixity signature"
dupSigDeclErr :: NonEmpty (LocatedN RdrName, Sig GhcPs) -> RnM ()
dupSigDeclErr :: NonEmpty (LocatedN RdrName, Sig GhcPs)
-> IOEnv (Env TcGblEnv TcLclEnv) ()
dupSigDeclErr pairs :: NonEmpty (LocatedN RdrName, Sig GhcPs)
pairs@((L SrcSpanAnnN
loc RdrName
name, Sig GhcPs
sig) :| [(LocatedN RdrName, Sig GhcPs)]
_)
= SrcSpan -> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErrAt (SrcSpanAnnN -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
loc) (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Duplicate" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what_it_is
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"s for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
name)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((SrcSpan -> SDoc) -> [SrcSpan] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([SrcSpan] -> [SDoc]) -> [SrcSpan] -> [SDoc]
forall a b. (a -> b) -> a -> b
$ (SrcSpan -> SrcSpan -> Ordering) -> [SrcSpan] -> [SrcSpan]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy SrcSpan -> SrcSpan -> Ordering
SrcLoc.leftmost_smallest
([SrcSpan] -> [SrcSpan]) -> [SrcSpan] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ ((LocatedN RdrName, Sig GhcPs) -> SrcSpan)
-> [(LocatedN RdrName, Sig GhcPs)] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map (LocatedN RdrName -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA (LocatedN RdrName -> SrcSpan)
-> ((LocatedN RdrName, Sig GhcPs) -> LocatedN RdrName)
-> (LocatedN RdrName, Sig GhcPs)
-> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LocatedN RdrName, Sig GhcPs) -> LocatedN RdrName
forall a b. (a, b) -> a
fst)
([(LocatedN RdrName, Sig GhcPs)] -> [SrcSpan])
-> [(LocatedN RdrName, Sig GhcPs)] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ NonEmpty (LocatedN RdrName, Sig GhcPs)
-> [(LocatedN RdrName, Sig GhcPs)]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (LocatedN RdrName, Sig GhcPs)
pairs)
]
where
what_it_is :: SDoc
what_it_is = Sig GhcPs -> SDoc
forall (p :: Pass). IsPass p => Sig (GhcPass p) -> SDoc
hsSigDoc Sig GhcPs
sig
misplacedSigErr :: LSig GhcRn -> RnM ()
misplacedSigErr :: LSig (GhcPass 'Renamed) -> IOEnv (Env TcGblEnv TcLclEnv) ()
misplacedSigErr (L SrcSpanAnnA
loc Sig (GhcPass 'Renamed)
sig)
= SrcSpan -> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErrAt (SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Misplaced" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Sig (GhcPass 'Renamed) -> SDoc
forall (p :: Pass). IsPass p => Sig (GhcPass p) -> SDoc
hsSigDoc Sig (GhcPass 'Renamed)
sig SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
colon, Sig (GhcPass 'Renamed) -> SDoc
forall a. Outputable a => a -> SDoc
ppr Sig (GhcPass 'Renamed)
sig]
defaultSigErr :: Sig GhcPs -> TcRnMessage
defaultSigErr :: Sig GhcPs -> TcRnMessage
defaultSigErr Sig GhcPs
sig = DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc -> ConTag -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Unexpected default signature:")
ConTag
2 (Sig GhcPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr Sig GhcPs
sig)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use DefaultSignatures to enable default signatures" ]
bindInHsBootFileErr :: LHsBindLR GhcRn GhcPs -> RnM ()
bindInHsBootFileErr :: LHsBindLR (GhcPass 'Renamed) GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) ()
bindInHsBootFileErr (L SrcSpanAnnA
loc HsBindLR (GhcPass 'Renamed) GhcPs
_)
= SrcSpan -> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErrAt (SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Bindings in hs-boot files are not allowed" ]
nonStdGuardErr :: (Outputable body,
Anno (Stmt GhcRn body) ~ SrcSpanAnnA)
=> [LStmtLR GhcRn GhcRn body] -> SDoc
nonStdGuardErr :: forall body.
(Outputable body,
Anno (Stmt (GhcPass 'Renamed) body) ~ SrcSpanAnnA) =>
[LStmtLR (GhcPass 'Renamed) (GhcPass 'Renamed) body] -> SDoc
nonStdGuardErr [LStmtLR (GhcPass 'Renamed) (GhcPass 'Renamed) body]
guards
= SDoc -> ConTag -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"accepting non-standard pattern guards (use PatternGuards to suppress this message)")
ConTag
4 ([GenLocated SrcSpanAnnA (Stmt (GhcPass 'Renamed) body)] -> SDoc
forall a. Outputable a => [a] -> SDoc
interpp'SP [LStmtLR (GhcPass 'Renamed) (GhcPass 'Renamed) body]
[GenLocated SrcSpanAnnA (Stmt (GhcPass 'Renamed) body)]
guards)
dupMinimalSigErr :: [LSig GhcPs] -> RnM ()
dupMinimalSigErr :: [LSig GhcPs] -> IOEnv (Env TcGblEnv TcLclEnv) ()
dupMinimalSigErr sigs :: [LSig GhcPs]
sigs@(L SrcSpanAnnA
loc Sig GhcPs
_ : [LSig GhcPs]
_)
= SrcSpan -> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
addErrAt (SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> TcRnMessage -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints (SDoc -> DiagnosticMessage) -> SDoc -> DiagnosticMessage
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Multiple minimal complete definitions"
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((SrcSpan -> SDoc) -> [SrcSpan] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([SrcSpan] -> [SDoc]) -> [SrcSpan] -> [SDoc]
forall a b. (a -> b) -> a -> b
$ (SrcSpan -> SrcSpan -> Ordering) -> [SrcSpan] -> [SrcSpan]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy SrcSpan -> SrcSpan -> Ordering
SrcLoc.leftmost_smallest ([SrcSpan] -> [SrcSpan]) -> [SrcSpan] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig GhcPs) -> SrcSpan)
-> [GenLocated SrcSpanAnnA (Sig GhcPs)] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (Sig GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA [LSig GhcPs]
[GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Combine alternative minimal complete definitions with `|'" ]
dupMinimalSigErr [] = String -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. HasCallStack => String -> a
panic String
"dupMinimalSigErr"