I'm currently experiencing a very odd issue in an internal app at my workplace: adding a new module breaks an async func that was bridged from an objc completion handler, though no code in the module is actually run. All of the relevant code is compiled with the Swift 6.2.3 compiler in Swift 6 mode, and the crash only occurs when a specific dependency is built with Bazel; XcodeBuild builds of the dep work fine. Recently, it started crashing 100% deterministically, here is the relevant part of the stack trace:
#0 0x00000001003a9a0c in UnsafeContinuation.resume<>(returning:) ()
#1 0x00000001003a261c in _resumeUnsafeContinuation<()>(_:_:) ()
#2 0x00000001003a2510 in @objc completion handler block implementation for @escaping @callee_unowned @convention(block) @Sendable () -> () with result type () ()
#3 0x0000000112f811e4 in WTF::Detail::CallableWrapper<WTF::CompletionHandler<void (IPC::Connection*, IPC::Decoder*)> IPC::Connection::makeAsyncReplyCompletionHandler<Messages::WebCookieManager::SetCookie, WTF::CompletionHandler<void ()>>(WTF::CompletionHandler<void ()>&&, WTF::ThreadLikeAssertion)::'lambda'(IPC::Connection*, IPC::Decoder*), void, IPC::Connection*, IPC::Decoder*>::call ()
#4 0x0000000112db68d8 in WTF::Detail::CallableWrapper<WebKit::AuxiliaryProcessProxy::sendMessage(WTF::UniqueRef<IPC::Encoder>&&, WTF::OptionSet<IPC::SendOption, (WTF::ConcurrencyTag)0>, std::__1::optional<IPC::ConnectionAsyncReplyHandler>, WebKit::AuxiliaryProcessProxy::ShouldStartProcessThrottlerActivity)::$_1, void, IPC::Connection*, IPC::Decoder*>::call ()
#5 0x00000001133464f8 in IPC::Connection::dispatchMessage ()
#6 0x000000011336149c in WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(WTF::UniqueRef<IPC::Decoder>)::$_2, void>::call ()
#7 0x000000010d671e98 in WTF::RunLoop::performWork ()
#8 0x000000010d673628 in WTF::RunLoop::performWork ()
#9 0x000000010cb5b3a4 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
As you can see, it's a Swift continuation that's crashing, but it's not in our code, it's inside of a webkit function that originally was written with a completion handler but was bridged to async. This one, specifically.
I isolated the reproduction to a single line of code in an open source dependency: a call to this function in SafariServices.
This function is never called in my program. Its presence in the binary is enough to break setCookies. When I delete it, the crash simply vanishes.
My current theory is that clearWebsiteData() calls setCookie internally, and that that somehow interferes with Swift's ability to generate stubs for setCookie (As far as I'm aware this code is not part of the Webkit open source project, so I don't think I can confirm this myself). This theory only makes sense if we are generated stubs for the completion handler functions, but I haven't looked into whether that's how this Swift feature is implemented.
I also thought that perhaps causing SafariServices to be linked into my program might mess with WebKit in a +load or +initialize function, but merely importing SafariServices is not enough to repro as far as I can tell.
Are there any build flags we should be looking at that could explain this? Any pointers on how the compiler is implemented that might be helpful to debug this?