import RnMonad
import ParseIface ( parseIface )
-import Name ( Name {-instance NamedThing-}, nameOccName,
- nameModule, isLocalName, nameIsLocalOrFrom,
- NamedThing(..),
+import Name ( Name {-instance NamedThing-},
+ nameModule, isLocalName, nameIsLocalOrFrom
)
-import Name ( mkNameEnv, extendNameEnv )
+import NameEnv
import Module ( Module,
moduleName, isHomeModule,
ModuleName, WhereFrom(..),
extendModuleEnv, mkVanillaModule
)
-import RdrName ( RdrName, rdrNameOcc )
+import RdrName ( rdrNameOcc )
import SrcLoc ( mkSrcLoc )
import Maybes ( maybeToBool, orElse )
import StringBuffer ( hGetStringBuffer )
= tryLoadInterface doc mod from `thenRn` \ (ifaces, maybe_err) ->
case maybe_err of
Nothing -> returnRn ifaces
- Just err -> failWithRn ifaces err
+ Just err -> failWithRn ifaces (elaborate err)
+ where
+ elaborate err = hang (ptext SLIT("failed to load interface for") <+> quotes (ppr mod) <> colon)
+ 4 err
tryLoadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d (ModIface, Maybe Message)
-- Returns (Just err) if an error happened
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,
= 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
= 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
(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
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)
if b then returnRn hi_boot_ver_path
else returnRn hi_boot_path
| otherwise = returnRn hi_path
- where (Just hi_path) = ml_hi_file locn
- (hi_base, hi_suf) = splitFilename hi_path
- hi_boot_path = hi_base ++ ".hi-boot"
- hi_boot_ver_path = hi_base ++ ".hi-boot-" ++ cHscIfaceFileVersion
+ where (Just hi_path) = ml_hi_file locn
+ (hi_base, _hi_suf) = splitFilename hi_path
+ hi_boot_path = hi_base ++ ".hi-boot"
+ hi_boot_ver_path = hi_base ++ ".hi-boot-" ++ cHscIfaceFileVersion
\end{code}
@readIface@ tries just the one file.
= 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}