summaryrefslogtreecommitdiff
path: root/compiler/GHC.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-02-17 18:12:30 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-29 05:09:25 -0500
commit18757cab04c5c5c48eaceea19469d4811c5d0371 (patch)
tree5437de47247b8fe69f8b83db6a66524cabddee3f /compiler/GHC.hs
parentb5fb58fd1a4a24b9273d9d2de65b6347e1654e98 (diff)
downloadhaskell-18757cab04c5c5c48eaceea19469d4811c5d0371.tar.gz
Refactor runtime interpreter code
In #14335 we want to be able to use both the internal interpreter (for the plugins) and the external interpreter (for TH and GHCi) at the same time. This patch performs some preliminary refactoring: the `hsc_interp` field of HscEnv replaces `hsc_iserv` and is now used to indicate which interpreter (internal, external) to use to execute TH and GHCi. Opt_ExternalInterpreter flag and iserv options in DynFlags are now queried only when we set the session DynFlags. It should help making GHC multi-target in the future by selecting an interpreter according to the selected target.
Diffstat (limited to 'compiler/GHC.hs')
-rw-r--r--compiler/GHC.hs42
1 files changed, 40 insertions, 2 deletions
diff --git a/compiler/GHC.hs b/compiler/GHC.hs
index af0fb5885a..fb1ac703a2 100644
--- a/compiler/GHC.hs
+++ b/compiler/GHC.hs
@@ -299,11 +299,13 @@ import GHC.ByteCode.Types
import GHC.Runtime.Eval
import GHC.Runtime.Eval.Types
import GHC.Runtime.Interpreter
+import GHC.Runtime.Interpreter.Types
import GHCi.RemoteTypes
import GHC.Core.Ppr.TyThing ( pprFamInst )
import GHC.Driver.Main
import GHC.Driver.Make
+import GHC.Driver.Hooks
import GHC.Driver.Pipeline ( compileOne' )
import GHC.Driver.Monad
import TcRnMonad ( finalSafeMode, fixSafeInstances, initIfaceTcRn )
@@ -373,6 +375,8 @@ import System.Exit ( exitWith, ExitCode(..) )
import Exception
import Data.IORef
import System.FilePath
+import Control.Concurrent
+import Control.Applicative ((<|>))
import Maybes
import System.IO.Error ( isDoesNotExistError )
@@ -486,7 +490,7 @@ withCleanupSession ghc = ghc `gfinally` cleanup
liftIO $ do
cleanTempFiles dflags
cleanTempDirs dflags
- stopIServ hsc_env -- shut down the IServ
+ stopInterp hsc_env -- shut down the IServ
-- exceptions will be blocked while we clean the temporary files,
-- so there shouldn't be any difficulty if we receive further
-- signals.
@@ -594,8 +598,42 @@ setSessionDynFlags dflags = do
dflags' <- checkNewDynFlags dflags
dflags'' <- liftIO $ interpretPackageEnv dflags'
(dflags''', preload) <- liftIO $ initPackages dflags''
+
+ -- Interpreter
+ interp <- if gopt Opt_ExternalInterpreter dflags
+ then do
+ let
+ prog = pgm_i dflags ++ flavour
+ flavour
+ | WayProf `elem` ways dflags = "-prof"
+ | WayDyn `elem` ways dflags = "-dyn"
+ | otherwise = ""
+ msg = text "Starting " <> text prog
+ tr <- if verbosity dflags >= 3
+ then return (logInfo dflags (defaultDumpStyle dflags) msg)
+ else return (pure ())
+ let
+ conf = IServConfig
+ { iservConfProgram = prog
+ , iservConfOpts = getOpts dflags opt_i
+ , iservConfHook = createIservProcessHook (hooks dflags)
+ , iservConfTrace = tr
+ }
+ s <- liftIO $ newMVar (IServPending conf)
+ return (Just (ExternalInterp (IServ s)))
+ else
+#if defined(HAVE_INTERNAL_INTERPRETER)
+ return (Just InternalInterp)
+#else
+ return Nothing
+#endif
+
modifySession $ \h -> h{ hsc_dflags = dflags'''
- , hsc_IC = (hsc_IC h){ ic_dflags = dflags''' } }
+ , hsc_IC = (hsc_IC h){ ic_dflags = dflags''' }
+ , hsc_interp = hsc_interp h <|> interp
+ -- we only update the interpreter if there wasn't
+ -- already one set up
+ }
invalidateModSummaryCache
return preload