Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 436d708da9283630f51ba699e2ef24d8fecd1edb
https://github.com/WebKit/WebKit/commit/436d708da9283630f51ba699e2ef24d8fecd1edb
Author: Richard Robinson <[email protected]>
Date: 2026-08-27 (Thu, 27 Aug 2026)
Changed paths:
M Source/WTF/wtf/CompletionHandler.h
M Source/WTF/wtf/module.modulemap
M Source/WebKit/Shared/WTFCompletionHandler+Extras.swift
M Tools/TestWebKitAPI/Helpers/WTFCompletionHandler+Extras.swift
M Tools/TestWebKitAPI/TestWTFLibrary/SwiftCxxInteropTestbed.cpp
M Tools/TestWebKitAPI/TestWTFLibrary/SwiftCxxInteropTestbed.h
M Tools/TestWebKitAPI/Tests/WTF/cocoa/SwiftCxxInteropTests.swift
Log Message:
-----------
[Swift in WebKit] Make it possible for CxxCompletionHandler to be used with
noncopyable arguments
https://bugs.webkit.org/show_bug.cgi?id=322659
rdar://185932647
Reviewed by Adrian Taylor.
CxxCompletionHandler currently has `BitwiseCopyable & Sendable` for its
`Argument` associatedtype,
and uses `pointer.load(as:)` to copy the value. This is fine for trivial
copyable types, but meant
that noncopyable argument types were prohibited.
Relax this restriction by changing the requirement to `~Copyable` and transfer
the ownership of the
argument instead of copying it. In the non-trivial case, this works by
constructing the argument
into a new buffer which Swift then relocates and moves the value out of.
To facilitate this, a new `CxxConsumingCompletionHandler` protocol is added
because the importer
spells `operator()` as `callAsFunction(consuming:)` when the C++ parameter is
an rvalue reference.
Test: Tools/TestWebKitAPI/Tests/WTF/cocoa/SwiftCxxInteropTests.swift
* Source/WTF/wtf/CompletionHandler.h:
(WTF::CompletionHandler<Out):
* Source/WTF/wtf/module.modulemap:
* Source/WebKit/Shared/WTFCompletionHandler+Extras.swift:
(CxxCompletionHandler.callAsFunction(_:)):
(CxxConsumingCompletionHandler.callAsFunction(_:)):
(SwiftClosureBoxBase.call(with:)):
(SwiftVoidClosureBox.call(with:)):
(SwiftClosureBox.call(with:)):
* Tools/TestWebKitAPI/Helpers/WTFCompletionHandler+Extras.swift:
(CxxCompletionHandler.callAsFunction(_:)):
(CxxConsumingCompletionHandler.callAsFunction(_:)):
(SwiftClosureBoxBase.call(with:)):
(SwiftVoidClosureBox.call(with:)):
(SwiftClosureBox.call(with:)):
* Tools/TestWebKitAPI/TestWTFLibrary/SwiftCxxInteropTestbed.cpp:
(SwiftCxxInteropTestbed::liveMoveOnlyProbes):
(SwiftCxxInteropTestbed::MoveOnlyProbe::MoveOnlyProbe):
(SwiftCxxInteropTestbed::MoveOnlyProbe::~MoveOnlyProbe):
(SwiftCxxInteropTestbed::liveMoveOnlyProbeCount):
(SwiftCxxInteropTestbed::liveCopyCountingProbes):
(SwiftCxxInteropTestbed::copyCountingProbeCopies):
(SwiftCxxInteropTestbed::CopyCountingProbe::CopyCountingProbe):
(SwiftCxxInteropTestbed::CopyCountingProbe::~CopyCountingProbe):
(SwiftCxxInteropTestbed::liveCopyCountingProbeCount):
(SwiftCxxInteropTestbed::copyCountingProbeCopyCount):
(SwiftCxxInteropTestbed::resetCopyCountingProbeCounts):
(SwiftCxxInteropTestbed::callMoveOnlyProbeCompletionHandler):
(SwiftCxxInteropTestbed::callMoveOnlyProbeByValueCompletionHandler):
(SwiftCxxInteropTestbed::callCopyCountingProbeCompletionHandler):
(SwiftCxxInteropTestbed::storedMoveOnlyProbeCompletionHandler):
(SwiftCxxInteropTestbed::storeMoveOnlyProbeCompletionHandler):
(SwiftCxxInteropTestbed::invokeStoredMoveOnlyProbeCompletionHandler):
(SwiftCxxInteropTestbed::resetStoredMoveOnlyProbeCompletionHandler):
* Tools/TestWebKitAPI/TestWTFLibrary/SwiftCxxInteropTestbed.h:
(SwiftCxxInteropTestbed::MoveOnlyProbe::value const):
(SwiftCxxInteropTestbed::CopyCountingProbe::value const):
* Tools/TestWebKitAPI/Tests/WTF/cocoa/SwiftCxxInteropTests.swift:
(SwiftCxxInteropTests.moveOnlyCompletionHandlerReceivesItsArgument):
(SwiftCxxInteropTests.moveOnlyByValueCompletionHandlerReceivesItsArgument):
(SwiftCxxInteropTests.moveOnlyArgumentIsDestroyedWhenTheClosureIgnoresIt):
(SwiftCxxInteropTests.storedMoveOnlyCompletionHandlerSurvivesUntilInvoked):
(SwiftCxxInteropTests.copyableArgumentIsCopiedRatherThanTakenFromTheCaller):
Canonical link: https://commits.webkit.org/319991@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications