Skip to content

Sema: Fix request cycle involving protocol typealiases in preparation for RequirementMachine support #41332

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
Feb 11, 2022

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Feb 11, 2022

The RequirementMachine eagerly resolves protocol typealiases while building a rewrite system. This was causing a request cycle because structural type resolution would request the generic signature of a type unnecessarily, and that generic signature could then reference the protocol itself.

Here is an example (my next PR actually adds an explicit test case, but there are a bunch of examples in the test suite already that boil down to this and fail with -requirement-machine-protocol-signatures=on):

protocol P where A == B {
  associatedtype A
  typealias B = Foo<Self>
}

struct Foo<T : P> {}

While building the requirement signature of P we resolve the structural type of B, which would previously trigger the computation of the generic signature of Foo, which would ask for the requirement signature of P. However structural type resolution doesn't check generic requirements on the bound generic type, so it need the generic signature except for in a couple of specific cases (which will still cause a cycle with an example like the above, but that's okay).

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov force-pushed the rqm-typealias-cycle-fix branch from 905831c to 6c714f4 Compare February 11, 2022 15:39
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov requested a review from CodaFi February 11, 2022 15:46
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@slavapestov slavapestov merged commit f13f3bd into swiftlang:main Feb 11, 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.

1 participant