[project @ 2001-05-28 13:57:19 by simonmar]
authorsimonmar <unknown>
Mon, 28 May 2001 13:57:19 +0000 (13:57 +0000)
committersimonmar <unknown>
Mon, 28 May 2001 13:57:19 +0000 (13:57 +0000)
When we auto-load a module because the user typed a qualified name at
the prompt, we better not auto-load a home interface (because we won't
have the code to go with it).

So, introduce a new constructor in the WhereFrom datatype, namely
ImportByCmdLine for these auto-imports, and make findAndReadIface fail
if it tries to load a home interface by this route.

ToDo: GHCi should *never* demand-load a home interface under any
circumstances, but we don't have an ASSERT for this yet.

ghc/compiler/basicTypes/Module.lhs
ghc/compiler/rename/RnEnv.lhs
ghc/compiler/rename/RnHiFiles.lhs
ghc/compiler/rename/RnMonad.lhs

index 998dc1e..bb2b674 100644 (file)
@@ -141,6 +141,9 @@ data WhereFrom = ImportByUser               -- Ordinary user import: look for M.hi
               | ImportBySystem         -- Non user import.  Look for M.hi if M is in
                                        -- the module this module depends on, or is a system-ish module; 
                                        -- M.hi-boot otherwise
+              | ImportByCmdLine        -- The user typed a qualified name at
+                                       -- the GHCi prompt, try to demand-load
+                                       -- the interface.
 
 instance Outputable WhereFrom where
   ppr ImportByUser       = empty
index 8f53698..4d04154 100644 (file)
@@ -287,7 +287,7 @@ lookupQualifiedName rdr_name
        mod = rdrNameModule rdr_name
        occ = rdrNameOcc rdr_name
    in
-   loadInterface (ppr rdr_name) mod ImportBySystem `thenRn` \ iface ->
+   loadInterface (ppr rdr_name) mod ImportByCmdLine `thenRn` \ iface ->
    case  [ name | (_,avails) <- mi_exports iface,
           avail             <- avails,
           name              <- availNames avail,
index 87f8953..6d4f26f 100644 (file)
@@ -118,6 +118,7 @@ tryLoadInterface doc_str mod_name from
                        ImportByUser       -> not (mi_boot iface)
                        ImportByUserSource -> mi_boot iface
                        ImportBySystem     -> True
+                       ImportByCmdLine    -> True
                   -> returnRn (iface, Nothing) ;       -- Already loaded
                        -- The not (mi_boot iface) test checks that the already-loaded
                        -- interface isn't a boot iface.  This can conceivably happen,
@@ -133,6 +134,7 @@ tryLoadInterface doc_str mod_name from
          = case (from, mod_info) of
                (ImportByUser,       _)             -> False    -- Not hi-boot
                (ImportByUserSource, _)             -> True     -- hi-boot
+               (ImportByCmdLine,    _)             -> False
                (ImportBySystem, Just (_, is_boot)) -> is_boot
                (ImportBySystem, Nothing)           -> False
                        -- We're importing a module we know absolutely
@@ -144,6 +146,9 @@ tryLoadInterface doc_str mod_name from
          = case (from, mod_info) of 
                (ImportByUserSource, Just (_,False)) -> True
                other                                -> False
+
+       home_allowed | ImportByCmdLine <- from = True
+                    | otherwise               = False
    in
 
        -- Issue a warning for a redundant {- SOURCE -} import
@@ -160,7 +165,8 @@ tryLoadInterface doc_str mod_name from
        (warnSelfImport this_mod)               `thenRn_`
 
        -- READ THE MODULE IN
-   findAndReadIface doc_str mod_name hi_boot_file   `thenRn` \ read_result ->
+   findAndReadIface doc_str mod_name hi_boot_file home_allowed
+                                           `thenRn` \ read_result ->
    case read_result of {
        Left err ->     -- Not found, so add an empty export env to the Ifaces map
                        -- so that we don't look again
@@ -470,18 +476,26 @@ new_top_bndrs mod names_w_locs
 findAndReadIface :: SDoc -> ModuleName 
                 -> IsBootInterface     -- True  <=> Look for a .hi-boot file
                                        -- False <=> Look for .hi file
+                -> Bool                -- True <=> can read home interface
                 -> RnM d (Either Message (Module, ParsedIface))
        -- Nothing <=> file not found, or unreadable, or illegible
        -- Just x  <=> successfully found and parsed 
 
-findAndReadIface doc_str mod_name hi_boot_file
+findAndReadIface doc_str mod_name hi_boot_file home_allowed
   = traceRn trace_msg                  `thenRn_`
 
     ioToRnM (findModule mod_name)      `thenRn` \ maybe_found ->
     case maybe_found of
 
       Right (Just (wanted_mod,locn))
-        -> mkHiPath hi_boot_file locn `thenRn` \ file -> 
+        -> -- in CmdLineMode, we cannot demand-load home interfaces
+          -- because the corresponding code won't be loaded, so we
+          -- check for this here and emit an error message.
+          if (home_allowed && isHomeModule wanted_mod)
+             then returnRn (Left (notLoaded wanted_mod))
+             else
+
+          mkHiPath hi_boot_file locn `thenRn` \ file -> 
           readIface file `thenRn` \ read_result ->
           case read_result of
                 Left bad -> returnRn (Left bad)
@@ -618,6 +632,9 @@ warnRedundantSourceImport mod_name
   = ptext SLIT("Unnecessary {- SOURCE -} in the import of module")
           <+> quotes (ppr mod_name)
 
+notLoaded mod
+  = ptext SLIT("Module") <+> quotes (ppr mod) <+> ptext SLIT("is not loaded")
+
 warnSelfImport mod
   = ptext SLIT("Importing my own interface: module") <+> ppr mod
 \end{code}
index 6a6acbb..7e8c679 100644 (file)
@@ -168,6 +168,9 @@ data RnMode = SourceMode            -- Renaming source code
 
 isInterfaceMode InterfaceMode = True
 isInterfaceMode _ = False
+
+isCmdLineMode CmdLineMode = True
+isCmdLineMode _ = False
 \end{code}
 
 %===================================================