Skip to content

[5.7] RequirementMachine: Teach concrete contraction about nested associated types #58813

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

Conversation

slavapestov
Copy link
Contributor

Cherry-pick of #58553

Concrete contraction is a hacky pre-processing pass to eliminate conformance
requirements that are made concrete; eg, if you have

<T, U where T : P, T : G<U>, U : Q>

We eliminate T : P if G<U> : P.

Generalize this to handle type parameters as well, so that

<T, U where T.X : P, T.X : G<U>, U : Q>

becomes

<T, U where T.X : G<U>, U : Q>

This fixes a regression with the test case in test/Generics/rdar91594361.swift.

Fixes rdar://problem/91594361.

Clean up the different cases by passing a 'Position' enum to
substTypeParameter().

Also generalize it to work with arbitrary type parameters instead
of generic parameters only, but leave this code path disabled
for now.
…ignature completion fails

- If P is declared to inherit from Q and Q has an associated type named U, then
  isValidTypeInContext() returns true for a type 'T.U' where 'T' is a generic
  parameter conforming to P, and 'U' is the unresolved DependentMemberType, and
  the type 'T.U' will simplify to the term 'T.[P:U]'.

- However, if completion failed while building the rewrite system for P's
  requirement signature, then the requirement signature for P won't have a
  rule [P].[Q] => [P]. As a result, getTypeForTerm() will fail when given
  'T.[P:U]', because the property map entry for 'T' will not contain a
  conformance to Q.

Work around this by manually adding protocol inheritance rules when building
a signature from a protocol whose requirement signature failed to compute.

This was triggered by the test case I added in the previous commit to
test/Generics/non_confluent.swift.
@slavapestov slavapestov requested a review from a team as a code owner May 11, 2022 02:10
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit d5ac631 into swiftlang:release/5.7 May 12, 2022
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.7 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants