Skip to content

Protocol conformances in WebKitSwift needlessly use @retroactive #47166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

aestes
Copy link
Contributor

@aestes aestes commented Jun 25, 2025

55b925e

Protocol conformances in WebKitSwift needlessly use @retroactive
https://bugs.webkit.org/show_bug.cgi?id=294955
rdar://154261967

Reviewed by Richard Robinson.

WebKitSwift vends Objective-C interfaces declared in headers imported by the WebKitSwift.h umbrella
header, but implements these interfaces in Swift using @objc @implementation extensions. In order
for the Swift compiler to see the Objective-C declarations, WebKitSwift defines a clang module
named WebKitSwift that imports WebKitSwift.h, and Swift files containing the implementations import
the WebKitSwift clang module. Since the WebKitSwift Swift module is named libWebKitSwift,
technically the Objective-C declarations come from a different module than their implementations.

This presents a problem when we attempt to conform these types to a protocol imported from another
module. Since the Swift compiler thinks both the interface and the protocol are from imported
modules, a "extension declares a conformance of imported type 'Foo' to imported protocol 'Bar'"
warning is emitted. Previously we have silenced this warning by annotating the conformance with
@retroactive, but it turns out this is unnecessary.

Similar to how Swift overlays are implemented in mixed-source frameworks, we can convince Swift
that our Objective-C interfaces come from the same module that implements them by giving both the
clang and Swift modules the same name (WebKitSwift), and importing the clang module via
`@_exported import WebKitSwift`. This allows us to remove the needless @retroactive attributes.

* Source/WebKit/Configurations/WebKitSwift.xcconfig:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebKitSwift/GroupActivities/WKGroupSession.swift:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaPlayer.swift:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaTypes.swift:
* Source/WebKit/WebKitSwift/MarketplaceKit/WKMarketplaceKit.swift:
* Source/WebKit/WebKitSwift/Preview/WKPreviewWindowController.swift:
* Source/WebKit/WebKitSwift/RealityKit/WKRKEntity.swift:
* Source/WebKit/WebKitSwift/StageMode/WKStageMode.swift:
* Source/WebKit/WebKitSwift/TextAnimation/WKTextAnimationManagerIOS.swift:
* Source/WebKit/WebKitSwift/WebKitSwift.swift: Copied from Source/WebKit/WebKitSwift/MarketplaceKit/WKMarketplaceKit.swift.
* Source/WebKit/WebKitSwift/WritingTools/IntelligenceTextEffectViewManager.swift:
* Source/WebKit/WebKitSwift/WritingTools/PlatformIntelligenceTextEffectView.swift:
* Source/WebKit/WebKitSwift/WritingTools/WKIntelligenceReplacementTextEffectCoordinator.swift:
* Source/WebKit/WebKitSwift/WritingTools/WKIntelligenceSmartReplyTextEffectCoordinator.swift:

Canonical link: https://commits.webkit.org/296629@main

9e255a0

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@aestes aestes self-assigned this Jun 25, 2025
@aestes aestes added the Media Bugs related to the HTML 5 Media elements. label Jun 25, 2025
@aestes aestes force-pushed the eng/Protocol-conformances-in-WebKitSwift-needlessly-use-retroactive branch from 5ad2b99 to 0319b32 Compare June 25, 2025 05:50
@aestes aestes force-pushed the eng/Protocol-conformances-in-WebKitSwift-needlessly-use-retroactive branch from 0319b32 to ff880b1 Compare June 25, 2025 05:55
@@ -23,6 +23,8 @@

#if ENABLE_MEDIA_SESSION_COORDINATOR && HAVE_GROUP_ACTIVITIES

@_exported import WebKitSwift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this actually needed in every file? _WebKit_SwiftUI does a similar thing, but I only have it in a single dedicated file there

@aestes aestes force-pushed the eng/Protocol-conformances-in-WebKitSwift-needlessly-use-retroactive branch from ff880b1 to 9e255a0 Compare June 25, 2025 16:36
@aestes aestes added the merge-queue Applied to send a pull request to merge-queue label Jun 25, 2025
https://bugs.webkit.org/show_bug.cgi?id=294955
rdar://154261967

Reviewed by Richard Robinson.

WebKitSwift vends Objective-C interfaces declared in headers imported by the WebKitSwift.h umbrella
header, but implements these interfaces in Swift using @objc @implementation extensions. In order
for the Swift compiler to see the Objective-C declarations, WebKitSwift defines a clang module
named WebKitSwift that imports WebKitSwift.h, and Swift files containing the implementations import
the WebKitSwift clang module. Since the WebKitSwift Swift module is named libWebKitSwift,
technically the Objective-C declarations come from a different module than their implementations.

This presents a problem when we attempt to conform these types to a protocol imported from another
module. Since the Swift compiler thinks both the interface and the protocol are from imported
modules, a "extension declares a conformance of imported type 'Foo' to imported protocol 'Bar'"
warning is emitted. Previously we have silenced this warning by annotating the conformance with
@retroactive, but it turns out this is unnecessary.

Similar to how Swift overlays are implemented in mixed-source frameworks, we can convince Swift
that our Objective-C interfaces come from the same module that implements them by giving both the
clang and Swift modules the same name (WebKitSwift), and importing the clang module via
`@_exported import WebKitSwift`. This allows us to remove the needless @retroactive attributes.

* Source/WebKit/Configurations/WebKitSwift.xcconfig:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebKitSwift/GroupActivities/WKGroupSession.swift:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaPlayer.swift:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaTypes.swift:
* Source/WebKit/WebKitSwift/MarketplaceKit/WKMarketplaceKit.swift:
* Source/WebKit/WebKitSwift/Preview/WKPreviewWindowController.swift:
* Source/WebKit/WebKitSwift/RealityKit/WKRKEntity.swift:
* Source/WebKit/WebKitSwift/StageMode/WKStageMode.swift:
* Source/WebKit/WebKitSwift/TextAnimation/WKTextAnimationManagerIOS.swift:
* Source/WebKit/WebKitSwift/WebKitSwift.swift: Copied from Source/WebKit/WebKitSwift/MarketplaceKit/WKMarketplaceKit.swift.
* Source/WebKit/WebKitSwift/WritingTools/IntelligenceTextEffectViewManager.swift:
* Source/WebKit/WebKitSwift/WritingTools/PlatformIntelligenceTextEffectView.swift:
* Source/WebKit/WebKitSwift/WritingTools/WKIntelligenceReplacementTextEffectCoordinator.swift:
* Source/WebKit/WebKitSwift/WritingTools/WKIntelligenceSmartReplyTextEffectCoordinator.swift:

Canonical link: https://commits.webkit.org/296629@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Protocol-conformances-in-WebKitSwift-needlessly-use-retroactive branch from 9e255a0 to 55b925e Compare June 25, 2025 20:05
@webkit-commit-queue
Copy link
Collaborator

Committed 296629@main (55b925e): https://commits.webkit.org/296629@main

Reviewed commits have been landed. Closing PR #47166 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 55b925e into WebKit:main Jun 25, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants