-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtime] Avoid +class overrides when initializing an ObjC class. #24618
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
[Runtime] Avoid +class overrides when initializing an ObjC class. #24618
Conversation
swift_getInitializedObjCClass called [c class] to trigger class initialization, and returned the value. This wreaked havoc when the class in question overrides +class. Instead, ignore the return value and return c. Switch from +class to +self, which is much less likely to be overridden. Calling an overridden method could have performance downsides or even cause unwanted side effects. rdar://problem/49853091
@swift-ci please test |
I think it's possible to write a terrible test case for this that would fail the old way. |
I think you're right! |
That does indeed trigger a failure with the old code. New code works. |
@swift-ci please test |
Build failed |
Build failed |
@@ -0,0 +1,25 @@ | |||
// RUN: mkdir -p %t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: %empty-directory(%t)
will also clear out any contents left over from the last run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. We have a bunch of tests with each one, and I happened to crib from one with mkdir
. Seems better to do it with empty-directory
though.
rdar://problem/49853091
3faade6
to
893e291
Compare
@swift-ci please test |
Build failed |
Build failed |
swift_getInitializedObjCClass called [c class] to trigger class initialization, and returned the value. This wreaked havoc when the class in question overrides +class. Instead, ignore the return value and return c. Switch from +class to +self, which is much less likely to be overridden. Calling an overridden method could have performance downsides or even cause unwanted side effects.
rdar://problem/49853091