import HscTypes ( ModuleLocation(..),
ModIface(..), emptyModIface,
VersionInfo(..), ImportedModuleInfo,
- lookupIfaceByModName,
+ lookupIfaceByModName, RdrExportItem,
ImportVersion, WhetherHasOrphans, IsBootInterface,
DeclsMap, GatedDecl, IfaceInsts, IfaceRules,
AvailInfo, GenAvailInfo(..), Avails, Deprecations(..)
)
-import HsSyn ( TyClDecl(..), InstDecl(..),
- FixitySig(..), RuleDecl(..),
- tyClDeclNames, tyClDeclSysNames, hsTyVarNames, getHsInstHead,
+import HsSyn ( TyClDecl(..), InstDecl(..), RuleDecl(..),
+ tyClDeclNames, tyClDeclSysNames, hsTyVarNames,
+ getHsInstHead,
)
import RdrHsSyn ( RdrNameTyClDecl, RdrNameInstDecl, RdrNameRuleDecl )
import RnHsSyn ( extractHsTyNames_s )
import RnMonad
import ParseIface ( parseIface )
+import PrelNames ( gHC_PRIM_Name, gHC_PRIM )
import Name ( Name {-instance NamedThing-},
nameModule, isLocalName, nameIsLocalOrFrom
)
import ListSetOps ( minusList )
import Outputable
import Bag
+import BinIface ( {- just instances -} )
+import qualified Binary
+import Panic
import Config
import IOExts
+import Exception ( tryAllIO, Exception(DynException) )
+import Dynamic ( fromDynamic )
import Directory
+import List ( isSuffixOf )
\end{code}
-- Loading the export list
-----------------------------------------------------
-loadExports :: (Version, [ExportItem]) -> RnM d (Version, [(ModuleName,Avails)])
+loadExports :: (Version, [RdrExportItem]) -> RnM d (Version, [(ModuleName,Avails)])
loadExports (vers, items)
= mapRn loadExport items `thenRn` \ avails_s ->
returnRn (vers, avails_s)
-loadExport :: ExportItem -> RnM d (ModuleName, Avails)
+loadExport :: RdrExportItem -> RnM d (ModuleName, Avails)
loadExport (mod, entities)
= mapRn (load_entity mod) entities `thenRn` \ avails ->
returnRn (mod, avails)
where
mod_name = moduleName mod
-loadFixDecl mod_name sig@(FixitySig rdr_name fixity loc)
+loadFixDecl mod_name (rdr_name, fixity)
= newGlobalName mod_name (rdrNameOcc rdr_name) `thenRn` \ name ->
returnRn (name, fixity)
findAndReadIface doc_str mod_name hi_boot_file
= traceRn trace_msg `thenRn_`
+ -- Check for GHC.Prim, and return its static interface
+ if mod_name == gHC_PRIM_Name
+ then returnRn (Right (gHC_PRIM, ghcPrimIface))
+ else
+
-- In interactive or --make mode, we are *not allowed* to demand-load
-- a home package .hi file. So don't even look for them.
-- This helps in the case where you are sitting in eg. ghc/lib/std
= --ioToRnM (putStrLn ("reading iface " ++ file_path)) `thenRn_`
traceRn (ptext SLIT("readIFace") <+> text file_path) `thenRn_`
- ioToRnM (hGetStringBuffer False file_path) `thenRn` \ read_result ->
- case read_result of {
- Left io_error -> bale_out (text (show io_error)) ;
+ let hi_boot_ver = "hi-boot-" ++ cHscIfaceFileVersion in
+ if ".hi-boot" `isSuffixOf` file_path
+ || hi_boot_ver `isSuffixOf` file_path then
+
+ ioToRnM (hGetStringBuffer False file_path) `thenRn` \ read_result ->
+ case read_result of {
+ Left io_error -> bale_out (text (show io_error));
Right contents ->
- case parseIface contents (mkPState loc exts) of
- POk _ iface -> returnRn (Right iface)
+ case parseIface contents (mkPState loc exts) of {
+ POk _ iface -> returnRn (Right iface);
PFailed err -> bale_out err
- }
+ }}
+
+ else
+ ioToRnM_no_fail (tryAllIO (Binary.getBinFileWithDict file_path))
+ `thenRn` \ either_iface ->
+
+ case either_iface of
+ Right iface -> returnRn (Right iface)
+ Left (DynException d) | Just e <- fromDynamic d
+ -> bale_out (text (show (e :: GhcException)))
+
+ Left err -> bale_out (text (show err))
+
where
exts = ExtFlags {glasgowExtsEF = True,
parrEF = True}