Skip to content

Commit

Permalink
upgrade to Ghc 9.8.1 (#2624)
Browse files Browse the repository at this point in the history
This PR updates the stackage LTS resolver to `nightly-2024-02-06` which
uses GHC 9.8.1

## Upgrade notes

You will need to update your HLS to
[2.6.0.0](https://github.com/haskell/haskell-language-server/releases/tag/2.6.0.0),
this release contains support for GHC 9.8.1

## Fixes

### `haskeline` / `repline`

We have removed the custom haskeline / repline forks used in the build.
This is because we had trouble overriding haskeline as it is bundled
with GHC and the stackage resolver uses this bundled version. We were
using a custom fork of haskeline to implement
[mapInputT_](https://github.com/anoma/juvix/blob/15c0685c911a7ce3d2ee8c1597a1e6dd96e707bf/app/Commands/Repl.hs#L409)
in the Juvix REPL, required to implement error handling. This requires
private API from the Haskeline library.

Instead of using a custom fork we use TemplateHaskell to obtain access
to the private API we need. See
[DarkArts.hs](https://github.com/anoma/juvix/blob/15c0685c911a7ce3d2ee8c1597a1e6dd96e707bf/src/Juvix/Prelude/DarkArts.hs)
and
[HaskelineJB.hs](https://github.com/anoma/juvix/blob/15c0685c911a7ce3d2ee8c1597a1e6dd96e707bf/app/HaskelineJH.hs).

To obtain access to the private API, we adapted a method from [a Tweag
blogpost](https://www.tweag.io/blog/2021-01-07-haskell-dark-arts-part-i/)
and [repo](https://github.com/tweag/th-jailbreak) - updating it for GHC
9.8.1.

### `aeson-better-errors`

The `aeson-better-errors` library has not been updated to work with
`mtl-2.3.0` so it cannot work with the new stackage resolver. We are
using a [fork](https://github.com/Vekhir/aeson-better-errors.git) which
has been updated.

We should consider replacing this library in future, see
#2621

###  `path`

The `path` library now includes API `splitDrive` and `dropDrive` so we
can remove our versions of those functions from the prelude.

### `with-utf8`

We no longer need to depend on `with-utf8`. We were using this package
for UTF-8 versions of `readFile` and `writeFile` APIs. These APIs are
now available in the `text` package.

### Compiler warnings

GHC 9.8.1 introduces several new compiler warnings. 

* We have suppressed `missing-role-annotations` and
`missing-poly-kind-signatures`
* We added our own versions of `head` and `tail` to work around the new
`partial-tx` warning introduced for those functions in `Data.List`.
* We fixed up the code to avoid the
[term-variable-capture](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-warnings.html#ghc-flag--Wterm-variable-capture)
warning.
  • Loading branch information
janmasrovira authored Feb 7, 2024
1 parent 795212b commit 13f64af
Show file tree
Hide file tree
Showing 24 changed files with 1,068 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG VARIANT="ubuntu-22.04"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
ENV DEBIAN_FRONTEND=noninteractive
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
ENV BOOTSTRAP_HASKELL_GHC_VERSION=9.4.5
ENV BOOTSTRAP_HASKELL_GHC_VERSION=9.8.1
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=3.10.1.0
ENV BOOTSTRAP_HASKELL_STACK_VERSION=2.11.1
ENV BOOTSTRAP_HASKELL_INSTALL_STACK=1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-static-binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build:
name: Build static binary
runs-on: ubuntu-latest
container: quay.io/benz0li/ghc-musl:9.4.5
container: quay.io/benz0li/ghc-musl:9.8.1
steps:
- name: checkout code
uses: actions/checkout@v3
Expand Down
9 changes: 3 additions & 6 deletions app/Commands/Extra/Package.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Commands.Extra.Package where

import Data.Text.IO.Utf8 qualified as Utf8
import Juvix.Compiler.Pipeline.Package.Base
import Juvix.Compiler.Pipeline.Package.Loader
import Juvix.Extra.Paths
Expand All @@ -11,11 +10,9 @@ renderPackage = renderPackageVersion currentPackageVersion

writePackageFile' :: (Member (Embed IO) r) => PackageVersion -> Path Abs Dir -> Package -> Sem r ()
writePackageFile' v root pkg =
embed
( Utf8.writeFile @IO
(toFilePath (root <//> packageFilePath))
(renderPackageVersion v pkg)
)
writeFileEnsureLn
(root <//> packageFilePath)
(renderPackageVersion v pkg)

writePackageFile :: (Member (Embed IO) r) => Path Abs Dir -> Package -> Sem r ()
writePackageFile = writePackageFile' currentPackageVersion
Expand Down
33 changes: 25 additions & 8 deletions app/Commands/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import Control.Monad.Except qualified as Except
import Control.Monad.Reader qualified as Reader
import Control.Monad.State.Strict qualified as State
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Reader (mapReaderT)
import Data.String.Interpolate (i, __i)
import Evaluator
import HaskelineJB
import Juvix.Compiler.Concrete.Data.Scope (scopePath)
import Juvix.Compiler.Concrete.Data.Scope qualified as Scoped
import Juvix.Compiler.Concrete.Data.ScopedName (absTopModulePath)
Expand Down Expand Up @@ -337,7 +339,7 @@ printDefinition = replParseIdentifiers >=> printIdentifiers
KNameFixity -> impossible
KNameAlias -> impossible
where
printLocation :: (HasLoc s) => s -> Repl ()
printLocation :: (HasLoc c) => c -> Repl ()
printLocation def = do
s' <- ppConcrete s
let txt :: Text = " is " <> prettyText (nameKindWithArticle (getNameKind s)) <> " defined at " <> prettyText (getLoc def)
Expand Down Expand Up @@ -404,12 +406,33 @@ replCommands opts = catchable ++ nonCatchable
("dev", dev)
]

mapInputT_ :: (m () -> m ()) -> InputT m () -> InputT m ()
mapInputT_ f =
mkInputT
. mapReaderT
( mapReaderT
( mapReaderT
(mapReaderT (mapReaderT f))
)
)
. unInputT

catchAll :: Repl () -> Repl ()
catchAll = Repline.dontCrash . catchJuvixError
where
catchJuvixError :: Repl () -> Repl ()
catchJuvixError (HaskelineT m) = HaskelineT (mapInputT_ catchErrorS m)
catchJuvixError = mkHaskelineT . mapInputT_ catchErrorS . unHaskelineT
where
printErrorS :: JuvixError -> ReplS ()
printErrorS e = do
opts <- State.gets (^. replStateGlobalOptions)
hasAnsi <- liftIO (Ansi.hSupportsANSIColor stderr)
liftIO
. hPutStrLn stderr
. run
. runReader (project' @GenericOptions opts)
$ Error.render (not (opts ^. globalNoColors) && hasAnsi) False e

catchErrorS :: ReplS () -> ReplS ()
catchErrorS = (`Except.catchError` printErrorS)

Expand Down Expand Up @@ -583,12 +606,6 @@ renderOut = render'
renderOutLn :: (P.HasAnsiBackend a, P.HasTextBackend a) => a -> Repl ()
renderOutLn t = renderOut t >> replNewline

printErrorS :: JuvixError -> ReplS ()
printErrorS e = do
opts <- State.gets (^. replStateGlobalOptions)
hasAnsi <- liftIO (Ansi.hSupportsANSIColor stderr)
liftIO $ hPutStrLn stderr $ run (runReader (project' @GenericOptions opts) (Error.render (not (opts ^. globalNoColors) && hasAnsi) False e))

runTransformations ::
forall r.
(Members '[State Artifacts, Error JuvixError, Reader EntryPoint] r) =>
Expand Down
40 changes: 40 additions & 0 deletions app/HaskelineJB.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module HaskelineJB where

import Control.Monad.Trans.Reader
import GHC.IORef
import Juvix.Prelude.DarkArts
import System.Console.Haskeline
import System.Console.Repline

type InputTArg m a =
ReaderT
RunTerm
( ReaderT
(IORef History)
( ReaderT
(IORef KillRing)
( ReaderT
Prefs
(ReaderT (Settings m) m)
)
)
)
a

type KillRing = $(importHiddenConT "haskeline" "System.Console.Haskeline.Command.KillRing" "KillRing")

type RunTerm = $(importHiddenConT "haskeline" "System.Console.Haskeline.Term" "RunTerm")

type History = $(importHiddenConT "haskeline" "System.Console.Haskeline.History" "History")

unInputT :: InputT m a -> InputTArg m a
unInputT = $(importHiddenField "InputT" "haskeline" "System.Console.Haskeline.InputT" "unInputT")

mkInputT :: InputTArg m a -> InputT m a
mkInputT = $(importHiddenCon "haskeline" "System.Console.Haskeline.InputT" "InputT")

unHaskelineT :: HaskelineT m a -> InputT m a
unHaskelineT = $(importHiddenField "HaskelineT" "repline" "System.Console.Repline" "unHaskeline")

mkHaskelineT :: InputT m a -> HaskelineT m a
mkHaskelineT = $(importHiddenCon "repline" "System.Console.Repline" "HaskelineT")
2 changes: 1 addition & 1 deletion app/TopCommand/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,4 @@ descr =
)
where
foot :: Doc
foot = bold "maintainers: " <> "The Juvix Team"
foot = annotate bold "maintainers: " <> "The Juvix Team"
11 changes: 3 additions & 8 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
-- Generated by stack2cabal

with-compiler: ghc-9.4.5
with-compiler: ghc-9.8.1

packages:
./

source-repository-package
type: git
location: https://github.com/janmasrovira/haskeline.git
tag: 81e393e156508a20fcc197acc945b0f44aa4f82b

source-repository-package
type: git
location: https://github.com/janmasrovira/repline.git
tag: a735ab1459db408adda080eb5ea21b96fb4a6011
location: https://github.com/Vekhir/aeson-better-errors.git
tag: 1ec49ab7d1472046b680b5a64ae2930515b47714

allow-older: *
allow-newer: *
Expand Down
Loading

0 comments on commit 13f64af

Please sign in to comment.