Skip to content

Conversation

hamishknight
Copy link
Contributor

This PR splits off the computation of whether a class inherits its superclass' designated and convenience inits into a request. This leaves addImplicitInheritedConstructorsToClass just with the job of synthesizing designated init overrides.

This makes sure we don't attempt to synthesize
a memberwise or default initializer for an invalid
decl, or one in a module interface.
This commit introduces a request for computing
whether a class inherits both designated and
convenience initializers from its superclass.

The shared logic of finding initializers which the
subclass hasn't overriden has been factored out
into `collectNonOveriddenSuperclassInits`.
Now that the computation of
`inheritsSuperclassInitializers` has been split off
into a request, we can avoid calling
`addImplicitInheritedConstructorsToClass` for clang
decls.
This commit removes some code that's no longer
needed. In addition, now that we've requestified
`inheritsSuperclassInitializers`, we can directly
diagnose on non-inherited required convenience
inits within the loop.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test OS X platform

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@swiftlang swiftlang deleted a comment from swift-ci Oct 29, 2019
@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility release

}
for (auto member : decl->getMembers()) {
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
if (ctor->isRecursiveValidation())
Copy link
Contributor

Choose a reason for hiding this comment

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

@slavapestov Is there a reason we need any of this as a preflight? It seems bogus to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did try removing it, and it passed the validation test suite, I just wasn't sure whether or not it might cause us to start emitting circularity diagnostics for code that we previously silently accepted, so thought I'd leave it for a future PR.

I'd be more than happy to remove it now if you and Slava don't think it'd be a problem :)

// expected-error@-2 {{circular reference}}
// expected-note@-3 {{through reference here}}

init(x: Int) {} // expected-error {{circular reference}}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted to emit a better diagnostic, you could override diagnoseCycle and try to detect this case. It's probably not worth the extra hassle in this patch.

See also rdar://55263708

Copy link
Contributor Author

@hamishknight hamishknight Oct 30, 2019

Choose a reason for hiding this comment

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

Yeah, I talked with Slava about this – the goal is to eventually have a principled way to avoid these kinds of duplicate cycle diagnostics. For now though, I think it's okay.

Thanks for the review!

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Modulo nitpicks, this looks fantastic! Nice cleanup.

Continue to cache the InheritsSuperclassInits bit
on the AST.
@harlanhaskins
Copy link
Contributor

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1b70794

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1b70794

@hamishknight
Copy link
Contributor Author

@CodaFi If it's good with you, I'll go ahead and merge this now and look into removing the isRecursiveValidation() check in a follow-up.

@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test

@CodaFi
Copy link
Contributor

CodaFi commented Oct 31, 2019

@hamishknight Merge away! But please squash this so the merge commit doesn't show up in the history.

@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test Linux platform

@CodaFi
Copy link
Contributor

CodaFi commented Oct 31, 2019

Looks like you picked up the SourceKit failure

@swift-ci please smoke test Linux platform

@harlanhaskins
Copy link
Contributor

@swift-ci please smoke test Linux platform

@hamishknight hamishknight merged commit 16cff49 into swiftlang:master Oct 31, 2019
@hamishknight hamishknight deleted the inheritance-request branch October 31, 2019 18:07
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