Skip to content

RequirementMachine: Same-type requirements imply same-shape requirements #67064

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 6 commits into from
Jul 4, 2023

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Jun 30, 2023

We want T.A == U.B to imply shape(T) == shape(U) if T (and thus U) is a parameter pack.

To do this, we introduce some new rewrite rules:

  1. For each associated type symbol [P:A], a rule ([P:A].[shape] => [P:A]).
  2. For each non-pack generic parameter τ_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 rule

t_d_i.[shape] => T_D_I.[shape]

If T is a term corresponding to some type parameter, we say that T.[shape] is a shape term. If T'.[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:

τ_d_i.[shape] => τ_D_I.[shape]

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.

@slavapestov slavapestov force-pushed the rqm-same-type-same-shape branch from 30d7326 to 5bf07c1 Compare July 3, 2023 19:23
@slavapestov slavapestov marked this pull request as ready for review July 3, 2023 19:24
@slavapestov slavapestov requested a review from hborla as a code owner July 3, 2023 19:24
We want `T.A == U.B` to imply `shape(T) == shape(U)` if T (and thus U)
is a parameter pack.

To do this, we introduce some new rewrite rules:

1) For each associated type symbol `[P:A]`, a rule `([P:A].[shape] => [P:A])`.
2) For each non-pack generic parameter `τ_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 rule

    t_d_i.[shape] => T_D_I.[shape]

If T is a term corresponding to some type parameter, we say that `T.[shape]` is
a shape term. If `T'.[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:

    τ_d_i.[shape] => τ_D_I.[shape]

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.
@slavapestov slavapestov force-pushed the rqm-same-type-same-shape branch from 5bf07c1 to e01822c Compare July 3, 2023 22:41
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 438c067 into swiftlang:main Jul 4, 2023
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