1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-19 21:01:48 +03:00
juvix/app/Commands/Dev/Geb/Infer.hs
Paul Cadman 32449e1212
Use system locale independent readFile and writeFile APIs from with-utf8 (#2473)
The problem with readFile and writeFile from text
[Data.Text.IO](https://hackage.haskell.org/package/text-2.0.2/docs/Data-Text-IO.html)
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.

I cannot reproduce the issue with using the old APIs on my machine, it
can be reproduced on Arch linux. I'm not sure how to write a specific
test for this.

* Closes https://github.com/anoma/juvix/issues/2472
2023-10-26 09:13:33 +01:00

34 lines
1.1 KiB
Haskell

module Commands.Dev.Geb.Infer where
import Commands.Base
import Commands.Dev.Geb.Infer.Options
import Juvix.Compiler.Backend.Geb qualified as Geb
runCommand ::
forall r.
(Member App r, Member (Embed IO) r) =>
GebInferOptions ->
Sem r ()
runCommand opts = do
let b :: AppPath File
b = opts ^. gebInferOptionsInputFile
f :: Path Abs File <- fromAppPathFile b
content :: Text <- readFile (toFilePath f)
case Geb.runParser f content of
Right (Geb.ExpressionMorphism gebTerm) ->
case Geb.inferObject' gebTerm of
Left err -> exitJuvixError (JuvixError err)
Right obj -> renderStdOut (Geb.ppOut opts obj)
Right (Geb.ExpressionTypedMorphism tyMorph) -> do
case run . runError @Geb.CheckingError $ Geb.check' tyMorph of
Left err -> exitJuvixError (JuvixError err)
Right _ -> do
renderStdOut $
Geb.ppOut
opts
(tyMorph ^. Geb.typedMorphismObject)
embed $ putStrLn ""
Right (Geb.ExpressionObject _) ->
exitJuvixError (error @JuvixError "No inference for objects")
Left err -> exitJuvixError (JuvixError err)