firebase-ios-sdk
firebase-ios-sdk copied to clipboard
[Core] Make instance manager conform to Swift 6 principles
Problem: Static property 'cachedInstances' is not concurrency-safe because it is nonisolated global shared mutable state
The fix-it to add nonisolated(unsafe) is for when it's okay to Disable concurrency-safety checks if accesses are protected by an external synchronization mechanism.
The "external synchronization mechanism" is the added lock. I went with NSLock of os_unfair_lock because the latter would need to be another static var and require an extra nonisolated(unsafe) attribute. This would be technically okay, but it looked cleaner to use the NSLock. NSLock is slightly slower but I think it would have a negligible effect based on the use case here.
Because core internal has < iOS 13 availability, structured concurrency cannot be used.
The added test crashes with the current implementation, and succeeds with this PR's changes.
#no-changelog