Skip to content

[ModuleInterface] Support classes with missing designated inits #26060

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

Closed

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Jul 10, 2019

When a superclass in one module has a designated init that is non-public (or
@usableFromInline), and another class attempts to subclass that class from a
different module, we would have enough information in a binary module to
know that the class can't be subclassed because it's missing designated
initializers.

But if we're in a module interface, there's no indication that there was
an un-printed initializer. Introduce a new attribute
@_hasMissingDesignatedInits on classes that have non-public or usable
from inline designated initializers, and ensure that the bit is set when
we parse one.

Also, if a class inherits from something that has missing designated inits, but it overrides all designated initializers anyway, it should be allowed to inherit convenience inits even if they're missing from the interface. As such, add another attribute @_inheritsSuperclassInitializers, and promote the existing bit to an attribute. This'll ensure that we follow initializer inheritance the same way we would with bits in the serialized module.

Fixes rdar://51249311

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for the internal subclass case? I think we haven't completely solved the problem without saying "but this class does override all the designated initializers, even though you can't see them".

@slavapestov
Copy link
Contributor

This should replace ClassDecl::inheritsSuperclassInitializers() and setInheritsSuperclassInitializers() too, together with the existing code for computing that in TypeChecker::addImplicitConstructors().

@harlanhaskins harlanhaskins force-pushed the an-inconvenient-init branch 4 times, most recently from 1c8ed5e to f76a1b4 Compare July 24, 2019 23:08
@harlanhaskins
Copy link
Contributor Author

I'd really like, at some point, to pull out this logic from addImplicitConstructors, but it's really tightly woven with the logic for diagnosing missing overrides and creating implicit overrides.

@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

@harlanhaskins harlanhaskins force-pushed the an-inconvenient-init branch 2 times, most recently from ec45b56 to 1be55c1 Compare July 25, 2019 20:57
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@harlanhaskins harlanhaskins force-pushed the an-inconvenient-init branch from 1be55c1 to e59b95d Compare July 26, 2019 21:11
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@harlanhaskins harlanhaskins force-pushed the an-inconvenient-init branch from e59b95d to c3eeabb Compare July 27, 2019 06:19
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@harlanhaskins harlanhaskins force-pushed the an-inconvenient-init branch from c3eeabb to 6074884 Compare July 29, 2019 17:52
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@harlanhaskins
Copy link
Contributor Author

@nkcsgexi Can you look at the api-digester changes here and tell me if they make sense?

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9a6bbdac1ba695c88f34170e52e5e6c027ff13b7

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Nov 20, 2019
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9a6bbdac1ba695c88f34170e52e5e6c027ff13b7

@harlanhaskins
Copy link
Contributor Author

@swift-ci please clean test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9a6bbdac1ba695c88f34170e52e5e6c027ff13b7

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 20c51258f9308573a65c061c904045ea511ae046

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 20c51258f9308573a65c061c904045ea511ae046

Harlan Haskins added 4 commits November 21, 2019 17:28
Since this is going to be something modules tell clients, rather than something clients discover about modules, serialize it.
We’re going to start serializing this for public types that have non-public-or-@usableFromInline initializers, so turn it into a request that we can query and cache it in the existing bit.
Specially print @_hasMissingDesignatedInitializers and @_inheritsConvenienceInitializers in module interfaces

Fixes rdar://51249311
…alizers

Because we won’t be serializing this attribute, add custom diagnostics for the cases where:

- We add @_hasMissingDesignatedInits to an open class, which means subclasses won’t be able to inherit its inits
- We remove @_inheritsConvenienceInitializers, which means APIs are removed
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b9468463a3d7604e95abcc0ca5d769928f9eeb80

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b9468463a3d7604e95abcc0ca5d769928f9eeb80

@CodaFi
Copy link
Contributor

CodaFi commented Jan 6, 2020

Shepherded in #28629

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.

6 participants