on master help sign in
Get rid of Parse.fromFile / make file read responsibility of caller
commit7be64c0c1685b3d276378a7f6589efa108ee3c75 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 16 Apr 2019, 14:56 (8 years ago) parent2421dd6
5 files changed+12−24
builder/src/Build.hs+6−6 builder/src/Deps/Diff.hs+2−2 builder/src/Elm/Outline.hs+3−2 compiler/src/Json/Decode.hs−6 compiler/src/Parse/Primitives.hs+1−8
builder/src/Build.hs+6−6
@@ -258,9 +258,9 @@ crawlModule env@(Env _ root pkg srcDirs locals foreigns) mvar name =
258258crawlFile :: Env -> MVar StatusDict -> ModuleName.Raw -> FilePath -> IO Status
259259crawlFile env@(Env _ root pkg _ _ _) mvar expectedName path =
260260 do time <- File.getTime path
261− result <- Parse.fromFile pkg (root </> path)
261+ bytes <- File.readUtf8 (root </> path)
262262
263− case result of
263+ case Parse.fromByteString pkg bytes of
264264 Right modul@(Src.Module maybeActualName _ imports values _ _ _ _) ->
265265 case maybeActualName of
266266 Just actualName ->
@@ -317,8 +317,8 @@ checkModule env@(Env _ root pkg _ _ _) foreigns resultsMVar name status =
317317 depsStatus <- checkDeps root results deps
318318 case depsStatus of
319319 DepsChange ifaces ->
320− do result <- Parse.fromFile pkg path
321− case result of
320+ do bytes <- File.readUtf8 path
321+ case Parse.fromByteString pkg bytes of
322322 Right modul -> compile env local ifaces modul
323323 Left syntaxError ->
324324 return $ RProblem $ Problem.BadSyntax $
@@ -811,8 +811,8 @@ crawlMain env@(Env _ _ pkg _ _ _) mvar given =
811811
812812 LOutside path ->
813813 do time <- File.getTime path
814− result <- Parse.fromFile pkg path
815− case result of
814+ bytes <- File.readUtf8 path
815+ case Parse.fromByteString pkg bytes of
816816 Right modul@(Src.Module _ _ imports values _ _ _ _) ->
817817 do let deps = map Src.getImportName imports
818818 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 =
361361 exists <- File.exists path
362362 if exists
363363 then
364− do result <- D.fromFile Docs.decoder path
365− case result of
364+ do bytes <- File.readUtf8 path
365+ case D.fromByteString Docs.decoder bytes of
366366 Right docs ->
367367 return $ Right docs
368368
builder/src/Elm/Outline.hs+3−2
@@ -29,6 +29,7 @@ import qualified Elm.Licenses as Licenses
2929import qualified Elm.ModuleName as ModuleName
3030import qualified Elm.Package as Pkg
3131import qualified Elm.Version as V
32+import qualified File
3233import qualified Json.Decode as D
3334import qualified Json.Encode as E
3435import qualified Reporting.Exit as Exit
@@ -173,8 +174,8 @@ encodeDeps encodeValue deps =
173174
174175read :: FilePath -> IO (Either Exit.Outline Outline)
175176read root =
176− do result <- D.fromFile decoder (root </> "elm.json")
177− case result of
177+ do bytes <- File.readUtf8 (root </> "elm.json")
178+ case D.fromByteString decoder bytes of
178179 Left err ->
179180 return $ Left (Exit.OutlineHasBadStructure err)
180181
compiler/src/Json/Decode.hs−6
@@ -2,7 +2,6 @@
22{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings, UnboxedTuples #-}
33module Json.Decode
44 ( fromByteString
5− , fromFile
65 , Decoder
76 , string
87 , bool
@@ -37,11 +36,6 @@ fromByteString decoder src =
3736 fromAST decoder (P.fromByteString pFile src)
3837
3938
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−
4539fromAST :: Decoder e a -> P.Result E.Context E.ParseExpectation AST -> Either (E.Error e) a
4640fromAST (Decoder decode) parserResult =
4741 case parserResult of
compiler/src/Parse/Primitives.hs+1−8
@@ -3,7 +3,6 @@
33module Parse.Primitives
44 ( Result(..)
55 , fromByteString
6− , fromFile
76 , Parser(..)
87 , State(..)
98 , Context(..)
@@ -26,7 +25,6 @@ import Foreign.Ptr (Ptr, plusPtr)
2625import Foreign.Storable (peek)
2726import GHC.ForeignPtr (touchForeignPtr, unsafeForeignPtrToPtr)
2827
29−import qualified File.IO as IO
3028import qualified Reporting.Annotation as A
3129
3230
@@ -155,7 +153,7 @@ instance Monad (Parser c x) where
155153
156154
157155data Result c x a
158− = Ok a (State c)
156+ = Ok !a (State c)
159157 | Err Word16 Word16 (Context c) x
160158
161159
@@ -171,11 +169,6 @@ fromByteString (Parser parser) (B.PS fp offset length) =
171169 return result
172170
173171
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−
179172
180173-- POSITION
181174