on master help sign in
Get rid of Parse.fromFile / make file read responsibility of caller
7be64c0Evan Czaplicki
builder/src/Build.hs+6−6
@@ -258,9 +258,9 @@ crawlModule env@(Env _ root pkg srcDirs locals foreigns) mvar name =
258crawlFile :: Env -> MVar StatusDict -> ModuleName.Raw -> FilePath -> IO Status
258crawlFile :: Env -> MVar StatusDict -> ModuleName.Raw -> FilePath -> IO Status
259crawlFile env@(Env _ root pkg _ _ _) mvar expectedName path =
259crawlFile env@(Env _ root pkg _ _ _) mvar expectedName path =
260 do time <- File.getTime path
260 do time <- File.getTime path
261− result <- Parse.fromFile pkg (root </> path)
261+ bytes <- File.readUtf8 (root </> path)
262
262
263− case result of
263+ case Parse.fromByteString pkg bytes of
264 Right modul@(Src.Module maybeActualName _ imports values _ _ _ _) ->
264 Right modul@(Src.Module maybeActualName _ imports values _ _ _ _) ->
265 case maybeActualName of
265 case maybeActualName of
266 Just actualName ->
266 Just actualName ->
@@ -317,8 +317,8 @@ checkModule env@(Env _ root pkg _ _ _) foreigns resultsMVar name status =
317 depsStatus <- checkDeps root results deps
317 depsStatus <- checkDeps root results deps
318 case depsStatus of
318 case depsStatus of
319 DepsChange ifaces ->
319 DepsChange ifaces ->
320− do result <- Parse.fromFile pkg path
320+ do bytes <- File.readUtf8 path
321− case result of
321+ case Parse.fromByteString pkg bytes of
322 Right modul -> compile env local ifaces modul
322 Right modul -> compile env local ifaces modul
323 Left syntaxError ->
323 Left syntaxError ->
324 return $ RProblem $ Problem.BadSyntax $
324 return $ RProblem $ Problem.BadSyntax $
@@ -811,8 +811,8 @@ crawlMain env@(Env _ _ pkg _ _ _) mvar given =
811
811
812 LOutside path ->
812 LOutside path ->
813 do time <- File.getTime path
813 do time <- File.getTime path
814− result <- Parse.fromFile pkg path
814+ bytes <- File.readUtf8 path
815− case result of
815+ case Parse.fromByteString pkg bytes of
816 Right modul@(Src.Module _ _ imports values _ _ _ _) ->
816 Right modul@(Src.Module _ _ imports values _ _ _ _) ->
817 do let deps = map Src.getImportName imports
817 do let deps = map Src.getImportName imports
818 let local = Details.Local path time deps (any isMain values)
818 let local = Details.Local path time deps (any isMain values)
builder/src/Deps/Diff.hs+2−2
@@ -361,8 +361,8 @@ getDocs cache manager name version =
361 exists <- File.exists path
361 exists <- File.exists path
362 if exists
362 if exists
363 then
363 then
364− do result <- D.fromFile Docs.decoder path
364+ do bytes <- File.readUtf8 path
365− case result of
365+ case D.fromByteString Docs.decoder bytes of
366 Right docs ->
366 Right docs ->
367 return $ Right docs
367 return $ Right docs
368
368
builder/src/Elm/Outline.hs+3−2
@@ -29,6 +29,7 @@ import qualified Elm.Licenses as Licenses
29import qualified Elm.ModuleName as ModuleName
29import qualified Elm.ModuleName as ModuleName
30import qualified Elm.Package as Pkg
30import qualified Elm.Package as Pkg
31import qualified Elm.Version as V
31import qualified Elm.Version as V
32+import qualified File
32import qualified Json.Decode as D
33import qualified Json.Decode as D
33import qualified Json.Encode as E
34import qualified Json.Encode as E
34import qualified Reporting.Exit as Exit
35import qualified Reporting.Exit as Exit
@@ -173,8 +174,8 @@ encodeDeps encodeValue deps =
173
174
174read :: FilePath -> IO (Either Exit.Outline Outline)
175read :: FilePath -> IO (Either Exit.Outline Outline)
175read root =
176read root =
176− do result <- D.fromFile decoder (root </> "elm.json")
177+ do bytes <- File.readUtf8 (root </> "elm.json")
177− case result of
178+ case D.fromByteString decoder bytes of
178 Left err ->
179 Left err ->
179 return $ Left (Exit.OutlineHasBadStructure err)
180 return $ Left (Exit.OutlineHasBadStructure err)
180
181
compiler/src/Json/Decode.hs−6
@@ -2,7 +2,6 @@
2{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings, UnboxedTuples #-}
2{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings, UnboxedTuples #-}
3module Json.Decode
3module Json.Decode
4 ( fromByteString
4 ( fromByteString
5− , fromFile
6 , Decoder
5 , Decoder
7 , string
6 , string
8 , bool
7 , bool
@@ -37,11 +36,6 @@ fromByteString decoder src =
37 fromAST decoder (P.fromByteString pFile src)
36 fromAST decoder (P.fromByteString pFile src)
38
37
39
38
40−fromFile :: Decoder e a -> FilePath -> IO (Either (E.Error e) a)
41−fromFile decoder path =
42− fromAST decoder <$> P.fromFile pFile path
43−
44−
45fromAST :: Decoder e a -> P.Result E.Context E.ParseExpectation AST -> Either (E.Error e) a
39fromAST :: Decoder e a -> P.Result E.Context E.ParseExpectation AST -> Either (E.Error e) a
46fromAST (Decoder decode) parserResult =
40fromAST (Decoder decode) parserResult =
47 case parserResult of
41 case parserResult of
compiler/src/Parse/Primitives.hs+1−8
@@ -3,7 +3,6 @@
3module Parse.Primitives
3module Parse.Primitives
4 ( Result(..)
4 ( Result(..)
5 , fromByteString
5 , fromByteString
6− , fromFile
7 , Parser(..)
6 , Parser(..)
8 , State(..)
7 , State(..)
9 , Context(..)
8 , Context(..)
@@ -26,7 +25,6 @@ import Foreign.Ptr (Ptr, plusPtr)
26import Foreign.Storable (peek)
25import Foreign.Storable (peek)
27import GHC.ForeignPtr (touchForeignPtr, unsafeForeignPtrToPtr)
26import GHC.ForeignPtr (touchForeignPtr, unsafeForeignPtrToPtr)
28
27
29−import qualified File.IO as IO
30import qualified Reporting.Annotation as A
28import qualified Reporting.Annotation as A
31
29
32
30
@@ -155,7 +153,7 @@ instance Monad (Parser c x) where
155
153
156
154
157data Result c x a
155data Result c x a
158− = Ok a (State c)
156+ = Ok !a (State c)
159 | Err Word16 Word16 (Context c) x
157 | Err Word16 Word16 (Context c) x
160
158
161
159
@@ -171,11 +169,6 @@ fromByteString (Parser parser) (B.PS fp offset length) =
171 return result
169 return result
172
170
173
171
174−fromFile :: Parser c x a -> FilePath -> IO (Result c x a)
175−fromFile parser path =
176− fromByteString parser <$> IO.readUtf8 path -- TODO try mmap
177−
178−
179
172
180-- POSITION
173-- POSITION
181
174