[Git][ghc/ghc][master] compiler: only invoke keepCAFsForGHCi if internal-interpreter is enabled
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: c254c54b by Cheng Shao at 2025-10-02T07:29:33-04:00 compiler: only invoke keepCAFsForGHCi if internal-interpreter is enabled This patch makes the ghc library only invoke keepCAFsForGHCi if internal-interpreter is enabled. For cases when it's not (e.g. the host build of a cross ghc), this avoids unnecessarily retaining all CAFs in the heap. Also fixes the type signature of c_keepCAFsForGHCi to match the C ABI. - - - - - 3 changed files: - compiler/GHC.hs - compiler/cbits/keepCAFsForGHCi.c - compiler/ghc.cabal.in Changes: ===================================== compiler/GHC.hs ===================================== @@ -463,6 +463,9 @@ import System.Exit ( exitWith, ExitCode(..) ) import System.FilePath import System.IO.Error ( isDoesNotExistError ) +#if defined(HAVE_INTERNAL_INTERPRETER) +import Foreign.C +#endif -- %************************************************************************ -- %* * @@ -597,12 +600,12 @@ withCleanupSession ghc = ghc `MC.finally` cleanup initGhcMonad :: GhcMonad m => Maybe FilePath -> m () initGhcMonad mb_top_dir = setSession =<< liftIO ( do -#if !defined(javascript_HOST_ARCH) +#if defined(HAVE_INTERNAL_INTERPRETER) -- The call to c_keepCAFsForGHCi must not be optimized away. Even in non-debug builds. -- So we can't use assertM here. -- See Note [keepCAFsForGHCi] in keepCAFsForGHCi.c for details about why. !keep_cafs <- c_keepCAFsForGHCi - massert keep_cafs + massert $ keep_cafs /= 0 #endif initHscEnv mb_top_dir ) @@ -2092,7 +2095,7 @@ mkApiErr :: DynFlags -> SDoc -> GhcApiError mkApiErr dflags msg = GhcApiError (showSDoc dflags msg) -#if !defined(javascript_HOST_ARCH) +#if defined(HAVE_INTERNAL_INTERPRETER) foreign import ccall unsafe "keepCAFsForGHCi" - c_keepCAFsForGHCi :: IO Bool + c_keepCAFsForGHCi :: IO CBool #endif ===================================== compiler/cbits/keepCAFsForGHCi.c ===================================== @@ -21,7 +21,7 @@ // the constructor to be run, allowing the assertion to succeed in the first place // as keepCAFs will have been set already during initialization of constructors. - +#if defined(HAVE_INTERNAL_INTERPRETER) bool keepCAFsForGHCi(void) __attribute__((constructor)); @@ -32,4 +32,4 @@ bool keepCAFsForGHCi(void) return was_set; } - +#endif ===================================== compiler/ghc.cabal.in ===================================== @@ -156,6 +156,7 @@ Library if flag(internal-interpreter) CPP-Options: -DHAVE_INTERNAL_INTERPRETER + cc-options: -DHAVE_INTERNAL_INTERPRETER -- if no dynamic system linker is available, don't try DLLs. if flag(dynamic-system-linker) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c254c54b3b4354722172c2c91c4ccc00... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c254c54b3b4354722172c2c91c4ccc00... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)