[ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.

This makes it easier to understand conceptually why a ValueOwnershipKind with
Any ownership is invalid and also allowed me to explicitly document the lattice
that relates ownership constraints/value ownership kinds.
This commit is contained in:
Michael Gottesman
2020-11-10 12:51:08 -08:00
parent 1ff9147b2b
commit c026e95cce
81 changed files with 548 additions and 502 deletions

View File

@@ -906,7 +906,7 @@ getEndPointsOfDataDependentChain(SILValue value, SILFunction *fun,
/// from a guaranteed basic block parameter representing a phi node.
static Optional<BorrowedValue>
getUniqueBorrowScopeIntroducingValue(SILValue value) {
assert(value.getOwnershipKind() == ValueOwnershipKind::Guaranteed &&
assert(value.getOwnershipKind() == OwnershipKind::Guaranteed &&
"parameter must be a guarenteed value");
return getSingleBorrowIntroducingValue(value);
}
@@ -938,10 +938,10 @@ static void replaceAllUsesAndFixLifetimes(SILValue foldedVal,
}
assert(!foldedVal->getType().isTrivial(*fun));
assert(fun->hasOwnership());
assert(foldedVal.getOwnershipKind() == ValueOwnershipKind::Owned &&
assert(foldedVal.getOwnershipKind() == OwnershipKind::Owned &&
"constant value must have owned ownership kind");
if (originalVal.getOwnershipKind() == ValueOwnershipKind::Owned) {
if (originalVal.getOwnershipKind() == OwnershipKind::Owned) {
originalVal->replaceAllUsesWith(foldedVal);
// Destroy originalVal, which is now unused, immediately after its
// definition. Note that originalVal's destorys are now transferred to
@@ -959,7 +959,7 @@ static void replaceAllUsesAndFixLifetimes(SILValue foldedVal,
// Therefore, create a borrow of foldedVal at the beginning of the scope and
// use the borrow in place of the originalVal. Also, end the borrow and
// destroy foldedVal at the end of the borrow scope.
assert(originalVal.getOwnershipKind() == ValueOwnershipKind::Guaranteed);
assert(originalVal.getOwnershipKind() == OwnershipKind::Guaranteed);
Optional<BorrowedValue> originalScopeBegin =
getUniqueBorrowScopeIntroducingValue(originalVal);
@@ -1011,7 +1011,7 @@ static void substituteConstants(FoldState &foldState) {
// other hand, if we are folding an owned value, we can insert the constant
// value at the point where the owned value is defined.
SILInstruction *insertionPoint = definingInst;
if (constantSILValue.getOwnershipKind() == ValueOwnershipKind::Guaranteed) {
if (constantSILValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
Optional<BorrowedValue> borrowIntroducer =
getUniqueBorrowScopeIntroducingValue(constantSILValue);
if (!borrowIntroducer) {