Commit cd9688f0 authored by Vaibhav Sagar's avatar Vaibhav Sagar

ihaskell: update

parent 584127f8
...@@ -63,13 +63,13 @@ library ...@@ -63,13 +63,13 @@ library
cmdargs >=0.10, cmdargs >=0.10,
containers >=0.5, containers >=0.5,
directory -any, directory -any,
exceptions -any,
filepath -any, filepath -any,
ghc >=8.0, ghc >=8.0,
ghc-parser >=0.2.1, ghc-parser >=0.2.1,
ghc-paths >=0.1, ghc-paths >=0.1,
haskeline -any, haskeline -any,
hlint >=1.9, hlint >=1.9,
haskell-src-exts >=1.18,
http-client >= 0.4, http-client >= 0.4,
http-client-tls >= 0.2, http-client-tls >= 0.2,
mtl >=2.1, mtl >=2.1,
...@@ -88,7 +88,11 @@ library ...@@ -88,7 +88,11 @@ library
utf8-string -any, utf8-string -any,
vector -any, vector -any,
ipython-kernel >=0.10.2.0, ipython-kernel >=0.10.2.0,
ghc-boot >=8.0 && <8.11 ghc-boot >=8.0 && <9.1
if impl (ghc < 8.10)
build-depends:
haskell-src-exts >=1.18
exposed-modules: IHaskell.Display exposed-modules: IHaskell.Display
IHaskell.Convert IHaskell.Convert
...@@ -135,10 +139,10 @@ executable ihaskell ...@@ -135,10 +139,10 @@ executable ihaskell
default-language: Haskell2010 default-language: Haskell2010
build-depends: build-depends:
ihaskell -any, ihaskell -any,
base >=4.9 && < 4.15, base >=4.9 && < 4.16,
text >=0.11, text >=0.11,
transformers -any, transformers -any,
ghc >=8.0 && < 8.11, ghc >=8.0 && < 9.1,
process >=1.1, process >=1.1,
aeson >=0.7, aeson >=0.7,
bytestring >=0.10, bytestring >=0.10,
......
...@@ -22,10 +22,18 @@ import qualified Data.List.Split.Internals as Split ...@@ -22,10 +22,18 @@ import qualified Data.List.Split.Internals as Split
import System.Environment (getEnv) import System.Environment (getEnv)
import GHC import GHC
#if MIN_VERSION_ghc(9,0,0)
import GHC.Unit.Database
import GHC.Unit.State
import GHC.Driver.Session
import GHC.Driver.Monad as GhcMonad
import GHC.Utils.Outputable (showPpr)
#else
import GHC.PackageDb import GHC.PackageDb
import DynFlags import DynFlags
import GhcMonad import GhcMonad
import Outputable (showPpr) import Outputable (showPpr)
#endif
import System.Directory import System.Directory
import Control.Exception (try) import Control.Exception (try)
...@@ -74,9 +82,15 @@ complete code posOffset = do ...@@ -74,9 +82,15 @@ complete code posOffset = do
unqualNames = nub $ filter (not . isQualified) rdrNames unqualNames = nub $ filter (not . isQualified) rdrNames
qualNames = nub $ scopeNames ++ filter isQualified rdrNames qualNames = nub $ scopeNames ++ filter isQualified rdrNames
#if MIN_VERSION_ghc(9,0,0)
let Just db = unitDatabases flags
getNames = map (moduleNameString . exposedName) . unitExposedModules
moduleNames = nub $ concatMap getNames $ concatMap unitDatabaseUnits db
#else
let Just db = pkgDatabase flags let Just db = pkgDatabase flags
getNames = map (moduleNameString . exposedName) . exposedModules getNames = map (moduleNameString . exposedName) . exposedModules
moduleNames = nub $ concatMap getNames $ concatMap snd db moduleNames = nub $ concatMap getNames $ concatMap snd db
#endif
let target = completionTarget line pos let target = completionTarget line pos
completion = completionType line pos target completion = completionType line pos target
......
...@@ -28,7 +28,6 @@ import qualified Data.Set as Set ...@@ -28,7 +28,6 @@ import qualified Data.Set as Set
import Data.Char as Char import Data.Char as Char
import Data.Dynamic import Data.Dynamic
import qualified Data.Serialize as Serialize import qualified Data.Serialize as Serialize
import qualified Debugger
import System.Directory import System.Directory
import System.Posix.IO (fdToHandle) import System.Posix.IO (fdToHandle)
import System.IO (hGetChar, hSetEncoding, utf8) import System.IO (hGetChar, hSetEncoding, utf8)
...@@ -38,18 +37,33 @@ import System.Exit ...@@ -38,18 +37,33 @@ import System.Exit
import Data.Maybe (mapMaybe) import Data.Maybe (mapMaybe)
import System.Environment (getEnv) import System.Environment (getEnv)
import qualified GHC.Paths #if MIN_VERSION_ghc(9,0,0)
import InteractiveEval import qualified GHC.Runtime.Debugger as Debugger
import GHC.Runtime.Eval
import GHC.Driver.Session
import GHC.Driver.Types
import GHC.Unit.State
import Control.Monad.Catch as MC
import GHC.Utils.Outputable hiding ((<>))
import GHC.Data.Bag
import GHC.Unit.Types (UnitId)
import qualified GHC.Utils.Error as ErrUtils
#else
import qualified Debugger
import Bag
import DynFlags import DynFlags
import Exception (gtry)
import HscTypes import HscTypes
import GhcMonad (liftIO) import InteractiveEval
import GHC hiding (Stmt, TypeSig) import Exception (gtry)
import Exception hiding (evaluate) import Exception hiding (evaluate)
import GhcMonad (liftIO)
import Outputable hiding ((<>)) import Outputable hiding ((<>))
import Packages import Packages
import Bag
import qualified ErrUtils import qualified ErrUtils
#endif
import qualified GHC.Paths
import GHC hiding (Stmt, TypeSig)
import IHaskell.Types import IHaskell.Types
import IHaskell.IPython import IHaskell.IPython
...@@ -61,13 +75,31 @@ import IHaskell.Eval.Util ...@@ -61,13 +75,31 @@ import IHaskell.Eval.Util
import IHaskell.BrokenPackages import IHaskell.BrokenPackages
import StringUtils (replace, split, strip, rstrip) import StringUtils (replace, split, strip, rstrip)
#if MIN_VERSION_ghc(8,2,0) #if MIN_VERSION_ghc(9,0,0)
import GHC.Data.FastString
#elif MIN_VERSION_ghc(8,2,0)
import FastString (unpackFS) import FastString (unpackFS)
#else #else
import Paths_ihaskell (version) import Paths_ihaskell (version)
import Data.Version (versionBranch) import Data.Version (versionBranch)
#endif #endif
#if MIN_VERSION_ghc(9,0,0)
gcatch :: Ghc a -> (SomeException -> Ghc a) -> Ghc a
gcatch = MC.catch
gtry :: IO a -> IO (Either SomeException a)
gtry = MC.try
gfinally :: Ghc a -> Ghc b -> Ghc a
gfinally = MC.finally
ghandle :: (MonadCatch m, Exception e) => (e -> m a) -> m a -> m a
ghandle = MC.handle
throw :: SomeException -> Ghc a
throw = MC.throwM
#endif
-- | Set GHC's verbosity for debugging -- | Set GHC's verbosity for debugging
...@@ -157,9 +189,19 @@ interpret libdir allowedStdin needsSupportLibraries action = runGhc (Just libdir ...@@ -157,9 +189,19 @@ interpret libdir allowedStdin needsSupportLibraries action = runGhc (Just libdir
-- Run the rest of the interpreter -- Run the rest of the interpreter
action hasSupportLibraries action hasSupportLibraries
#if MIN_VERSION_ghc(9,0,0)
packageIdString' :: DynFlags -> UnitInfo -> String
#else
packageIdString' :: DynFlags -> PackageConfig -> String packageIdString' :: DynFlags -> PackageConfig -> String
#endif
packageIdString' dflags pkg_cfg = packageIdString' dflags pkg_cfg =
#if MIN_VERSION_ghc(8,2,0) #if MIN_VERSION_ghc(9,0,0)
case (lookupUnit (unitState dflags) $ mkUnit pkg_cfg) of
Nothing -> "(unknown)"
Just cfg -> let
PackageName name = unitPackageName cfg
in unpackFS name
#elif MIN_VERSION_ghc(8,2,0)
case (lookupPackage dflags $ packageConfigId pkg_cfg) of case (lookupPackage dflags $ packageConfigId pkg_cfg) of
Nothing -> "(unknown)" Nothing -> "(unknown)"
Just cfg -> let Just cfg -> let
...@@ -169,11 +211,19 @@ packageIdString' dflags pkg_cfg = ...@@ -169,11 +211,19 @@ packageIdString' dflags pkg_cfg =
fromMaybe "(unknown)" (unitIdPackageIdString dflags $ packageConfigId pkg_cfg) fromMaybe "(unknown)" (unitIdPackageIdString dflags $ packageConfigId pkg_cfg)
#endif #endif
#if MIN_VERSION_ghc(9,0,0)
getPackageConfigs :: DynFlags -> [GenUnitInfo UnitId]
getPackageConfigs dflags =
foldMap unitDatabaseUnits pkgDb
where
Just pkgDb = unitDatabases dflags
#else
getPackageConfigs :: DynFlags -> [PackageConfig] getPackageConfigs :: DynFlags -> [PackageConfig]
getPackageConfigs dflags = getPackageConfigs dflags =
foldMap snd pkgDb foldMap snd pkgDb
where where
Just pkgDb = pkgDatabase dflags Just pkgDb = pkgDatabase dflags
#endif
-- | Initialize our GHC session with imports and a value for 'it'. Return whether the IHaskell -- | Initialize our GHC session with imports and a value for 'it'. Return whether the IHaskell
-- library is available. -- library is available.
...@@ -183,7 +233,11 @@ initializeImports importSupportLibraries = do ...@@ -183,7 +233,11 @@ initializeImports importSupportLibraries = do
-- version of the ihaskell library. Also verify that the packages we load are not broken. -- version of the ihaskell library. Also verify that the packages we load are not broken.
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
broken <- liftIO getBrokenPackages broken <- liftIO getBrokenPackages
#if MIN_VERSION_ghc(9,0,0)
dflgs <- liftIO $ initUnits dflags
#else
(dflgs, _) <- liftIO $ initPackages dflags (dflgs, _) <- liftIO $ initPackages dflags
#endif
let db = getPackageConfigs dflgs let db = getPackageConfigs dflgs
packageNames = map (packageIdString' dflgs) db packageNames = map (packageIdString' dflgs) db
hiddenPackages = Set.intersection hiddenPackageNames (Set.fromList packageNames) hiddenPackages = Set.intersection hiddenPackageNames (Set.fromList packageNames)
...@@ -786,7 +840,11 @@ evalCommand _ (Directive GetDoc query) state = safely state $ do ...@@ -786,7 +840,11 @@ evalCommand _ (Directive GetDoc query) state = safely state $ do
evalCommand _ (Directive SPrint binding) state = wrapExecution state $ do evalCommand _ (Directive SPrint binding) state = wrapExecution state $ do
flags <- getSessionDynFlags flags <- getSessionDynFlags
contents <- liftIO $ newIORef [] contents <- liftIO $ newIORef []
#if MIN_VERSION_ghc(9,0,0)
let action = \_dflags _warn _sev _srcspan msg -> modifyIORef' contents (showSDoc flags msg :)
#else
let action = \_dflags _sev _srcspan _ppr _style msg -> modifyIORef' contents (showSDoc flags msg :) let action = \_dflags _sev _srcspan _ppr _style msg -> modifyIORef' contents (showSDoc flags msg :)
#endif
let flags' = flags { log_action = action } let flags' = flags { log_action = action }
_ <- setSessionDynFlags flags' _ <- setSessionDynFlags flags'
Debugger.pprintClosureCommand False False binding Debugger.pprintClosureCommand False False binding
...@@ -1028,7 +1086,11 @@ doLoadModule name modName = do ...@@ -1028,7 +1086,11 @@ doLoadModule name modName = do
_ <- setSessionDynFlags $ flip gopt_set Opt_BuildDynamicToo _ <- setSessionDynFlags $ flip gopt_set Opt_BuildDynamicToo
flags flags
{ hscTarget = objTarget flags { hscTarget = objTarget flags
#if MIN_VERSION_ghc(9,0,0)
, log_action = \_dflags _warn _sev _srcspan msg -> modifyIORef' errRef (showSDoc flags msg :)
#else
, log_action = \_dflags _sev _srcspan _ppr _style msg -> modifyIORef' errRef (showSDoc flags msg :) , log_action = \_dflags _sev _srcspan _ppr _style msg -> modifyIORef' errRef (showSDoc flags msg :)
#endif
} }
-- Load the new target. -- Load the new target.
......
...@@ -8,11 +8,20 @@ import IHaskellPrelude ...@@ -8,11 +8,20 @@ import IHaskellPrelude
import IHaskell.Eval.Evaluate (typeCleaner, Interpreter) import IHaskell.Eval.Evaluate (typeCleaner, Interpreter)
import GHC import GHC
#if MIN_VERSION_ghc(9,0,0)
import GHC.Utils.Outputable
import Control.Monad.Catch (handle)
#else
import Outputable import Outputable
import Exception import Exception
#endif
info :: String -> Interpreter String info :: String -> Interpreter String
#if MIN_VERSION_ghc(9,0,0)
info name = handle handler $ do
#else
info name = ghandle handler $ do info name = ghandle handler $ do
#endif
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
#if MIN_VERSION_ghc(8,2,0) #if MIN_VERSION_ghc(8,2,0)
result <- exprType TM_Inst name result <- exprType TM_Inst name
......
...@@ -12,7 +12,11 @@ import qualified Prelude as P ...@@ -12,7 +12,11 @@ import qualified Prelude as P
import Data.List.Split (splitOn) import Data.List.Split (splitOn)
#if MIN_VERSION_ghc(9,0,0)
import qualified Control.Monad.Catch as MC
#else
import Exception (ghandle) import Exception (ghandle)
#endif
import IHaskell.Eval.Evaluate (Interpreter) import IHaskell.Eval.Evaluate (Interpreter)
import IHaskell.Display import IHaskell.Display
...@@ -44,7 +48,11 @@ inspect code pos = do ...@@ -44,7 +48,11 @@ inspect code pos = do
let identifier = getIdentifier code pos let identifier = getIdentifier code pos
handler :: SomeException -> Interpreter (Maybe a) handler :: SomeException -> Interpreter (Maybe a)
handler _ = return Nothing handler _ = return Nothing
#if MIN_VERSION_ghc(9,0,0)
response <- MC.handle handler (Just <$> getType identifier)
#else
response <- ghandle handler (Just <$> getType identifier) response <- ghandle handler (Just <$> getType identifier)
#endif
let prefix = identifier ++ " :: " let prefix = identifier ++ " :: "
fmt str = Display [plain $ prefix ++ str] fmt str = Display [plain $ prefix ++ str]
return $ fmt <$> response return $ fmt <$> response
...@@ -33,12 +33,21 @@ import qualified Data.ByteString.Char8 as CBS ...@@ -33,12 +33,21 @@ import qualified Data.ByteString.Char8 as CBS
#endif #endif
-- GHC imports. -- GHC imports.
import DynFlags #if MIN_VERSION_ghc(9,0,0)
#if MIN_VERSION_ghc(8,6,0) import GHC.Core.InstEnv (is_cls, is_tys)
import GHC.Core.Unify
import GHC.Core.Ppr.TyThing
import GHC.Driver.CmdLine
import GHC.Driver.Monad (modifySession)
import GHC.Driver.Session
import GHC.Driver.Types
import GHC.Types.Name (pprInfixName)
import GHC.Types.Name.Set
import qualified GHC.Driver.Session as DynFlags
import qualified GHC.Utils.Outputable as O
import qualified GHC.Utils.Ppr as Pretty
#else #else
import FastString import DynFlags
#endif
import GHC
import GhcMonad import GhcMonad
import HscTypes import HscTypes
import NameSet import NameSet
...@@ -48,6 +57,12 @@ import InstEnv (ClsInst(..)) ...@@ -48,6 +57,12 @@ import InstEnv (ClsInst(..))
import Unify (tcMatchTys) import Unify (tcMatchTys)
import qualified Pretty import qualified Pretty
import qualified Outputable as O import qualified Outputable as O
#endif
#if MIN_VERSION_ghc(8,6,0)
#else
import FastString
#endif
import GHC
import Control.Monad (void) import Control.Monad (void)
import Data.Function (on) import Data.Function (on)
...@@ -55,7 +70,8 @@ import Data.List (nubBy) ...@@ -55,7 +70,8 @@ import Data.List (nubBy)
import StringUtils (replace) import StringUtils (replace)
#if MIN_VERSION_ghc(8,4,0) #if MIN_VERSION_ghc(9,0,0)
#elif MIN_VERSION_ghc(8,4,0)
import CmdLineParser (warnMsg) import CmdLineParser (warnMsg)
#endif #endif
...@@ -228,7 +244,9 @@ doc :: GhcMonad m => O.SDoc -> m String ...@@ -228,7 +244,9 @@ doc :: GhcMonad m => O.SDoc -> m String
doc sdoc = do doc sdoc = do
flags <- getSessionDynFlags flags <- getSessionDynFlags
unqual <- getPrintUnqual unqual <- getPrintUnqual
#if MIN_VERSION_ghc(8,2,0) #if MIN_VERSION_ghc(9,0,0)
let style = O.mkUserStyle unqual O.AllTheWay
#elif MIN_VERSION_ghc(8,2,0)
let style = O.mkUserStyle flags unqual O.AllTheWay let style = O.mkUserStyle flags unqual O.AllTheWay
#else #else
let style = O.mkUserStyle unqual O.AllTheWay let style = O.mkUserStyle unqual O.AllTheWay
...@@ -270,7 +288,11 @@ initGhci sandboxPackages = do ...@@ -270,7 +288,11 @@ initGhci sandboxPackages = do
case sandboxPackages of case sandboxPackages of
Nothing -> packageDBFlags originalFlags Nothing -> packageDBFlags originalFlags
Just path -> Just path ->
#if MIN_VERSION_ghc(9,0,0)
let pkg = PackageDB $ PkgDbPath path
#else
let pkg = PackageDB $ PkgConfFile path let pkg = PackageDB $ PkgConfFile path
#endif
in packageDBFlags originalFlags ++ [pkg] in packageDBFlags originalFlags ++ [pkg]
void $ setSessionDynFlags $ dflags void $ setSessionDynFlags $ dflags
......
...@@ -161,7 +161,10 @@ testEval = ...@@ -161,7 +161,10 @@ testEval =
":! printf \"hello\\nworld\"" `becomes` ["hello\nworld"] ":! printf \"hello\\nworld\"" `becomes` ["hello\nworld"]
it "evaluates directives" $ do it "evaluates directives" $ do
#if MIN_VERSION_ghc(8,2,0) #if MIN_VERSION_ghc(9,0,0)
-- brackets around the type variable
":typ 3" `becomes` ["3 :: forall {p}. Num p => p"]
#elif MIN_VERSION_ghc(8,2,0)
-- It's `p` instead of `t` for some reason -- It's `p` instead of `t` for some reason
":typ 3" `becomes` ["3 :: forall p. Num p => p"] ":typ 3" `becomes` ["3 :: forall p. Num p => p"]
#else #else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment