From 2635afe6f00e8f6b43c7f30efe29950f6d144cb2 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. (cherry picked from commit c78d8f55afacfd559b1602bc2fbc35b1f326f1c1) (cherry picked from commit 8ebb034829275c15f325e8dd74f7581758cea076) --- 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 8beaa8986ec..3642eb79cfb 100644 --- a/compiler/GHC/HsToCore/Foreign/C.hs +++ b/compiler/GHC/HsToCore/Foreign/C.hs @@ -543,8 +543,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 86b806ff83b..d7bb55f2c51 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_BASE_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