RequirementMachine: Same-type requirements imply same-shape requirements #67064
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.
We want
T.A == U.B
to implyshape(T) == shape(U)
if T (and thus U) is a parameter pack.To do this, we introduce some new rewrite rules:
[P:A]
, a rule([P:A].[shape] => [P:A])
.τ_d_i
, a ruleτ_d_i.[shape] => [shape]
.Now consider a rewrite rule
(τ_d_i.[P:A] => τ_D_I.[Q:B])
. The left-hand side overlaps with the rule([P:A].[shape] => [shape])
on the termτ_d_i.[P:A].[shape]
. Resolving the overlap gives us a new ruleIf T is a term corresponding to some type parameter, we say that
T.[shape]
is a shape term. IfT'.[shape]
is a reduced term, we say that T' is the reduced shape of T.Recall that shape requirements are represented as rules of the form:
Now, the rules of the first kind reduce our shape term
T.[shape]
toτ_d_i.[shape]
, whereτ_d_i
is the root generic parameter of T.If
τ_d_i
is not a pack, a rule of the second kind reduces it to[shape]
, so the reduced shape of a non-pack parameter T is the empty term.Otherwise, if
τ_d_i
is a pack,τ_d_i.[shape]
might reduce toτ_D_I.[shape]
via a shape requirement. In this case,τ_D_I
is the reduced shape of T.Fixes rdar://problem/101813873.