Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e049f5845b55a11b97481108c22178deea44e7d4
https://github.com/WebKit/WebKit/commit/e049f5845b55a11b97481108c22178deea44e7d4
Author: Adrian Taylor <[email protected]>
Date: 2026-10-07 (Wed, 07 Oct 2026)
Changed paths:
M Configurations/CommonBase.xcconfig
M Source/WTF/wtf/PlatformHave.h
M Source/WebKit/CMakeLists.txt
M Source/WebKit/Configurations/AllowedSPI.toml
M Source/WebKit/Platform/IPC/MessageCheck.swift
A Source/WebKit/Platform/spi/Cocoa/_Concurrency_SPI.swiftinterface
M Source/WebKit/Scripts/webkit/messages.py
M Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp
M Source/WebKit/Scripts/webkit/tests/MessageNames.cpp
M Source/WebKit/Scripts/webkit/tests/MessageNames.h
M
Source/WebKit/Scripts/webkit/tests/TestWithStreamSwiftEnabledByMessageReceiver.swift
M
Source/WebKit/Scripts/webkit/tests/TestWithStreamSwiftMessageReceiver.swift
M Source/WebKit/Scripts/webkit/tests/TestWithSwift.messages.in
M
Source/WebKit/Scripts/webkit/tests/TestWithSwiftConditionallyAndEnabledByMessageReceiver.swift
M
Source/WebKit/Scripts/webkit/tests/TestWithSwiftConditionallyMessageReceiver.swift
M Source/WebKit/Scripts/webkit/tests/TestWithSwiftMessageReceiver.cpp
M Source/WebKit/Scripts/webkit/tests/TestWithSwiftMessageReceiver.swift
M Source/WebKit/Scripts/webkit/tests/TestWithSwiftMessages.h
A Source/WebKit/Shared/Concurrency+Extras.swift
M Source/WebKit/Shared/IPCTesterReceiver.swift
M Source/WebKit/UIProcess/WebBackForwardList.swift
M Source/WebKit/WebKit.xcodeproj/project.pbxproj
M Source/cmake/WebKitSwiftFlags.cmake
Log Message:
-----------
[Swift] Swift IPC handlers should return their reply and may be async
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.
* 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/322959@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications