Skip to content
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

[silgen] Fix lifetime management of tuple elements so we don't leak #39600

Merged
merged 2 commits into from Oct 15, 2021

Conversation

gottesmm
Copy link
Member

@gottesmm gottesmm commented Oct 5, 2021

I also deleted the first fix that turned out to be incorrect.

rdar://83770295


Description: In SILGen, we were previously when initializing tuples in memory by preparing cleanups for that element and then emitting the sub-initialization, one by one. This behavior is incorrect since a sub-initialization /could/ cause an early exit meaning that any later tuple element would not have its cleanup created yet, causing us to leak along the early exit path. In an early commit (the one being reverted in this PR), I tried to work around this by introducing a new scope+some fancy stuff around using persistently active that didn't work out. In the non-revert commit I fix the actual issue by just setting up all of the tuple elements before I emit the sub-initializations.
Risk: Low, doesn't touch scopes. Just sets up cleanups before we run sub-initializations of tuples.
Review by: @atrick
Testing: Ran/added compiler tests.
Radar: rdar://83770295

…re paths when initializing sub-tuple patterns"

This reverts commit be922b9.

By adding some extra scopes here we are triggering some broken behavior in a
bunch of projects. I am going to see if I can do another fix for this. That
being said in the short term, we are reverting to unblock those projects.

rdar://83770295
(cherry picked from commit 49bc96d)
… elts and then perform sub-initialization.

Previsouly we were evaluating a tuple elt and then performing the relevant
sub-initialization. The problem is that a sub-initialization can invoke code
that could perform an early exit cleanup. So any later tuple-elements that may
need to be cleaned up along such path will not have had their cleanups
initialized, resulting in a leak along such paths.

With this commit, we instead evaluate all of the tuple elements and only them
perform the sub-initialization ensuring that any early exits clean up all of the
tuple elements.

rdar://83770295
(cherry picked from commit f641808)
@gottesmm gottesmm requested a review from atrick October 5, 2021 23:05
@gottesmm gottesmm requested a review from a team as a code owner October 5, 2021 23:05
@gottesmm
Copy link
Member Author

gottesmm commented Oct 5, 2021

@swift-ci test

Copy link
Member

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed for CCC

@gottesmm
Copy link
Member Author

gottesmm commented Oct 8, 2021

@swift-ci nominate

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.

None yet

3 participants