-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: Fix subclass scope calculation for constructors #22989
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
Conversation
The logic here was buggy; we would dyn_cast the decl to a FuncDecl and return early if the cast failed; the ConstructorDecl logic had no effect at all. Furthermore, it was wrong, for two reasons: - even non-required designated inits still appear in the vtable - in the resilient case, the constructor needs public linkage unlike other non-final public methods, since it is referenced directly by subclasses when they perform a super.init() delegation Fixes <https://bugs.swift.org/browse/SR-9939>, <rdar://problem/48403349>.
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
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.
👍🏻
if (classType->isResilient()) | ||
if (classType->isResilient()) { | ||
if (isa<ConstructorDecl>(decl)) | ||
return SubclassScope::NotApplicable; |
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.
This doesn't look right; surely required
initializers still show up, at least?
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.
If a base class is resilient, vtable of a derived class in another module is always built dynamically, so the base class methods don't need to have their linkage made more visible.
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.
But why are constructors different from other methods?
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.
Because they can be called directly via super.init delegation
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.
I still don't understand. That's an optimization, just like it is for devirtualizing method calls. (Why? Because of resilient superclass insertion.)
The logic here was buggy; we would dyn_cast the decl to a FuncDecl and
return early if the cast failed; the ConstructorDecl logic had no
effect at all.
Furthermore, it was wrong, for two reasons:
other non-final public methods, since it is referenced directly
by subclasses when they perform a super.init() delegation
Fixes https://bugs.swift.org/browse/SR-9939, rdar://problem/48403349.