Skip to content

More errors instead of crashes for conditional conformances that are invalid or involve hard-to-resolve recursion #17356

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 3 commits into from
Jun 21, 2018

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Jun 20, 2018

Two cases go from being a crash to being a more explanatory error with locations etc.:

This doesn't fix the recursion itself. It also doesn't use the request evaluator, because I want to put this into the 4.2 branch.

@huonw huonw requested a review from DougGregor June 20, 2018 13:23
@huonw huonw force-pushed the lazier-conditional-requirements branch 2 times, most recently from 969ac4b to c29c6d5 Compare June 20, 2018 13:30
@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Jun 20, 2018

So you now guard against conditional requirements not being computed in the conformance logic.


protocol P {}
struct A<C> {}
extension A: P where A: P {} // expected-error {{requirement involves recursion that is not currently supported}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this ever be supported or make sense? I think the existing does not refer to gen param or assoc type is more appropriate and expressive in these cases.

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 don't think this particular form of tautological recursion makes sense, and I agree that that error message you quote gets to the fundamental error. I do however want to land this to stop the crashers since they come up so often, and then we can hammer on making the exact error messages perfect after that. I'll file a JIRA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

LGTM. Eager to see the request-evaluator version as well :)

@@ -2926,10 +2926,16 @@ static void dumpProtocolConformanceRec(
}
}

for (auto requirement : normal->getConditionalRequirements()) {
if (auto condReqs = normal->getConditionalRequirementsIfAvailable()) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. It's unfortunate that the dumper can modify state here by triggering the computation of conditional requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stopped the mutation in these cases.

@@ -2957,10 +2963,15 @@ static void dumpProtocolConformanceRec(
SubstitutionMap::DumpStyle::Full, indent + 2,
visited);
out << '\n';
for (auto subReq : conf->getConditionalRequirements()) {
if (auto condReqs = conf->getConditionalRequirementsIfAvailable()) {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about dumping mutating state.

huonw added 2 commits June 21, 2018 10:53
This doesn't fix the fundamental problem of correctly handling such cases, but
it is better than the "error message" that occurred previously:

    Assertion failed: ((bool)typeSig == (bool)extensionSig && "unexpected generic-ness mismatch on conformance").

Fixes the crash rdar://problem/41281406 (that in
https://bugs.swift.org/browse/SR-6569 (rdar://problem/36068136)),
https://bugs.swift.org/browse/SR-8019 (rdar://problem/41216423) and
https://bugs.swift.org/browse/SR-7989 (rdar://problem/41126254).
…n error cases.

When we're trying to diagnose something, it's a bad look if we crash
instead. This changes the bad-associated-type recovery path to not require that
the conditional requirements have been computed, and instead detects that as a
possible error.

Fixes https://bugs.swift.org/browse/SR-8033.
@huonw huonw force-pushed the lazier-conditional-requirements branch from c29c6d5 to a21a779 Compare June 21, 2018 00:53
@huonw
Copy link
Contributor Author

huonw commented Jun 21, 2018

@swift-ci please smoke test

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