on master help sign in
Rename InterfaceSerialization file and change the function names in it
commit170006534d6ca6810cddf58a0a2aaf2e31cc04a2 authorEvan Czaplicki <info@elm-lang.org> dateSat 4 Jan 2014, 15:19 (13 years ago) parent7e64531
5 files changed+57−63
Elm.cabal+2−2 compiler/Build/File.hs+5−5 compiler/Build/Interface.hs+46 compiler/InterfaceSerialization.hs−51 compiler/Metadata/Prelude.hs+4−5
Elm.cabal+2−2
@@ -60,7 +60,6 @@ Library
6060 Transform.SortDefinitions,
6161 Transform.Substitute,
6262 Metadata.Prelude,
63− InterfaceSerialization,
6463 Parse.Binop,
6564 Parse.Declaration,
6665 Parse.Expression,
@@ -87,6 +86,7 @@ Library
8786 Build.Dependencies,
8887 Build.File,
8988 Build.Flags,
89+ Build.Interface,
9090 Build.Print,
9191 Build.Source,
9292 Build.Utils,
@@ -140,7 +140,6 @@ Executable elm
140140 Transform.SortDefinitions,
141141 Transform.Substitute,
142142 Metadata.Prelude,
143− InterfaceSerialization,
144143 Parse.Binop,
145144 Parse.Declaration,
146145 Parse.Expression,
@@ -167,6 +166,7 @@ Executable elm
167166 Build.Dependencies,
168167 Build.File,
169168 Build.Flags,
169+ Build.Interface,
170170 Build.Print,
171171 Build.Source,
172172 Build.Utils,
compiler/Build/File.hs+5−5
@@ -15,10 +15,10 @@ import qualified Data.ByteString.Lazy as L
1515
1616import qualified Build.Utils as Utils
1717import qualified Build.Flags as Flag
18−import qualified Build.Source as Source
18+import qualified Build.Interface as Interface
1919import qualified Build.Print as Print
20+import qualified Build.Source as Source
2021import qualified Generate.JavaScript as JS
21−import qualified InterfaceSerialization as IS
2222import qualified Parse.Module as Parser
2323import qualified SourceSyntax.Module as M
2424
@@ -57,9 +57,9 @@ alreadyCompiled flags filePath = do
5757retrieve :: Flag.Flags -> Map.Map String M.ModuleInterface -> FilePath
5858 -> IO (String, M.ModuleInterface)
5959retrieve flags interfaces filePath = do
60− bytes <- IS.loadInterface (Utils.elmi flags filePath)
61− let binary = IS.interfaceDecode (Utils.elmi flags filePath) =<< bytes
62− case IS.validVersion filePath =<< binary of
60+ bytes <- Interface.load (Utils.elmi flags filePath)
61+ let binary = Interface.decode (Utils.elmi flags filePath) =<< bytes
62+ case Interface.isValid filePath =<< binary of
6363 Right (name, interface) ->
6464 do when (Flag.print_types flags) (Print.interfaceTypes interfaces interface)
6565 return (name, interface)
compiler/Build/Interface.hsnew file+46
@@ -0,0 +1,46 @@
1+{-# OPTIONS_GHC -W #-}
2+module Build.Interface (load,decode,isValid) where
3+
4+import qualified Data.ByteString.Lazy as L
5+import qualified Data.Binary as Binary
6+
7+import qualified Elm.Internal.Version as Version
8+import System.Directory (doesFileExist)
9+
10+import SourceSyntax.Module
11+
12+load :: FilePath -> IO (Either String L.ByteString)
13+load filePath = do
14+ exists <- doesFileExist filePath
15+ if exists
16+ then do
17+ byteString <- L.readFile filePath
18+ return $ Right byteString
19+
20+ else
21+ return $ Left $ "Unable to find file " ++ filePath ++
22+ " for deserialization!"
23+
24+decode :: Binary.Binary a => FilePath -> L.ByteString -> Either String a
25+decode filePath bytes =
26+ case Binary.decodeOrFail bytes of
27+ Right (_, _, binaryInfo) -> Right binaryInfo
28+
29+ Left (_, offset, err) ->
30+ Left $ concat $
31+ [ "Error reading build artifact: ", filePath, "\n"
32+ , " The exact error was '", err, "' at offset ", show offset, ".\n"
33+ , " The file was generated by a previous build and may be outdated or corrupt.\n"
34+ , " Please remove the file and try again."
35+ ]
36+
37+isValid :: FilePath -> (String, ModuleInterface) -> Either String (String, ModuleInterface)
38+isValid filePath (name, interface) =
39+ if iVersion interface == Version.elmVersion
40+ then Right (name, interface)
41+ else Left $ concat
42+ [ "Error reading build artifact: ", filePath, "\n"
43+ , " It was generated by a different version of the compiler: "
44+ , show (iVersion interface), "\n"
45+ , " Please remove the file and try again.\n"
46+ ]
compiler/InterfaceSerialization.hsdeleted−51
@@ -1,51 +0,0 @@
1−{-# OPTIONS_GHC -W #-}
2−module InterfaceSerialization ( loadInterface
3− , interfaceDecode
4− , validVersion
5− ) where
6−
7−import qualified Data.ByteString.Lazy as L
8−import qualified Data.Binary as Binary
9−
10−import qualified Elm.Internal.Version as Version
11−import System.Directory (doesFileExist)
12−
13−import SourceSyntax.Module
14−
15−loadInterface :: FilePath -> IO (Either String L.ByteString)
16−loadInterface filePath = do
17− exists <- doesFileExist filePath
18− if exists
19− then do
20− byteString <- L.readFile filePath
21− return $ Right byteString
22−
23− else
24− return $ Left $ "Unable to find file " ++ filePath ++
25− " for deserialization!"
26−
27−interfaceDecode :: Binary.Binary a =>
28− FilePath -> L.ByteString -> Either String a
29−interfaceDecode filePath bytes = do
30− case Binary.decodeOrFail bytes of
31− Right (_, _, binaryInfo) -> Right binaryInfo
32−
33− Left (_, offset, err) ->
34− Left $ concat [ "Error reading build artifact: ", filePath, "\n"
35− , " The exact error was '", err, "' at offset ", show offset, ".\n"
36− , " The file was generated by a previous build and may be outdated or corrupt.\n"
37− , " Please remove the file and try again."
38− ]
39−
40−validVersion :: FilePath -> (String, ModuleInterface) ->
41− Either String (String, ModuleInterface)
42−validVersion filePath (name, interface) =
43− if iVersion interface == Version.elmVersion then
44− Right (name, interface)
45− else
46− Left $ concat
47− [ "Error reading build artifact: ", filePath, "\n"
48− , " It was generated by a different version of the compiler: "
49− , show (iVersion interface), "\n"
50− , " Please remove the file and try again.\n"
51− ]
compiler/Metadata/Prelude.hs+4−5
@@ -7,8 +7,7 @@ import qualified Paths_Elm as Path
77import System.Exit
88import System.IO
99import SourceSyntax.Module
10−
11−import qualified InterfaceSerialization as IS
10+import qualified Build.Interface as Interface
1211
1312add :: Bool -> Module def -> Module def
1413add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
@@ -49,9 +48,9 @@ hasInterfaces ifaces = Right ifaces
4948
5049readDocs :: FilePath -> IO Interfaces
5150readDocs filePath = do
52− bytes <- IS.loadInterface filePath
53− let interfaces = IS.interfaceDecode filePath =<< bytes
54− case mapM (IS.validVersion filePath) =<< hasInterfaces =<< interfaces of
51+ bytes <- Interface.load filePath
52+ let interfaces = Interface.decode filePath =<< bytes
53+ case mapM (Interface.isValid filePath) =<< hasInterfaces =<< interfaces of
5554 Right ifaces -> return $ Map.fromList ifaces
5655 Left err -> do
5756 hPutStrLn stderr err