Skip to content

Don't inherit convenience inits if a designated init is missing. #8708

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

Conversation

jrose-apple
Copy link
Contributor

(which can happen if an imported class has un-importable initializers)

Our initializer model guarantees that it's safe to inherit convenience initializers when a subclass has implemented all designated initializers, since each convenience initializer will be implemented by calling one of the designated initializers. If one of the designated initializers can't be implemented in Swift, however, then inheriting the convenience initializer would not be safe.

This is potentially a source-breaking change, so the importer will only actually record that it failed to import something in when compiling in Swift 4 mode. I also found an unrelated bug about initializer inheritance, which I filed as SR-4566.

I'm using this as groundwork for the "deserialization recovery" I've been doing. I'd like to do something better than dropping a designated initializer just because the declaration it overrides has changed, but this is a safe default, at least.

rdar://problem/31563662

@jrose-apple jrose-apple requested a review from DougGregor April 11, 2017 21:26
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple jrose-apple force-pushed the missing-designated-initializer branch from 47a4909 to 2a72eb3 Compare April 11, 2017 21:33
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 47a4909df8772fdcce33ab82540e0928b835590b
Test requested by - @jrose-apple

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 47a4909df8772fdcce33ab82540e0928b835590b
Test requested by - @jrose-apple

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@CodaFi
Copy link
Contributor

CodaFi commented Apr 12, 2017

@swift-ci please smoke test linux platform

@jrose-apple
Copy link
Contributor Author

Review ping, since I think this one could definitely use a second pair of eyes.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Minor comment aside, LGTM!

/// This can occur, for example, if the class is an Objective-C class with
/// initializers that cannot be represented in Swift.
bool hasMissingDesignatedInitializers() const {
(void)getMembers();
Copy link
Member

Choose a reason for hiding this comment

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

Can we lookupDirect on the name init instead, so we only deserialize initializers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean when we actually do that? Yeah, good point.

@@ -107,6 +107,7 @@ __weak id globalWeakVar;
- (id)getObjectFromVarArgs:(id)first, ...;
@end


Copy link
Member

Choose a reason for hiding this comment

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

Spurious whitespace addition.

@jrose-apple jrose-apple force-pushed the missing-designated-initializer branch from 2a72eb3 to f206384 Compare April 24, 2017 17:40
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple jrose-apple force-pushed the missing-designated-initializer branch from f206384 to d255f9f Compare April 24, 2017 17:47
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

(which can happen if an imported class has un-importable initializers)

Our initializer model guarantees that it's safe to inherit convenience
initializers when a subclass has implemented all designated
initializers, since each convenience initializer will be implemented
by calling one of the designated initializers. If one of the
designated initializers /can't/ be implemented in Swift, however,
then inheriting the convenience initializer would not be safe.

This is potentially a source-breaking change, so the importer will
only actually record that it failed to import something in when
compiling in Swift 4 mode.

rdar://problem/31563662
@jrose-apple jrose-apple force-pushed the missing-designated-initializer branch from d255f9f to c1b4c94 Compare April 24, 2017 17:54
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 7397340 into swiftlang:master Apr 24, 2017
@jrose-apple jrose-apple deleted the missing-designated-initializer branch April 24, 2017 18:47
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.

4 participants