Sema: Fix request cycle involving protocol typealiases in preparation for RequirementMachine support #41332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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):
While building the requirement signature of
P
we resolve the structural type ofB
, which would previously trigger the computation of the generic signature ofFoo
, which would ask for the requirement signature ofP
. 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).