Skip to content

Commit 9eb717a

Browse files
committed
[ownership] Ban ownership constraints with preferredKind OwnershipKind::Unowned.
It used to be that we had certain instructions that could only have operands with OwnershipKind::{None,Unowned}. This changed with the addition of OperandOwnership which caused us to begin accepting owned and guaranteed in all positions where we accept unowned values with the proviso that certain forwarding instructions are now allowed to force their result to be unowned even though their argument is owned or guaranteed. This setup massively simplifies RAUWing values in OSSA by eliminating the need to insert conversion unchecked_ownership_conversion instructions from owned->unowned when replacing an unowned value with an owned or guaranteed value. Now, these uses can just take the owned or guaranteed value directly and we wish to maintain that property. Thus we are banning it in SIL by writing a verifier check.
1 parent cf4f47b commit 9eb717a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,18 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11331133
UseLifetimeConstraint::NonLifetimeEnding,
11341134
"In non-ossa all non-type dependent operands must have a "
11351135
"constraint of Any, NonLifetimeEnding");
1136+
} else {
1137+
// Perform some structural checks on the operand if we have ownership.
1138+
1139+
// Make sure that our operand constraint isn't Unowned. There do not
1140+
// exist in SIL today any instructions that require an Unowned
1141+
// value. This is because we want to always allow for guaranteed and
1142+
// owned values to be passed as values to operands that take unowned.
1143+
auto constraint = operand.getOwnershipConstraint();
1144+
require(constraint.getPreferredKind() != OwnershipKind::Unowned,
1145+
"Operand constraint should never have an unowned preferred "
1146+
"kind since guaranteed and owned values can always be passed "
1147+
"in unowned positions");
11361148
}
11371149
}
11381150

0 commit comments

Comments
 (0)