From daa23450e41c06ce8dd4f3ba4f5f6164db96913e Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Sat, 2 Mar 2024 14:00:10 +0000 Subject: [PATCH] Remove objc_retainAutoreleasedReturnValue workaround. The compiler has now been fixed to not generate calls to this function unless ObjC interop is enabled. rdar://123945799 --- src/swift/CMakeLists.txt | 13 ------------- src/swift/DispatchStubs.cc | 37 ------------------------------------- 2 files changed, 50 deletions(-) diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index c073e136d..4fffc84a4 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -1,16 +1,3 @@ - -# NOTE(compnerd) Today regardless of whether or not ObjC interop is enabled, -# swift will use an autoreleased return value convention for certain CF -# functions (including some that are used/related to dispatch). This means that -# the swift compiler in callers to such functions will call the function, and -# then pass the result of the function to objc_retainAutoreleasedReturnValue. In -# a context where we have ObjC interop disabled, we do not have access to the -# objc runtime so an implementation of objc_retainAutoreleasedReturnValue is not -# available. To work around this, we provide a shim for -# objc_retainAutoreleasedReturnValue in DispatchStubs.cc that just calls retain -# on the object. Once we fix the swift compiler to switch to a different model -# for handling these arguments with objc-interop disabled these shims can be -# eliminated. add_library(DispatchStubs STATIC DispatchStubs.cc) target_include_directories(DispatchStubs PRIVATE diff --git a/src/swift/DispatchStubs.cc b/src/swift/DispatchStubs.cc index 0625cc91f..dc320da29 100644 --- a/src/swift/DispatchStubs.cc +++ b/src/swift/DispatchStubs.cc @@ -56,40 +56,3 @@ static void _dispatch_overlay_constructor() { } #endif /* USE_OBJC */ - -#if !USE_OBJC -DISPATCH_RUNTIME_STDLIB_INTERFACE -extern "C" void * objc_retainAutoreleasedReturnValue(void *obj); -#endif - -#if !USE_OBJC - -// For CF functions with 'Get' semantics, the compiler currently assumes that -// the result is autoreleased and must be retained. It does so on all platforms -// by emitting a call to objc_retainAutoreleasedReturnValue. On Darwin, this is -// implemented by the ObjC runtime. On non-ObjC platforms, there is no runtime, -// and therefore we have to stub it out here ourselves. The compiler will -// eventually call swift_release to balance the retain below. This is a -// workaround until the compiler no longer emits this callout on non-ObjC -// platforms. -extern "C" -#if defined(_WIN32) -__declspec(dllimport) -#endif -void swift_retain(void *); - -DISPATCH_RUNTIME_STDLIB_INTERFACE -extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) { - if (obj) { - swift_retain(obj); - return obj; - } - else return NULL; -} - -#if defined(_WIN32) -extern "C" void *(*__imp_objc_retainAutoreleasedReturnValue)(void *) = - &objc_retainAutoreleasedReturnValue; -#endif - -#endif // !USE_OBJC