Sven Tennie pushed to branch wip/supersven/interpreter-flags at Glasgow Haskell Compiler / GHC Commits: 9efefc8c by Sven Tennie at 2026-04-26T13:11:24+02:00 ghc: Distinguish between having an interpreter and having an internal one Actually, these are related but different things: - ghc can run an interpreter (either internal or external) - ghc is compiled with an internal interpreter Splitting the logic solves compiler warnings and expresses the intent better. - - - - - 6 changed files: - + changelog.d/T19174.md - ghc/GHC/Driver/Session/Mode.hs - ghc/GHCi/UI.hs - ghc/Main.hs - ghc/ghc-bin.cabal.in - hadrian/src/Settings/Packages.hs Changes: ===================================== changelog.d/T19174.md ===================================== @@ -0,0 +1,17 @@ +section: compiler +issues: #19174 +mrs: !15714 +synopsis: + Introduce HAVE_INTERPRETER flag separate from HAVE_INTERNAL_INTERPRETER +description: + GHC now distinguishes between having any interpreter support (internal or + external) via the `HAVE_INTERPRETER` CPP flag, and having specifically + an internal interpreter via `HAVE_INTERNAL_INTERPRETER`. The `ghc-bin` + package now has separate `interpreter` and `internal-interpreter` cabal + flags. Interactive mode and GHCi UI features now check `HAVE_INTERPRETER` + instead of `HAVE_INTERNAL_INTERPRETER`, while internal interpreter-specific + code (like the directory change handler in GHCi) remains guarded by + `HAVE_INTERNAL_INTERPRETER`. In cross-compilation builds, the + `internal-interpreter` flag is disabled while the `interpreter` flag can + still be enabled for external interpreter support. + This does not change current behaviour, but prevents compiler warnings. ===================================== ghc/GHC/Driver/Session/Mode.hs ===================================== @@ -132,7 +132,7 @@ isDoEvalMode :: Mode -> Bool isDoEvalMode (Right (Right (DoEval _))) = True isDoEvalMode _ = False -#if defined(HAVE_INTERNAL_INTERPRETER) +#if defined(HAVE_INTERPRETER) isInteractiveMode :: PostLoadMode -> Bool isInteractiveMode DoInteractive = True isInteractiveMode _ = False ===================================== ghc/GHCi/UI.hs ===================================== @@ -1909,7 +1909,9 @@ changeDirectory dir = do fhv <- compileGHCiExpr $ "System.Directory.setCurrentDirectory " ++ show dir' liftIO $ evalIO interp fhv +#if defined(HAVE_INTERNAL_INTERPRETER) _ -> pure () +#endif trySuccess :: GhciMonad m => m SuccessFlag -> m SuccessFlag trySuccess act = ===================================== ghc/Main.hs ===================================== @@ -36,7 +36,7 @@ import GHC.Driver.Config.Diagnostic import GHC.Platform import GHC.Platform.Host -#if defined(HAVE_INTERNAL_INTERPRETER) +#if defined(HAVE_INTERPRETER) import GHCi.UI ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings, languageEditionMsg ) #endif @@ -288,7 +288,7 @@ doRun units srcs args = do args' = drop 1 $ dropWhile (/= "--") $ map unLoc args ghciUI :: [String] -> [(FilePath, Maybe Phase)] -> Maybe [String] -> Ghc () -#if !defined(HAVE_INTERNAL_INTERPRETER) +#if !defined(HAVE_INTERPRETER) ghciUI _ _ _ = throwGhcException (CmdLineError "not built for interactive use") #else @@ -332,7 +332,7 @@ showBanner :: PostLoadMode -> DynFlags -> IO () showBanner _postLoadMode dflags = do let verb = verbosity dflags -#if defined(HAVE_INTERNAL_INTERPRETER) +#if defined(HAVE_INTERPRETER) -- Show the GHCi banner when (isInteractiveMode _postLoadMode && verb >= 1) $ do putStrLn ghciWelcomeMsg ===================================== ghc/ghc-bin.cabal.in ===================================== @@ -22,6 +22,11 @@ Flag internal-interpreter Default: False Manual: True +Flag interpreter + Description: Build with interpreter support, both internal and external. + Default: False + Manual: True + Flag threaded Description: Link the ghc executable against the threaded RTS Default: True @@ -56,7 +61,7 @@ Executable ghc -rtsopts=all "-with-rtsopts=-K512M -H -I5 -T" - if flag(internal-interpreter) + if flag(interpreter) -- NB: this is never built by the bootstrapping GHC+libraries Build-depends: deepseq >= 1.4 && < 1.6, @@ -65,7 +70,7 @@ Executable ghc haskeline == 0.8.*, exceptions == 0.10.*, time >= 1.8 && < 1.16 - CPP-Options: -DHAVE_INTERNAL_INTERPRETER + CPP-Options: -DHAVE_INTERPRETER Other-Modules: GHCi.Leak GHCi.UI @@ -82,6 +87,9 @@ Executable ghc UnboxedTuples ViewPatterns + if flag(internal-interpreter) + CPP-Options: -DHAVE_INTERNAL_INTERPRETER + if flag(threaded) ghc-options: -threaded ===================================== hadrian/src/Settings/Packages.hs ===================================== @@ -114,7 +114,8 @@ packageArgs = do , compilerStageOption ghcDebugAssertions ? arg "-DDEBUG" ] , builder (Cabal Flags) ? mconcat - [ (expr (ghcWithInterpreter stage)) `cabalFlag` "internal-interpreter" + [ expr (ghcWithInterpreter stage) `cabalFlag` "interpreter" + , andM [expr (ghcWithInterpreter stage), notCross] `cabalFlag` "internal-interpreter" , ifM stage0 -- We build a threaded stage 1 if the bootstrapping compiler -- supports it. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9efefc8c446eff2553330d563945b13c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9efefc8c446eff2553330d563945b13c... You're receiving this email because of your account on gitlab.haskell.org.