Skip to content

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

Merged
merged 1 commit into from
Mar 1, 2019

Conversation

slavapestov
Copy link
Contributor

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.

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>.
@slavapestov slavapestov requested a review from jckarter February 28, 2019 18:55
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

Copy link
Contributor

@jckarter jckarter left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.)

@slavapestov slavapestov merged commit 55c919f into swiftlang:master Mar 1, 2019
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.

3 participants