+ qual_mod_name = case as_mod of
+ Nothing -> imp_mod_name
+ Just another_name -> another_name
+ imp_spec = ImportSpec { is_mod = imp_mod_name, is_qual = qual_only,
+ is_loc = loc, is_as = qual_mod_name }
+ mk_deprec = mi_dep_fn iface
+ in
+
+ -- Get the total imports, and filter them according to the import list
+ exportsToAvails filtered_exports `thenM` \ total_avails ->
+ filterImports iface imp_spec
+ imp_details total_avails `thenM` \ (avail_env, gbl_env) ->
+
+ let
+ -- Compute new transitive dependencies
+ orphans | is_orph = insert imp_mod_name (dep_orphs deps)
+ | otherwise = dep_orphs deps
+
+ (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, want_boot) : filter not_self (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
+ -- from imp_mod
+ ([], insert (mi_package iface) (dep_pkgs deps))
+
+ not_self (m, _) = m /= this_mod_name
+
+ import_all = case imp_details of
+ Just (is_hiding, ls) -- Imports are spec'd explicitly
+ | not is_hiding -> Just (not (null ls))
+ _ -> Nothing -- Everything is imported,
+ -- (or almost everything [hiding])
+
+ -- 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.
+ imports = ImportAvails {
+ imp_qual = unitModuleEnvByName qual_mod_name avail_env,
+ imp_env = avail_env,
+ imp_mods = unitModuleEnv imp_mod (imp_mod, import_all),
+ imp_orphs = orphans,
+ imp_dep_mods = mkModDeps dependent_mods,
+ imp_dep_pkgs = dependent_pkgs }
+