[Core] Make storage class conform to Sendable and subsequent changes #13939
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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