Skip to content

RequirementMachine: Teach concrete contraction about nested associated types #58553

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

@slavapestov slavapestov commented Apr 30, 2022

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.

@slavapestov slavapestov changed the title RequirementMachine: Teach concrete contraction about nested associate… RequirementMachine: Teach concrete contraction about nested associated types Apr 30, 2022
@slavapestov slavapestov force-pushed the rqm-concrete-contraction-type-parameters branch from b2769c1 to 5e8df62 Compare April 30, 2022 05:08
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

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 force-pushed the rqm-concrete-contraction-type-parameters branch from 5e8df62 to ae56af3 Compare May 10, 2022 01:24
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@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.

1 participant