-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[Core] Make storage class conform to Sendable and subsequent changes #13939
Conversation
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?
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):
@Sendable
closurelet oldHeartbeatsBundle = try? load(from: storage)
Needed to conform
HeartbeatStorage
class toSendable
(requirements).The problem was the second requirement: Contain only stored properties that are immutable and sendable
Jumping into the
Storage.swift
file, the two conforming classes,FileStorage
andUserDefaultsStorage
, wrapped Foundation APIsFileManager
andUserDefaults
, 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.@Sendable
closureThis is straightforward–
DispatchQueue.async
takes an Sendable closure so we need to pass it one. This bubbled upwards to the_Objc_HeartbeatController
level (this is the public API level used byFirebaseCore
module). I re-generated theFirebaseCoreInternal-Swift.h
and did not see any difference to the asyncFlush API's signature when adding the@Sendable
attribute.FirebaseCoreInternal and its test suite builds with language mode set to Swift 6. 🎉
#no-changelog