+ is_lib = isLibModule mod -- Don't record dependencies when importing a library module
+ add (imp_mod, version, has_orphans, _) deps
+ | is_lib && not has_orphans = deps
+ | otherwise = addToFM_C combine deps imp_mod (version, has_orphans, Nothing)
+ -- Record dependencies for modules that are
+ -- either are dependent via a non-library module
+ -- or contain orphan rules or instance decls
+
+ -- Don't ditch a module that's already loaded!!
+ combine old@(_, _, Just _) new = old
+ combine old@(_, _, Nothing) new = new
+
+loadExport :: ModuleName -> ExportItem -> RnM d [AvailInfo]
+loadExport this_mod (mod, entities)
+ | mod == this_mod = returnRn []
+ -- 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.) 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. A bit bogus
+ -- but it's a bogus thing to do!