[project @ 2005-02-14 13:27:52 by simonmar]
authorsimonmar <unknown>
Mon, 14 Feb 2005 13:28:05 +0000 (13:28 +0000)
committersimonmar <unknown>
Mon, 14 Feb 2005 13:28:05 +0000 (13:28 +0000)
Put the GlobalRdrEnv back into the ModIface, so it gets preserved when
we reload a module without recompiling it.

ghc/compiler/compMan/CompManager.lhs
ghc/compiler/iface/BinIface.hs
ghc/compiler/iface/MkIface.lhs
ghc/compiler/main/DriverPipeline.hs
ghc/compiler/main/HscMain.lhs
ghc/compiler/main/HscTypes.lhs

index 9a576b7..87e59fa 100644 (file)
@@ -253,7 +253,7 @@ mkTopLevEnv :: HomePackageTable -> String -> IO GlobalRdrEnv
 mkTopLevEnv hpt mod
  = case lookupModuleEnv hpt (mkModule mod) of
       Nothing      -> throwDyn (ProgramError ("mkTopLevEnv: not a home module " ++ mod))
-      Just details -> case hm_globals details of
+      Just details -> case mi_globals (hm_iface details) of
                        Nothing  -> throwDyn (ProgramError ("mkTopLevEnv: not interpreted " ++ mod))
                        Just env -> return env
 
@@ -264,7 +264,7 @@ cmGetContext CmState{cm_ic=ic} =
 cmModuleIsInterpreted :: CmState -> String -> IO Bool
 cmModuleIsInterpreted cmstate str 
  = case lookupModuleEnv (cmHPT cmstate) (mkModule str) of
-      Just details       -> return (isJust (hm_globals details))
+      Just details       -> return (isJust (mi_globals (hm_iface details)))
       _not_a_home_module -> return False
 
 -----------------------------------------------------------------------------
@@ -1038,11 +1038,10 @@ upsweep_mod hsc_env (old_hpt, old_linkables) summary
            -- Compilation "succeeded", and may or may not have returned a new
            -- linkable (depending on whether compilation was actually performed
           -- or not).
-           CompOK new_details new_globals new_iface maybe_new_linkable
+           CompOK new_details new_iface maybe_new_linkable
               -> do let 
                        new_linkable = maybe_new_linkable `orElse` old_linkable
                        new_info = HomeModInfo { hm_iface = new_iface,
-                                                hm_globals = new_globals,
                                                 hm_details = new_details,
                                                 hm_linkable = new_linkable }
                     return (Just new_info)
index b246be2..b809e3a 100644 (file)
@@ -173,6 +173,7 @@ instance Binary ModIface where
                 mi_fixities  = fixities,
                 mi_deprecs   = deprecs,
                 mi_decls     = decls,
+                mi_globals   = Nothing,
                 mi_insts     = insts,
                 mi_rules     = rules,
                 mi_rule_vers = rule_vers,
index 29110c7..354e31e 100644 (file)
@@ -263,6 +263,7 @@ mkIface hsc_env location maybe_old_iface
                      mg_usages = usages,
                      mg_deps   = deps,
                      mg_exports = exports,
+                     mg_rdr_env = rdr_env,
                      mg_fix_env = fix_env,
                      mg_deprecs = src_deprecs,
                      mg_insts = insts, 
@@ -306,7 +307,8 @@ mkIface hsc_env location maybe_old_iface
                        mi_rules    = iface_rules,
                        mi_fixities = fixities,
                        mi_deprecs  = deprecs,
-       
+                       mi_globals  = Just rdr_env,
+
                        -- Left out deliberately: filled in by addVersionInfo
                        mi_mod_vers  = initialVersion,
                        mi_exp_vers  = initialVersion,
index 55fed5c..96df7c8 100644 (file)
@@ -137,9 +137,6 @@ compile :: HscEnv
 
 data CompResult
    = CompOK   ModDetails               -- New details
-             (Maybe GlobalRdrEnv)      -- Lexical environment for the module
-                                       -- (Maybe because we may have loaded it from
-                                       --  its precompiled interface)
               ModIface                 -- New iface
               (Maybe Linkable) -- New code; Nothing => compilation was not reqd
                                --                      (old code is still valid)
@@ -207,13 +204,13 @@ compile hsc_env mod_summary
    case hsc_result of
       HscFail -> return CompErrs
 
-      HscNoRecomp details iface -> return (CompOK details Nothing iface Nothing)
+      HscNoRecomp details iface -> return (CompOK details iface Nothing)
 
