+ -- Filter the imports according to the import list
+ filterImports imp_mod is_boot imp_spec avails `thenM` \ (filtered_avails, explicits) ->
+
+ let
+ (sub_dep_mods, sub_dep_pkgs) = mi_deps iface
+
+ -- Compute new transitive dependencies: take the ones in
+ -- the interface and add
+ (dependent_mods, dependent_pkgs)
+ | isHomeModule imp_mod
+ = -- Imported module is from the home package
+ -- Take its dependent modules and
+ -- (a) remove this_mod (might be there as a hi-boot)
+ -- (b) add imp_mod itself
+ -- Take its dependent packages unchanged
+ ((imp_mod_name, is_orph, is_boot) : filter not_self sub_dep_mods,
+ sub_dep_pkgs)
+ | otherwise
+ = -- Imported module is from another package
+ -- Take only the orphan modules from its dependent modules
+ -- (sigh! it would be better to dump them entirely)
+ -- Add the package imp_mod comes from to the dependent packages
+ -- from imp_mod
+ (filter sub_is_orph sub_dep_mods,
+ insert (mi_package iface) sub_dep_pkgs)
+
+ not_self (m, _, _) = m /= this_mod_name
+ sub_is_orph (_, orph, _) = orph
+
+ import_all = case imp_spec of
+ (Just (False, _)) -> False -- Imports are spec'd explicitly
+ other -> True -- Everything is imported,
+ -- (or almost everything [hiding])
+
+ qual_mod_name = case as_mod of
+ Nothing -> imp_mod_name
+ Just another_name -> another_name
+
+ -- unqual_avails is the Avails that are visible in *unqualified* form
+ -- We need to know this so we know what to export when we see
+ -- module M ( module P ) where ...
+ -- Then we must export whatever came from P unqualified.
+ avail_env = mkAvailEnv filtered_avails
+ unqual_avails | qual_only = emptyAvailEnv -- Qualified import
+ | otherwise = avail_env -- Unqualified import
+
+ mk_prov name = NonLocalDef (UserImport imp_mod iloc (name `elemNameSet` explicits))
+ gbl_env = mkGlobalRdrEnv qual_mod_name (not qual_only)
+ mk_prov filtered_avails deprecs
+ imports = ImportAvails {
+ imp_unqual = unitModuleEnvByName qual_mod_name unqual_avails,
+ imp_env = avail_env,
+ imp_mods = unitModuleEnv imp_mod (imp_mod, import_all),
+ dep_mods = mkModDeps dependent_mods,
+ dep_pkgs = dependent_pkgs }
+
+ in