Skip to content
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

RequirementMachine: Fix request evaluator cycle if a typealias requirement becomes redundant #42043

Merged
merged 2 commits into from Mar 27, 2022

Conversation

slavapestov
Copy link
Member

@slavapestov slavapestov commented Mar 26, 2022

If a typealias introduces a same-type requirement that is redundant (see the test case), we would produce a diagnostic with a sugared TypeAliasType. The diagnostic engine would call getUnderlyingType() on this typealias, which triggers computing the requirement signature of the protocol we're currently diagnosing redundancies for.

This sort of thing is a fundamental problem with our diagnostics engine, but we can re-arrange things a little to avoid this scenario in this test case at least, by unwrapping the TypeAliasType when introducing implied same-type requirements from protocol typealiases.

…tingTypealias()

Diagnostics are emitted from weird places sometimes, and as a result the emission
is fragile for two reasons:

- Kicking off requests can trigger cycles
- Doing anything that can re-entrantly diagnose something else might crash

In this case, the problem is getUnderlyingType(), which might kick off type
resolution on the typealias. Since we already have a Type, just check that
instead of getting a new one.
A protocol typealias 'typealias T = X' introduces a same-type requirement
'Self.T == Self.X'. However the right hand side of the requirement was
wrapped in a sugared TypeAliasType.

This meant if the requirement surfaced in a redundancy diagnostic, it
would print as 'Self.T == Self.T'. It could also trigger a request cycle
via isInterestingTypealias() in DiagnosticEngine.cpp.
@slavapestov slavapestov requested a review from hborla March 26, 2022 23:07
Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

Thank you!

@slavapestov
Copy link
Member Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 7fccd25 into apple:main Mar 27, 2022
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.

None yet

2 participants