-      HscRecomp details rdr_env iface
+      HscRecomp details iface
                stub_h_exists stub_c_exists maybe_interpreted_code 
 
        | isHsBoot src_flavour  -- No further compilation to do
-       -> return (CompOK details rdr_env iface Nothing)
+       -> return (CompOK details iface Nothing)
 
        | otherwise             -- Normal Haskell source files
        -> do
@@ -255,7 +252,7 @@ compile hsc_env mod_summary
           let linkable = LM unlinked_time this_mod
                             (hs_unlinked ++ stub_unlinked)
 
-          return (CompOK details rdr_env iface (Just linkable))
+          return (CompOK details iface (Just linkable))
 
 -----------------------------------------------------------------------------
 -- stub .h and .c files (for foreign export support)
@@ -698,7 +695,7 @@ runPhase (Hsc src_flavour) stop dflags basename suff input_fn get_output_fn _may
                SysTools.touch dflags' "Touching object file" o_file
                return (StopLn, dflags', Just location4, o_file)
 
-           HscRecomp _details _rdr_env _iface 
+           HscRecomp _details _iface 
                      stub_h_exists stub_c_exists
                      _maybe_interpreted_code -> do
 
index ab5916d..7b3e84b 100644 (file)
@@ -141,7 +141,6 @@ data HscResult
 
    -- Did recompilation
    | HscRecomp   ModDetails            -- new details (HomeSymbolTable additions)
-                (Maybe GlobalRdrEnv)           
                  ModIface              -- new iface (if any compilation was done)
                 Bool                   -- stub_h exists
                 Bool                   -- stub_c exists
@@ -296,15 +295,13 @@ hscBootBackEnd hsc_env mod_summary maybe_checked_iface (Just ds_result)
                         mkIface hsc_env (ms_location mod_summary)
                                 maybe_checked_iface ds_result
 
-       ; let { final_globals = Just $! (mg_rdr_env ds_result)
-             ; final_details = ModDetails { md_types = mg_types ds_result,
+       ; let { final_details = ModDetails { md_types = mg_types ds_result,
                                             md_insts = mg_insts ds_result,
                                             md_rules = mg_rules ds_result } }
          -- And the answer is ...
        ; dumpIfaceStats hsc_env
 
        ; return (HscRecomp final_details
-                           final_globals
                            final_iface
                             False False Nothing)
        }
@@ -387,9 +384,6 @@ hscBackEnd hsc_env mod_summary maybe_checked_iface (Just ds_result)
        ; final_iface <-
             if one_shot then return (error "no final iface")
                         else return new_iface
-       ; let { final_globals | one_shot  = Nothing
-                             | otherwise = Just $! (mg_rdr_env tidy_result) }
-       ; final_globals `seq` return ()
 
            -- Build the final ModDetails (except in one-shot mode, where
            -- we won't need this information after compilation).
@@ -409,7 +403,6 @@ hscBackEnd hsc_env mod_summary maybe_checked_iface (Just ds_result)
        ; dumpIfaceStats hsc_env
 
        ; return (HscRecomp final_details
-                           final_globals
                            final_iface
                             stub_h_exists stub_c_exists
                            maybe_bcos)
index 0f1a708..26267c0 100644 (file)
@@ -169,8 +169,6 @@ emptyPackageIfaceTable = emptyModuleEnv
 
 data HomeModInfo 
   = HomeModInfo { hm_iface    :: ModIface,
-                 hm_globals  :: Maybe GlobalRdrEnv,    -- Its top level environment
-                                                       -- Nothing <-> compiled module
                  hm_details  :: ModDetails,
                  hm_linkable :: Linkable }
 \end{code}
@@ -284,6 +282,11 @@ data ModIface
                -- the version of the parent class/tycon changes
        mi_decls :: [(Version,IfaceDecl)],      -- Sorted
 
+        mi_globals  :: !(Maybe GlobalRdrEnv),
+               -- Its top level environment or Nothing if we read this
+               -- interface from an interface file.  (We need the source
+               -- file to figure out the top-level environment.)
+
                -- Instance declarations and rules
        mi_insts     :: [IfaceInst],    -- Sorted
        mi_rules     :: [IfaceRule],    -- Sorted
@@ -399,6 +402,7 @@ emptyModIface pkg mod
               mi_insts = [],
               mi_rules = [],
               mi_decls = [],
+              mi_globals  = Nothing,
               mi_rule_vers = initialVersion,
               mi_dep_fn = emptyIfaceDepCache,
               mi_fix_fn = emptyIfaceFixCache,