[project @ 2000-12-18 14:19:35 by simonpj]
authorsimonpj <unknown>
Mon, 18 Dec 2000 14:19:35 +0000 (14:19 +0000)
committersimonpj <unknown>
Mon, 18 Dec 2000 14:19:35 +0000 (14:19 +0000)
A module's dependencies in its .hi file should not include itself!

ghc/compiler/DEPEND-NOTES
ghc/compiler/rename/RnHiFiles.lhs
ghc/compiler/rename/RnMonad.lhs

index 6610879..f92764e 100644 (file)
@@ -24,7 +24,7 @@ then
 then
        Unify, PprType (PprEnv)
 then
-       Literal (TysPrim, PprType), DataCon
+       Literal (TysPrim, PprType), DataCon (PprType)
 then
        TysWiredIn (DataCon.mkDataCon, loop MkId.mkDataConId, loop Generics.mkGenInfo)
 then
index 2020749..c50d2dd 100644 (file)
@@ -106,6 +106,7 @@ tryLoadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d (ModIface, Maybe Me
   -- (If the load fails, we plug in a vanilla placeholder)
 tryLoadInterface doc_str mod_name from
  = getHomeIfaceTableRn         `thenRn` \ hit ->
+   getModuleRn                 `thenRn` \ this_mod ->
    getIfacesRn                         `thenRn` \ ifaces@(Ifaces { iPIT = pit }) ->
 
        -- CHECK WHETHER WE HAVE IT ALREADY
@@ -148,6 +149,12 @@ tryLoadInterface doc_str mod_name from
    warnCheckRn (not redundant_source_import)
                (warnRedundantSourceImport mod_name)    `thenRn_`
 
+       -- Check that we aren't importing ourselves. 
+       -- That only happens in Rename.checkOldIface, 
+       -- which doesn't call tryLoadInterface
+   warnCheckRn (moduleName this_mod == mod_name)
+               (warnSelfImport this_mod)               `thenRn_`
+
        -- READ THE MODULE IN
    findAndReadIface doc_str mod_name hi_boot_file   `thenRn` \ read_result ->
    case read_result of {
@@ -198,7 +205,14 @@ tryLoadInterface doc_str mod_name from
                        ImportByUser -> addModDeps mod is_loaded (pi_usages iface) mod_map
                        other        -> mod_map
        mod_map2 = delFromFM mod_map1 mod_name
-       is_loaded m = maybeToBool (lookupIfaceByModName hit pit m)
+
+       this_mod_name = moduleName this_mod
+       is_loaded m   =  m == this_mod_name 
+                     || maybeToBool (lookupIfaceByModName hit pit m)
+               -- We treat the currently-being-compiled module as 'loaded' because
+               -- even though it isn't yet in the HIT or PIT; otherwise it gets
+               -- put into iImpModInfo, and then spat out into its own interface
+               -- file as a dependency
 
        -- Now add info about this module to the PIT
        has_orphans = pi_orphan iface
@@ -262,13 +276,12 @@ addModDeps mod is_loaded new_deps mod_deps
 
 loadExports :: (Version, [ExportItem]) -> RnM d (Version, [(ModuleName,Avails)])
 loadExports (vers, items)
-  = getModuleRn                                `thenRn` \ this_mod ->
-    mapRn (loadExport this_mod) items          `thenRn` \ avails_s ->
+  = mapRn loadExport items     `thenRn` \ avails_s ->
     returnRn (vers, avails_s)
 
 
-loadExport :: Module -> ExportItem -> RnM d (ModuleName, Avails)
-loadExport this_mod (mod, entities)
+loadExport :: ExportItem -> RnM d (ModuleName, Avails)
+loadExport (mod, entities)
   = mapRn (load_entity mod) entities   `thenRn` \ avails ->
     returnRn (mod, avails)
   where
@@ -602,5 +615,8 @@ hiModuleNameMismatchWarn requested_mod read_mod =
 warnRedundantSourceImport mod_name
   = ptext SLIT("Unnecessary {- SOURCE -} in the import of module")
           <+> quotes (ppr mod_name)
+
+warnSelfImport mod
+  = ptext SLIT("Importing my own interface: module") <+> ppr mod
 \end{code}
 
index 6a4943d..ff541af 100644 (file)
@@ -290,8 +290,8 @@ data Ifaces = Ifaces {
     }
 
 type ImportedModuleInfo = FiniteMap ModuleName (WhetherHasOrphans, IsBootInterface)
-       -- Contains info ONLY about modules that have not yet
-       --- been loaded into the iPIT
+       -- Contains info ONLY about modules that 
+       -- have not yet been loaded into the iPIT
 \end{code}