Skip to content

Commit

Permalink
Use readFile and writeFile from with-utf8
Browse files Browse the repository at this point in the history
The problem with readFile and writeFile from text Data.Text.IO is that
they use the system locale to determine the text encoding format.

Our assumption is that all Juvix source files are UTF-8 encoded.
  • Loading branch information
paulcadman committed Oct 25, 2023
1 parent ef1148b commit b0c5153
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/Commands/Dev/Asm/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runCommand opts = do
{ _entryPointTarget = tgt,
_entryPointDebug = opts ^. compileDebug
}
s <- embed (readFile (toFilePath file))
s <- readFile (toFilePath file)
case Asm.runParser (toFilePath file) s of
Left err -> exitJuvixError (JuvixError err)
Right tab -> do
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Asm/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Juvix.Compiler.Asm.Translation.FromSource qualified as Asm
runCommand :: forall r. (Members '[Embed IO, App] r) => AsmRunOptions -> Sem r ()
runCommand opts = do
afile :: Path Abs File <- fromAppPathFile file
s <- embed (readFile (toFilePath afile))
s <- readFile (toFilePath afile)
case Asm.runParser (toFilePath afile) s of
Left err -> exitJuvixError (JuvixError err)
Right tab -> runAsm (not (opts ^. asmRunNoValidate)) tab
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Asm/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Juvix.Compiler.Asm.Translation.FromSource qualified as Asm
runCommand :: forall r. (Members '[Embed IO, App] r) => AsmValidateOptions -> Sem r ()
runCommand opts = do
afile :: Path Abs File <- fromAppPathFile file
s <- embed (readFile (toFilePath afile))
s <- readFile (toFilePath afile)
case Asm.runParser (toFilePath afile) s of
Left err -> exitJuvixError (JuvixError err)
Right tab -> do
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Asm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runCommand :: forall r a. (Members '[Embed IO, App] r, CanonicalProjection a Cor
runCommand opts = do
gopts <- askGlobalOptions
inputFile :: Path Abs File <- fromAppPathFile sinputFile
s' <- embed (readFile $ toFilePath inputFile)
s' <- readFile $ toFilePath inputFile
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile Core.emptyInfoTable s'))
r <- runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.toStripped' tab
tab' <- Asm.fromCore . Stripped.fromCore <$> getRight r
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Juvix.Compiler.Core.Translation.FromSource qualified as Core
runCommand :: forall r. (Members '[Embed IO, App] r) => CompileOptions -> Sem r ()
runCommand opts = do
file <- getFile
s <- embed (readFile (toFilePath file))
s <- readFile (toFilePath file)
tab <- getRight (mapLeft JuvixError (Core.runParserMain file Core.emptyInfoTable s))
let arg = PipelineArg opts file tab
case opts ^. compileTarget of
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Juvix.Compiler.Core.Translation.FromSource qualified as Core
runCommand :: forall r. (Members '[Embed IO, App] r) => CoreEvalOptions -> Sem r ()
runCommand opts = do
f :: Path Abs File <- fromAppPathFile b
s <- embed (readFile (toFilePath f))
s <- readFile (toFilePath f)
case Core.runParser f Core.emptyInfoTable s of
Left err -> exitJuvixError (JuvixError err)
Right (tab, Just node) -> do evalAndPrint opts tab node
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Juvix.Compiler.Core.Translation.FromSource qualified as Core
runCommand :: forall r. (Members '[Embed IO, App] r) => CoreNormalizeOptions -> Sem r ()
runCommand opts = do
f :: Path Abs File <- fromAppPathFile b
s <- embed (readFile (toFilePath f))
s <- readFile (toFilePath f)
case Core.runParser f Core.emptyInfoTable s of
Left err -> exitJuvixError (JuvixError err)
Right (tab, Just node) -> do normalizeAndPrint opts tab node
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runCommand ::
runCommand opts = do
gopts <- askGlobalOptions
inputFile :: Path Abs File <- fromAppPathFile sinputFile
s' <- embed . readFile . toFilePath $ inputFile
s' <- readFile . toFilePath $ inputFile
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile Core.emptyInfoTable s'))
let r = run $ runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.applyTransformations (project opts ^. coreReadTransformations) tab
tab0 <- getRight $ mapLeft JuvixError r
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ runRepl opts tab = do
Right (tab', Nothing) ->
runRepl opts tab'
':' : 'l' : ' ' : f -> do
s' <- embed (readFile f)
s' <- readFile f
sf <- someBaseToAbs' (someFile f)
case Core.runParser sf Core.emptyInfoTable s' of
Left err -> do
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Core/Strip.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ runCommand :: forall r a. (Members '[Embed IO, App] r, CanonicalProjection a Cor
runCommand opts = do
gopts <- askGlobalOptions
inputFile :: Path Abs File <- fromAppPathFile sinputFile
s' <- embed (readFile $ toFilePath inputFile)
s' <- readFile $ toFilePath inputFile
(tab, _) <- getRight (mapLeft JuvixError (Core.runParser inputFile Core.emptyInfoTable s'))
let r =
run $
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Geb/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runCommand opts = do
let b :: AppPath File
b = opts ^. gebInferOptionsInputFile
f :: Path Abs File <- fromAppPathFile b
content :: Text <- embed (readFile (toFilePath f))
content :: Text <- readFile (toFilePath f)
case Geb.runParser f content of
Right (Geb.ExpressionMorphism morph) -> do
case Geb.inferObject' morph of
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Geb/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runCommand opts = do
let b :: AppPath File
b = project opts ^. gebEvalOptionsInputFile
f :: Path Abs File <- fromAppPathFile b
content :: Text <- embed (readFile (toFilePath f))
content :: Text <- readFile (toFilePath f)
case Geb.runParser f content of
Left err -> exitJuvixError (JuvixError err)
Right gebTerm -> do
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Geb/Infer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runCommand opts = do
let b :: AppPath File
b = opts ^. gebInferOptionsInputFile
f :: Path Abs File <- fromAppPathFile b
content :: Text <- embed (readFile (toFilePath f))
content :: Text <- readFile (toFilePath f)
case Geb.runParser f content of
Right (Geb.ExpressionMorphism gebTerm) ->
case Geb.inferObject' gebTerm of
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Geb/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runCommand opts = do
let b :: AppPath File
b = opts ^. gebReadOptionsInputFile
f :: Path Abs File <- fromAppPathFile b
content :: Text <- embed (readFile (toFilePath f))
content :: Text <- readFile (toFilePath f)
case Geb.runParser f content of
Left err -> exitJuvixError (JuvixError err)
Right gebTerm -> do
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dependencies:
- unordered-containers == 0.2.*
- utf8-string == 1.0.*
- versions == 6.0.*
- with-utf8 == 1.0.*
- xdg-basedir == 0.2.*
- yaml == 0.11.*

Expand Down
4 changes: 3 additions & 1 deletion src/Juvix/Prelude/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module Juvix.Prelude.Base
module Data.String,
module Data.Text.Encoding,
module Data.Text.IO,
module Data.Text.IO.Utf8,
module Data.Traversable,
module Data.Tuple.Extra,
module Data.Typeable,
Expand Down Expand Up @@ -144,7 +145,8 @@ import Data.String
import Data.Text (Text, pack, strip, unpack)
import Data.Text qualified as Text
import Data.Text.Encoding
import Data.Text.IO
import Data.Text.IO hiding (appendFile, readFile, writeFile)
import Data.Text.IO.Utf8
import Data.Traversable
import Data.Tuple.Extra hiding (both)
import Data.Type.Equality (type (~))
Expand Down

0 comments on commit b0c5153

Please sign in to comment.