mk_prov name = NonLocalDef (UserImport imp_mod iloc (name `elemNameSet` explicits))
gbl_env = mkGlobalRdrEnv qual_mod unqual_imp mk_prov filtered_avails deprecs
- imports = mkImportAvails qual_mod unqual_imp gbl_env filtered_avails
+ imports = mkImportAvails qual_mod unqual_imp filtered_avails
in
returnM (gbl_env, imports { imp_mods = dir_imp})
}
-- Optimisation: filter out names for built-in syntax
-- They just clutter up the environment (esp tuples), and the parser
-- will generate Exact RdrNames for them, so the cluttered
- -- envt is no use. To avoid doing this filter all the type,
+ -- envt is no use. To avoid doing this filter all the time,
-- we use -fno-implicit-prelude as a clue that the filter is
- -- worth while. Really, it's only useful for Base and Tuple.
+ -- worth while. Really, it's only useful for GHC.Base and GHC.Tuple.
--
-- It's worth doing because it makes the environment smaller for
-- every module that imports the Prelude
-- but that stops them being Exact, so they get looked up. Sigh.
-- It doesn't matter because it only affects the Data.Tuple really.
-- The important thing is to trim down the exports.
- imports = mkImportAvails mod_name unqual_imp gbl_env avails'
+ imports = mkImportAvails mod_name unqual_imp avails'
avails' | implicit_prelude = filter not_built_in_syntax avails
| otherwise = avails
not_built_in_syntax a = not (all isBuiltInSyntaxName (availNames a))
= case lookupModuleEnvByName mod_avail_env mod of
Nothing -> addErr (modExportErr mod) `thenM_`
returnM acc
- Just mod_avails
- -> foldlM (check_occs warn_dup_exports ie)
- occs mod_avails `thenM` \ occs' ->
- let
+ Just avail_env
+ -> let
+ mod_avails = availEnvElts avail_env
avails' = foldl addAvail avails mod_avails
in
+ foldlM (check_occs warn_dup_exports ie)
+ occs mod_avails `thenM` \ occs' ->
+
returnM (mod:mods, occs', avails')
exports_from_item acc@(mods, occs, avails) ie
import HscTypes ( GhciMode, ExternalPackageState, HomePackageTable, NameCache,
GlobalRdrEnv, LocalRdrEnv, FixityEnv, TypeEnv, TyThing,
Avails, GenAvailInfo(..), AvailInfo, availName,
- IsBootInterface, Deprecations, unQualInScope )
+ IsBootInterface, Deprecations )
import TcType ( TcTyVarSet, TcType, TcTauType, TcThetaType, TcPredType, TcKind,
tcCmpPred, tcCmpType, tcCmpTypes )
import InstEnv ( DFunId, InstEnv )
-- i.e. *excluding* class ops and constructors
-- (which appear inside their parent AvailTC)
- imp_unqual :: ModuleEnv Avails,
+ imp_unqual :: ModuleEnv AvailEnv,
-- Used to figure out "module M" export specifiers
-- Domain is only modules with *unqualified* imports
-- (see 1.4 Report Section 5.1.1)
- -- The list of Avails is cumulative, not necessarily
- -- nicely uniquified. For example, we might have Maybe(Nothing)
- -- and Maybe(Just) in the list, separately.
+ -- We keep the stuff as an AvailEnv so that it's easy to
+ -- combine stuff coming from different (unqualified)
+ -- imports of the same module
imp_mods :: ModuleEnv (Module, Bool)
-- Domain is all directly-imported modules
(ImportAvails { imp_env = env1, imp_unqual = unqual1, imp_mods = mods1 })
(ImportAvails { imp_env = env2, imp_unqual = unqual2, imp_mods = mods2 })
= ImportAvails { imp_env = env1 `plusAvailEnv` env2,
- imp_unqual = plusModuleEnv_C (++) unqual1 unqual2,
+ imp_unqual = plusModuleEnv_C plusAvailEnv unqual1 unqual2,
imp_mods = mods1 `plusModuleEnv` mods2 }
mkImportAvails :: ModuleName -> Bool
- -> GlobalRdrEnv -> [AvailInfo] -> ImportAvails
-mkImportAvails mod_name unqual_imp gbl_env avails
+ -> [AvailInfo] -> ImportAvails
+mkImportAvails mod_name unqual_imp avails
= ImportAvails { imp_unqual = mod_avail_env,
imp_env = entity_avail_env,
imp_mods = emptyModuleEnv }-- Stays empty for module being compiled;
-- module M ( module P ) where ...
-- Then we must export whatever came from P unqualified.
- unqual_avails | not unqual_imp = [] -- Short cut when no unqualified imports
- | otherwise = pruneAvails (unQualInScope gbl_env) avails
+ unqual_avails | not unqual_imp = emptyAvailEnv -- Qualified import
+ | otherwise = entity_avail_env -- Unqualified import
entity_avail_env = foldl insert emptyAvailEnv avails
insert env avail = extendNameEnv_C plusAvail env (availName avail) avail