Skip to content

Commit 9544a00

Browse files
authored
Merge pull request #19774 from gottesmm/pr-067f98271f9149a6bef29983356763a2ed07c177
[ownership] Accept @owned partial apply in callee_guaranteed context.
2 parents 4f23442 + 2a6e6b0 commit 9544a00

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,12 @@ OperandOwnershipKindMap OperandOwnershipKindClassifier::visitCallee(
844844
if (substCalleeType->isNoEscape())
845845
return Map::compatibilityMap(ValueOwnershipKind::Trivial,
846846
UseLifetimeConstraint::MustBeLive);
847-
return Map::compatibilityMap(ValueOwnershipKind::Guaranteed,
848-
UseLifetimeConstraint::MustBeLive);
847+
// We want to accept guaranteed/owned in this position since we
848+
// treat the use of an owned parameter as an instantaneously
849+
// borrowed value for the duration of the call.
850+
return Map::compatibilityMap(
851+
{{ValueOwnershipKind::Guaranteed, UseLifetimeConstraint::MustBeLive},
852+
{ValueOwnershipKind::Owned, UseLifetimeConstraint::MustBeLive}});
849853
}
850854

851855
llvm_unreachable("Unhandled ParameterConvention in switch.");

test/SIL/ownership-verifier/use_verifier.sil

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,3 +1112,15 @@ bb0k(%0 : @owned $Builtin.NativeObject):
11121112
return %9999 : $()
11131113
}
11141114

1115+
sil @owned_partial_apply_used_as_callee_guaranteed : $@convention(thin) () -> () {
1116+
bb0:
1117+
%0 = function_ref @allocate_object : $@convention(thin) () -> @owned Builtin.NativeObject
1118+
%1 = partial_apply %0() : $@convention(thin) () -> @owned Builtin.NativeObject
1119+
%2 = convert_function %1 : $@callee_owned () -> @owned Builtin.NativeObject to $@callee_guaranteed () -> @owned Builtin.NativeObject
1120+
%3 = apply %2() : $@callee_guaranteed () -> @owned Builtin.NativeObject
1121+
destroy_value %3 : $Builtin.NativeObject
1122+
destroy_value %2 : $@callee_guaranteed () -> @owned Builtin.NativeObject
1123+
%9999 = tuple()
1124+
return %9999 : $()
1125+
}
1126+

0 commit comments

Comments
 (0)