[project @ 2005-05-24 14:52:08 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / HscTypes.lhs
index 4fd33c4..d5727fe 100644 (file)
@@ -86,7 +86,7 @@ import TyCon          ( TyCon, tyConSelIds, tyConDataCons )
 import DataCon         ( dataConImplicitIds )
 import Packages                ( PackageIdH, PackageId, PackageConfig )
 import DynFlags                ( DynFlags(..), isOneShot )
-import DriverPhases    ( HscSource(..), isHsBoot, hscSourceString )
+import DriverPhases    ( HscSource(..), isHsBoot, hscSourceString, Phase )
 import BasicTypes      ( Version, initialVersion, IPName, 
                          Fixity, defaultFixity, DeprecTxt )
 
@@ -96,7 +96,7 @@ import FiniteMap      ( FiniteMap )
 import CoreSyn         ( CoreRule )
 import Maybes          ( orElse, fromJust, expectJust )
 import Outputable
-import SrcLoc          ( SrcSpan )
+import SrcLoc          ( SrcSpan, Located )
 import UniqSupply      ( UniqSupply )
 import FastString      ( FastString )
 
@@ -188,15 +188,20 @@ hscEPS hsc_env = readIORef (hsc_EPS hsc_env)
 data Target = Target TargetId (Maybe (StringBuffer,ClockTime))
 
 data TargetId
-  = TargetModule Module           -- ^ A module name: search for the file
-  | TargetFile   FilePath  -- ^ A filename: parse it to find the module name.
+  = TargetModule Module
+       -- ^ A module name: search for the file
+  | TargetFile FilePath (Maybe Phase)
+       -- ^ A filename: preprocess & parse it to find the module name.
+       -- If specified, the Phase indicates how to compile this file
+       -- (which phase to start from).  Nothing indicates the starting phase
+       -- should be determined from the suffix of the filename.
   deriving Eq
 
 pprTarget :: Target -> SDoc
 pprTarget (Target id _) = pprTargetId id
 
 pprTargetId (TargetModule m) = ppr m
-pprTargetId (TargetFile f)   = text f
+pprTargetId (TargetFile f _) = text f
 
 type FinderCache = ModuleEnv FinderCacheEntry
 type FinderCacheEntry = (ModLocation, Maybe (PackageConfig,Bool))
@@ -220,6 +225,10 @@ data HomeModInfo
                --      the old linkable because it was out of date.
                -- after a complete compilation (GHC.load), all hm_linkable
                -- fields in the HPT will be Just.
+               --
+               -- When re-linking a module (hscNoRecomp), we construct
+               -- the HomModInfo by building a new ModDetails from the
+               -- old ModIface (only).
 \end{code}
 
 Simple lookups in the symbol table.
@@ -332,9 +341,19 @@ data ModIface
        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.)
+               -- Binds all the things defined at the top level in
+               -- the *original source* code for this module. which
+               -- is NOT the same as mi_exports, nor mi_decls (which
+               -- may contains declarations for things not actually
+               -- defined by the user).  Used for GHCi and for inspecting
+               -- the contents of modules via the GHC API only.
+               --
+               -- (We need the source file to figure out the
+               -- top-level environment, if we didn't compile this module
+               -- from source then this field contains Nothing).
+               --
+               -- Strictly speaking this field should live in the
+               -- HomeModInfo, but that leads to more plumbing.
 
                -- Instance declarations and rules
        mi_insts     :: [IfaceInst],    -- Sorted
@@ -919,8 +938,8 @@ data ModSummary
         ms_location  :: ModLocation,           -- Location
         ms_hs_date   :: ClockTime,             -- Timestamp of source file
        ms_obj_date  :: Maybe ClockTime,        -- Timestamp of object, maybe
-        ms_srcimps   :: [Module],              -- Source imports
-        ms_imps      :: [Module],              -- Non-source imports
+        ms_srcimps   :: [Located Module],      -- Source imports
+        ms_imps      :: [Located Module],      -- Non-source imports
         ms_hspp_file :: Maybe FilePath,                -- Filename of preprocessed source,
                                                -- once we have preprocessed it.
        ms_hspp_buf  :: Maybe StringBuffer      -- The actual preprocessed source, maybe.
@@ -987,7 +1006,12 @@ data Linkable = LM {
  }
 
 isObjectLinkable :: Linkable -> Bool
-isObjectLinkable l = all isObject (linkableUnlinked l)
+isObjectLinkable l = not (null unlinked) && all isObject unlinked
+  where unlinked = linkableUnlinked l
+       -- A linkable with no Unlinked's is treated as a BCO.  We can
+       -- generate a linkable with no Unlinked's as a result of
+       -- compiling a module in HscNothing mode, and this choice
+       -- happens to work well with checkStability in module GHC.
 
 instance Outputable Linkable where
    ppr (LM when_made mod unlinkeds)