@@ -11,7 +11,6 @@ import System.IO.Unsafe (unsafePerformIO)
11import SourceSyntax.Module
11import SourceSyntax.Module
12import qualified Data.Binary as Binary
12import qualified Data.Binary as Binary
13import qualified Data.ByteString.Lazy as BS
13import qualified Data.ByteString.Lazy as BS
14−import Data.Either.Unwrap (fromRight)
16import qualified InterfaceSerialization as IS
15import qualified InterfaceSerialization as IS
@@ -50,22 +49,23 @@ safeReadDocs name =
51firstModuleInterface :: Interfaces -> Either String (String, ModuleInterface)
50firstModuleInterface :: Interfaces -> Either String (String, ModuleInterface)
52firstModuleInterface interfaces =
51firstModuleInterface interfaces =
53− if Map.null interfaces then
52+ case Map.toList interfaces of
54− Left "No interfaces found in serialized Prelude!"
53+ [] -> Left "No interfaces found in serialized Prelude!"
55− else
54+ iface:_ -> Right iface
56− Right $ head $ Map.toList interfaces
58readDocs :: FilePath -> IO Interfaces
56readDocs :: FilePath -> IO Interfaces
59readDocs filePath = do
57readDocs filePath = do
60 bytes <- IS.loadInterface filePath
58 bytes <- IS.loadInterface filePath
61− let interfaces = bytes >>= IS.interfaceDecode filePath
59+ let interfaces = IS.interfaceDecode filePath =<< bytes
63− -- Although every ModuleInterface that is deserialized in this collection
61+ -- Although every ModuleInterface that is deserialized in this collection
64− -- contains the compiler version, we only check the first ModuleInterface
62+ -- contains the compiler version, we only check the first ModuleInterface
65− -- since it doesn't make sense that different modules in Prelude would have
63+ -- since it doesn't make sense that different modules in Prelude would
66− -- been compiled by different compiler versions.
64+ -- have been compiled by different compiler versions.
67− case interfaces >>= firstModuleInterface >>= IS.validVersion filePath of
65+ isValid = IS.validVersion filePath =<< firstModuleInterface =<< interfaces
67+ case (interfaces, isValid) of
68− Left err -> do
68+ (_, Left err) -> do
69 hPutStrLn stderr err
69 hPutStrLn stderr err
70 exitFailure
70 exitFailure
@@ -73,4 +73,6 @@ readDocs filePath = do
73 -- returns a Right value. The toList/fromList is necessary because of a
73 -- returns a Right value. The toList/fromList is necessary because of a
74 -- problem with looking up keys in the Map after deserialization. Example
74 -- problem with looking up keys in the Map after deserialization. Example
75 -- at https://gist.github.com/jsl/7294493.
75 -- at https://gist.github.com/jsl/7294493.
76+ -- TODO: try switching to Data.ByteString.Lazy.Char8
76− Right _ -> return $ Map.fromList $ Map.toList $ fromRight interfaces
78+ return $ Map.fromList $ Map.toList ifaces