Cheng Shao pushed to branch wip/set-keep-cafs-by-need at Glasgow Haskell Compiler / GHC Commits: 84e920db by Cheng Shao at 2025-10-01T19:40:52+02: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. - - - - - 2 changed files: - compiler/GHC.hs - compiler/cbits/keepCAFsForGHCi.c 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 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/84e920db468a676498b74bf2a5a95d58... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/84e920db468a676498b74bf2a5a95d58... You're receiving this email because of your account on gitlab.haskell.org.