[project @ 2000-10-16 08:24:18 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / Rename.lhs
index 93437ca..cf67969 100644 (file)
@@ -15,7 +15,7 @@ import RnHsSyn                ( RenamedHsModule, RenamedHsDecl,
                          extractHsTyNames, extractHsCtxtTyNames
                        )
 
-import CmdLineOpts     ( opt_HiMap, opt_D_dump_rn_trace, opt_D_dump_minimal_imports,
+import CmdLineOpts     ( dopt_D_dump_rn_trace, dopt_D_dump_minimal_imports,
                          opt_D_dump_rn, opt_D_dump_rn_stats, opt_WarnDeprecations,
                          opt_WarnUnusedBinds
                        )
@@ -72,34 +72,32 @@ import IO           ( openFile, IOMode(..) )
 
 
 \begin{code}
-type RenameResult = ( Module           -- This module
+type RenameResult = ( PersistentCompilerState,
+                   , Module            -- This module
                    , RenamedHsModule   -- Renamed module
                    , Maybe ParsedIface -- The existing interface file, if any
                    , ParsedIface       -- The new interface
-                   , RnNameSupply      -- Final env; for renaming derivings
-                   , FixityEnv         -- The fixity environment; for derivings
                    , [Module])         -- Imported modules
                   
-renameModule :: UniqSupply -> RdrNameHsModule -> IO (Maybe RenameResult)
-renameModule us this_mod@(HsModule mod_name vers exports imports local_decls _ loc)
+renameModule :: PersistentCompilerState -> HomeSymbolTable
+            -> RdrNameHsModule -> IO (Maybe RenameResult)
+renameModule old_pcs hst this_mod@(HsModule mod_name vers exports imports local_decls _ loc)
   =    -- Initialise the renamer monad
     do {
-       ((maybe_rn_stuff, dump_action), rn_errs_bag, rn_warns_bag) 
-          <- initRn (mkThisModule mod_name) us 
-                    (mkSearchPath opt_HiMap) loc
-                    (rename this_mod) ;
+       ((maybe_rn_stuff, dump_action), msgs, new_pcs) 
+          <- initRn dflags finder old_pcs hst loc (rename this_mod) ;
 
        -- Check for warnings
-       printErrorsAndWarnings rn_errs_bag rn_warns_bag ;
+       printErrorsAndWarnings msgs ;
 
        -- Dump any debugging output
        dump_action ;
 
        -- Return results
        if not (isEmptyBag rn_errs_bag) then
-           do { ghcExit 1 ; return Nothing }
+           return (old_pcs, Nothing)
         else
-           return maybe_rn_stuff
+           return (new_pcs, maybe_rn_stuff)
     }
 \end{code}
 
@@ -620,7 +618,7 @@ fixitiesFromLocalDecls gbl_env decls
                       `thenRn_` returnRn acc 
                    | otherwise -> returnRn acc ;
        
-           Just (name:_) ->
+           Just ((name,_):_) ->
 
                -- Check for duplicate fixity decl
          case lookupNameEnv acc name of {
@@ -710,14 +708,18 @@ reportUnusedNames mod_name direct_import_mods
                    , case parent_avail of { AvailTC _ _ -> True; other -> False }
                    ]
 
-       defined_names = mkNameSet (concat (rdrEnvElts gbl_env))
-       defined_but_not_used =
-          nameSetToList (defined_names `minusNameSet` really_used_names)
+       defined_names, defined_but_not_used :: [(Name,Provenance)]
+       defined_names        = concat (rdrEnvElts gbl_env)
+       defined_but_not_used = filter not_used defined_names
+       not_used name        = not (name `elemNameSet` really_used_names)
 
        -- Filter out the ones only defined implicitly
-       bad_locals     = [n | n <- defined_but_not_used, isLocallyDefined             n]
-       bad_imp_names  = [n | n <- defined_but_not_used, isUserImportedExplicitlyName n,
-                                                        not (module_unused n)]
+       bad_locals :: [Name]
+       bad_locals     = [n     | (n,LocalDef) <- defined_but_not_used]
+       
+       bad_imp_names :: [(Name,Provenance)]
+       bad_imp_names  = [(n,p) | (n,p@(UserImport mod _ True) <- defined_but_not_used,
+                                 not (module_unused mod)]
 
        deprec_used deprec_env = [ (n,txt)
                                  | n <- nameSetToList mentioned_names,
@@ -772,12 +774,9 @@ reportUnusedNames mod_name direct_import_mods
                               not (maybeToBool (lookupFM minimal_imports m)),
                               moduleName m /= pRELUDE_Name]
 
-       module_unused :: Name -> Bool
-       -- Name is imported from a module that's completely unused,
-       -- so don't report stuff about the name (the module covers it)
-       module_unused n = expectJust "module_unused" (maybeUserImportedFrom n)
-                         `elem` unused_imp_mods
-                               -- module_unused is only called if it's user-imported
+       module_unused :: Module -> Bool
+       module_unused mod = mod `elem` unused_imp_mods
+
     in
     warnUnusedModules unused_imp_mods                          `thenRn_`
     warnUnusedLocalBinds bad_locals                            `thenRn_`