summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorMichael Sloan <mgsloan@gmail.com>2018-07-26 17:21:08 -0400
committerBen Gamari <ben@smart-cactus.org>2018-07-27 12:29:40 -0400
commit60ecf43a5a0b1cc732560058a06ca5b2f2e27773 (patch)
tree49a9e854a15d762373a65a24f1bbf5b8d1ea2ffd /ghc
parente5f3de2cf2f52e7079cbee624ae91beecf663f87 (diff)
downloadhaskell-60ecf43a5a0b1cc732560058a06ca5b2f2e27773.tar.gz
Modifications to support loading GHC into GHCi
This change was previously part of [D4904](https://phabricator.haskell.org/D4904), but is being split off to aid in getting this reviewed and merged. * The compiler code is built with `NoImplicitPrelude`, but GHCi's modules are incompatible with it. So, this adds the pragma to all GHCi modules that didn't have it, and adds imports of Prelude. * In order to run GHC within itself, a `call of 'initGCStatistics` needed to be skipped. This uses CPP to skip it when `-DGHC_LOADED_INTO_GHCI` is set. * There is an environment variable workaround suggested by Ben Gamari [1], where `_GHC_TOP_DIR` can be used to specify GHC's top dir if `-B` isn't provided. This can be used to solve a problem where the GHC being run within GHCi attempts to look in `inplace/lib/lib/` instead of `inplace/lib/`. [1]: https://phabricator.haskell.org/D4904#135438 Reviewers: goldfire, bgamari, erikd, alpmestan Reviewed By: alpmestan Subscribers: alpmestan, lelf, rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4986
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/Leak.hs1
-rw-r--r--ghc/GHCi/UI/Tags.hs5
-rw-r--r--ghc/Main.hs14
-rw-r--r--ghc/ghc-bin.cabal.in5
4 files changed, 23 insertions, 2 deletions
diff --git a/ghc/GHCi/Leak.hs b/ghc/GHCi/Leak.hs
index aec1ab544e..47fed9c28f 100644
--- a/ghc/GHCi/Leak.hs
+++ b/ghc/GHCi/Leak.hs
@@ -16,6 +16,7 @@ import GHC.Types (IO (..))
import HscTypes
import Outputable
import Platform (target32Bit)
+import Prelude
import System.Mem
import System.Mem.Weak
import UniqDFM
diff --git a/ghc/GHCi/UI/Tags.hs b/ghc/GHCi/UI/Tags.hs
index d8af7f8718..09a8406d96 100644
--- a/ghc/GHCi/UI/Tags.hs
+++ b/ghc/GHCi/UI/Tags.hs
@@ -25,13 +25,14 @@ import OccName (pprOccName)
import ConLike
import MonadUtils
+import Control.Monad
import Data.Function
+import Data.List
import Data.Maybe
import Data.Ord
import DriverPhases
import Panic
-import Data.List
-import Control.Monad
+import Prelude
import System.Directory
import System.IO
import System.IO.Error
diff --git a/ghc/Main.hs b/ghc/Main.hs
index 276546bc95..ea80910afb 100644
--- a/ghc/Main.hs
+++ b/ghc/Main.hs
@@ -74,6 +74,7 @@ import Control.Monad
import Data.Char
import Data.List
import Data.Maybe
+import Prelude
-----------------------------------------------------------------------------
-- ToDo:
@@ -929,5 +930,18 @@ people since we're linking GHC dynamically, but most things themselves
link statically.
-}
+-- If GHC_LOADED_INTO_GHCI is not set when GHC is loaded into GHCi, then
+-- running it causes an error like this:
+--
+-- Loading temp shared object failed:
+-- /tmp/ghc13836_0/libghc_1872.so: undefined symbol: initGCStatistics
+--
+-- Skipping the foreign call fixes this problem, and the outer GHCi
+-- should have already made this call anyway.
+#if defined(GHC_LOADED_INTO_GHCI)
+initGCStatistics :: IO ()
+initGCStatistics = return ()
+#else
foreign import ccall safe "initGCStatistics"
initGCStatistics :: IO ()
+#endif
diff --git a/ghc/ghc-bin.cabal.in b/ghc/ghc-bin.cabal.in
index 85a92501d2..5c51058d81 100644
--- a/ghc/ghc-bin.cabal.in
+++ b/ghc/ghc-bin.cabal.in
@@ -84,3 +84,8 @@ Executable ghc
CPP
NondecreasingIndentation
TupleSections
+
+ -- This should match the default-extensions used in 'ghc.cabal'. This way,
+ -- GHCi can be used to load it all at once.
+ Default-Extensions:
+ NoImplicitPrelude