[Core] Make storage class conform to Sendable and subsequent changes #13939
+135 −106
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):
@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