Skip to content

[Stdlib] Eagerly realize EmptyDictionarySingleton and EmptySetSingleton. #29848

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

Merged
merged 1 commit into from
Feb 17, 2020

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Feb 14, 2020

These objects can escape into ObjC without their class being realized first, which can cause a crash if the unrealized class gets passed into the ObjC runtime.

rdar://problem/59295395

@mikeash mikeash requested a review from Catfish-Man February 14, 2020 16:57
@mikeash
Copy link
Contributor Author

mikeash commented Feb 14, 2020

@swift-ci please test

These objects can escape into ObjC without their class being realized first, which can cause a crash if the unrealized class gets passed into the ObjC runtime.

rdar://problem/59295395
@mikeash mikeash force-pushed the eagerly-realize-empty-singletons branch from 12ed357 to 440d279 Compare February 14, 2020 16:58
@mikeash
Copy link
Contributor Author

mikeash commented Feb 14, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 12ed357aef27991504b2849d2241a3863ef51aa4

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 12ed357aef27991504b2849d2241a3863ef51aa4

@Catfish-Man
Copy link
Contributor

Huh hadn’t seen that attribute to me. Makes sense though!

@mikeash
Copy link
Contributor Author

mikeash commented Feb 14, 2020

Yeah, I hadn't seen it before either. That seemed like the most straightforward fix, so I went hunting for it really hoping it existed. Thankfully, it does.

@DougGregor
Copy link
Member

You can thank NSCoding for this funny little attribute, I think

@compnerd
Copy link
Member

@DougGregor this reminds me of an issue with lazy value witness table initialization. In Foundation, we have an issue where the value witness for _NSCFConstantString is not realized before the first use. This results in an invalid memory access as the VW is not ready for use. There is a pretty clever/horrible workaround of:

if let _ = "" as? _NSCFConstantString { }

since we do not have a convenient way to invoke swift_getForeignTypeMetadata.

Thoughts on having something similar for that case?

@mikeash mikeash merged commit 57a3df5 into swiftlang:master Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants