Commit 6dad1002 authored by Vaibhav Sagar's avatar Vaibhav Sagar Committed by GitHub

Merge pull request #735 from gibiansky/ghc821-nix

Work with GHC 8.2
parents 8d6a6696 384a9840
...@@ -33,7 +33,7 @@ library ...@@ -33,7 +33,7 @@ library
-- other-modules: -- other-modules:
-- other-extensions: -- other-extensions:
build-depends: base >=4.6 && < 5, build-depends: base >=4.6 && < 5,
ghc >=7.6 && <8.1 ghc >=7.6 && <8.3
if impl(ghc >= 7.6) && impl(ghc < 7.8) if impl(ghc >= 7.6) && impl(ghc < 7.8)
hs-source-dirs: generic-src src-7.6 hs-source-dirs: generic-src src-7.6
......
...@@ -53,7 +53,7 @@ library ...@@ -53,7 +53,7 @@ library
-- other-modules: -- other-modules:
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base >=4.6 && <4.10, build-depends: base >=4.6 && <4.11,
here, here,
text, text,
bytestring, bytestring,
......
...@@ -54,7 +54,7 @@ library ...@@ -54,7 +54,7 @@ library
other-modules: IHaskell.Display.Diagrams.Animation other-modules: IHaskell.Display.Diagrams.Animation
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base >=4.6 && <4.10, build-depends: base >=4.6 && <4.11,
text, text,
bytestring, bytestring,
directory, directory,
......
...@@ -54,7 +54,7 @@ library ...@@ -54,7 +54,7 @@ library
-- other-modules: -- other-modules:
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base >=4.6 && <4.10, build-depends: base >=4.6 && <4.11,
bytestring, bytestring,
gnuplot >= 0.5.4, gnuplot >= 0.5.4,
ihaskell >= 0.6.2 ihaskell >= 0.6.2
......
...@@ -14,7 +14,7 @@ cabal-version: >=1.16 ...@@ -14,7 +14,7 @@ cabal-version: >=1.16
library library
exposed-modules: IHaskell.Display.Hatex exposed-modules: IHaskell.Display.Hatex
build-depends: base >=4.6 && <4.10, build-depends: base >=4.6 && <4.11,
text, text,
HaTeX >= 3.9, HaTeX >= 3.9,
ihaskell >= 0.5 ihaskell >= 0.5
......
...@@ -57,7 +57,7 @@ library ...@@ -57,7 +57,7 @@ library
-- other-modules: -- other-modules:
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base >=4.6 && <4.10, build-depends: base >=4.6 && <4.11,
magic >= 1.0.8, magic >= 1.0.8,
text, text,
bytestring, bytestring,
......
...@@ -92,7 +92,7 @@ library ...@@ -92,7 +92,7 @@ library
build-depends: bin-package-db build-depends: bin-package-db
if impl(ghc >= 8.0) if impl(ghc >= 8.0)
build-depends: ghc-boot >=8.0 && <8.1 build-depends: ghc-boot >=8.0 && <8.3
exposed-modules: IHaskell.Display exposed-modules: IHaskell.Display
IHaskell.Convert IHaskell.Convert
...@@ -134,7 +134,7 @@ executable ihaskell ...@@ -134,7 +134,7 @@ executable ihaskell
default-language: Haskell2010 default-language: Haskell2010
build-depends: build-depends:
ihaskell -any, ihaskell -any,
base >=4.6 && < 4.10, base >=4.6 && < 4.11,
text >=0.11, text >=0.11,
transformers -any, transformers -any,
ghc >=7.6 || < 7.11, ghc >=7.6 || < 7.11,
......
...@@ -29,7 +29,9 @@ import Data.Maybe (fromJust) ...@@ -29,7 +29,9 @@ import Data.Maybe (fromJust)
import System.Environment (getEnv) import System.Environment (getEnv)
import GHC hiding (Qualified) import GHC hiding (Qualified)
#if MIN_VERSION_ghc(7,10,0) #if MIN_VERSION_ghc(8,2,0)
import GHC.PackageDb
#elif MIN_VERSION_ghc(7,10,0)
import GHC.PackageDb (ExposedModule(exposedName)) import GHC.PackageDb (ExposedModule(exposedName))
#endif #endif
import DynFlags import DynFlags
...@@ -61,6 +63,9 @@ data CompletionType = Empty ...@@ -61,6 +63,9 @@ data CompletionType = Empty
| KernelOption String | KernelOption String
| Extension String | Extension String
deriving (Show, Eq) deriving (Show, Eq)
#if MIN_VERSION_ghc(8,2,0)
exposedName = fst
#endif
#if MIN_VERSION_ghc(7,10,0) #if MIN_VERSION_ghc(7,10,0)
extName (FlagSpec { flagSpecName = name }) = name extName (FlagSpec { flagSpecName = name }) = name
#else #else
......
...@@ -188,7 +188,13 @@ interpret libdir allowedStdin action = runGhc (Just libdir) $ do ...@@ -188,7 +188,13 @@ interpret libdir allowedStdin action = runGhc (Just libdir) $ do
packageIdString' :: DynFlags -> PackageConfig -> String packageIdString' :: DynFlags -> PackageConfig -> String
packageIdString' dflags pkg_cfg = packageIdString' dflags pkg_cfg =
#if MIN_VERSION_ghc(8,0,0) #if MIN_VERSION_ghc(8,2,0)
case (lookupPackage dflags $ packageConfigId pkg_cfg) of
Nothing -> "(unknown)"
Just cfg -> let
PackageName name = packageName cfg
in unpackFS name
#elif MIN_VERSION_ghc(8,0,0)
fromMaybe "(unknown)" (unitIdPackageIdString dflags $ packageConfigId pkg_cfg) fromMaybe "(unknown)" (unitIdPackageIdString dflags $ packageConfigId pkg_cfg)
#elif MIN_VERSION_ghc(7,10,2) #elif MIN_VERSION_ghc(7,10,2)
fromMaybe "(unknown)" (packageKeyPackageIdString dflags $ packageConfigId pkg_cfg) fromMaybe "(unknown)" (packageKeyPackageIdString dflags $ packageConfigId pkg_cfg)
...@@ -222,8 +228,13 @@ initializeImports = do ...@@ -222,8 +228,13 @@ initializeImports = do
initStr = "ihaskell-" initStr = "ihaskell-"
#if MIN_VERSION_ghc(8,2,0)
-- Name of the ihaskell package, i.e. "ihaskell"
iHaskellPkgName = "ihaskell"
#else
-- Name of the ihaskell package, e.g. "ihaskell-1.2.3.4" -- Name of the ihaskell package, e.g. "ihaskell-1.2.3.4"
iHaskellPkgName = initStr ++ intercalate "." (map show (versionBranch version)) iHaskellPkgName = initStr ++ intercalate "." (map show (versionBranch version))
#endif
#if !MIN_VERSION_ghc(8,0,0) #if !MIN_VERSION_ghc(8,0,0)
unitId = packageId unitId = packageId
...@@ -254,7 +265,11 @@ initializeImports = do ...@@ -254,7 +265,11 @@ initializeImports = do
dropFirstAndLast = reverse . drop 1 . reverse . drop 1 dropFirstAndLast = reverse . drop 1 . reverse . drop 1
toImportStmt :: String -> String toImportStmt :: String -> String
#if MIN_VERSION_ghc(8,2,0)
toImportStmt = printf importFmt . concatMap capitalize . drop 1 . split "-"
#else
toImportStmt = printf importFmt . concatMap capitalize . dropFirstAndLast . split "-" toImportStmt = printf importFmt . concatMap capitalize . dropFirstAndLast . split "-"
#endif
displayImports = map toImportStmt displayPkgs displayImports = map toImportStmt displayPkgs
...@@ -841,16 +856,28 @@ evalCommand output (Expression expr) state = do ...@@ -841,16 +856,28 @@ evalCommand output (Expression expr) state = do
-- is no appropriate typeclass instance, this will throw an exception and thus `attempt` will return -- is no appropriate typeclass instance, this will throw an exception and thus `attempt` will return
-- False, and we just resort to plaintext. -- False, and we just resort to plaintext.
let displayExpr = printf "(IHaskell.Display.display (%s))" expr :: String let displayExpr = printf "(IHaskell.Display.display (%s))" expr :: String
#if MIN_VERSION_ghc(8,2,0)
canRunDisplay <- attempt $ exprType TM_Inst displayExpr
#else
canRunDisplay <- attempt $ exprType displayExpr canRunDisplay <- attempt $ exprType displayExpr
#endif
-- Check if this is a widget. -- Check if this is a widget.
let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String
#if MIN_VERSION_ghc(8,2,0)
isWidget <- attempt $ exprType TM_Inst widgetExpr
#else
isWidget <- attempt $ exprType widgetExpr isWidget <- attempt $ exprType widgetExpr
#endif
-- Check if this is a template haskell declaration -- Check if this is a template haskell declaration
let declExpr = printf "((id :: IHaskellTH.DecsQ -> IHaskellTH.DecsQ) (%s))" expr :: String let declExpr = printf "((id :: IHaskellTH.DecsQ -> IHaskellTH.DecsQ) (%s))" expr :: String
let anyExpr = printf "((id :: IHaskellPrelude.Int -> IHaskellPrelude.Int) (%s))" expr :: String let anyExpr = printf "((id :: IHaskellPrelude.Int -> IHaskellPrelude.Int) (%s))" expr :: String
#if MIN_VERSION_ghc(8,2,0)
isTHDeclaration <- liftM2 (&&) (attempt $ exprType TM_Inst declExpr) (not <$> attempt (exprType TM_Inst anyExpr))
#else
isTHDeclaration <- liftM2 (&&) (attempt $ exprType declExpr) (not <$> attempt (exprType anyExpr)) isTHDeclaration <- liftM2 (&&) (attempt $ exprType declExpr) (not <$> attempt (exprType anyExpr))
#endif
write state $ "Can Display: " ++ show canRunDisplay write state $ "Can Display: " ++ show canRunDisplay
write state $ "Is Widget: " ++ show isWidget write state $ "Is Widget: " ++ show isWidget
...@@ -946,7 +973,11 @@ evalCommand output (Expression expr) state = do ...@@ -946,7 +973,11 @@ evalCommand output (Expression expr) state = do
then display :: Display then display :: Display
else removeSvg display else removeSvg display
#if MIN_VERSION_ghc(8,2,0)
isIO expr = attempt $ exprType TM_Inst $ printf "((\\x -> x) :: IO a -> IO a) (%s)" expr
#else
isIO expr = attempt $ exprType $ printf "((\\x -> x) :: IO a -> IO a) (%s)" expr isIO expr = attempt $ exprType $ printf "((\\x -> x) :: IO a -> IO a) (%s)" expr
#endif
postprocessShowError :: EvalOut -> EvalOut postprocessShowError :: EvalOut -> EvalOut
postprocessShowError evalOut = evalOut { evalResult = Display $ map postprocess disps } postprocessShowError evalOut = evalOut { evalResult = Display $ map postprocess disps }
...@@ -996,7 +1027,11 @@ evalCommand _ (Declaration decl) state = wrapExecution state $ do ...@@ -996,7 +1027,11 @@ evalCommand _ (Declaration decl) state = wrapExecution state $ do
-- Get all the type strings. -- Get all the type strings.
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
types <- forM nonDataNames $ \name -> do types <- forM nonDataNames $ \name -> do
#if MIN_VERSION_ghc(8,2,0)
theType <- showSDocUnqual dflags . ppr <$> exprType TM_Inst name
#else
theType <- showSDocUnqual dflags . ppr <$> exprType name theType <- showSDocUnqual dflags . ppr <$> exprType name
#endif
return $ name ++ " :: " ++ theType return $ name ++ " :: " ++ theType
return $ Display [html $ unlines $ map formatGetType types] return $ Display [html $ unlines $ map formatGetType types]
...@@ -1309,7 +1344,11 @@ evalStatementOrIO publish state cmd = do ...@@ -1309,7 +1344,11 @@ evalStatementOrIO publish state cmd = do
else do else do
-- Get all the type strings. -- Get all the type strings.
types <- forM nonItNames $ \name -> do types <- forM nonItNames $ \name -> do
#if MIN_VERSION_ghc(8,2,0)
theType <- showSDocUnqual dflags . ppr <$> exprType TM_Inst name
#else
theType <- showSDocUnqual dflags . ppr <$> exprType name theType <- showSDocUnqual dflags . ppr <$> exprType name
#endif
return $ name ++ " :: " ++ theType return $ name ++ " :: " ++ theType
let joined = unlines types let joined = unlines types
......
{-# LANGUAGE NoImplicitPrelude, OverloadedStrings #-} {-# LANGUAGE CPP, NoImplicitPrelude, OverloadedStrings #-}
{- | Description : Inspect type and function information and documentation. -} {- | Description : Inspect type and function information and documentation. -}
module IHaskell.Eval.Info (info) where module IHaskell.Eval.Info (info) where
...@@ -19,7 +19,11 @@ import Exception ...@@ -19,7 +19,11 @@ import Exception
info :: String -> Interpreter String info :: String -> Interpreter String
info name = ghandle handler $ do info name = ghandle handler $ do
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
#if MIN_VERSION_ghc(8,2,0)
result <- exprType TM_Inst name
#else
result <- exprType name result <- exprType name
#endif
return $ typeCleaner $ showPpr dflags result return $ typeCleaner $ showPpr dflags result
where where
handler :: SomeException -> Interpreter String handler :: SomeException -> Interpreter String
......
...@@ -224,7 +224,11 @@ doc :: GhcMonad m => O.SDoc -> m String ...@@ -224,7 +224,11 @@ 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)
let style = O.mkUserStyle flags unqual O.AllTheWay
#else
let style = O.mkUserStyle unqual O.AllTheWay let style = O.mkUserStyle unqual O.AllTheWay
#endif
let cols = pprCols flags let cols = pprCols flags
d = O.runSDoc sdoc (O.initSDocContext flags style) d = O.runSDoc sdoc (O.initSDocContext flags style)
return $ Pretty.fullRender Pretty.PageMode cols 1.5 string_txt "" d return $ Pretty.fullRender Pretty.PageMode cols 1.5 string_txt "" d
...@@ -256,6 +260,21 @@ initGhci sandboxPackages = do ...@@ -256,6 +260,21 @@ initGhci sandboxPackages = do
#else #else
dflags = flag Opt_ExtendedDefaultRules . unflag Opt_MonomorphismRestriction $ originalFlags dflags = flag Opt_ExtendedDefaultRules . unflag Opt_MonomorphismRestriction $ originalFlags
#endif #endif
#if MIN_VERSION_ghc(8,2,0)
pkgFlags =
case sandboxPackages of
Nothing -> packageDBFlags originalFlags
Just path ->
let pkg = PackageDB $ PkgConfFile path
in packageDBFlags originalFlags ++ [pkg]
void $ setSessionDynFlags $ dflags
{ hscTarget = HscInterpreted
, ghcLink = LinkInMemory
, pprCols = 300
, packageDBFlags = pkgFlags
}
#else
pkgConfs = pkgConfs =
case sandboxPackages of case sandboxPackages of
Nothing -> extraPkgConfs originalFlags Nothing -> extraPkgConfs originalFlags
...@@ -269,6 +288,7 @@ initGhci sandboxPackages = do ...@@ -269,6 +288,7 @@ initGhci sandboxPackages = do
, pprCols = 300 , pprCols = 300
, extraPkgConfs = pkgConfs , extraPkgConfs = pkgConfs
} }
#endif
-- | Evaluate a single import statement. If this import statement is importing a module which was -- | Evaluate a single import statement. If this import statement is importing a module which was
-- previously imported implicitly (such as `Prelude`) or if this module has a `hiding` annotation, -- previously imported implicitly (such as `Prelude`) or if this module has a `hiding` annotation,
...@@ -359,7 +379,11 @@ cleanUpDuplicateInstances = modifySession $ \hscEnv -> ...@@ -359,7 +379,11 @@ cleanUpDuplicateInstances = modifySession $ \hscEnv ->
-- | Get the type of an expression and convert it to a string. -- | Get the type of an expression and convert it to a string.
getType :: GhcMonad m => String -> m String getType :: GhcMonad m => String -> m String
getType expr = do getType expr = do
#if MIN_VERSION_ghc(8,2,0)
result <- exprType TM_Inst expr
#else
result <- exprType expr result <- exprType expr
#endif
flags <- getSessionDynFlags flags <- getSessionDynFlags
let typeStr = O.showSDocUnqual flags $ O.ppr result let typeStr = O.showSDocUnqual flags $ O.ppr result
return typeStr return typeStr
......
...@@ -159,6 +159,11 @@ testEval = ...@@ -159,6 +159,11 @@ testEval =
"putStrLn \"Привет!\"" `becomes` ["Привет!"] "putStrLn \"Привет!\"" `becomes` ["Привет!"]
it "evaluates directives" $ do it "evaluates directives" $ do
#if MIN_VERSION_ghc(8,2,0)
-- It's `p` instead of `t` for some reason
":typ 3" `becomes` ["3 :: forall p. Num p => p"]
#else
":typ 3" `becomes` ["3 :: forall t. Num t => t"] ":typ 3" `becomes` ["3 :: forall t. Num t => t"]
#endif
":k Maybe" `becomes` ["Maybe :: * -> *"] ":k Maybe" `becomes` ["Maybe :: * -> *"]
":in String" `pages` ["type String = [Char] \t-- Defined in \8216GHC.Base\8217"] ":in String" `pages` ["type String = [Char] \t-- Defined in \8216GHC.Base\8217"]
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