+ 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 }
+ 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) ->
+
+ getDOpts `thenM` \ dflags ->
+
+ let
+ -- Compute new transitive dependencies
+
+ orphans | is_orph = ASSERT( not (imp_mod_name `elem` dep_orphs deps) )
+ imp_mod_name : dep_orphs deps
+ | otherwise = dep_orphs deps
+
+ (dependent_mods, dependent_pkgs)
+ = case mi_package iface of
+ HomePackage ->
+ -- 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)
+
+ ExtPackage pkg ->
+ -- 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)
+
+ 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_env = unitModuleEnv qual_mod_name avail_env,
+ imp_mods = unitModuleEnv imp_mod (imp_mod, import_all, loc),
+ imp_orphs = orphans,
+ imp_dep_mods = mkModDeps dependent_mods,
+ imp_dep_pkgs = dependent_pkgs }
+