on master help sign in
Rename InterfaceSerialization file and change the function names in it
1700065Evan Czaplicki
Elm.cabal+2−2
@@ -60,7 +60,6 @@ Library
60 Transform.SortDefinitions,
60 Transform.SortDefinitions,
61 Transform.Substitute,
61 Transform.Substitute,
62 Metadata.Prelude,
62 Metadata.Prelude,
63− InterfaceSerialization,
64 Parse.Binop,
63 Parse.Binop,
65 Parse.Declaration,
64 Parse.Declaration,
66 Parse.Expression,
65 Parse.Expression,
@@ -87,6 +86,7 @@ Library
87 Build.Dependencies,
86 Build.Dependencies,
88 Build.File,
87 Build.File,
89 Build.Flags,
88 Build.Flags,
89+ Build.Interface,
90 Build.Print,
90 Build.Print,
91 Build.Source,
91 Build.Source,
92 Build.Utils,
92 Build.Utils,
@@ -140,7 +140,6 @@ Executable elm
140 Transform.SortDefinitions,
140 Transform.SortDefinitions,
141 Transform.Substitute,
141 Transform.Substitute,
142 Metadata.Prelude,
142 Metadata.Prelude,
143− InterfaceSerialization,
144 Parse.Binop,
143 Parse.Binop,
145 Parse.Declaration,
144 Parse.Declaration,
146 Parse.Expression,
145 Parse.Expression,
@@ -167,6 +166,7 @@ Executable elm
167 Build.Dependencies,
166 Build.Dependencies,
168 Build.File,
167 Build.File,
169 Build.Flags,
168 Build.Flags,
169+ Build.Interface,
170 Build.Print,
170 Build.Print,
171 Build.Source,
171 Build.Source,
172 Build.Utils,
172 Build.Utils,
compiler/Build/File.hs+5−5
@@ -15,10 +15,10 @@ import qualified Data.ByteString.Lazy as L
15
15
16import qualified Build.Utils as Utils
16import qualified Build.Utils as Utils
17import qualified Build.Flags as Flag
17import qualified Build.Flags as Flag
18−import qualified Build.Source as Source
18+import qualified Build.Interface as Interface
19import qualified Build.Print as Print
19import qualified Build.Print as Print
20+import qualified Build.Source as Source
20import qualified Generate.JavaScript as JS
21import qualified Generate.JavaScript as JS
21−import qualified InterfaceSerialization as IS
22import qualified Parse.Module as Parser
22import qualified Parse.Module as Parser
23import qualified SourceSyntax.Module as M
23import qualified SourceSyntax.Module as M
24
24
@@ -57,9 +57,9 @@ alreadyCompiled flags filePath = do
57retrieve :: Flag.Flags -> Map.Map String M.ModuleInterface -> FilePath
57retrieve :: Flag.Flags -> Map.Map String M.ModuleInterface -> FilePath
58 -> IO (String, M.ModuleInterface)
58 -> IO (String, M.ModuleInterface)
59retrieve flags interfaces filePath = do
59retrieve flags interfaces filePath = do
60− bytes <- IS.loadInterface (Utils.elmi flags filePath)
60+ bytes <- Interface.load (Utils.elmi flags filePath)
61− let binary = IS.interfaceDecode (Utils.elmi flags filePath) =<< bytes
61+ let binary = Interface.decode (Utils.elmi flags filePath) =<< bytes
62− case IS.validVersion filePath =<< binary of
62+ case Interface.isValid filePath =<< binary of
63 Right (name, interface) ->
63 Right (name, interface) ->
64 do when (Flag.print_types flags) (Print.interfaceTypes interfaces interface)
64 do when (Flag.print_types flags) (Print.interfaceTypes interfaces interface)
65 return (name, interface)
65 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
7import System.Exit
7import System.Exit
8import System.IO
8import System.IO
9import SourceSyntax.Module
9import SourceSyntax.Module
10−
11−import qualified InterfaceSerialization as IS
10+import qualified Build.Interface as Interface
12
11
13add :: Bool -> Module def -> Module def
12add :: Bool -> Module def -> Module def
14add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
13add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) decls
@@ -49,9 +48,9 @@ hasInterfaces ifaces = Right ifaces
49
48
50readDocs :: FilePath -> IO Interfaces
49readDocs :: FilePath -> IO Interfaces
51readDocs filePath = do
50readDocs filePath = do
52− bytes <- IS.loadInterface filePath
51+ bytes <- Interface.load filePath
53− let interfaces = IS.interfaceDecode filePath =<< bytes
52+ let interfaces = Interface.decode filePath =<< bytes
54− case mapM (IS.validVersion filePath) =<< hasInterfaces =<< interfaces of
53+ case mapM (Interface.isValid filePath) =<< hasInterfaces =<< interfaces of
55 Right ifaces -> return $ Map.fromList ifaces
54 Right ifaces -> return $ Map.fromList ifaces
56 Left err -> do
55 Left err -> do
57 hPutStrLn stderr err
56 hPutStrLn stderr err