Skip to content

[silgen] Teach CleanupCloner how to handle OwnedValueWritebackCleanups correctly. #31898

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

Conversation

gottesmm
Copy link
Contributor

Previously we would just forward the cleanup and create a normal "destroy"
cleanup resulting in early deallocation and use after frees along error paths.

As part of this I also had to tweak how DI recognizes self init writebacks to
not use SILLocations. This is approach is more robust (since we aren't relying
on SourceLocs/have verifiers to make sure we don't violate SIL) and also avoids
issues from the write back store not necessarily have the same SILLocation.

rdar://problem/59830255

@gottesmm gottesmm requested review from jckarter and slavapestov May 19, 2020 22:19
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci asan test

@gottesmm
Copy link
Contributor Author

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

I am not sure if all of the testing is necessary, but given that I am changing DI here I just want to be careful out of an abundance of caution.

@gottesmm
Copy link
Contributor Author

This also creates the infrastructure necessary to fix the Formal vs Lexical cleanup mixup issues as well. I just didn't want to fix that here. That should be in a different PR.

@@ -785,6 +785,7 @@ void LifetimeChecker::doIt() {
break;
case DIUseKind::LoadForTypeOfSelf:
handleLoadForTypeOfSelfUse(Use);
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't this actually effected anything since this is the last entry in the switch, but I saw this so I just wanted to handle it quickly just to prevent future bugs.

@gottesmm
Copy link
Contributor Author

@swift-ci Please Test Source Compatibility Release

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9f8bcd73a3268eaf9b0154c5d63dbf9d345f888b

…s correctly.

Previously we would just forward the cleanup and create a normal "destroy"
cleanup resulting in early deallocation and use after frees along error paths.

As part of this I also had to tweak how DI recognizes self init writebacks to
not use SILLocations. This is approach is more robust (since we aren't relying
on SourceLocs/have verifiers to make sure we don't violate SIL) and also avoids
issues from the write back store not necessarily have the same SILLocation.

<rdar://problem/59830255>
@gottesmm gottesmm force-pushed the pr-40f1eb4aa2e642a971e6af034157dc9e8c1b31cf branch from 9f8bcd7 to f57a6cf Compare May 19, 2020 23:15
@gottesmm
Copy link
Contributor Author

@swift-ci test

4 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9f8bcd73a3268eaf9b0154c5d63dbf9d345f888b

@gottesmm
Copy link
Contributor Author

@swift-ci test windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - f57a6cf

@gottesmm
Copy link
Contributor Author

@swift-ci test OS X platform

@gottesmm
Copy link
Contributor Author

@swift-ci asan

@gottesmm
Copy link
Contributor Author

@swift-ci test source compatibility

1 similar comment
@gottesmm
Copy link
Contributor Author

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

@swift-ci asan

@gottesmm
Copy link
Contributor Author

Debug failed due to failure to clone from GitHub.

@gottesmm
Copy link
Contributor Author

@swift-ci Please Test Source Compatibility Debug

@gottesmm
Copy link
Contributor Author

The one debug test that failed failed due to some weird configuration issue in the project. The compiler didn't crash.

// This is to handle situations where we do not actually consume self as a
// result of situations such as:
//
// 1. The usage of a metatype to allocate the object.
Copy link
Contributor

@jckarter jckarter May 20, 2020

Choose a reason for hiding this comment

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

Using a dynamic metatype value shouldn't by itself change how we consume the original self value, because that doesn't change the ownership semantics of the init. Is that really what's going on here? I trust that it's doing the right thing, because the tests look reasonably comprehensive, but this comment is confusing. What is the actual difference in SIL generation between swift 5 dynamic self and swift 4 mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was here also for swift 4 mode. It is not related to the current change directly. What happens here is that we do a load [take] to get the metatype. The meta type is used to call a factory init that produces the actual value we care about and then we need to store back the partially initialized value so it can be destroyed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically, this comment used to be:

    // If this load's value is being stored back into the delegating                                                                     
    // mark_uninitialized buffer and it is a self init use, skip the                                                                     
    // use. This is to handle situations where due to usage of a metatype to                                                             
    // allocate, we do not actually consume self. 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I explained offline to JoeG this in person. He is fine with the explanation.

@gottesmm gottesmm merged commit b8c74b4 into swiftlang:master May 21, 2020
@gottesmm gottesmm deleted the pr-40f1eb4aa2e642a971e6af034157dc9e8c1b31cf branch May 21, 2020 18:02
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.

3 participants