Skip to content

SILGen and SIL type lowering support for vanishing tuples #64887

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 8 commits into from
Apr 4, 2023

Conversation

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Apr 4, 2023

The language says that ( type-tuple-body ) is a tuple type only if type-tuple-body is not a single non-expansion component; otherwise it is merely parentheses. We follow this same idea in substitution: substitution of type parameter packs can change the number of components in a tuple, and the result is no longer a tuple if there is a single non-expansion component. These "vanishing" tuples pose an annoyance for the lowering of types and expressions: lowering must often consider the unsubstituted type of declarations (the "abstraction pattern"), and it has historically been true that the substituted type will be a tuple if the unsubstituted type is. There is therefore quite a bit of code in lowering that assumes that e.g. it can check whether the substituted type is a tuple before it checks the unsubstituted type. This code must be fixed to be primarily driven by the unsubstituted type. (The original tuple structure is usually very significant! For example, if we take a formal parameter of type (Int, repeat each T), we will actually have two lowered parameters, one of which completely disappears from the substituted type if T is substituted with an empty pack.)

rjmccall added 8 commits April 3, 2023 23:04
AbstractionPattern.

The old logic was wrong for vanishing tuples: a non-tuple substituted
type might correspond to multiple lowered parameters if it's the result
of substituting into a vanishing tuple that also contains empty pack
expansions.

Test to follow later in this PR.
Fixes a host of problems with stored type members with types dependent
on a type parameter pack; I ran into it specifically with vanishing
tuples.

Test to follow.
Fixes rdar://107459964 and rdar://107478603.
@rjmccall
Copy link
Contributor Author

rjmccall commented Apr 4, 2023

@swift-ci Please test

@rjmccall
Copy link
Contributor Author

rjmccall commented Apr 4, 2023

@swift-ci Please test

@rjmccall rjmccall merged commit 9c9671b into swiftlang:main Apr 4, 2023
@rjmccall rjmccall deleted the vanishing-tuple-silgen branch April 4, 2023 16:41
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