-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Core] Make storage class conform to Sendable and subsequent changes #13939
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
paulb777
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to add Swift 6 compliance testing in CI?
andrewheard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Nick!
Jumping into the Storage.swift file, the two conforming classes, FileStorage and UserDefaultsStorage, wrapped Foundation APIs FileManager and UserDefaults, respectively. Both Foundation APIs are not Sendable and it would be risky for us to add such conformance. So, I followed the approach discussed in forums.developer.apple.com/forums/thread/757527 to remove them as stored properties and instead initialize them in each context they are needed. It's not great, but avoids having to use unchecked Sendable.
This looks very reasonable to me. I don't think calling, e.g., FileManager.default should be expensive at all. It makes testing slightly more difficult since we can't inject a fake but we weren't doing it for FileManager anyway and you worked around it for UserDefaults. LGTM.
Addresses two more Swift 6 errors (with more changes to address the errors from that resulted from the initial changes):
@Sendableclosurelet oldHeartbeatsBundle = try? load(from: storage)
Needed to conform
HeartbeatStorageclass toSendable(requirements).The problem was the second requirement: Contain only stored properties that are immutable and sendable
Jumping into the
Storage.swiftfile, the two conforming classes,FileStorageandUserDefaultsStorage, wrapped Foundation APIsFileManagerandUserDefaults, respectively. Both Foundation APIs are not Sendable and it would be risky for us to add such conformance. So, I followed the approach discussed in https://forums.developer.apple.com/forums/thread/757527 to remove them as stored properties and instead initialize them in each context they are needed. It's not great, but avoids having to use unchecked Sendable.@SendableclosureThis is straightforward–
DispatchQueue.asynctakes an Sendable closure so we need to pass it one. This bubbled upwards to the_Objc_HeartbeatControllerlevel (this is the public API level used byFirebaseCoremodule). I re-generated theFirebaseCoreInternal-Swift.hand did not see any difference to the asyncFlush API's signature when adding the@Sendableattribute.FirebaseCoreInternal and its test suite builds with language mode set to Swift 6. 🎉
#no-changelog