From c78d8f55afacfd559b1602bc2fbc35b1f326f1c1 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Thu, 20 Feb 2025 23:44:59 +0000
Subject: [PATCH] rts: fix top handler closure type signatures

This commit fixes the runIO/runNonIO closure type signatures in the
RTS which should be extern StgClosure. This allows us to remove an
unnecessary type cast in the C foreign desugaring logic, as well as
unneeded complications of JSFFI desugaring logic that also needs to
generate C stubs that may refer to those top handler closures.
Otherwise, we'll have to take special care to avoid generating "extern
StgClosure" declarations for them as we would for other closures, just
to avoid conflicting type signature error at stub compile time.
---
 compiler/GHC/HsToCore/Foreign/C.hs |  3 +--
 rts/include/RtsAPI.h               | 12 ++++++------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/compiler/GHC/HsToCore/Foreign/C.hs b/compiler/GHC/HsToCore/Foreign/C.hs
index fb6dea2f79a..3a091a3de9e 100644
--- a/compiler/GHC/HsToCore/Foreign/C.hs
+++ b/compiler/GHC/HsToCore/Foreign/C.hs
@@ -515,8 +515,7 @@ mkFExportCBits dflags c_nm maybe_target arg_htys res_hty is_IO_res_ty cc
      ,   text "rts_inCall" <> parens (
                 char '&' <> cap <>
                 text "rts_apply" <> parens (
-                    cap <>
-                    text "(HaskellObj)"
+                    cap
                  <> (if is_IO_res_ty
                       then text "runIO_closure"
                       else text "runNonIO_closure")
diff --git a/rts/include/RtsAPI.h b/rts/include/RtsAPI.h
index 226b4287b51..f34f82ac4f9 100644
--- a/rts/include/RtsAPI.h
+++ b/rts/include/RtsAPI.h
@@ -587,15 +587,15 @@ void rts_done (void);
 //      the base package itself.
 //
 #if defined(COMPILING_WINDOWS_DLL) && !defined(COMPILING_GHC_INTERNAL_PACKAGE)
-__declspec(dllimport) extern StgWord ghczminternal_GHCziInternalziTopHandler_runIO_closure[];
-__declspec(dllimport) extern StgWord ghczminternal_GHCziInternalziTopHandler_runNonIO_closure[];
+__declspec(dllimport) extern StgClosure ghczminternal_GHCziInternalziTopHandler_runIO_closure;
+__declspec(dllimport) extern StgClosure ghczminternal_GHCziInternalziTopHandler_runNonIO_closure;
 #else
-extern StgWord ghczminternal_GHCziInternalziTopHandler_runIO_closure[];
-extern StgWord ghczminternal_GHCziInternalziTopHandler_runNonIO_closure[];
+extern StgClosure ghczminternal_GHCziInternalziTopHandler_runIO_closure;
+extern StgClosure ghczminternal_GHCziInternalziTopHandler_runNonIO_closure;
 #endif
 
-#define runIO_closure     ghczminternal_GHCziInternalziTopHandler_runIO_closure
-#define runNonIO_closure  ghczminternal_GHCziInternalziTopHandler_runNonIO_closure
+#define runIO_closure     DLL_IMPORT_DATA_REF(ghczminternal_GHCziInternalziTopHandler_runIO_closure)
+#define runNonIO_closure  DLL_IMPORT_DATA_REF(ghczminternal_GHCziInternalziTopHandler_runNonIO_closure)
 
 /* ------------------------------------------------------------------------ */
 
-- 
GitLab