Skip to content
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 instance manager conform to Swift 6 principles #13933

Merged
merged 8 commits into from
Oct 23, 2024
Merged

Conversation

ncooke3
Copy link
Member

@ncooke3 ncooke3 commented Oct 19, 2024

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

@paulb777 paulb777 self-requested a review October 19, 2024 00:26
@ncooke3 ncooke3 merged commit 66f44fc into main Oct 23, 2024
62 checks passed
@ncooke3 ncooke3 deleted the nc/swift-6 branch October 23, 2024 17:18
@firebase firebase locked and limited conversation to collaborators Nov 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants