Repository navigation
[Swift] Swift IPC handlers should return their reply and may be async [reland] - #76310
Merged
webkit-commit-queue merged 1 commit intoOct 9, 2026
Conversation
Collaborator
|
EWS run on previous version of this PR (hash a8b6d09) Details
|
adetaylor
force-pushed
the
eng/reland-swift-ipc-async-handlers
branch
from
October 8, 2026 13:05
a8b6d09 to
36cbac4
Compare
Collaborator
|
EWS run on current version of this PR (hash 36cbac4) Details
|
rr-codes
approved these changes
Oct 8, 2026
… [reland] https://bugs.webkit.org/show_bug.cgi?id=324524 Reviewed by Richard Robinson A handler for a message with a reply now returns it, and any handler may be async. For instance, IPCTesterReceiver's deferred reply no longer deals with WTF::CompletionHandler and becomes simply: func deferredReplyMessage(connection: IPC.Connection, arg1: UInt32) async -> UInt64 { deferredReplyArgument = arg1 return await withCheckedContinuation { pendingDeferredReply = $0 } } so the reply is whatever the handler returns, whenever it returns. It cannot forget to reply or reply twice, and no C++ reply type appears in its signature. Async or not, throwing or not, all four combinations go through one generated call, since a single `await` and a single `try` each cover a whole expression: let reply = try await mayThrowInvalidMessage(target.foo(connection: connection, ...)) Nothing in .messages.in says whether a handler is async: handleMessageSynchronous moves the reply encoder into the completion handler, so Synchronous only means the sender blocks, and deferring is the receiver's choice. A handler without a reply may need to await too, so every message is dispatched the same way. Everything runs on the main thread. Handlers are @mainactor. @mainactor functions are not exposed to C++, so the generated wrapper stays synchronous, enters the actor with MainActor.assumeIsolated - which also asserts IPC dispatched us on the main thread - and starts the handler with Task.immediate, which runs it inline until its first suspension and inherits the actor, so the remainder stays on the main thread too. Running inline is what keeps Swift-handled messages in order with C++-handled ones; Task.init would not. The body lives in a @mainactor static method because a typed `catch` inside a closure widens to `any Error`. mayThrowInvalidMessage's async overload is nonisolated(nonsending), without which awaiting it would send the reply out of the actor. Adds -Werror RegionIsolation, without which none of this is checked: data-race diagnostics are only warnings when a C++ type is involved, because C++ modules carry no concurrency annotations. That is most of our Swift. None of this crosses a real boundary - it is one thread and one stack frame - but the wrapper must be nonisolated for C++ to call it, because swiftc silently omits @mainactor members from the generated C++ header. Everything under Scripts/webkit/tests/ is messages_unittest.py -r output, except TestWithSwift.messages.in, which gains a message with an empty reply. This is a reland; the previous version hit a Swift compiler bug rdar://189495426 on Windows alone. This is worked around in this version by packing the function arguments into a struct. * Source/WebKit/Platform/IPC/MessageCheck.swift: (mayThrowInvalidMessage(_:)): (Task.immediateOnMainActor(_:)): (InvalidMessage.markMessageInvalid(_:on:)): Deleted. * Source/WebKit/Scripts/webkit/messages.py: (swift_reply_completion_argument): (generate_swift_message_handler): (swift_dispatch_target_and_function): * Source/WebKit/Scripts/webkit/tests/TestWithStreamSwiftEnabledByMessageReceiver.swift: * Source/WebKit/Scripts/webkit/tests/TestWithStreamSwiftMessageReceiver.swift: * Source/WebKit/Scripts/webkit/tests/TestWithSwiftConditionallyAndEnabledByMessageReceiver.swift: * Source/WebKit/Scripts/webkit/tests/TestWithSwiftConditionallyMessageReceiver.swift: * Source/WebKit/Scripts/webkit/tests/TestWithSwiftMessageReceiver.swift: * Source/WebKit/Shared/IPCTesterReceiver.swift: (IPCTesterReceiver.asyncMessage): (IPCTesterReceiver.deferredReplyMessage): (IPCTesterReceiver.completeDeferredReply(connection:arg1:)): (IPCTesterReceiver.pendingDeferredReply): (IPCTesterReceiver.deferredReply): Deleted. (IPCTesterReceiver.completeDeferredReply(_:arg1:)): * Source/WebKit/UIProcess/WebBackForwardList.swift: (WebBackForwardList.backForwardAddItem): (WebBackForwardList.backForwardSetChildItem): (WebBackForwardList.backForwardClearChildren): (WebBackForwardList.backForwardUpdateItem): (WebBackForwardList.backForwardGoToItem): (WebBackForwardList.backForwardListContainsItem): (WebBackForwardList.backForwardAllItems): (WebBackForwardList.backForwardItemAtIndexForWebContent): (WebBackForwardList.backForwardListCounts): * Source/cmake/WebKitSwiftFlags.cmake: * Source/WTF/wtf/PlatformHave.h: * Source/WebKit/Configurations/AllowedSPI.toml: * Source/WebKit/Platform/spi/Cocoa/_Concurrency_SPI.swiftinterface: Added. * Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp: (IPC::jsValueForArguments): (IPC::jsValueForReplyArguments): (IPC::messageArgumentDescriptions): (IPC::messageReplyArgumentDescriptions): * Source/WebKit/Scripts/webkit/tests/MessageNames.cpp: * Source/WebKit/Scripts/webkit/tests/MessageNames.h: * Source/WebKit/Scripts/webkit/tests/TestWithSwift.messages.in: * Source/WebKit/Scripts/webkit/tests/TestWithSwiftMessageReceiver.cpp: (WebKit::TestWithSwiftMessageForwarder::didReceiveMessage): (CompletionHandlers::TestWithSwift::completeWithDefaultReply): (IPC::jsValueForDecodedMessage<MessageName::TestWithSwift_TestMessageWithEmptyReply>): (IPC::jsValueForDecodedMessageReply<MessageName::TestWithSwift_TestMessageWithEmptyReply>): (IPC::jsValueForDecodedMessage<MessageName::TestWithSwift_TestMessageWithEmptyReplyReply>): * Source/WebKit/Scripts/webkit/tests/TestWithSwiftMessages.h: (Messages::TestWithSwift::TestMessageWithEmptyReply::name): (Messages::TestWithSwift::TestMessageWithEmptyReply::asyncMessageReplyName): (Messages::TestWithSwift::TestMessageWithEmptyReply::TestMessageWithEmptyReply): (Messages::TestWithSwift::TestMessageWithEmptyReply::encode): (Messages::TestWithSwift::TestMessageWithEmptyReplyReply::name): (Messages::TestWithSwift::TestMessageWithEmptyReplyReply::TestMessageWithEmptyReplyReply): (Messages::TestWithSwift::TestMessageWithEmptyReplyReply::encode): * Configurations/CommonBase.xcconfig: * Source/WebKit/CMakeLists.txt: * Source/WebKit/Shared/Concurrency+Extras.swift: Added. (Task.immediateOnMainActor(_:)): * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/323222@main
webkit-commit-queue
force-pushed
the
eng/reland-swift-ipc-async-handlers
branch
from
October 9, 2026 12:15
36cbac4 to
9fdd260
Compare
Collaborator
|
Committed 323222@main (9fdd260): https://commits.webkit.org/323222@main Reviewed commits have been landed. Closing PR #76310 and removing active labels. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
9fdd260
36cbac4