{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TupleSections #-}
module GHC.Tc.Gen.Export (rnExports, exports_from_avail, classifyGREs) where
import GHC.Prelude
import GHC.Hs
import GHC.Builtin.Names
import GHC.Tc.Errors.Types
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.Env
( TyThing(AConLike, AnId), tcLookupGlobal, tcLookupTyCon )
import GHC.Tc.Utils.TcType
import GHC.Rename.Doc
import GHC.Rename.Module
import GHC.Rename.Names
import GHC.Rename.Env
import GHC.Rename.Unbound ( reportUnboundName )
import GHC.Utils.Error
import GHC.Unit.Module
import GHC.Unit.Module.Imported
import GHC.Unit.Module.Warnings
import GHC.Core.TyCon
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Core.ConLike
import GHC.Core.PatSyn
import GHC.Data.Maybe
import GHC.Data.FastString (fsLit)
import GHC.Driver.Env
import GHC.Driver.DynFlags
import GHC.Parser.PostProcess ( setRdrNameSpace )
import qualified GHC.LanguageExtensions as LangExt
import GHC.Types.Unique.Map
import GHC.Types.SrcLoc as SrcLoc
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Name.Set
import GHC.Types.Avail
import GHC.Types.SourceFile
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Types.Name.Reader
import Control.Arrow ( first )
import Control.Monad ( when )
import qualified Data.List.NonEmpty as NE
import Data.Traversable ( for )
import Data.List ( sortBy )
data ExportAccum
= ExportAccum {
ExportAccum -> ExportOccMap
expacc_exp_occs :: ExportOccMap,
ExportAccum -> UniqMap ModuleName [Name]
expacc_mods :: UniqMap ModuleName [Name],
ExportAccum -> ExportWarnSpanNames
expacc_warn_spans :: ExportWarnSpanNames,
ExportAccum -> DontWarnExportNames
expacc_dont_warn :: DontWarnExportNames
}
emptyExportAccum :: ExportAccum
emptyExportAccum :: ExportAccum
emptyExportAccum = ExportOccMap
-> UniqMap ModuleName [Name]
-> ExportWarnSpanNames
-> DontWarnExportNames
-> ExportAccum
ExportAccum ExportOccMap
forall a. OccEnv a
emptyOccEnv UniqMap ModuleName [Name]
forall k a. UniqMap k a
emptyUniqMap [] DontWarnExportNames
forall a. NameEnv a
emptyNameEnv
accumExports :: (ExportAccum -> x -> TcRn (ExportAccum, Maybe y))
-> [x]
-> TcRn ([y], ExportWarnSpanNames, DontWarnExportNames)
accumExports :: forall x y.
(ExportAccum -> x -> TcRn (ExportAccum, Maybe y))
-> [x] -> TcRn ([y], ExportWarnSpanNames, DontWarnExportNames)
accumExports ExportAccum -> x -> TcRn (ExportAccum, Maybe y)
f [x]
xs = do
(ExportAccum ExportOccMap
_ UniqMap ModuleName [Name]
_ ExportWarnSpanNames
export_warn_spans DontWarnExportNames
dont_warn_export, [Maybe y]
ys)
<- (ExportAccum -> x -> TcRn (ExportAccum, Maybe y))
-> ExportAccum
-> [x]
-> IOEnv (Env TcGblEnv TcLclEnv) (ExportAccum, [Maybe y])
forall (m :: * -> *) (t :: * -> *) acc x y.
(Monad m, Traversable t) =>
(acc -> x -> m (acc, y)) -> acc -> t x -> m (acc, t y)
mapAccumLM ExportAccum -> x -> TcRn (ExportAccum, Maybe y)
f' ExportAccum
emptyExportAccum [x]
xs
([y], ExportWarnSpanNames, DontWarnExportNames)
-> TcRn ([y], ExportWarnSpanNames, DontWarnExportNames)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( [Maybe y] -> [y]
forall a. [Maybe a] -> [a]
catMaybes [Maybe y]
ys
, ExportWarnSpanNames
export_warn_spans
, DontWarnExportNames
dont_warn_export )
where f' :: ExportAccum -> x -> TcRn (ExportAccum, Maybe y)
f' ExportAccum
acc x
x
= (ExportAccum, Maybe y)
-> Maybe (ExportAccum, Maybe y) -> (ExportAccum, Maybe y)
forall a. a -> Maybe a -> a
fromMaybe (ExportAccum
acc, Maybe y
forall a. Maybe a
Nothing) (Maybe (ExportAccum, Maybe y) -> (ExportAccum, Maybe y))
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (ExportAccum, Maybe y))
-> TcRn (ExportAccum, Maybe y)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcRn (ExportAccum, Maybe y)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (ExportAccum, Maybe y))
forall r. TcRn r -> TcRn (Maybe r)
attemptM (ExportAccum -> x -> TcRn (ExportAccum, Maybe y)
f ExportAccum
acc x
x)
type ExportOccMap = OccEnv (Name, IE GhcPs)
rnExports :: Bool
-> Maybe (LocatedL [LIE GhcPs])
-> RnM TcGblEnv
rnExports :: Bool -> Maybe (LocatedL [LIE GhcPs]) -> RnM TcGblEnv
rnExports Bool
explicit_mod Maybe (LocatedL [LIE GhcPs])
exports
= RnM TcGblEnv -> RnM TcGblEnv
forall r. TcM r -> TcM r
checkNoErrs (RnM TcGblEnv -> RnM TcGblEnv) -> RnM TcGblEnv -> RnM TcGblEnv
forall a b. (a -> b) -> a -> b
$
do { HscEnv
hsc_env <- TcRnIf TcGblEnv TcLclEnv HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; TcGblEnv
tcg_env <- RnM TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
TcGblEnv { tcg_mod :: TcGblEnv -> Module
tcg_mod = Module
this_mod
, tcg_rdr_env :: TcGblEnv -> GlobalRdrEnv
tcg_rdr_env = GlobalRdrEnv
rdr_env
, tcg_imports :: TcGblEnv -> ImportAvails
tcg_imports = ImportAvails
imports
, tcg_warns :: TcGblEnv -> Warnings GhcRn
tcg_warns = Warnings GhcRn
warns
, tcg_src :: TcGblEnv -> HscSource
tcg_src = HscSource
hsc_src } = TcGblEnv
tcg_env
default_main :: RdrName
default_main | HomeUnitEnv -> Module
mainModIs (HscEnv -> HomeUnitEnv
hsc_HUE HscEnv
hsc_env) Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
this_mod
, Just String
main_fun <- DynFlags -> Maybe String
mainFunIs DynFlags
dflags
= NameSpace -> FastString -> RdrName
mkUnqual NameSpace
varName (String -> FastString
fsLit String
main_fun)
| Bool
otherwise
= RdrName
main_RDR_Unqual
; Bool
has_main <- (Bool -> Bool
not (Bool -> Bool) -> ([Name] -> Bool) -> [Name] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Name] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null) ([Name] -> Bool)
-> IOEnv (Env TcGblEnv TcLclEnv) [Name]
-> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RdrName -> IOEnv (Env TcGblEnv TcLclEnv) [Name]
lookupInfoOccRn RdrName
default_main
; let real_exports :: Maybe (LocatedL [LIE GhcPs])
real_exports
| Bool
explicit_mod = Maybe (LocatedL [LIE GhcPs])
exports
| Bool
has_main
= LocatedAn AnnList [LocatedAn AnnListItem (IE GhcPs)]
-> Maybe (LocatedAn AnnList [LocatedAn AnnListItem (IE GhcPs)])
forall a. a -> Maybe a
Just ([LocatedAn AnnListItem (IE GhcPs)]
-> LocatedAn AnnList [LocatedAn AnnListItem (IE GhcPs)]
forall a an. a -> LocatedAn an a
noLocA [IE GhcPs -> LocatedAn AnnListItem (IE GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XIEVar GhcPs -> LIEWrappedName GhcPs -> IE GhcPs
forall pass. XIEVar pass -> LIEWrappedName pass -> IE pass
IEVar Maybe (LocatedP (WarningTxt GhcPs))
XIEVar GhcPs
forall a. Maybe a
Nothing
(IEWrappedName GhcPs -> LocatedAn AnnListItem (IEWrappedName GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XIEName GhcPs -> LIdP GhcPs -> IEWrappedName GhcPs
forall p. XIEName p -> LIdP p -> IEWrappedName p
IEName XIEName GhcPs
NoExtField
noExtField (LIdP GhcPs -> IEWrappedName GhcPs)
-> LIdP GhcPs -> IEWrappedName GhcPs
forall a b. (a -> b) -> a -> b
$ RdrName -> GenLocated SrcSpanAnnN RdrName
forall a an. a -> LocatedAn an a
noLocA RdrName
default_main)))])
| Bool
otherwise = Maybe (LocatedL [LIE GhcPs])
Maybe (LocatedAn AnnList [LocatedAn AnnListItem (IE GhcPs)])
forall a. Maybe a
Nothing
; let do_it :: RnM
(Maybe [(LIE GhcRn, [AvailInfo])], [AvailInfo],
ExportWarnNames GhcRn)
do_it = Maybe (LocatedL [LIE GhcPs])
-> GlobalRdrEnv
-> ImportAvails
-> Module
-> RnM
(Maybe [(LIE GhcRn, [AvailInfo])], [AvailInfo],
ExportWarnNames GhcRn)
exports_from_avail Maybe (LocatedL [LIE GhcPs])
real_exports GlobalRdrEnv
rdr_env ImportAvails
imports Module
this_mod
; (Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
rn_exports, [AvailInfo]
final_avails, ExportWarnNames GhcRn
new_export_warns)
<- if HscSource
hsc_src HscSource -> HscSource -> Bool
forall a. Eq a => a -> a -> Bool
== HscSource
HsigFile
then do (Maybe
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
mb_r, Messages TcRnMessage
msgs) <- IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
-> TcRn
(Maybe
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn),
Messages TcRnMessage)
forall a. TcRn a -> TcRn (Maybe a, Messages TcRnMessage)
tryTc RnM
(Maybe [(LIE GhcRn, [AvailInfo])], [AvailInfo],
ExportWarnNames GhcRn)
IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
do_it
case Maybe
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
mb_r of
Just (Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
r -> (Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
r
Maybe
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
Nothing -> Messages TcRnMessage -> TcRn ()
addMessages Messages TcRnMessage
msgs TcRn ()
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
forall a b.
IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) b
-> IOEnv (Env TcGblEnv TcLclEnv) b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
forall env a. IOEnv env a
failM
else IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
forall r. TcM r -> TcM r
checkNoErrs RnM
(Maybe [(LIE GhcRn, [AvailInfo])], [AvailInfo],
ExportWarnNames GhcRn)
IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
do_it
; let final_ns :: NameSet
final_ns = [AvailInfo] -> NameSet
availsToNameSet [AvailInfo]
final_avails
; String -> SDoc -> TcRn ()
traceRn String
"rnExports: Exports:" ([AvailInfo] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [AvailInfo]
final_avails)
; TcGblEnv -> RnM TcGblEnv
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env { tcg_exports = final_avails
, tcg_rn_exports = case tcg_rn_exports tcg_env of
Maybe [(LIE GhcRn, [AvailInfo])]
Nothing -> Maybe [(LIE GhcRn, [AvailInfo])]
Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
forall a. Maybe a
Nothing
Just [(LIE GhcRn, [AvailInfo])]
_ -> Maybe [(LIE GhcRn, [AvailInfo])]
Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
rn_exports
, tcg_dus = tcg_dus tcg_env `plusDU`
usesOnly final_ns
, tcg_warns = insertWarnExports
warns new_export_warns}) }
type ExportWarnSpanNames = [(Name, WarningTxt GhcRn, SrcSpan)]
type DontWarnExportNames = NameEnv (NE.NonEmpty SrcSpan)
exports_from_avail :: Maybe (LocatedL [LIE GhcPs])
-> GlobalRdrEnv
-> ImportAvails
-> Module
-> RnM (Maybe [(LIE GhcRn, Avails)], Avails, ExportWarnNames GhcRn)
exports_from_avail :: Maybe (LocatedL [LIE GhcPs])
-> GlobalRdrEnv
-> ImportAvails
-> Module
-> RnM
(Maybe [(LIE GhcRn, [AvailInfo])], [AvailInfo],
ExportWarnNames GhcRn)
exports_from_avail Maybe (LocatedL [LIE GhcPs])
Nothing GlobalRdrEnv
rdr_env ImportAvails
_imports Module
_this_mod
= do {
; TcRnMessage -> TcRn ()
addDiagnostic
(ModuleName -> TcRnMessage
TcRnMissingExportList (ModuleName -> TcRnMessage) -> ModuleName -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
_this_mod)
; let avails :: [AvailInfo]
avails =
(AvailInfo -> AvailInfo) -> [AvailInfo] -> [AvailInfo]
forall a b. (a -> b) -> [a] -> [b]
map AvailInfo -> AvailInfo
fix_faminst ([AvailInfo] -> [AvailInfo])
-> (GlobalRdrEnv -> [AvailInfo]) -> GlobalRdrEnv -> [AvailInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GlobalRdrEltX GREInfo] -> [AvailInfo]
forall info. [GlobalRdrEltX info] -> [AvailInfo]
gresToAvailInfo
([GlobalRdrEltX GREInfo] -> [AvailInfo])
-> (GlobalRdrEnv -> [GlobalRdrEltX GREInfo])
-> GlobalRdrEnv
-> [AvailInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GlobalRdrEltX GREInfo -> Bool)
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall a. (a -> Bool) -> [a] -> [a]
filter GlobalRdrEltX GREInfo -> Bool
forall info. GlobalRdrEltX info -> Bool
isLocalGRE ([GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo])
-> (GlobalRdrEnv -> [GlobalRdrEltX GREInfo])
-> GlobalRdrEnv
-> [GlobalRdrEltX GREInfo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalRdrEnv -> [GlobalRdrEltX GREInfo]
forall info. GlobalRdrEnvX info -> [GlobalRdrEltX info]
globalRdrEnvElts (GlobalRdrEnv -> [AvailInfo]) -> GlobalRdrEnv -> [AvailInfo]
forall a b. (a -> b) -> a -> b
$ GlobalRdrEnv
rdr_env
; (Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
forall a. Maybe a
Nothing, [AvailInfo]
avails, []) }
where
fix_faminst :: AvailInfo -> AvailInfo
fix_faminst avail :: AvailInfo
avail@(AvailTC Name
n [Name]
ns)
| AvailInfo -> Bool
availExportsDecl AvailInfo
avail
= AvailInfo
avail
| Bool
otherwise
= Name -> [Name] -> AvailInfo
AvailTC Name
n (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
ns)
fix_faminst AvailInfo
avail = AvailInfo
avail
exports_from_avail (Just (L SrcSpanAnnL
_ [LIE GhcPs]
rdr_items)) GlobalRdrEnv
rdr_env ImportAvails
imports Module
this_mod
= do ([(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
ie_avails, ExportWarnSpanNames
export_warn_spans, DontWarnExportNames
dont_warn_export)
<- (ExportAccum
-> LocatedAn AnnListItem (IE GhcPs)
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])))
-> [LocatedAn AnnListItem (IE GhcPs)]
-> TcRn
([(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
ExportWarnSpanNames, DontWarnExportNames)
forall x y.
(ExportAccum -> x -> TcRn (ExportAccum, Maybe y))
-> [x] -> TcRn ([y], ExportWarnSpanNames, DontWarnExportNames)
accumExports ExportAccum
-> LIE GhcPs -> RnM (ExportAccum, Maybe (LIE GhcRn, [AvailInfo]))
ExportAccum
-> LocatedAn AnnListItem (IE GhcPs)
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
do_litem [LIE GhcPs]
[LocatedAn AnnListItem (IE GhcPs)]
rdr_items
let final_exports :: [AvailInfo]
final_exports = [AvailInfo] -> [AvailInfo]
nubAvails (((GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]) -> [AvailInfo])
-> [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
-> [AvailInfo]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]) -> [AvailInfo]
forall a b. (a, b) -> b
snd [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
ie_avails)
ExportWarnNames GhcRn
export_warn_names <- ExportWarnSpanNames
-> DontWarnExportNames -> RnM (ExportWarnNames GhcRn)
aggregate_warnings ExportWarnSpanNames
export_warn_spans DontWarnExportNames
dont_warn_export
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])],
[AvailInfo], ExportWarnNames GhcRn)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
-> Maybe [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
forall a. a -> Maybe a
Just [(GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])]
ie_avails, [AvailInfo]
final_exports, ExportWarnNames GhcRn
export_warn_names)
where
do_litem :: ExportAccum -> LIE GhcPs
-> RnM (ExportAccum, Maybe (LIE GhcRn, Avails))
do_litem :: ExportAccum
-> LIE GhcPs -> RnM (ExportAccum, Maybe (LIE GhcRn, [AvailInfo]))
do_litem ExportAccum
acc LIE GhcPs
lie = SrcSpan
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (LocatedAn AnnListItem (IE GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LIE GhcPs
LocatedAn AnnListItem (IE GhcPs)
lie) (ExportAccum
-> LIE GhcPs -> RnM (ExportAccum, Maybe (LIE GhcRn, [AvailInfo]))
exports_from_item ExportAccum
acc LIE GhcPs
lie)
kids_env :: NameEnv [GlobalRdrElt]
kids_env :: NameEnv [GlobalRdrEltX GREInfo]
kids_env = [GlobalRdrEltX GREInfo] -> NameEnv [GlobalRdrEltX GREInfo]
mkChildEnv (GlobalRdrEnv -> [GlobalRdrEltX GREInfo]
forall info. GlobalRdrEnvX info -> [GlobalRdrEltX info]
globalRdrEnvElts GlobalRdrEnv
rdr_env)
expand_tyty_gre :: GlobalRdrElt -> [GlobalRdrElt]
expand_tyty_gre :: GlobalRdrEltX GREInfo -> [GlobalRdrEltX GREInfo]
expand_tyty_gre (gre :: GlobalRdrEltX GREInfo
gre@GRE { gre_par :: forall info. GlobalRdrEltX info -> Parent
gre_par = ParentIs Name
p })
| Name -> Bool
isTyConName Name
p
, Name -> Bool
isTyConName (GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
gre)
= [GlobalRdrEltX GREInfo
gre, GlobalRdrEltX GREInfo
gre{ gre_par = NoParent }]
expand_tyty_gre GlobalRdrEltX GREInfo
gre
= [GlobalRdrEltX GREInfo
gre]
imported_modules :: [ModuleName]
imported_modules = [ ImportedModsVal -> ModuleName
imv_name ImportedModsVal
imv
| [ImportedBy]
xs <- ModuleEnv [ImportedBy] -> [[ImportedBy]]
forall a. ModuleEnv a -> [a]
moduleEnvElts (ModuleEnv [ImportedBy] -> [[ImportedBy]])
-> ModuleEnv [ImportedBy] -> [[ImportedBy]]
forall a b. (a -> b) -> a -> b
$ ImportAvails -> ModuleEnv [ImportedBy]
imp_mods ImportAvails
imports
, ImportedModsVal
imv <- [ImportedBy] -> [ImportedModsVal]
importedByUser [ImportedBy]
xs ]
exports_from_item :: ExportAccum -> LIE GhcPs
-> RnM (ExportAccum, Maybe (LIE GhcRn, Avails))
exports_from_item :: ExportAccum
-> LIE GhcPs -> RnM (ExportAccum, Maybe (LIE GhcRn, [AvailInfo]))
exports_from_item expacc :: ExportAccum
expacc@ExportAccum{
expacc_exp_occs :: ExportAccum -> ExportOccMap
expacc_exp_occs = ExportOccMap
occs,
expacc_mods :: ExportAccum -> UniqMap ModuleName [Name]
expacc_mods = UniqMap ModuleName [Name]
earlier_mods,
expacc_warn_spans :: ExportAccum -> ExportWarnSpanNames
expacc_warn_spans = ExportWarnSpanNames
export_warn_spans,
expacc_dont_warn :: ExportAccum -> DontWarnExportNames
expacc_dont_warn = DontWarnExportNames
dont_warn_export
} (L SrcSpanAnnA
loc ie :: IE GhcPs
ie@(IEModuleContents (Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps, EpAnn [AddEpAnn]
_) lmod :: XRec GhcPs ModuleName
lmod@(L SrcSpanAnnA
_ ModuleName
mod)))
| Just [Name]
exported_names <- UniqMap ModuleName [Name] -> ModuleName -> Maybe [Name]
forall k a. Uniquable k => UniqMap k a -> k -> Maybe a
lookupUniqMap UniqMap ModuleName [Name]
earlier_mods ModuleName
mod
= do { TcRnMessage -> TcRn ()
addDiagnostic (ModuleName -> TcRnMessage
TcRnDupeModuleExport ModuleName
mod)
; (ExportWarnSpanNames
export_warn_spans', DontWarnExportNames
dont_warn_export', Maybe (LocatedP (WarningTxt GhcRn))
_) <-
ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name]
exported_names
Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps
(SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
; (ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportAccum
expacc{ expacc_warn_spans = export_warn_spans'
, expacc_dont_warn = dont_warn_export' }
, Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
forall a. Maybe a
Nothing ) }
| Bool
otherwise
= do { let { exportValid :: Bool
exportValid = (ModuleName
mod ModuleName -> [ModuleName] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ModuleName]
imported_modules)
Bool -> Bool -> Bool
|| (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
this_mod ModuleName -> ModuleName -> Bool
forall a. Eq a => a -> a -> Bool
== ModuleName
mod)
; gre_prs :: [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)]
gre_prs = ModuleName
-> [GlobalRdrEltX GREInfo]
-> [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)]
forall info.
ModuleName
-> [GlobalRdrEltX info]
-> [(GlobalRdrEltX info, GlobalRdrEltX info)]
pickGREsModExp ModuleName
mod (GlobalRdrEnv -> [GlobalRdrEltX GREInfo]
forall info. GlobalRdrEnvX info -> [GlobalRdrEltX info]
globalRdrEnvElts GlobalRdrEnv
rdr_env)
; new_gres :: [GlobalRdrEltX GREInfo]
new_gres = [ GlobalRdrEltX GREInfo
gre'
| (GlobalRdrEltX GREInfo
gre, GlobalRdrEltX GREInfo
_) <- [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)]
gre_prs
, GlobalRdrEltX GREInfo
gre' <- GlobalRdrEltX GREInfo -> [GlobalRdrEltX GREInfo]
expand_tyty_gre GlobalRdrEltX GREInfo
gre ]
; new_exports :: [AvailInfo]
new_exports = (GlobalRdrEltX GREInfo -> AvailInfo)
-> [GlobalRdrEltX GREInfo] -> [AvailInfo]
forall a b. (a -> b) -> [a] -> [b]
map GlobalRdrEltX GREInfo -> AvailInfo
forall info. GlobalRdrEltX info -> AvailInfo
availFromGRE [GlobalRdrEltX GREInfo]
new_gres
; all_gres :: [GlobalRdrEltX GREInfo]
all_gres = ((GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo])
-> [GlobalRdrEltX GREInfo]
-> [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)]
-> [GlobalRdrEltX GREInfo]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(GlobalRdrEltX GREInfo
gre1,GlobalRdrEltX GREInfo
gre2) [GlobalRdrEltX GREInfo]
gres -> GlobalRdrEltX GREInfo
gre1 GlobalRdrEltX GREInfo
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall a. a -> [a] -> [a]
: GlobalRdrEltX GREInfo
gre2 GlobalRdrEltX GREInfo
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall a. a -> [a] -> [a]
: [GlobalRdrEltX GREInfo]
gres) [] [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)]
gre_prs
; exported_names :: [Name]
exported_names = (GlobalRdrEltX GREInfo -> Name)
-> [GlobalRdrEltX GREInfo] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName [GlobalRdrEltX GREInfo]
new_gres
; mods :: UniqMap ModuleName [Name]
mods = UniqMap ModuleName [Name]
-> ModuleName -> [Name] -> UniqMap ModuleName [Name]
forall k a. Uniquable k => UniqMap k a -> k -> a -> UniqMap k a
addToUniqMap UniqMap ModuleName [Name]
earlier_mods ModuleName
mod [Name]
exported_names
}
; Bool -> TcRnMessage -> TcRn ()
checkErr Bool
exportValid (ModuleName -> TcRnMessage
TcRnExportedModNotImported ModuleName
mod)
; Bool -> TcRnMessage -> TcRn ()
warnIf (Bool
exportValid Bool -> Bool -> Bool
&& [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(GlobalRdrEltX GREInfo, GlobalRdrEltX GREInfo)]
gre_prs) (ModuleName -> TcRnMessage
TcRnNullExportedModule ModuleName
mod)
; String -> SDoc -> TcRn ()
traceRn String
"efa" (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [GlobalRdrEltX GREInfo] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [GlobalRdrEltX GREInfo]
all_gres)
; DeprecationWarnings -> [GlobalRdrEltX GREInfo] -> TcRn ()
addUsedGREs DeprecationWarnings
ExportDeprecationWarnings [GlobalRdrEltX GREInfo]
all_gres
; ExportOccMap
occs' <- ExportOccMap
-> IE GhcPs -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
check_occs ExportOccMap
occs IE GhcPs
ie [GlobalRdrEltX GREInfo]
new_gres
; (ExportWarnSpanNames
export_warn_spans', DontWarnExportNames
dont_warn_export', Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn) <-
ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name]
exported_names
Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps
(SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
; String -> SDoc -> TcRn ()
traceRn String
"export_mod"
([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
, [AvailInfo] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [AvailInfo]
new_exports ])
; (ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportAccum { expacc_exp_occs :: ExportOccMap
expacc_exp_occs = ExportOccMap
occs'
, expacc_mods :: UniqMap ModuleName [Name]
expacc_mods = UniqMap ModuleName [Name]
mods
, expacc_warn_spans :: ExportWarnSpanNames
expacc_warn_spans = ExportWarnSpanNames
export_warn_spans'
, expacc_dont_warn :: DontWarnExportNames
expacc_dont_warn = DontWarnExportNames
dont_warn_export' }
, (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
forall a. a -> Maybe a
Just (SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEModuleContents GhcRn -> XRec GhcRn ModuleName -> IE GhcRn
forall pass.
XIEModuleContents pass -> XRec pass ModuleName -> IE pass
IEModuleContents Maybe (LocatedP (WarningTxt GhcRn))
XIEModuleContents GhcRn
warn_txt_rn XRec GhcPs ModuleName
XRec GhcRn ModuleName
lmod), [AvailInfo]
new_exports) ) }
exports_from_item ExportAccum
acc LIE GhcPs
lie = do
Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
m_doc_ie <- LIE GhcPs -> RnM (Maybe (LIE GhcRn))
lookup_doc_ie LIE GhcPs
lie
case Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
m_doc_ie of
Just GenLocated SrcSpanAnnA (IE GhcRn)
new_ie -> (ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ExportAccum
acc, (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnA (IE GhcRn)
new_ie, []))
Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
Nothing -> do
Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
m_ie <- ExportAccum
-> LIE GhcPs -> RnM (Maybe (ExportAccum, LIE GhcRn, AvailInfo))
lookup_ie ExportAccum
acc LIE GhcPs
lie
case Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
m_ie of
Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
Nothing -> (ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ExportAccum
acc, Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
forall a. Maybe a
Nothing)
Just (ExportAccum
acc', GenLocated SrcSpanAnnA (IE GhcRn)
new_ie, AvailInfo
avail)
-> (ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
-> TcRn
(ExportAccum,
Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ExportAccum
acc', (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn), [AvailInfo])
forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnA (IE GhcRn)
new_ie, [AvailInfo
avail]))
lookup_ie :: ExportAccum -> LIE GhcPs -> RnM (Maybe (ExportAccum, LIE GhcRn, AvailInfo))
lookup_ie :: ExportAccum
-> LIE GhcPs -> RnM (Maybe (ExportAccum, LIE GhcRn, AvailInfo))
lookup_ie expacc :: ExportAccum
expacc@ExportAccum{
expacc_exp_occs :: ExportAccum -> ExportOccMap
expacc_exp_occs = ExportOccMap
occs,
expacc_warn_spans :: ExportAccum -> ExportWarnSpanNames
expacc_warn_spans = ExportWarnSpanNames
export_warn_spans,
expacc_dont_warn :: ExportAccum -> DontWarnExportNames
expacc_dont_warn = DontWarnExportNames
dont_warn_export
} (L SrcSpanAnnA
loc ie :: IE GhcPs
ie@(IEVar XIEVar GhcPs
warn_txt_ps LIEWrappedName GhcPs
l))
= do Maybe (GlobalRdrEltX GREInfo)
mb_gre <- RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
lookupGreAvailRn (RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo)))
-> RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
forall a b. (a -> b) -> a -> b
$ LIEWrappedName GhcPs -> IdP GhcPs
forall (p :: Pass). LIEWrappedName (GhcPass p) -> IdP (GhcPass p)
lieWrappedName LIEWrappedName GhcPs
l
Maybe (GlobalRdrEltX GREInfo)
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for Maybe (GlobalRdrEltX GREInfo)
mb_gre ((GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)))
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall a b. (a -> b) -> a -> b
$ \ GlobalRdrEltX GREInfo
gre -> do
let avail :: AvailInfo
avail = GlobalRdrEltX GREInfo -> AvailInfo
forall info. GlobalRdrEltX info -> AvailInfo
availFromGRE GlobalRdrEltX GREInfo
gre
name :: Name
name = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
gre
ExportOccMap
occs' <- ExportOccMap
-> IE GhcPs -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
check_occs ExportOccMap
occs IE GhcPs
ie [GlobalRdrEltX GREInfo
gre]
(ExportWarnSpanNames
export_warn_spans', DontWarnExportNames
dont_warn_export', Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn)
<- ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name
name]
Maybe (LocatedP (WarningTxt GhcPs))
XIEVar GhcPs
warn_txt_ps
(SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportAccum
expacc{ expacc_exp_occs = occs'
, expacc_warn_spans = export_warn_spans'
, expacc_dont_warn = dont_warn_export' }
, SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEVar GhcRn -> LIEWrappedName GhcRn -> IE GhcRn
forall pass. XIEVar pass -> LIEWrappedName pass -> IE pass
IEVar Maybe (LocatedP (WarningTxt GhcRn))
XIEVar GhcRn
warn_txt_rn (LIEWrappedName GhcPs -> IdP GhcRn -> LIEWrappedName GhcRn
replaceLWrappedName LIEWrappedName GhcPs
l IdP GhcRn
Name
name))
, AvailInfo
avail )
lookup_ie expacc :: ExportAccum
expacc@ExportAccum{
expacc_exp_occs :: ExportAccum -> ExportOccMap
expacc_exp_occs = ExportOccMap
occs,
expacc_warn_spans :: ExportAccum -> ExportWarnSpanNames
expacc_warn_spans = ExportWarnSpanNames
export_warn_spans,
expacc_dont_warn :: ExportAccum -> DontWarnExportNames
expacc_dont_warn = DontWarnExportNames
dont_warn_export
} (L SrcSpanAnnA
loc ie :: IE GhcPs
ie@(IEThingAbs (Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps, EpAnn [AddEpAnn]
ann) LIEWrappedName GhcPs
l))
= do Maybe (GlobalRdrEltX GREInfo)
mb_gre <- RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
lookupGreAvailRn (RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo)))
-> RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
forall a b. (a -> b) -> a -> b
$ LIEWrappedName GhcPs -> IdP GhcPs
forall (p :: Pass). LIEWrappedName (GhcPass p) -> IdP (GhcPass p)
lieWrappedName LIEWrappedName GhcPs
l
Maybe (GlobalRdrEltX GREInfo)
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for Maybe (GlobalRdrEltX GREInfo)
mb_gre ((GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)))
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall a b. (a -> b) -> a -> b
$ \ GlobalRdrEltX GREInfo
gre -> do
let avail :: AvailInfo
avail = GlobalRdrEltX GREInfo -> AvailInfo
forall info. GlobalRdrEltX info -> AvailInfo
availFromGRE GlobalRdrEltX GREInfo
gre
name :: Name
name = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
gre
ExportOccMap
occs' <- ExportOccMap
-> IE GhcPs -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
check_occs ExportOccMap
occs IE GhcPs
ie [GlobalRdrEltX GREInfo
gre]
(ExportWarnSpanNames
export_warn_spans', DontWarnExportNames
dont_warn_export', Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn)
<- ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name
name]
Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps
(SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportAccum
expacc{ expacc_exp_occs = occs'
, expacc_warn_spans = export_warn_spans'
, expacc_dont_warn = dont_warn_export' }
, SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEThingAbs GhcRn -> LIEWrappedName GhcRn -> IE GhcRn
forall pass. XIEThingAbs pass -> LIEWrappedName pass -> IE pass
IEThingAbs (Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn, EpAnn [AddEpAnn]
ann) (LIEWrappedName GhcPs -> IdP GhcRn -> LIEWrappedName GhcRn
replaceLWrappedName LIEWrappedName GhcPs
l IdP GhcRn
Name
name))
, AvailInfo
avail )
lookup_ie expacc :: ExportAccum
expacc@ExportAccum{
expacc_exp_occs :: ExportAccum -> ExportOccMap
expacc_exp_occs = ExportOccMap
occs,
expacc_warn_spans :: ExportAccum -> ExportWarnSpanNames
expacc_warn_spans = ExportWarnSpanNames
export_warn_spans,
expacc_dont_warn :: ExportAccum -> DontWarnExportNames
expacc_dont_warn = DontWarnExportNames
dont_warn_export
} (L SrcSpanAnnA
loc ie :: IE GhcPs
ie@(IEThingAll (Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps, EpAnn [AddEpAnn]
ann) LIEWrappedName GhcPs
l))
= do Maybe (GlobalRdrEltX GREInfo)
mb_gre <- RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
lookupGreAvailRn (RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo)))
-> RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
forall a b. (a -> b) -> a -> b
$ LIEWrappedName GhcPs -> IdP GhcPs
forall (p :: Pass). LIEWrappedName (GhcPass p) -> IdP (GhcPass p)
lieWrappedName LIEWrappedName GhcPs
l
Maybe (GlobalRdrEltX GREInfo)
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for Maybe (GlobalRdrEltX GREInfo)
mb_gre ((GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)))
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall a b. (a -> b) -> a -> b
$ \ GlobalRdrEltX GREInfo
par -> do
[GlobalRdrEltX GREInfo]
all_kids <- IE GhcPs
-> LIEWrappedName GhcPs
-> GlobalRdrEltX GREInfo
-> RnM [GlobalRdrEltX GREInfo]
lookup_ie_kids_all IE GhcPs
ie LIEWrappedName GhcPs
l GlobalRdrEltX GREInfo
par
let name :: Name
name = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
par
all_gres :: [GlobalRdrEltX GREInfo]
all_gres = GlobalRdrEltX GREInfo
par GlobalRdrEltX GREInfo
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall a. a -> [a] -> [a]
: [GlobalRdrEltX GREInfo]
all_kids
all_names :: [Name]
all_names = (GlobalRdrEltX GREInfo -> Name)
-> [GlobalRdrEltX GREInfo] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName [GlobalRdrEltX GREInfo]
all_gres
ExportOccMap
occs' <- ExportOccMap
-> IE GhcPs -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
check_occs ExportOccMap
occs IE GhcPs
ie [GlobalRdrEltX GREInfo]
all_gres
(ExportWarnSpanNames
export_warn_spans', DontWarnExportNames
dont_warn_export', Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn)
<- ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name]
all_names
Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps
(SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportAccum
expacc{ expacc_exp_occs = occs'
, expacc_warn_spans = export_warn_spans'
, expacc_dont_warn = dont_warn_export' }
, SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEThingAll GhcRn -> LIEWrappedName GhcRn -> IE GhcRn
forall pass. XIEThingAll pass -> LIEWrappedName pass -> IE pass
IEThingAll (Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn, EpAnn [AddEpAnn]
ann) (LIEWrappedName GhcPs -> IdP GhcRn -> LIEWrappedName GhcRn
replaceLWrappedName LIEWrappedName GhcPs
l IdP GhcRn
Name
name))
, Name -> [Name] -> AvailInfo
AvailTC Name
name [Name]
all_names )
lookup_ie expacc :: ExportAccum
expacc@ExportAccum{
expacc_exp_occs :: ExportAccum -> ExportOccMap
expacc_exp_occs = ExportOccMap
occs,
expacc_warn_spans :: ExportAccum -> ExportWarnSpanNames
expacc_warn_spans = ExportWarnSpanNames
export_warn_spans,
expacc_dont_warn :: ExportAccum -> DontWarnExportNames
expacc_dont_warn = DontWarnExportNames
dont_warn_export
} (L SrcSpanAnnA
loc ie :: IE GhcPs
ie@(IEThingWith (Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps, EpAnn [AddEpAnn]
ann) LIEWrappedName GhcPs
l IEWildcard
wc [LIEWrappedName GhcPs]
sub_rdrs))
= do Maybe (GlobalRdrEltX GREInfo)
mb_gre <- IE GhcPs
-> RnM (Maybe (GlobalRdrEltX GREInfo))
-> RnM (Maybe (GlobalRdrEltX GREInfo))
forall (p :: Pass) a.
OutputableBndrId p =>
IE (GhcPass p) -> TcM a -> TcM a
addExportErrCtxt IE GhcPs
ie
(RnM (Maybe (GlobalRdrEltX GREInfo))
-> RnM (Maybe (GlobalRdrEltX GREInfo)))
-> RnM (Maybe (GlobalRdrEltX GREInfo))
-> RnM (Maybe (GlobalRdrEltX GREInfo))
forall a b. (a -> b) -> a -> b
$ RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
lookupGreAvailRn (RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo)))
-> RdrName -> RnM (Maybe (GlobalRdrEltX GREInfo))
forall a b. (a -> b) -> a -> b
$ LIEWrappedName GhcPs -> IdP GhcPs
forall (p :: Pass). LIEWrappedName (GhcPass p) -> IdP (GhcPass p)
lieWrappedName LIEWrappedName GhcPs
l
Maybe (GlobalRdrEltX GREInfo)
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for Maybe (GlobalRdrEltX GREInfo)
mb_gre ((GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)))
-> (GlobalRdrEltX GREInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall a b. (a -> b) -> a -> b
$ \ GlobalRdrEltX GREInfo
par -> do
([GenLocated SrcSpanAnnA (IEWrappedName GhcRn)]
subs, [GlobalRdrEltX GREInfo]
with_kids)
<- IE GhcPs
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
forall (p :: Pass) a.
OutputableBndrId p =>
IE (GhcPass p) -> TcM a -> TcM a
addExportErrCtxt IE GhcPs
ie
(TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo]))
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
forall a b. (a -> b) -> a -> b
$ GlobalRdrEltX GREInfo
-> [LIEWrappedName GhcPs]
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
lookup_ie_kids_with GlobalRdrEltX GREInfo
par [LIEWrappedName GhcPs]
sub_rdrs
[GlobalRdrEltX GREInfo]
wc_kids <-
case IEWildcard
wc of
IEWildcard
NoIEWildcard -> [GlobalRdrEltX GREInfo] -> RnM [GlobalRdrEltX GREInfo]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return []
IEWildcard Int
_ -> IE GhcPs
-> LIEWrappedName GhcPs
-> GlobalRdrEltX GREInfo
-> RnM [GlobalRdrEltX GREInfo]
lookup_ie_kids_all IE GhcPs
ie LIEWrappedName GhcPs
l GlobalRdrEltX GREInfo
par
let name :: Name
name = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
par
all_kids :: [GlobalRdrEltX GREInfo]
all_kids = [GlobalRdrEltX GREInfo]
with_kids [GlobalRdrEltX GREInfo]
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall a. [a] -> [a] -> [a]
++ [GlobalRdrEltX GREInfo]
wc_kids
all_gres :: [GlobalRdrEltX GREInfo]
all_gres = GlobalRdrEltX GREInfo
par GlobalRdrEltX GREInfo
-> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall a. a -> [a] -> [a]
: [GlobalRdrEltX GREInfo]
all_kids
all_names :: [Name]
all_names = (GlobalRdrEltX GREInfo -> Name)
-> [GlobalRdrEltX GREInfo] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName [GlobalRdrEltX GREInfo]
all_gres
ExportOccMap
occs' <- ExportOccMap
-> IE GhcPs -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
check_occs ExportOccMap
occs IE GhcPs
ie [GlobalRdrEltX GREInfo]
all_gres
(ExportWarnSpanNames
export_warn_spans', DontWarnExportNames
dont_warn_export', Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn)
<- ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name]
all_names
Maybe (LocatedP (WarningTxt GhcPs))
warn_txt_ps
(SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportAccum
expacc{ expacc_exp_occs = occs'
, expacc_warn_spans = export_warn_spans'
, expacc_dont_warn = dont_warn_export' }
, SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEThingWith GhcRn
-> LIEWrappedName GhcRn
-> IEWildcard
-> [LIEWrappedName GhcRn]
-> IE GhcRn
forall pass.
XIEThingWith pass
-> LIEWrappedName pass
-> IEWildcard
-> [LIEWrappedName pass]
-> IE pass
IEThingWith (Maybe (LocatedP (WarningTxt GhcRn))
warn_txt_rn, EpAnn [AddEpAnn]
ann) (LIEWrappedName GhcPs -> IdP GhcRn -> LIEWrappedName GhcRn
replaceLWrappedName LIEWrappedName GhcPs
l IdP GhcRn
Name
name) IEWildcard
wc [LIEWrappedName GhcRn]
[GenLocated SrcSpanAnnA (IEWrappedName GhcRn)]
subs)
, Name -> [Name] -> AvailInfo
AvailTC Name
name [Name]
all_names )
lookup_ie ExportAccum
_ LIE GhcPs
_ = String
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (ExportAccum, GenLocated SrcSpanAnnA (IE GhcRn), AvailInfo))
forall a. HasCallStack => String -> a
panic String
"lookup_ie"
lookup_ie_kids_with :: GlobalRdrElt -> [LIEWrappedName GhcPs]
-> RnM ([LIEWrappedName GhcRn], [GlobalRdrElt])
lookup_ie_kids_with :: GlobalRdrEltX GREInfo
-> [LIEWrappedName GhcPs]
-> TcM ([LIEWrappedName GhcRn], [GlobalRdrEltX GREInfo])
lookup_ie_kids_with GlobalRdrEltX GREInfo
gre [LIEWrappedName GhcPs]
sub_rdrs =
do { let name :: Name
name = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
gre
; [(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)]
kids <- Name
-> [LIEWrappedName GhcPs]
-> RnM [(LIEWrappedName GhcRn, GlobalRdrEltX GREInfo)]
lookupChildrenExport Name
name [LIEWrappedName GhcPs]
sub_rdrs
; ([GenLocated SrcSpanAnnA (IEWrappedName GhcRn)],
[GlobalRdrEltX GREInfo])
-> IOEnv
(Env TcGblEnv TcLclEnv)
([GenLocated SrcSpanAnnA (IEWrappedName GhcRn)],
[GlobalRdrEltX GREInfo])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (((GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn))
-> [(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)]
-> [GenLocated SrcSpanAnnA (IEWrappedName GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
forall a b. (a, b) -> a
fst [(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)]
kids, ((GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
-> GlobalRdrEltX GREInfo)
-> [(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)]
-> [GlobalRdrEltX GREInfo]
forall a b. (a -> b) -> [a] -> [b]
map (GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
-> GlobalRdrEltX GREInfo
forall a b. (a, b) -> b
snd [(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)]
kids) }
lookup_ie_kids_all :: IE GhcPs -> LIEWrappedName GhcPs -> GlobalRdrElt
-> RnM [GlobalRdrElt]
lookup_ie_kids_all :: IE GhcPs
-> LIEWrappedName GhcPs
-> GlobalRdrEltX GREInfo
-> RnM [GlobalRdrEltX GREInfo]
lookup_ie_kids_all IE GhcPs
ie (L SrcSpanAnnA
_ IEWrappedName GhcPs
rdr) GlobalRdrEltX GREInfo
gre =
do { let name :: Name
name = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
gre
gres :: [GlobalRdrEltX GREInfo]
gres = NameEnv [GlobalRdrEltX GREInfo] -> Name -> [GlobalRdrEltX GREInfo]
forall a. NameEnv [a] -> Name -> [a]
findChildren NameEnv [GlobalRdrEltX GREInfo]
kids_env Name
name
; RdrName -> [GlobalRdrEltX GREInfo] -> TcRn ()
addUsedKids (IEWrappedName GhcPs -> IdP GhcPs
forall (p :: Pass). IEWrappedName (GhcPass p) -> IdP (GhcPass p)
ieWrappedName IEWrappedName GhcPs
rdr) [GlobalRdrEltX GREInfo]
gres
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([GlobalRdrEltX GREInfo] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GlobalRdrEltX GREInfo]
gres) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
if Name -> Bool
isTyConName Name
name
then TcRnMessage -> TcRn ()
addTcRnDiagnostic (GlobalRdrEltX GREInfo -> TcRnMessage
TcRnDodgyExports GlobalRdrEltX GREInfo
gre)
else
TcRnMessage -> TcRn ()
addErr (IE GhcPs -> TcRnMessage
TcRnExportHiddenComponents IE GhcPs
ie)
; [GlobalRdrEltX GREInfo] -> RnM [GlobalRdrEltX GREInfo]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [GlobalRdrEltX GREInfo]
gres }
rn_warning_txt_loc :: LocatedP (WarningTxt GhcPs) -> RnM (LocatedP (WarningTxt GhcRn))
rn_warning_txt_loc :: LocatedP (WarningTxt GhcPs) -> RnM (LocatedP (WarningTxt GhcRn))
rn_warning_txt_loc (L SrcSpanAnnP
loc WarningTxt GhcPs
warn_txt) = SrcSpanAnnP -> WarningTxt GhcRn -> LocatedP (WarningTxt GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnP
loc (WarningTxt GhcRn -> LocatedP (WarningTxt GhcRn))
-> IOEnv (Env TcGblEnv TcLclEnv) (WarningTxt GhcRn)
-> RnM (LocatedP (WarningTxt GhcRn))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WarningTxt GhcPs
-> IOEnv (Env TcGblEnv TcLclEnv) (WarningTxt GhcRn)
rnWarningTxt WarningTxt GhcPs
warn_txt
process_warning :: ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM (ExportWarnSpanNames,
DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning :: ExportWarnSpanNames
-> DontWarnExportNames
-> [Name]
-> Maybe (LocatedP (WarningTxt GhcPs))
-> SrcSpan
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name]
names Maybe (LocatedP (WarningTxt GhcPs))
Nothing SrcSpan
loc
= (ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportWarnSpanNames
export_warn_spans
, (Name -> DontWarnExportNames -> DontWarnExportNames)
-> DontWarnExportNames -> [Name] -> DontWarnExportNames
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Name -> DontWarnExportNames -> DontWarnExportNames
update_dont_warn_export
DontWarnExportNames
dont_warn_export [Name]
names
, Maybe (LocatedP (WarningTxt GhcRn))
forall a. Maybe a
Nothing )
where
update_dont_warn_export :: Name -> DontWarnExportNames -> DontWarnExportNames
update_dont_warn_export :: Name -> DontWarnExportNames -> DontWarnExportNames
update_dont_warn_export Name
name DontWarnExportNames
dont_warn_export'
= (SrcSpan -> NonEmpty SrcSpan -> NonEmpty SrcSpan)
-> (SrcSpan -> NonEmpty SrcSpan)
-> DontWarnExportNames
-> Name
-> SrcSpan
-> DontWarnExportNames
forall a b.
(a -> b -> b) -> (a -> b) -> NameEnv b -> Name -> a -> NameEnv b
extendNameEnv_Acc SrcSpan -> NonEmpty SrcSpan -> NonEmpty SrcSpan
forall a. a -> NonEmpty a -> NonEmpty a
(NE.<|)
SrcSpan -> NonEmpty SrcSpan
forall a. a -> NonEmpty a
NE.singleton
DontWarnExportNames
dont_warn_export'
Name
name
SrcSpan
loc
process_warning ExportWarnSpanNames
export_warn_spans
DontWarnExportNames
dont_warn_export
[Name]
names (Just LocatedP (WarningTxt GhcPs)
warn_txt_ps) SrcSpan
loc
= do
LocatedP (WarningTxt GhcRn)
warn_txt_rn <- LocatedP (WarningTxt GhcPs) -> RnM (LocatedP (WarningTxt GhcRn))
rn_warning_txt_loc LocatedP (WarningTxt GhcPs)
warn_txt_ps
let new_export_warn_spans :: ExportWarnSpanNames
new_export_warn_spans = (Name -> (Name, WarningTxt GhcRn, SrcSpan))
-> [Name] -> ExportWarnSpanNames
forall a b. (a -> b) -> [a] -> [b]
map (, LocatedP (WarningTxt GhcRn) -> WarningTxt GhcRn
forall l e. GenLocated l e -> e
unLoc LocatedP (WarningTxt GhcRn)
warn_txt_rn, SrcSpan
loc) [Name]
names
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
-> RnM
(ExportWarnSpanNames, DontWarnExportNames,
Maybe (LocatedP (WarningTxt GhcRn)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( ExportWarnSpanNames
new_export_warn_spans ExportWarnSpanNames -> ExportWarnSpanNames -> ExportWarnSpanNames
forall a. [a] -> [a] -> [a]
++ ExportWarnSpanNames
export_warn_spans
, DontWarnExportNames
dont_warn_export
, LocatedP (WarningTxt GhcRn) -> Maybe (LocatedP (WarningTxt GhcRn))
forall a. a -> Maybe a
Just LocatedP (WarningTxt GhcRn)
warn_txt_rn )
aggregate_warnings :: ExportWarnSpanNames
-> DontWarnExportNames
-> RnM (ExportWarnNames GhcRn)
aggregate_warnings :: ExportWarnSpanNames
-> DontWarnExportNames -> RnM (ExportWarnNames GhcRn)
aggregate_warnings ExportWarnSpanNames
export_warn_spans DontWarnExportNames
dont_warn_export
= ([Maybe (Name, WarningTxt GhcRn)] -> ExportWarnNames GhcRn)
-> IOEnv (Env TcGblEnv TcLclEnv) [Maybe (Name, WarningTxt GhcRn)]
-> RnM (ExportWarnNames GhcRn)
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 [Maybe (Name, WarningTxt GhcRn)] -> ExportWarnNames GhcRn
forall a. [Maybe a] -> [a]
catMaybes
(IOEnv (Env TcGblEnv TcLclEnv) [Maybe (Name, WarningTxt GhcRn)]
-> RnM (ExportWarnNames GhcRn))
-> IOEnv (Env TcGblEnv TcLclEnv) [Maybe (Name, WarningTxt GhcRn)]
-> RnM (ExportWarnNames GhcRn)
forall a b. (a -> b) -> a -> b
$ (NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn)))
-> [NonEmpty (Name, WarningTxt GhcRn, SrcSpan)]
-> IOEnv (Env TcGblEnv TcLclEnv) [Maybe (Name, WarningTxt GhcRn)]
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 ((Name, NonEmpty (WarningTxt GhcRn, SrcSpan))
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn))
aggregate_single ((Name, NonEmpty (WarningTxt GhcRn, SrcSpan))
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn)))
-> (NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> (Name, NonEmpty (WarningTxt GhcRn, SrcSpan)))
-> NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> (Name, NonEmpty (WarningTxt GhcRn, SrcSpan))
extract_name)
([NonEmpty (Name, WarningTxt GhcRn, SrcSpan)]
-> IOEnv (Env TcGblEnv TcLclEnv) [Maybe (Name, WarningTxt GhcRn)])
-> [NonEmpty (Name, WarningTxt GhcRn, SrcSpan)]
-> IOEnv (Env TcGblEnv TcLclEnv) [Maybe (Name, WarningTxt GhcRn)]
forall a b. (a -> b) -> a -> b
$ ((Name, WarningTxt GhcRn, SrcSpan)
-> (Name, WarningTxt GhcRn, SrcSpan) -> Bool)
-> ExportWarnSpanNames
-> [NonEmpty (Name, WarningTxt GhcRn, SrcSpan)]
forall (f :: * -> *) a.
Foldable f =>
(a -> a -> Bool) -> f a -> [NonEmpty a]
NE.groupBy (\(Name
n1, WarningTxt GhcRn
_, SrcSpan
_) (Name
n2, WarningTxt GhcRn
_, SrcSpan
_) -> Name
n1 Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
n2)
(ExportWarnSpanNames
-> [NonEmpty (Name, WarningTxt GhcRn, SrcSpan)])
-> ExportWarnSpanNames
-> [NonEmpty (Name, WarningTxt GhcRn, SrcSpan)]
forall a b. (a -> b) -> a -> b
$ ((Name, WarningTxt GhcRn, SrcSpan)
-> (Name, WarningTxt GhcRn, SrcSpan) -> Ordering)
-> ExportWarnSpanNames -> ExportWarnSpanNames
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (\(Name
n1, WarningTxt GhcRn
_, SrcSpan
_) (Name
n2, WarningTxt GhcRn
_, SrcSpan
_) -> Name
n1 Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
n2) ExportWarnSpanNames
export_warn_spans
where
extract_name :: NE.NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> (Name, NE.NonEmpty (WarningTxt GhcRn, SrcSpan))
extract_name :: NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> (Name, NonEmpty (WarningTxt GhcRn, SrcSpan))
extract_name l :: NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
l@((Name
name, WarningTxt GhcRn
_, SrcSpan
_) NE.:| ExportWarnSpanNames
_)
= (Name
name, ((Name, WarningTxt GhcRn, SrcSpan) -> (WarningTxt GhcRn, SrcSpan))
-> NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
-> NonEmpty (WarningTxt GhcRn, SrcSpan)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map (\(Name
_, WarningTxt GhcRn
warn_txt, SrcSpan
span) -> (WarningTxt GhcRn
warn_txt, SrcSpan
span)) NonEmpty (Name, WarningTxt GhcRn, SrcSpan)
l)
aggregate_single :: (Name, NE.NonEmpty (WarningTxt GhcRn, SrcSpan))
-> RnM (Maybe (Name, WarningTxt GhcRn))
aggregate_single :: (Name, NonEmpty (WarningTxt GhcRn, SrcSpan))
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn))
aggregate_single (Name
name, (WarningTxt GhcRn
warn_txt_rn, SrcSpan
loc) NE.:| [(WarningTxt GhcRn, SrcSpan)]
warn_spans)
= do
case [SrcSpan] -> Maybe (NonEmpty SrcSpan)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [SrcSpan]
spans_different of
Maybe (NonEmpty SrcSpan)
Nothing -> () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just NonEmpty SrcSpan
spans_different
-> SrcSpan -> TcRnMessage -> TcRn ()
addErrAt SrcSpan
loc (Name -> NonEmpty SrcSpan -> TcRnMessage
TcRnDifferentExportWarnings Name
name NonEmpty SrcSpan
spans_different)
case DontWarnExportNames -> Name -> Maybe (NonEmpty SrcSpan)
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv DontWarnExportNames
dont_warn_export Name
name of
Maybe (NonEmpty SrcSpan)
Nothing -> Maybe (Name, WarningTxt GhcRn)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Name, WarningTxt GhcRn)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn)))
-> Maybe (Name, WarningTxt GhcRn)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn))
forall a b. (a -> b) -> a -> b
$ (Name, WarningTxt GhcRn) -> Maybe (Name, WarningTxt GhcRn)
forall a. a -> Maybe a
Just (Name
name, WarningTxt GhcRn
warn_txt_rn)
Just NonEmpty SrcSpan
not_warned_spans -> do
SrcSpan -> TcRnMessage -> TcRn ()
addDiagnosticAt SrcSpan
loc (Name -> NonEmpty SrcSpan -> TcRnMessage
TcRnIncompleteExportWarnings Name
name NonEmpty SrcSpan
not_warned_spans)
Maybe (Name, WarningTxt GhcRn)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (Name, WarningTxt GhcRn))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Name, WarningTxt GhcRn)
forall a. Maybe a
Nothing
where
spans_different :: [SrcSpan]
spans_different = ((WarningTxt GhcRn, SrcSpan) -> SrcSpan)
-> [(WarningTxt GhcRn, SrcSpan)] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map (WarningTxt GhcRn, SrcSpan) -> SrcSpan
forall a b. (a, b) -> b
snd ([(WarningTxt GhcRn, SrcSpan)] -> [SrcSpan])
-> [(WarningTxt GhcRn, SrcSpan)] -> [SrcSpan]
forall a b. (a -> b) -> a -> b
$ ((WarningTxt GhcRn, SrcSpan) -> Bool)
-> [(WarningTxt GhcRn, SrcSpan)] -> [(WarningTxt GhcRn, SrcSpan)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> ((WarningTxt GhcRn, SrcSpan) -> Bool)
-> (WarningTxt GhcRn, SrcSpan)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WarningTxt GhcRn -> WarningTxt GhcRn -> Bool
forall p1 p2. WarningTxt p1 -> WarningTxt p2 -> Bool
warningTxtSame WarningTxt GhcRn
warn_txt_rn (WarningTxt GhcRn -> Bool)
-> ((WarningTxt GhcRn, SrcSpan) -> WarningTxt GhcRn)
-> (WarningTxt GhcRn, SrcSpan)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WarningTxt GhcRn, SrcSpan) -> WarningTxt GhcRn
forall a b. (a, b) -> a
fst) [(WarningTxt GhcRn, SrcSpan)]
warn_spans
lookup_doc_ie :: LIE GhcPs -> RnM (Maybe (LIE GhcRn))
lookup_doc_ie :: LIE GhcPs -> RnM (Maybe (LIE GhcRn))
lookup_doc_ie (L SrcSpanAnnA
loc (IEGroup XIEGroup GhcPs
_ Int
lev LHsDoc GhcPs
doc)) = do
LHsDoc GhcRn
doc' <- LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc LHsDoc GhcPs
doc
Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv) (Maybe (GenLocated SrcSpanAnnA (IE GhcRn)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (GenLocated SrcSpanAnnA (IE GhcRn))))
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv) (Maybe (GenLocated SrcSpanAnnA (IE GhcRn)))
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (IE GhcRn)
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
forall a. a -> Maybe a
Just (SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEGroup GhcRn -> Int -> LHsDoc GhcRn -> IE GhcRn
forall pass. XIEGroup pass -> Int -> LHsDoc pass -> IE pass
IEGroup XIEGroup GhcRn
NoExtField
noExtField Int
lev LHsDoc GhcRn
doc'))
lookup_doc_ie (L SrcSpanAnnA
loc (IEDoc XIEDoc GhcPs
_ LHsDoc GhcPs
doc)) = do
LHsDoc GhcRn
doc' <- LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc LHsDoc GhcPs
doc
Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv) (Maybe (GenLocated SrcSpanAnnA (IE GhcRn)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(Maybe (GenLocated SrcSpanAnnA (IE GhcRn))))
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv) (Maybe (GenLocated SrcSpanAnnA (IE GhcRn)))
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (IE GhcRn)
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
forall a. a -> Maybe a
Just (SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEDoc GhcRn -> LHsDoc GhcRn -> IE GhcRn
forall pass. XIEDoc pass -> LHsDoc pass -> IE pass
IEDoc XIEDoc GhcRn
NoExtField
noExtField LHsDoc GhcRn
doc'))
lookup_doc_ie (L SrcSpanAnnA
loc (IEDocNamed XIEDocNamed GhcPs
_ String
str))
= Maybe (LIE GhcRn) -> RnM (Maybe (LIE GhcRn))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (LIE GhcRn) -> RnM (Maybe (LIE GhcRn)))
-> Maybe (LIE GhcRn) -> RnM (Maybe (LIE GhcRn))
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (IE GhcRn)
-> Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
forall a. a -> Maybe a
Just (SrcSpanAnnA -> IE GhcRn -> GenLocated SrcSpanAnnA (IE GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (XIEDocNamed GhcRn -> String -> IE GhcRn
forall pass. XIEDocNamed pass -> String -> IE pass
IEDocNamed XIEDocNamed GhcRn
NoExtField
noExtField String
str))
lookup_doc_ie LIE GhcPs
_ = Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
-> IOEnv
(Env TcGblEnv TcLclEnv) (Maybe (GenLocated SrcSpanAnnA (IE GhcRn)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (GenLocated SrcSpanAnnA (IE GhcRn))
forall a. Maybe a
Nothing
addUsedKids :: RdrName -> [GlobalRdrElt] -> RnM ()
addUsedKids :: RdrName -> [GlobalRdrEltX GREInfo] -> TcRn ()
addUsedKids RdrName
parent_rdr [GlobalRdrEltX GREInfo]
kid_gres
= DeprecationWarnings -> [GlobalRdrEltX GREInfo] -> TcRn ()
addUsedGREs DeprecationWarnings
ExportDeprecationWarnings (RdrName -> [GlobalRdrEltX GREInfo] -> [GlobalRdrEltX GREInfo]
forall info.
RdrName -> [GlobalRdrEltX info] -> [GlobalRdrEltX info]
pickGREs RdrName
parent_rdr [GlobalRdrEltX GREInfo]
kid_gres)
lookupChildrenExport :: Name -> [LIEWrappedName GhcPs]
-> RnM ([(LIEWrappedName GhcRn, GlobalRdrElt)])
lookupChildrenExport :: Name
-> [LIEWrappedName GhcPs]
-> RnM [(LIEWrappedName GhcRn, GlobalRdrEltX GREInfo)]
lookupChildrenExport Name
spec_parent [LIEWrappedName GhcPs]
rdr_items = (LocatedAn AnnListItem (IEWrappedName GhcPs)
-> TcRn
(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo))
-> [LocatedAn AnnListItem (IEWrappedName GhcPs)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
[(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)]
forall a b. (a -> TcRn b) -> [a] -> TcRn [b]
mapAndReportM LIEWrappedName GhcPs
-> RnM (LIEWrappedName GhcRn, GlobalRdrEltX GREInfo)
LocatedAn AnnListItem (IEWrappedName GhcPs)
-> TcRn
(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
doOne [LIEWrappedName GhcPs]
[LocatedAn AnnListItem (IEWrappedName GhcPs)]
rdr_items
where
doOne :: LIEWrappedName GhcPs
-> RnM (LIEWrappedName GhcRn, GlobalRdrElt)
doOne :: LIEWrappedName GhcPs
-> RnM (LIEWrappedName GhcRn, GlobalRdrEltX GREInfo)
doOne LIEWrappedName GhcPs
n = do
let bareName :: RdrName
bareName = (IEWrappedName GhcPs -> IdP GhcPs
IEWrappedName GhcPs -> RdrName
forall (p :: Pass). IEWrappedName (GhcPass p) -> IdP (GhcPass p)
ieWrappedName (IEWrappedName GhcPs -> RdrName)
-> (LocatedAn AnnListItem (IEWrappedName GhcPs)
-> IEWrappedName GhcPs)
-> LocatedAn AnnListItem (IEWrappedName GhcPs)
-> RdrName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocatedAn AnnListItem (IEWrappedName GhcPs) -> IEWrappedName GhcPs
forall l e. GenLocated l e -> e
unLoc) LIEWrappedName GhcPs
LocatedAn AnnListItem (IEWrappedName GhcPs)
n
what_lkup :: LookupChild
what_lkup :: LookupChild
what_lkup =
LookupChild
{ wantedParent :: Name
wantedParent = Name
spec_parent
, lookupDataConFirst :: Bool
lookupDataConFirst = Bool
True
, prioritiseParent :: Bool
prioritiseParent = Bool
False
}
ChildLookupResult
name <- Bool
-> DeprecationWarnings
-> Name
-> RdrName
-> LookupChild
-> RnM ChildLookupResult
lookupSubBndrOcc_helper Bool
False DeprecationWarnings
ExportDeprecationWarnings
Name
spec_parent RdrName
bareName LookupChild
what_lkup
String -> SDoc -> TcRn ()
traceRn String
"lookupChildrenExport" (ChildLookupResult -> SDoc
forall a. Outputable a => a -> SDoc
ppr ChildLookupResult
name)
let unboundName :: RdrName
unboundName :: RdrName
unboundName = if RdrName -> NameSpace
rdrNameSpace RdrName
bareName NameSpace -> NameSpace -> Bool
forall a. Eq a => a -> a -> Bool
== NameSpace
varName
then RdrName
bareName
else RdrName -> NameSpace -> RdrName
setRdrNameSpace RdrName
bareName NameSpace
dataName
case ChildLookupResult
name of
ChildLookupResult
NameNotFound ->
do { Name
ub <- RdrName -> RnM Name
reportUnboundName RdrName
unboundName
; let l :: SrcSpanAnnA
l = LocatedAn AnnListItem (IEWrappedName GhcPs) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc LIEWrappedName GhcPs
LocatedAn AnnListItem (IEWrappedName GhcPs)
n
gre :: GlobalRdrEltX GREInfo
gre = GREInfo -> Parent -> Name -> GlobalRdrEltX GREInfo
mkLocalGRE GREInfo
UnboundGRE Parent
NoParent Name
ub
; (GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
-> TcRn
(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> IEWrappedName GhcRn
-> GenLocated SrcSpanAnnA (IEWrappedName GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (XIEName GhcRn -> LIdP GhcRn -> IEWrappedName GhcRn
forall p. XIEName p -> LIdP p -> IEWrappedName p
IEName XIEName GhcRn
NoExtField
noExtField (SrcSpanAnnN -> Name -> GenLocated SrcSpanAnnN Name
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpanAnnN
forall a. SrcSpanAnn' a -> SrcSpanAnnN
la2na SrcSpanAnnA
l) Name
ub)), GlobalRdrEltX GREInfo
gre)}
FoundChild child :: GlobalRdrEltX GREInfo
child@(GRE { gre_name :: forall info. GlobalRdrEltX info -> Name
gre_name = Name
child_nm, gre_par :: forall info. GlobalRdrEltX info -> Parent
gre_par = Parent
par }) ->
do { Name -> Parent -> Name -> TcRn ()
checkPatSynParent Name
spec_parent Parent
par Name
child_nm
; (GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
-> TcRn
(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (LIEWrappedName GhcPs -> IdP GhcRn -> LIEWrappedName GhcRn
replaceLWrappedName LIEWrappedName GhcPs
n IdP GhcRn
Name
child_nm, GlobalRdrEltX GREInfo
child)
}
IncorrectParent Name
p GlobalRdrEltX GREInfo
c [Name]
gs -> Name
-> Name
-> [Name]
-> TcRn
(GenLocated SrcSpanAnnA (IEWrappedName GhcRn),
GlobalRdrEltX GREInfo)
forall a. Name -> Name -> [Name] -> TcM a
failWithDcErr Name
p (GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
c) [Name]
gs
checkPatSynParent :: Name
-> Parent
-> Name
-> TcM ()
checkPatSynParent :: Name -> Parent -> Name -> TcRn ()
checkPatSynParent Name
_ (ParentIs {}) Name
_
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkPatSynParent Name
parent Parent
NoParent Name
nm
| Name -> Bool
isUnboundName Name
parent
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { TyCon
parent_ty_con <- Name -> TcM TyCon
tcLookupTyCon Name
parent
; TyThing
mpat_syn_thing <- Name -> TcM TyThing
tcLookupGlobal Name
nm
; case TyThing
mpat_syn_thing of
AnId Id
i | Id -> Bool
isId Id
i
, RecSelId { sel_tycon :: IdDetails -> RecSelParent
sel_tycon = RecSelPatSyn PatSyn
p } <- Id -> IdDetails
idDetails Id
i
-> SDoc -> TyCon -> PatSyn -> TcRn ()
handle_pat_syn (Name -> SDoc
selErr Name
nm) TyCon
parent_ty_con PatSyn
p
AConLike (PatSynCon PatSyn
p) -> SDoc -> TyCon -> PatSyn -> TcRn ()
handle_pat_syn (PatSyn -> SDoc
psErr PatSyn
p) TyCon
parent_ty_con PatSyn
p
TyThing
_ -> Name -> Name -> [Name] -> TcRn ()
forall a. Name -> Name -> [Name] -> TcM a
failWithDcErr Name
parent Name
nm [] }
where
psErr :: PatSyn -> SDoc
psErr = String -> PatSyn -> SDoc
forall o. Outputable o => String -> o -> SDoc
exportErrCtxt String
"pattern synonym"
selErr :: Name -> SDoc
selErr = String -> Name -> SDoc
forall o. Outputable o => String -> o -> SDoc
exportErrCtxt String
"pattern synonym record selector"
handle_pat_syn :: SDoc
-> TyCon
-> PatSyn
-> TcM ()
handle_pat_syn :: SDoc -> TyCon -> PatSyn -> TcRn ()
handle_pat_syn SDoc
doc TyCon
ty_con PatSyn
pat_syn
| Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ TyCon -> Bool
isTyConWithSrcDataCons TyCon
ty_con
= SDoc -> TcRn () -> TcRn ()
forall a. SDoc -> TcM a -> TcM a
addErrCtxt SDoc
doc (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ TcRnMessage -> TcRn ()
forall a. TcRnMessage -> TcM a
failWithTc TcRnMessage
TcRnPatSynBundledWithNonDataCon
| Maybe TyCon
Nothing <- Maybe TyCon
mtycon
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Just TyCon
p_ty_con <- Maybe TyCon
mtycon, TyCon
p_ty_con TyCon -> TyCon -> Bool
forall a. Eq a => a -> a -> Bool
/= TyCon
ty_con
= SDoc -> TcRn () -> TcRn ()
forall a. SDoc -> TcM a -> TcM a
addErrCtxt SDoc
doc (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ TcRnMessage -> TcRn ()
forall a. TcRnMessage -> TcM a
failWithTc
(Type -> Type -> TcRnMessage
TcRnPatSynBundledWithWrongType Type
expected_res_ty Type
res_ty)
| Bool
otherwise
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
expected_res_ty :: Type
expected_res_ty = TyCon -> [Type] -> Type
mkTyConApp TyCon
ty_con ([Id] -> [Type]
mkTyVarTys (TyCon -> [Id]
tyConTyVars TyCon
ty_con))
([Id]
_, [Type]
_, [Id]
_, [Type]
_, [Scaled Type]
_, Type
res_ty) = PatSyn -> ([Id], [Type], [Id], [Type], [Scaled Type], Type)
patSynSig PatSyn
pat_syn
mtycon :: Maybe TyCon
mtycon = (TyCon, [Type]) -> TyCon
forall a b. (a, b) -> a
fst ((TyCon, [Type]) -> TyCon) -> Maybe (TyCon, [Type]) -> Maybe TyCon
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
tcSplitTyConApp_maybe Type
res_ty
check_occs :: ExportOccMap -> IE GhcPs -> [GlobalRdrElt] -> RnM ExportOccMap
check_occs :: ExportOccMap
-> IE GhcPs -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
check_occs ExportOccMap
occs IE GhcPs
ie [GlobalRdrEltX GREInfo]
gres
= do { Bool
drf <- Extension -> IOEnv (Env TcGblEnv TcLclEnv) Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.DuplicateRecordFields
; (ExportOccMap -> GlobalRdrEltX GREInfo -> RnM ExportOccMap)
-> ExportOccMap -> [GlobalRdrEltX GREInfo] -> RnM ExportOccMap
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM (Bool -> ExportOccMap -> GlobalRdrEltX GREInfo -> RnM ExportOccMap
check Bool
drf) ExportOccMap
occs [GlobalRdrEltX GREInfo]
gres }
where
check :: Bool -> ExportOccMap -> GlobalRdrElt -> RnM ExportOccMap
check :: Bool -> ExportOccMap -> GlobalRdrEltX GREInfo -> RnM ExportOccMap
check Bool
drf_enabled ExportOccMap
occs GlobalRdrEltX GREInfo
gre
= case ExportOccMap
-> GlobalRdrEltX GREInfo -> Either (Name, IE GhcPs) ExportOccMap
try_insert ExportOccMap
occs GlobalRdrEltX GREInfo
gre of
Right ExportOccMap
occs'
| Bool
drf_enabled Bool -> Bool -> Bool
|| Bool -> Bool
not (OccName -> Bool
isFieldOcc OccName
child_occ)
-> ExportOccMap -> RnM ExportOccMap
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ExportOccMap
occs'
| Bool
otherwise
-> do { let flds :: [(Name, IE GhcPs)]
flds = ((Name, IE GhcPs) -> Bool)
-> [(Name, IE GhcPs)] -> [(Name, IE GhcPs)]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(Name
_,IE GhcPs
ie') -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ IE GhcPs -> IE GhcPs -> Bool
dupFieldExport_ok IE GhcPs
ie IE GhcPs
ie')
([(Name, IE GhcPs)] -> [(Name, IE GhcPs)])
-> [(Name, IE GhcPs)] -> [(Name, IE GhcPs)]
forall a b. (a -> b) -> a -> b
$ ExportOccMap -> FastString -> [(Name, IE GhcPs)]
forall a. OccEnv a -> FastString -> [a]
lookupFieldsOccEnv ExportOccMap
occs (OccName -> FastString
occNameFS OccName
child_occ)
; case [(Name, IE GhcPs)]
flds of { [] -> ExportOccMap -> RnM ExportOccMap
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ExportOccMap
occs'; (Name, IE GhcPs)
clash1:[(Name, IE GhcPs)]
clashes ->
do { (GlobalRdrEltX GREInfo, IE GhcPs)
-> NonEmpty (Name, IE GhcPs) -> TcRn ()
addDuplicateFieldExportErr (GlobalRdrEltX GREInfo
gre,IE GhcPs
ie) ((Name, IE GhcPs)
clash1 (Name, IE GhcPs) -> [(Name, IE GhcPs)] -> NonEmpty (Name, IE GhcPs)
forall a. a -> [a] -> NonEmpty a
NE.:| [(Name, IE GhcPs)]
clashes)
; ExportOccMap -> RnM ExportOccMap
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ExportOccMap
occs } } }
Left (Name
child', IE GhcPs
ie')
| Name
child Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
child'
-> do { Bool -> TcRnMessage -> TcRn ()
warnIf (Bool -> Bool
not (Name -> IE GhcPs -> IE GhcPs -> Bool
dupExport_ok Name
child IE GhcPs
ie IE GhcPs
ie')) (GlobalRdrEltX GREInfo -> IE GhcPs -> IE GhcPs -> TcRnMessage
TcRnDuplicateExport GlobalRdrEltX GREInfo
gre IE GhcPs
ie IE GhcPs
ie')
; ExportOccMap -> RnM ExportOccMap
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ExportOccMap
occs }
| Bool
otherwise
-> do { GlobalRdrEnv
global_env <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; TcRnMessage -> TcRn ()
addErr (GlobalRdrEnv -> Name -> Name -> IE GhcPs -> IE GhcPs -> TcRnMessage
exportClashErr GlobalRdrEnv
global_env Name
child' Name
child IE GhcPs
ie' IE GhcPs
ie)
; ExportOccMap -> RnM ExportOccMap
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ExportOccMap
occs }
where
child :: Name
child = GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
gre
child_occ :: OccName
child_occ = Name -> OccName
forall name. HasOccName name => name -> OccName
occName Name
child
try_insert :: ExportOccMap -> GlobalRdrElt -> Either (Name, IE GhcPs) ExportOccMap
try_insert :: ExportOccMap
-> GlobalRdrEltX GREInfo -> Either (Name, IE GhcPs) ExportOccMap
try_insert ExportOccMap
occs GlobalRdrEltX GREInfo
child
= case ExportOccMap -> OccName -> Maybe (Name, IE GhcPs)
forall a. OccEnv a -> OccName -> Maybe a
lookupOccEnv ExportOccMap
occs OccName
occ of
Maybe (Name, IE GhcPs)
Nothing -> ExportOccMap -> Either (Name, IE GhcPs) ExportOccMap
forall a b. b -> Either a b
Right (ExportOccMap -> OccName -> (Name, IE GhcPs) -> ExportOccMap
forall a. OccEnv a -> OccName -> a -> OccEnv a
extendOccEnv ExportOccMap
occs OccName
occ (GlobalRdrEltX GREInfo -> Name
forall info. GlobalRdrEltX info -> Name
greName GlobalRdrEltX GREInfo
child, IE GhcPs
ie))
Just (Name, IE GhcPs)
x -> (Name, IE GhcPs) -> Either (Name, IE GhcPs) ExportOccMap
forall a b. a -> Either a b
Left (Name, IE GhcPs)
x
where
occ :: OccName
occ = GlobalRdrEltX GREInfo -> OccName
forall info. GlobalRdrEltX info -> OccName
greOccName GlobalRdrEltX GREInfo
child
dupExport_ok :: Name -> IE GhcPs -> IE GhcPs -> Bool
dupExport_ok :: Name -> IE GhcPs -> IE GhcPs -> Bool
dupExport_ok Name
child IE GhcPs
ie1 IE GhcPs
ie2
= Bool -> Bool
not ( IE GhcPs -> Bool
forall {pass}. IE pass -> Bool
single IE GhcPs
ie1 Bool -> Bool -> Bool
|| IE GhcPs -> Bool
forall {pass}. IE pass -> Bool
single IE GhcPs
ie2
Bool -> Bool -> Bool
|| (IE GhcPs -> Bool
explicit_in IE GhcPs
ie1 Bool -> Bool -> Bool
&& IE GhcPs -> Bool
explicit_in IE GhcPs
ie2) )
where
explicit_in :: IE GhcPs -> Bool
explicit_in (IEModuleContents {}) = Bool
False
explicit_in (IEThingAll XIEThingAll GhcPs
_ LIEWrappedName GhcPs
r)
= Name -> OccName
forall name. HasOccName name => name -> OccName
occName Name
child OccName -> OccName -> Bool
forall a. Eq a => a -> a -> Bool
== RdrName -> OccName
rdrNameOcc (IEWrappedName GhcPs -> IdP GhcPs
forall (p :: Pass). IEWrappedName (GhcPass p) -> IdP (GhcPass p)
ieWrappedName (IEWrappedName GhcPs -> IdP GhcPs)
-> IEWrappedName GhcPs -> IdP GhcPs
forall a b. (a -> b) -> a -> b
$ LocatedAn AnnListItem (IEWrappedName GhcPs) -> IEWrappedName GhcPs
forall l e. GenLocated l e -> e
unLoc LIEWrappedName GhcPs
LocatedAn AnnListItem (IEWrappedName GhcPs)
r)
explicit_in IE GhcPs
_ = Bool
True
single :: IE pass -> Bool
single IEVar {} = Bool
True
single IEThingAbs {} = Bool
True
single IE pass
_ = Bool
False
exportErrCtxt :: Outputable o => String -> o -> SDoc
exportErrCtxt :: forall o. Outputable o => String -> o -> SDoc
exportErrCtxt String
herald o
exp =
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text (String
herald String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
":") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> o -> SDoc
forall a. Outputable a => a -> SDoc
ppr o
exp
addExportErrCtxt :: (OutputableBndrId p)
=> IE (GhcPass p) -> TcM a -> TcM a
addExportErrCtxt :: forall (p :: Pass) a.
OutputableBndrId p =>
IE (GhcPass p) -> TcM a -> TcM a
addExportErrCtxt IE (GhcPass p)
ie = SDoc -> TcM a -> TcM a
forall a. SDoc -> TcM a -> TcM a
addErrCtxt SDoc
exportCtxt
where
exportCtxt :: SDoc
exportCtxt = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the export:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> IE (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr IE (GhcPass p)
ie
failWithDcErr :: Name -> Name -> [Name] -> TcM a
failWithDcErr :: forall a. Name -> Name -> [Name] -> TcM a
failWithDcErr Name
parent Name
child [Name]
parents = do
TyThing
ty_thing <- Name -> TcM TyThing
tcLookupGlobal Name
child
TcRnMessage -> TcM a
forall a. TcRnMessage -> TcM a
failWithTc (TcRnMessage -> TcM a) -> TcRnMessage -> TcM a
forall a b. (a -> b) -> a -> b
$ Name -> TyThing -> Name -> [Name] -> TcRnMessage
TcRnExportedParentChildMismatch Name
parent TyThing
ty_thing Name
child [Name]
parents
exportClashErr :: GlobalRdrEnv
-> Name -> Name
-> IE GhcPs -> IE GhcPs
-> TcRnMessage
exportClashErr :: GlobalRdrEnv -> Name -> Name -> IE GhcPs -> IE GhcPs -> TcRnMessage
exportClashErr GlobalRdrEnv
global_env Name
child1 Name
child2 IE GhcPs
ie1 IE GhcPs
ie2
= OccName
-> GlobalRdrEltX GREInfo
-> IE GhcPs
-> GlobalRdrEltX GREInfo
-> IE GhcPs
-> TcRnMessage
TcRnConflictingExports OccName
occ GlobalRdrEltX GREInfo
gre1' IE GhcPs
ie1' GlobalRdrEltX GREInfo
gre2' IE GhcPs
ie2'
where
occ :: OccName
occ = Name -> OccName
forall name. HasOccName name => name -> OccName
occName Name
child1
gre1 :: GlobalRdrEltX GREInfo
gre1 = Name -> GlobalRdrEltX GREInfo
get_gre Name
child1
gre2 :: GlobalRdrEltX GREInfo
gre2 = Name -> GlobalRdrEltX GREInfo
get_gre Name
child2
get_gre :: Name -> GlobalRdrEltX GREInfo
get_gre Name
child
= GlobalRdrEltX GREInfo
-> Maybe (GlobalRdrEltX GREInfo) -> GlobalRdrEltX GREInfo
forall a. a -> Maybe a -> a
fromMaybe (String -> SDoc -> GlobalRdrEltX GREInfo
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"exportClashErr" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
child))
(GlobalRdrEnv -> Name -> Maybe (GlobalRdrEltX GREInfo)
forall info.
Outputable info =>
GlobalRdrEnvX info -> Name -> Maybe (GlobalRdrEltX info)
lookupGRE_Name GlobalRdrEnv
global_env Name
child)
(GlobalRdrEltX GREInfo
gre1', IE GhcPs
ie1', GlobalRdrEltX GREInfo
gre2', IE GhcPs
ie2') =
case SrcSpan -> SrcSpan -> Ordering
SrcLoc.leftmost_smallest (GlobalRdrEltX GREInfo -> SrcSpan
forall info. Outputable info => GlobalRdrEltX info -> SrcSpan
greSrcSpan GlobalRdrEltX GREInfo
gre1) (GlobalRdrEltX GREInfo -> SrcSpan
forall info. Outputable info => GlobalRdrEltX info -> SrcSpan
greSrcSpan GlobalRdrEltX GREInfo
gre2) of
Ordering
LT -> (GlobalRdrEltX GREInfo
gre1, IE GhcPs
ie1, GlobalRdrEltX GREInfo
gre2, IE GhcPs
ie2)
Ordering
GT -> (GlobalRdrEltX GREInfo
gre2, IE GhcPs
ie2, GlobalRdrEltX GREInfo
gre1, IE GhcPs
ie1)
Ordering
EQ -> String
-> (GlobalRdrEltX GREInfo, IE GhcPs, GlobalRdrEltX GREInfo,
IE GhcPs)
forall a. HasCallStack => String -> a
panic String
"exportClashErr: clashing exports have identical location"
addDuplicateFieldExportErr :: (GlobalRdrElt, IE GhcPs)
-> NE.NonEmpty (Name, IE GhcPs)
-> RnM ()
addDuplicateFieldExportErr :: (GlobalRdrEltX GREInfo, IE GhcPs)
-> NonEmpty (Name, IE GhcPs) -> TcRn ()
addDuplicateFieldExportErr (GlobalRdrEltX GREInfo, IE GhcPs)
gre NonEmpty (Name, IE GhcPs)
others
= do { GlobalRdrEnv
rdr_env <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; let lkup :: Name -> GlobalRdrEltX GREInfo
lkup = String -> Maybe (GlobalRdrEltX GREInfo) -> GlobalRdrEltX GREInfo
forall a. HasDebugCallStack => String -> Maybe a -> a
expectJust String
"addDuplicateFieldExportErr" (Maybe (GlobalRdrEltX GREInfo) -> GlobalRdrEltX GREInfo)
-> (Name -> Maybe (GlobalRdrEltX GREInfo))
-> Name
-> GlobalRdrEltX GREInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalRdrEnv -> Name -> Maybe (GlobalRdrEltX GREInfo)
forall info.
Outputable info =>
GlobalRdrEnvX info -> Name -> Maybe (GlobalRdrEltX info)
lookupGRE_Name GlobalRdrEnv
rdr_env
other_gres :: NonEmpty (GlobalRdrEltX GREInfo, IE GhcPs)
other_gres = ((Name, IE GhcPs) -> (GlobalRdrEltX GREInfo, IE GhcPs))
-> NonEmpty (Name, IE GhcPs)
-> NonEmpty (GlobalRdrEltX GREInfo, IE GhcPs)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Name -> GlobalRdrEltX GREInfo)
-> (Name, IE GhcPs) -> (GlobalRdrEltX GREInfo, IE GhcPs)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Name -> GlobalRdrEltX GREInfo
lkup) NonEmpty (Name, IE GhcPs)
others
; TcRnMessage -> TcRn ()
addErr ((GlobalRdrEltX GREInfo, IE GhcPs)
-> NonEmpty (GlobalRdrEltX GREInfo, IE GhcPs) -> TcRnMessage
TcRnDuplicateFieldExport (GlobalRdrEltX GREInfo, IE GhcPs)
gre NonEmpty (GlobalRdrEltX GREInfo, IE GhcPs)
other_gres) }
dupFieldExport_ok :: IE GhcPs -> IE GhcPs -> Bool
dupFieldExport_ok :: IE GhcPs -> IE GhcPs -> Bool
dupFieldExport_ok IE GhcPs
ie1 IE GhcPs
ie2
| IEModuleContents {} <- IE GhcPs
ie1
, IE GhcPs
ie2 IE GhcPs -> IE GhcPs -> Bool
forall a. Eq a => a -> a -> Bool
== IE GhcPs
ie1
= Bool
True
| Bool
otherwise
= Bool
False