From 9c6003ae8b9b1cb9352126e52cac93b9b9cd35b5 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Sat, 30 May 2020 03:32:20 +0200 Subject: [PATCH] Use haskeline-0.8 (#540) The `MonadException` class was removed in favor of `MonadCatch`, so we can remove its instances, enabling us to remove the library dependency on haskeline. To simplify dependency resolution with GHC < 8.10, this also disables the executable in that configuration. --- hnix.cabal | 7 +++++-- main/Repl.hs | 23 +++++++++-------------- src/Nix/Fresh.hs | 7 +------ src/Nix/Standard.hs | 19 +------------------ src/Nix/Utils/Fix1.hs | 1 + 5 files changed, 17 insertions(+), 40 deletions(-) diff --git a/hnix.cabal b/hnix.cabal index a468bb8..6f54cf9 100644 --- a/hnix.cabal +++ b/hnix.cabal @@ -910,7 +910,6 @@ library Nix.Options.Parser build-depends: base16-bytestring >= 0.1.1 && < 0.2 - , haskeline >= 0.7.4.2 && < 0.8 , pretty-show >= 1.9.5 && < 1.11 , serialise >= 0.2.1 && < 0.3 -- if !flag(profiling) @@ -938,7 +937,7 @@ executable hnix , exceptions , filepath , free - , haskeline + , haskeline >= 0.8.0.0 && < 0.9 , hnix , mtl , optparse-applicative @@ -954,6 +953,10 @@ executable hnix , unordered-containers if flag(optimize) ghc-options: -fexpose-all-unfoldings -fspecialise-aggressively -O2 + if impl(ghc < 8.10) + -- GHC < 8.10 comes with haskeline < 0.8, which we don't support. + -- To simplify CI, we just disable the component. + buildable: False if impl(ghcjs) buildable: False default-language: Haskell2010 diff --git a/main/Repl.hs b/main/Repl.hs index c1382d9..f898f36 100644 --- a/main/Repl.hs +++ b/main/Repl.hs @@ -52,19 +52,14 @@ import Control.Monad.Identity import Control.Monad.Reader import Control.Monad.State.Strict -import System.Console.Haskeline.MonadException -import System.Console.Repline hiding ( options ) +import System.Console.Repline hiding ( options, prefix ) import System.Environment import System.Exit -main :: (MonadNix e t f m, MonadIO m, MonadException m) => m () +main :: (MonadNix e t f m, MonadIO m, MonadMask m) => m () main = flip evalStateT initState -#if MIN_VERSION_repline(0, 2, 0) $ evalRepl (return prefix) cmd options (Just ':') completer welcomeText -#else - $ evalRepl prefix cmd options completer welcomeText -#endif where prefix = "hnix> " welcomeText = @@ -86,7 +81,7 @@ initState :: MonadIO m => IState t f m initState = IState M.empty type Repl e t f m = HaskelineT (StateT (IState t f m) m) -hoistErr :: MonadIO m => Result a -> Repl e t f m a +hoistErr :: (MonadIO m, MonadThrow m) => Result a -> Repl e t f m a hoistErr (Success val) = return val hoistErr (Failure err) = do liftIO $ print err @@ -98,7 +93,7 @@ hoistErr (Failure err) = do exec :: forall e t f m - . (MonadNix e t f m, MonadIO m, MonadException m) + . (MonadNix e t f m, MonadIO m) => Bool -> Text.Text -> Repl e t f m (NValue t f m) @@ -129,7 +124,7 @@ exec update source = do cmd - :: (MonadNix e t f m, MonadIO m, MonadException m) + :: (MonadNix e t f m, MonadIO m) => String -> Repl e t f m () cmd source = do @@ -153,7 +148,7 @@ browse _ = do -- :load command load - :: (MonadNix e t f m, MonadIO m, MonadException m) + :: (MonadNix e t f m, MonadIO m) => [String] -> Repl e t f m () load args = do @@ -162,7 +157,7 @@ load args = do -- :type command typeof - :: (MonadNix e t f m, MonadException m, MonadIO m) + :: (MonadNix e t f m, MonadIO m) => [String] -> Repl e t f m () typeof args = do @@ -199,7 +194,7 @@ comp n = do ) options - :: (MonadNix e t f m, MonadIO m, MonadException m) + :: (MonadNix e t f m, MonadIO m) => [(String, [String] -> Repl e t f m ())] options = [ ( "load" @@ -213,7 +208,7 @@ options = help :: forall e t f m - . (MonadNix e t f m, MonadIO m, MonadException m) + . (MonadNix e t f m, MonadIO m) => [String] -> Repl e t f m () help _ = liftIO $ do diff --git a/src/Nix/Fresh.hs b/src/Nix/Fresh.hs index e9bbed2..44654eb 100644 --- a/src/Nix/Fresh.hs +++ b/src/Nix/Fresh.hs @@ -21,9 +21,6 @@ import Control.Monad.Reader import Control.Monad.Ref import Control.Monad.ST import Data.Typeable -#ifdef MIN_VERSION_haskeline -import System.Console.Haskeline.MonadException hiding(catch) -#endif import Nix.Var import Nix.Thunk @@ -42,9 +39,7 @@ newtype FreshIdT i m a = FreshIdT { unFreshIdT :: ReaderT (Var m i) m a } , MonadIO , MonadCatch , MonadThrow -#ifdef MIN_VERSION_haskeline - , MonadException -#endif + , MonadMask ) instance MonadTrans (FreshIdT i) where diff --git a/src/Nix/Standard.hs b/src/Nix/Standard.hs index bc4efbe..624b23d 100644 --- a/src/Nix/Standard.hs +++ b/src/Nix/Standard.hs @@ -47,9 +47,6 @@ import Nix.Utils.Fix1 import Nix.Value import Nix.Value.Monad import Nix.Var -#ifdef MIN_VERSION_haskeline -import System.Console.Haskeline.MonadException hiding(catch) -#endif -- All of the following type classes defer to the underlying 'm'. @@ -69,21 +66,6 @@ deriving instance MonadInstantiate (t (Fix1T t m) m) => MonadInstantiate (Fix1T deriving instance MonadExec (t (Fix1T t m) m) => MonadExec (Fix1T t m) deriving instance MonadIntrospect (t (Fix1T t m) m) => MonadIntrospect (Fix1T t m) -#ifdef MIN_VERSION_haskeline --- For whatever reason, using the default StateT instance provided by --- haskeline does not work. -instance MonadException m - => MonadException(StateT(HashMap FilePath NExprLoc) m) where - controlIO f = StateT $ \s -> controlIO $ \(RunIO run) -> let - run' = RunIO(fmap(StateT . const) . run . flip runStateT s) - in fmap(flip runStateT s) $ f run' - -instance MonadException m => MonadException(Fix1T StandardTF m) where - controlIO f = mkStandardT $ controlIO $ \(RunIO run) -> - let run' = RunIO(fmap mkStandardT . run . runStandardT) - in runStandardT <$> f run' -#endif - type MonadFix1T t m = (MonadTrans (Fix1T t), Monad (t (Fix1T t m) m)) instance (MonadFix1T t m, MonadRef m) => MonadRef (Fix1T t m) where @@ -219,6 +201,7 @@ newtype StandardTF r m a , MonadIO , MonadCatch , MonadThrow + , MonadMask , MonadReader (Context r (StdValue r)) , MonadState (HashMap FilePath NExprLoc) ) diff --git a/src/Nix/Utils/Fix1.hs b/src/Nix/Utils/Fix1.hs index f8da4c8..8b593b9 100644 --- a/src/Nix/Utils/Fix1.hs +++ b/src/Nix/Utils/Fix1.hs @@ -48,6 +48,7 @@ deriving instance MonadFix (t (Fix1T t m) m) => MonadFix (Fix1T t m) deriving instance MonadIO (t (Fix1T t m) m) => MonadIO (Fix1T t m) deriving instance MonadCatch (t (Fix1T t m) m) => MonadCatch (Fix1T t m) deriving instance MonadThrow (t (Fix1T t m) m) => MonadThrow (Fix1T t m) +deriving instance MonadMask (t (Fix1T t m) m) => MonadMask (Fix1T t m) deriving instance MonadReader e (t (Fix1T t m) m) => MonadReader e (Fix1T t m) deriving instance MonadState s (t (Fix1T t m) m) => MonadState s (Fix1T t m)