Skip to content

[ownership] Eliminate OperandOwnershipKindMap in favor of OwnershipConstraint #34683

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

I also used this as a moment to clarify the lattice that related
ValueOwnershipKind and OwnershipConstraint.

@gottesmm gottesmm requested a review from atrick November 11, 2020 03:03
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm force-pushed the pr-d6205adb8f293c5e7c3fad8419163cc936cc4adc branch from bde8a62 to f46d5a9 Compare November 11, 2020 03:06
@gottesmm
Copy link
Contributor Author

@swift-ci test

…nstraint.

I also used this as a moment to clarify the lattice that related
ValueOwnershipKind and OwnershipConstraint.
@gottesmm gottesmm force-pushed the pr-d6205adb8f293c5e7c3fad8419163cc936cc4adc branch from f46d5a9 to a294ab6 Compare November 11, 2020 03:07
@gottesmm
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@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.

🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉

I commented on a few things that are still somewhat baroque.

bool Operand::isLifetimeEnding() const {
auto constraint = getOwnershipConstraint();

// If we got back none, then our operand is for a type dependent operand. So
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify none means Optional::None

Comment on lines +364 to +367
// Otherwise, we may have a lifetime ending use. If we narrowed to None then
// we have a non lifetime ending use, otherwise we still have a lifetime
// ending use. If our value was not None, then obviously narrowing didn't
// happen.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment talks about "narrowing", but I don't know what's being narrowed or where it's being narrowed.

// Otherwise, narrowing only happened if our ownership constraint did not have
// an OwnershipKind of None, but we disallow that in any case, so we can just
// unconditionally return false.
assert(constraint->getPreferredKind() != OwnershipKind::None &&
Copy link
Contributor

Choose a reason for hiding this comment

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

assert(constraint->getPreferredKind() != OwnershipKind::None
I don't know how this assert is different than simply saying
constraint->isSatisfiedBy(get().getOwnershipKind())
which is always verified anyway. Why not just

// A trivial value can never have its lifetime ended.
return get().getOwnershipKind() != OwnershipKind::None

?

"Adding kind twice to the map with different constraints?!");
data[kindOffset] = true;
data[constraintOffset] = bool(constraint);
static OwnershipConstraint anyValueAcceptingConstraint() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a lot of difficulty parsing names like this and attempting to sort out their meaning. It accepts any value? Obviously not. "Constraint" is already in the type name, so why is it repeated?

Whereas if it were simply any() or even unconstrained() I would immediately know what that means.

I would also know what "acceptsAnyOwnership" means, so that would be ok. It's still unnecessarily verbose because constraints always imply acceptance and Ownership is already in the name.

Starting from a minimal recognizable name, before adding any more words, the question should be "how could any reasonable person be misled by the shorter name, and how would adding more words fix that problem without creating more confusion"?

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 think that any works well.

@gottesmm
Copy link
Contributor Author

I'll fix the issues you mentioned in a follow on commit.

@gottesmm gottesmm merged commit cd9218c into swiftlang:main Nov 11, 2020
@gottesmm gottesmm deleted the pr-d6205adb8f293c5e7c3fad8419163cc936cc4adc branch November 11, 2020 06:32
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.

2 participants