Commit 94a113df authored by Michal Terepeta's avatar Michal Terepeta

Fix whitespace/layout in RnNames.

parent 819dbcb5
......@@ -5,21 +5,21 @@
\begin{code}
module RnNames (
rnImports, getLocalNonValBinders,
rnExports, extendGlobalRdrEnvRn,
rnImports, getLocalNonValBinders,
rnExports, extendGlobalRdrEnvRn,
gresFromAvails,
reportUnusedNames, finishWarnings,
reportUnusedNames, finishWarnings,
) where
#include "HsVersions.h"
import DynFlags
import HsSyn
import TcEnv ( isBrackStage )
import TcEnv ( isBrackStage )
import RnEnv
import RnHsDoc ( rnHsDoc )
import IfaceEnv ( ifaceExportNames )
import LoadIface ( loadSrcInterface )
import IfaceEnv ( ifaceExportNames )
import LoadIface ( loadSrcInterface )
import TcRnMonad
import HeaderInfo ( mkPrelImports )
......@@ -41,16 +41,16 @@ import Data.List ( partition, (\\), delete )
import qualified Data.Set as Set
import System.IO
import Control.Monad
import Data.Map (Map)
import Data.Map ( Map )
import qualified Data.Map as Map
\end{code}
%************************************************************************
%* *
rnImports
%* *
%* *
\subsection{rnImports}
%* *
%************************************************************************
\begin{code}
......@@ -63,7 +63,7 @@ rnImports imports
-- warning for {- SOURCE -} ones that are unnecessary
= do this_mod <- getModule
implicit_prelude <- xoptM Opt_ImplicitPrelude
let prel_imports = mkPrelImports (moduleName this_mod) implicit_prelude imports
let prel_imports = mkPrelImports (moduleName this_mod) implicit_prelude imports
(source, ordinary) = partition is_source_import imports
is_source_import (L _ (ImportDecl _ _ is_boot _ _ _)) = is_boot
......@@ -83,16 +83,16 @@ rnImports imports
combine = foldr plus ([], emptyGlobalRdrEnv, emptyImportAvails,False)
where plus (decl, gbl_env1, imp_avails1,hpc_usage1)
(decls, gbl_env2, imp_avails2,hpc_usage2)
= (decl:decls,
= (decl:decls,
gbl_env1 `plusGlobalRdrEnv` gbl_env2,
imp_avails1 `plusImportAvails` imp_avails2,
hpc_usage1 || hpc_usage2)
hpc_usage1 || hpc_usage2)
rnImportDecl :: Module -> Bool
-> LImportDecl RdrName
-> RnM (LImportDecl Name, GlobalRdrEnv, ImportAvails,AnyHpcUsage)
-> LImportDecl RdrName
-> RnM (LImportDecl Name, GlobalRdrEnv, ImportAvails,AnyHpcUsage)
rnImportDecl this_mod implicit_prelude
rnImportDecl this_mod implicit_prelude
(L loc (ImportDecl { ideclName = loc_imp_mod_name, ideclPkgQual = mb_pkg
, ideclSource = want_boot, ideclQualified = qual_only
, ideclAs = as_mod, ideclHiding = imp_details }))
......@@ -102,11 +102,11 @@ rnImportDecl this_mod implicit_prelude
pkg_imports <- xoptM Opt_PackageImports
when (not pkg_imports) $ addErr packageImportErr
-- If there's an error in loadInterface, (e.g. interface
-- file not found) we get lots of spurious errors from 'filterImports'
-- If there's an error in loadInterface, (e.g. interface
-- file not found) we get lots of spurious errors from 'filterImports'
let
imp_mod_name = unLoc loc_imp_mod_name
doc = ppr imp_mod_name <+> ptext (sLit "is directly imported")
imp_mod_name = unLoc loc_imp_mod_name
doc = ppr imp_mod_name <+> ptext (sLit "is directly imported")
-- Check for a missing import list
-- (Opt_WarnMissingImportList also checks for T(..) items
......@@ -119,13 +119,13 @@ rnImportDecl this_mod implicit_prelude
iface <- loadSrcInterface doc imp_mod_name want_boot mb_pkg
-- Compiler sanity check: if the import didn't say
-- {-# SOURCE #-} we should not get a hi-boot file
-- Compiler sanity check: if the import didn't say
-- {-# SOURCE #-} we should not get a hi-boot file
WARN( not want_boot && mi_boot iface, ppr imp_mod_name ) (do
-- Issue a user warning for a redundant {- SOURCE -} import
-- NB that we arrange to read all the ordinary imports before
-- any of the {- SOURCE -} imports.
-- Issue a user warning for a redundant {- SOURCE -} import
-- NB that we arrange to read all the ordinary imports before
-- any of the {- SOURCE -} imports.
--
-- in --make and GHCi, the compilation manager checks for this,
-- and indeed we shouldn't do it here because the existence of
......@@ -133,104 +133,103 @@ rnImportDecl this_mod implicit_prelude
-- is not deterministic. The hs-boot test can show this up.
dflags <- getDOpts
warnIf (want_boot && not (mi_boot iface) && isOneShot (ghcMode dflags))
(warnRedundantSourceImport imp_mod_name)
(warnRedundantSourceImport imp_mod_name)
let
imp_mod = mi_module iface
warns = mi_warns iface
orph_iface = mi_orphan iface
has_finsts = mi_finsts iface
deps = mi_deps iface
filtered_exports = filter not_this_mod (mi_exports iface)
not_this_mod (mod,_) = mod /= this_mod
-- If the module exports anything defined in this module, just
-- ignore it. Reason: otherwise it looks as if there are two
-- local definition sites for the thing, and an error gets
-- reported. Easiest thing is just to filter them out up
-- front. This situation only arises if a module imports
-- itself, or another module that imported it. (Necessarily,
-- this invoves a loop.)
--
-- Tiresome consequence: if you say
-- module A where
-- import B( AType )
-- type AType = ...
--
-- module B( AType ) where
-- import {-# SOURCE #-} A( AType )
--
-- then you'll get a 'B does not export AType' message. Oh well.
qual_mod_name = case as_mod of
Nothing -> imp_mod_name
Just another_name -> another_name
imp_spec = ImpDeclSpec { is_mod = imp_mod_name, is_qual = qual_only,
is_dloc = loc, is_as = qual_mod_name }
-- in
-- Get the total exports from this module
imp_mod = mi_module iface
warns = mi_warns iface
orph_iface = mi_orphan iface
has_finsts = mi_finsts iface
deps = mi_deps iface
filtered_exports = filter not_this_mod (mi_exports iface)
not_this_mod (mod,_) = mod /= this_mod
-- If the module exports anything defined in this module, just
-- ignore it. Reason: otherwise it looks as if there are two
-- local definition sites for the thing, and an error gets
-- reported. Easiest thing is just to filter them out up
-- front. This situation only arises if a module imports
-- itself, or another module that imported it. (Necessarily,
-- this invoves a loop.)
--
-- Tiresome consequence: if you say
-- module A where
-- import B( AType )
-- type AType = ...
--
-- module B( AType ) where
-- import {-# SOURCE #-} A( AType )
--
-- then you'll get a 'B does not export AType' message. Oh well.
qual_mod_name = case as_mod of
Nothing -> imp_mod_name
Just another_name -> another_name
imp_spec = ImpDeclSpec { is_mod = imp_mod_name, is_qual = qual_only,
is_dloc = loc, is_as = qual_mod_name }
-- Get the total exports from this module
total_avails <- ifaceExportNames filtered_exports
-- filter the imports according to the import declaration
(new_imp_details, gbl_env) <-
-- filter the imports according to the import declaration
(new_imp_details, gbl_env) <-
filterImports iface imp_spec imp_details total_avails
dflags <- getDOpts
let
-- Compute new transitive dependencies
orphans | orph_iface = ASSERT( not (imp_mod `elem` dep_orphs deps) )
imp_mod : dep_orphs deps
| otherwise = dep_orphs deps
finsts | has_finsts = ASSERT( not (imp_mod `elem` dep_finsts deps) )
imp_mod : dep_finsts deps
| otherwise = dep_finsts deps
pkg = modulePackageId (mi_module iface)
(dependent_mods, dependent_pkgs)
| pkg == thisPackage dflags =
-- Imported module is from the home package
-- Take its dependent modules and add imp_mod itself
-- Take its dependent packages unchanged
--
-- NB: (dep_mods deps) might include a hi-boot file
-- for the module being compiled, CM. Do *not* filter
-- this out (as we used to), because when we've
-- finished dealing with the direct imports we want to
-- know if any of them depended on CM.hi-boot, in
-- which case we should do the hi-boot consistency
-- check. See LoadIface.loadHiBootInterface
((imp_mod_name, want_boot) : dep_mods deps, dep_pkgs deps)
| otherwise =
-- Imported module is from another package
-- Dump the dependent modules
-- Add the package imp_mod comes from to the dependent packages
ASSERT2( not (pkg `elem` dep_pkgs deps), ppr pkg <+> ppr (dep_pkgs deps) )
([], pkg : dep_pkgs deps)
-- True <=> import M ()
import_all = case imp_details of
Just (is_hiding, ls) -> not is_hiding && null ls
_ -> False
imports = ImportAvails {
imp_mods = unitModuleEnv imp_mod [(qual_mod_name, import_all, loc)],
imp_orphs = orphans,
imp_finsts = finsts,
imp_dep_mods = mkModDeps dependent_mods,
imp_dep_pkgs = dependent_pkgs
-- Compute new transitive dependencies
orphans | orph_iface = ASSERT( not (imp_mod `elem` dep_orphs deps) )
imp_mod : dep_orphs deps
| otherwise = dep_orphs deps
finsts | has_finsts = ASSERT( not (imp_mod `elem` dep_finsts deps) )
imp_mod : dep_finsts deps
| otherwise = dep_finsts deps
pkg = modulePackageId (mi_module iface)
(dependent_mods, dependent_pkgs)
| pkg == thisPackage dflags =
-- Imported module is from the home package
-- Take its dependent modules and add imp_mod itself
-- Take its dependent packages unchanged
--
-- NB: (dep_mods deps) might include a hi-boot file
-- for the module being compiled, CM. Do *not* filter
-- this out (as we used to), because when we've
-- finished dealing with the direct imports we want to
-- know if any of them depended on CM.hi-boot, in
-- which case we should do the hi-boot consistency
-- check. See LoadIface.loadHiBootInterface
((imp_mod_name, want_boot) : dep_mods deps, dep_pkgs deps)
| otherwise =
-- Imported module is from another package
-- Dump the dependent modules
-- Add the package imp_mod comes from to the dependent packages
ASSERT2( not (pkg `elem` dep_pkgs deps), ppr pkg <+> ppr (dep_pkgs deps) )
([], pkg : dep_pkgs deps)
-- True <=> import M ()
import_all = case imp_details of
Just (is_hiding, ls) -> not is_hiding && null ls
_ -> False
imports = ImportAvails {
imp_mods = unitModuleEnv imp_mod [(qual_mod_name, import_all, loc)],
imp_orphs = orphans,
imp_finsts = finsts,
imp_dep_mods = mkModDeps dependent_mods,
imp_dep_pkgs = dependent_pkgs
}
-- Complain if we import a deprecated module
ifDOptM Opt_WarnWarningsDeprecations (
case warns of
WarnAll txt -> addWarn (moduleWarn imp_mod_name txt)
_ -> return ()
-- Complain if we import a deprecated module
ifDOptM Opt_WarnWarningsDeprecations (
case warns of
WarnAll txt -> addWarn (moduleWarn imp_mod_name txt)
_ -> return ()
)
let new_imp_decl = L loc (ImportDecl loc_imp_mod_name mb_pkg want_boot
......@@ -247,21 +246,21 @@ warnRedundantSourceImport mod_name
%************************************************************************
%* *
importsFromLocalDecls
%* *
%* *
\subsection{importsFromLocalDecls}
%* *
%************************************************************************
From the top-level declarations of this module produce
* the lexical environment
* the ImportAvails
created by its bindings.
* the lexical environment
* the ImportAvails
created by its bindings.
Note [Top-level Names in Template Haskell decl quotes]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider a Template Haskell declaration quotation like this:
module M where
f x = h [d| f = 3 |]
f x = h [d| f = 3 |]
When renaming the declarations inside [d| ...|], we treat the
top level binders specially in two ways
......@@ -269,7 +268,7 @@ top level binders specially in two ways
Otherwise the NameCache gets confused by a second allocation of
M.f. (We used to invent a fake module ThFake to avoid this, but
that had other problems, notably in getting the correct answer for
nameIsLocalOrFrom in lookupFixity. So we now leave tcg_module
nameIsLocalOrFrom in lookupFixity. So we now leave tcg_module
unaffected.)
2. We make them *shadow* the outer bindings. If we don't do that,
......@@ -280,10 +279,10 @@ top level binders specially in two ways
where-clause, and hence is in the *local* RdrEnv not the *global*
RdrEnv.
* The *qualified* name M.f from the enclosing module must certainly
still be available. So we don't nuke it entirely; we just make
* The *qualified* name M.f from the enclosing module must certainly
still be available. So we don't nuke it entirely; we just make
it seem like qualified import.
* We only shadow *External* names (which come from the main module)
Do not shadow *Inernal* names because in the bracket
[d| class C a where f :: a
......@@ -298,56 +297,56 @@ top level binders specially in two ways
\begin{code}
extendGlobalRdrEnvRn :: [AvailInfo]
-> MiniFixityEnv
-> RnM (TcGblEnv, TcLclEnv)
-- Updates both the GlobalRdrEnv and the FixityEnv
-- We return a new TcLclEnv only because we might have to
-- delete some bindings from it;
-- see Note [Top-level Names in Template Haskell decl quotes]
-> MiniFixityEnv
-> RnM (TcGblEnv, TcLclEnv)
-- Updates both the GlobalRdrEnv and the FixityEnv
-- We return a new TcLclEnv only because we might have to
-- delete some bindings from it;
-- see Note [Top-level Names in Template Haskell decl quotes]
extendGlobalRdrEnvRn avails new_fixities
= do { (gbl_env, lcl_env) <- getEnvs
= do { (gbl_env, lcl_env) <- getEnvs
; stage <- getStage
; let rdr_env = tcg_rdr_env gbl_env
fix_env = tcg_fix_env gbl_env
-- Delete new_occs from global and local envs
-- If we are in a TemplateHaskell decl bracket,
-- we are going to shadow them
-- See Note [Top-level Names in Template Haskell decl quotes]
shadowP = isBrackStage stage
new_occs = map (nameOccName . gre_name) gres
rdr_env1 = transformGREs qual_gre new_occs rdr_env
lcl_env1 = lcl_env { tcl_rdr = delListFromOccEnv (tcl_rdr lcl_env) new_occs }
(rdr_env2, lcl_env2) | shadowP = (rdr_env1, lcl_env1)
| otherwise = (rdr_env, lcl_env)
rdr_env3 = foldl extendGlobalRdrEnv rdr_env2 gres
fix_env' = foldl extend_fix_env fix_env gres
(rdr_env', dups) = findLocalDupsRdrEnv rdr_env3 new_occs
gbl_env' = gbl_env { tcg_rdr_env = rdr_env', tcg_fix_env = fix_env' }
; mapM_ addDupDeclErr dups
; traceRn (text "extendGlobalRdrEnvRn" <+> (ppr new_fixities $$ ppr fix_env $$ ppr fix_env'))
; return (gbl_env', lcl_env2) }
; let rdr_env = tcg_rdr_env gbl_env
fix_env = tcg_fix_env gbl_env
-- Delete new_occs from global and local envs
-- If we are in a TemplateHaskell decl bracket,
-- we are going to shadow them
-- See Note [Top-level Names in Template Haskell decl quotes]
shadowP = isBrackStage stage
new_occs = map (nameOccName . gre_name) gres
rdr_env1 = transformGREs qual_gre new_occs rdr_env
lcl_env1 = lcl_env { tcl_rdr = delListFromOccEnv (tcl_rdr lcl_env) new_occs }
(rdr_env2, lcl_env2) | shadowP = (rdr_env1, lcl_env1)
| otherwise = (rdr_env, lcl_env)
rdr_env3 = foldl extendGlobalRdrEnv rdr_env2 gres
fix_env' = foldl extend_fix_env fix_env gres
(rdr_env', dups) = findLocalDupsRdrEnv rdr_env3 new_occs
gbl_env' = gbl_env { tcg_rdr_env = rdr_env', tcg_fix_env = fix_env' }
; mapM_ addDupDeclErr dups
; traceRn (text "extendGlobalRdrEnvRn" <+> (ppr new_fixities $$ ppr fix_env $$ ppr fix_env'))
; return (gbl_env', lcl_env2) }
where
gres = gresFromAvails LocalDef avails
-- If there is a fixity decl for the gre, add it to the fixity env
extend_fix_env fix_env gre
-- If there is a fixity decl for the gre, add it to the fixity env
extend_fix_env fix_env gre
| Just (L _ fi) <- lookupFsEnv new_fixities (occNameFS occ)
= extendNameEnv fix_env name (FixItem occ fi)
| otherwise
= fix_env
where
name = gre_name gre
name = gre_name gre
occ = nameOccName name
qual_gre :: GlobalRdrElt -> GlobalRdrElt
-- Transform top-level GREs from the module being compiled
-- so that they are out of the way of new definitions in a Template
-- so that they are out of the way of new definitions in a Template
-- Haskell bracket
-- See Note [Top-level Names in Template Haskell decl quotes]
-- Seems like 5 times as much work as it deserves!
......@@ -358,27 +357,27 @@ extendGlobalRdrEnvRn avails new_fixities
qual_gre gre@(GRE { gre_prov = LocalDef, gre_name = name })
| isExternalName name = gre { gre_prov = Imported [imp_spec] }
| otherwise = gre
-- Do not shadow Internal (ie Template Haskell) Names
-- See Note [Top-level Names in Template Haskell decl quotes]
where
mod = ASSERT2( isExternalName name, ppr name) moduleName (nameModule name)
imp_spec = ImpSpec { is_item = ImpAll, is_decl = decl_spec }
decl_spec = ImpDeclSpec { is_mod = mod, is_as = mod,
is_qual = True, -- Qualified only!
is_dloc = srcLocSpan (nameSrcLoc name) }
| otherwise = gre
-- Do not shadow Internal (ie Template Haskell) Names
-- See Note [Top-level Names in Template Haskell decl quotes]
where
mod = ASSERT2( isExternalName name, ppr name) moduleName (nameModule name)
imp_spec = ImpSpec { is_item = ImpAll, is_decl = decl_spec }
decl_spec = ImpDeclSpec { is_mod = mod, is_as = mod,
is_qual = True, -- Qualified only!
is_dloc = srcLocSpan (nameSrcLoc name) }
qual_gre gre@(GRE { gre_prov = Imported specs })
= gre { gre_prov = Imported (map qual_spec specs) }
= gre { gre_prov = Imported (map qual_spec specs) }
qual_spec spec@(ImpSpec { is_decl = decl_spec })
= spec { is_decl = decl_spec { is_qual = True } }
= spec { is_decl = decl_spec { is_qual = True } }
\end{code}
@getLocalDeclBinders@ returns the names for an @HsDecl@. It's
used for source code.
*** See "THE NAMING STORY" in HsDecls ****
*** See "THE NAMING STORY" in HsDecls ****
Instances of type families
~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -400,7 +399,7 @@ We might think that we can simply use 'lookupOccRn' when processing the type
instance to look up 'M.T'. Alas, we can't! The type family declaration is in
the *same* HsGroup as the type instance declaration. Hence, as we are
currently collecting the binders declared in that HsGroup, these binders will
not have been added to the global environment yet.
not have been added to the global environment yet.
In the case of type classes, this problem does not arise, as a class instance
does not define any binders of it's own. So, we simply don't attempt to look
......@@ -421,48 +420,48 @@ We solve this problem as follows:
(a) We process all type declarations other than type instances first.
(b) Then, we compute a 'GlobalRdrEnv' from the result of the first step.
(c) Finally, we process all type instances (both those on the toplevel and
(c) Finally, we process all type instances (both those on the toplevel and
those nested in class instances) and check for the family names in the
'GlobalRdrEnv' produced in the previous step before using 'lookupOccRn'.
\begin{code}
getLocalNonValBinders :: HsGroup RdrName -> RnM [AvailInfo]
-- Get all the top-level binders bound the group *except*
-- Get all the top-level binders bound the group *except*
-- for value bindings, which are treated separately
-- Specificaly we return AvailInfo for
-- type decls (incl constructors and record selectors)
-- class decls (including class ops)
-- associated types
-- foreign imports
-- (in hs-boot files) value signatures
-- type decls (incl constructors and record selectors)
-- class decls (including class ops)
-- associated types
-- foreign imports
-- (in hs-boot files) value signatures
getLocalNonValBinders group
= do { gbl_env <- getGblEnv
; get_local_binders gbl_env group }
= do { gbl_env <- getGblEnv
; get_local_binders gbl_env group }
get_local_binders :: TcGblEnv -> HsGroup RdrName -> RnM [GenAvailInfo Name]
get_local_binders gbl_env (HsGroup {hs_valds = ValBindsIn _ val_sigs,
hs_tyclds = tycl_decls,
hs_instds = inst_decls,
hs_fords = foreign_decls })
= do { -- separate out the family instance declarations
let (tyinst_decls1, tycl_decls_noinsts)
hs_tyclds = tycl_decls,
hs_instds = inst_decls,
hs_fords = foreign_decls })
= do { -- separate out the family instance declarations
let (tyinst_decls1, tycl_decls_noinsts)
= partition (isFamInstDecl . unLoc) tycl_decls
tyinst_decls = tyinst_decls1 ++ instDeclATs inst_decls
-- process all type/class decls except family instances
-- process all type/class decls except family instances
; tc_names <- mapM new_tc tycl_decls_noinsts
-- create a temporary rdr env of the type binders
-- create a temporary rdr env of the type binders
; let tc_gres = gresFromAvails LocalDef tc_names
tc_name_env = foldl extendGlobalRdrEnv emptyGlobalRdrEnv tc_gres
-- process all family instances
; ti_names <- mapM (new_ti tc_name_env) tyinst_decls
-- process all family instances
; ti_names <- mapM (new_ti tc_name_env) tyinst_decls
-- finish off with value binder in case of a hs-boot file
; val_names <- mapM new_simple val_bndrs
; return (val_names ++ tc_names ++ ti_names) }
-- finish off with value binder in case of a hs-boot file
; val_names <- mapM new_simple val_bndrs
; return (val_names ++ tc_names ++ ti_names) }
where
is_hs_boot = isHsBoot (tcg_src gbl_env) ;
......@@ -470,7 +469,7 @@ get_local_binders gbl_env (HsGroup {hs_valds = ValBindsIn _ val_sigs,
for_hs_bndrs = [nm | L _ (ForeignImport nm _ _) <- foreign_decls]
-- In a hs-boot file, the value binders come from the
-- *signatures*, and there should be no foreign binders
-- *signatures*, and there should be no foreign binders
val_bndrs :: [Located RdrName]
val_bndrs | is_hs_boot = [nm | L _ (TypeSig nm _) <- val_sigs]
| otherwise = for_hs_bndrs
......@@ -481,28 +480,28 @@ get_local_binders gbl_env (HsGroup {hs_valds = ValBindsIn _ val_sigs,
return (Avail nm)
new_tc tc_decl -- NOT for type/data instances
= do { main_name <- newTopSrcBinder main_rdr
; sub_names <- mapM newTopSrcBinder sub_rdrs
; return (AvailTC main_name (main_name : sub_names)) }
= do { main_name <- newTopSrcBinder main_rdr
; sub_names <- mapM newTopSrcBinder sub_rdrs
; return (AvailTC main_name (main_name : sub_names)) }
where
(main_rdr : sub_rdrs) = hsTyClDeclBinders tc_decl
(main_rdr : sub_rdrs) = hsTyClDeclBinders tc_decl
new_ti tc_name_env ti_decl -- ONLY for type/data instances
= do { main_name <- lookupFamInstDeclBndr tc_name_env main_rdr
; sub_names <- mapM newTopSrcBinder sub_rdrs
; return (AvailTC main_name sub_names) }
-- main_name is not bound here!
= do { main_name <- lookupFamInstDeclBndr tc_name_env main_rdr
; sub_names <- mapM newTopSrcBinder sub_rdrs
; return (AvailTC main_name sub_names) }
-- main_name is not bound here!
where
(main_rdr : sub_rdrs) = hsTyClDeclBinders ti_decl
(main_rdr : sub_rdrs) = hsTyClDeclBinders ti_decl
get_local_binders _ g = pprPanic "get_local_binders" (ppr g)
\end{code}
%************************************************************************
%* *
%* *
\subsection{Filtering imports}
%* *
%* *
%************************************************************************
@filterImports@ takes the @ExportEnv@ telling what the imported module makes
......@@ -510,11 +509,11 @@ available, and filters it through the import spec (if any).
\begin{code}
filterImports :: ModIface
-> ImpDeclSpec -- The span for the entire import decl
-> Maybe (Bool, [LIE RdrName]) -- Import spec; True => hiding
-> [AvailInfo] -- What's available
-> RnM (Maybe (Bool, [LIE Name]), -- Import spec w/ Names
GlobalRdrEnv) -- Same again, but in GRE form
-> ImpDeclSpec -- The span for the entire import decl
-> Maybe (Bool, [LIE RdrName]) -- Import spec; True => hiding
-> [AvailInfo] -- What's available
-> RnM (Maybe (Bool, [LIE Name]), -- Import spec w/ Names
GlobalRdrEnv) -- Same again, but in GRE form
filterImports _ decl_spec Nothing all_avails
= return (Nothing, mkGlobalRdrEnv (gresFromAvails prov all_avails))
where
......@@ -522,26 +521,26 @@ filterImports _ decl_spec Nothing all_avails
filterImports iface decl_spec (Just (want_hiding, import_items)) all_avails
= do -- check for errors, convert RdrNames to Names
= do -- check for errors, convert RdrNames to Names
opt_typeFamilies <- xoptM Opt_TypeFamilies
items1 <- mapM (lookup_lie opt_typeFamilies) import_items
let items2 :: [(LIE Name, AvailInfo)]
items2 = concat items1
-- NB the AvailInfo may have duplicates, and several items
-- for the same parent; e.g N(x) and N(y)
-- NB the AvailInfo may have duplicates, and several items
-- for the same parent; e.g N(x) and N(y)
names = availsToNameSet (map snd items2)
keep n = not (n `elemNameSet` names)
pruned_avails = filterAvails keep all_avails
hiding_prov = Imported [ImpSpec { is_decl = decl_spec, is_item = ImpAll }]