Some More Additional ManagedValue APIs #6836
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains two additional groups of new APIs for ManagedValue that allow for ownership invariants to be enforced via asserts.
ManagedValue transform(SILValue) &&;
The first patch contains a new method called transform. The key thing to notice is that it can only be called on RValue references, yet it returns a new ManagedValue. The reason for this is that transform is meant to "forward" a cleanup/transform and then destroy the original ManagedValue. This transformation happens in a bunch of places in SILGen. In most of these cases, the original cleanup is passed forward. I believe that in a SemanticARC world this will no longer be correct since in most cases where one is performing forwarding, one wants the destroy_value to occur on the newly forwarded value. In a future patch I may put the code into transform that enables the old cleanup to be destroyed and the new cleanup to be placed on the "transformed" ManagedValue.
Specific static constructor with asserts
The next patch adds new static constructors that create ManagedValues with specific semantics. There are asserts in each one of these to ensure that the relevant semantics are being followed. An example of this is the class method,
This first verifies that the given SILValue exists, that that
v.getOwnershipKind()
is Owned, before finally creating the ManagedValue.rdar://29791263