Skip to content

[5.9] SILGen and SIL type lowering for vanishing tuples #64894

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 6, 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.)

5.9 version of #64887

Explanation: as above
Scope: widespread crashes in SILGen when substitution turns a tuple containing pack expansions into an underlying element
Issue: rdar://107459964 and rdar://107478603
Risk: Low; the patch touches many common code paths, but the changes are modest and should only affect code using pack expansions
Testing: Regression tests added

rjmccall added 8 commits April 4, 2023 01:17
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 rjmccall changed the base branch from main to release/5.9 April 4, 2023 05:20
@rjmccall rjmccall requested a review from a team as a code owner April 4, 2023 05:20
@rjmccall rjmccall removed request for ktoso, rintaro and hyp April 4, 2023 05:21
@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 clean test macOS

@rjmccall
Copy link
Contributor Author

rjmccall commented Apr 5, 2023

@swift-ci Please test macOS

@rjmccall
Copy link
Contributor Author

rjmccall commented Apr 5, 2023

I guess the name of the game is to just keep building until I get a non-broken builder

@rjmccall
Copy link
Contributor Author

rjmccall commented Apr 5, 2023

@swift-ci Please test macOS

@xedin xedin removed their request for review April 5, 2023 20:42
@rjmccall rjmccall merged commit 4be3c18 into swiftlang:release/5.9 Apr 6, 2023
@rjmccall rjmccall deleted the vanishing-tuple-silgen-5.9 branch April 6, 2023 02:53
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants