Skip to content

[ownership] Only allow BranchPropagatedUser to be constructed from Operands. #27316

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

Conversation

gottesmm
Copy link
Contributor

This commit only changes how BranchPropagatedUser is constructed and does not
change the internal representation. This is a result of my noticing that
BranchPropagatedUser could also use an operand internally to represent its
state. To simplify how I am making the change, I am splitting the change into
two PRs that should be easy to validate:

  1. A commit that maps how the various users of BranchPropagatedUser have been
    constructing BPUs to a single routine that takes an Operand. This leaves
    BranchPropagatedUser's internal state alone as well as its user the Linear
    Lifetime Checker.

  2. A second commit that changes the internal bits of the BranchPropagatedUser to
    store an Operand instead of a PointerUnion.

This will allow me to use the first commit to validate the second.


NOTE: I split off two small helper adding commits.

I need this for some refactorings I am doing around BranchPropagatedUser.

We already had ApplySite::getCallee() which just returned the value of the
operand. I refactored it to call this instead.
I am doing some refactoring on BranchPropagatedUser that is requiring me to work
a lot more with arguments and I found a need for this to avoid trafficing in
operand indices.

As part of this I also needed to write the helper getConditionOperand() to get
the underlying operand. I refactored the already preset getCondition() to use
this helper instead since it was just semantically that method + get operand's
value.
…erands.

This commit only changes how BranchPropagatedUser is constructed and does not
change the internal representation. This is a result of my noticing that
BranchPropagatedUser could also use an operand internally to represent its
state. To simplify how I am making the change, I am splitting the change into
two PRs that should be easy to validate:

1. A commit that maps how the various users of BranchPropagatedUser have been
constructing BPUs to a single routine that takes an Operand. This leaves
BranchPropagatedUser's internal state alone as well as its user the Linear
Lifetime Checker.

2. A second commit that changes the internal bits of the BranchPropagatedUser to
store an Operand instead of a PointerUnion.

This will allow me to use the first commit to validate the second.
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

Once this is done, I am going to be able to introduce a new BorrowScopeIntroducingOperand higher level construct. This is going to let me change the place I marked with HERE, to use that to add support for checking an owned value being used in a guaranteed position of begin_apply as well as add support for adding in an implicit scope for mark_dependence and a new instruction called end_mark_dependence that I am going to add once this lands.

nonLifetimeEndingUsers[i]->getUser())) {
for (auto *use : bbi->getUses()) {
if (isa<EndBorrowInst>(use->getUser())) {
implicitRegularUsers.push_back(use);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here.

@gottesmm
Copy link
Contributor Author

It should also let me add support pretty easily for adding ref_element_addr users to the verification here.

@@ -96,6 +107,19 @@ class BranchPropagatedUser {
NumLowBitsAvailable =
llvm::PointerLikeTypeTraits<InnerTy>::NumLowBitsAvailable
};

private:
BranchPropagatedUser(SILInstruction *inst) : user(inst) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are still used by some internal details of BranchPropagatedUser. I wanted to keep this commit really clean and easy to read, so I made these private rather than modifying the in-class callers.

@gottesmm
Copy link
Contributor Author

Also note, my hope is that this is a stepping stone to getting rid of BranchPropagatedUser (or at least hiding it).

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 12aa95a

@gottesmm
Copy link
Contributor Author

@swift-ci test linux platform

@atrick
Copy link
Contributor

atrick commented Sep 24, 2019

Seems fine. I don't think you need to put effort into getting rid of BranchPropagatedUser. The underlying problem goes away when cond_br args go away. I had a patch for that about a year ago but didn't get around to updating all the SIL tests. I really think I'll be able to revive that soon.

@gottesmm
Copy link
Contributor Author

@atrick I am doing this for a bigger reason. I need this to add a BorrowScopeIntroducingOperand higher level construct.

@gottesmm gottesmm merged commit 64bad16 into swiftlang:master Sep 24, 2019
@gottesmm gottesmm deleted the pr-634f227f60306a17bbad2b205f6bc0cea46541cf branch September 24, 2019 19:42
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