Skip to content

Commit 455a3d5

Browse files
committed
Enable lifetime dependence inference on parameters with just ownership modifiers
1 parent 16e9902 commit 455a3d5

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lib/Sema/LifetimeDependence.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,21 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
293293
if (param->getValueOwnership() == ValueOwnership::Default) {
294294
continue;
295295
}
296+
if (param->getValueOwnership() == ValueOwnership::Owned &&
297+
paramTypeInContext->isEscapable()) {
298+
continue;
299+
}
296300

297-
if (!paramTypeInContext->isEscapable() ||
298-
paramTypeInContext->isNoncopyable()) {
299-
if (candidateParam) {
300-
diags.diagnose(
301-
returnLoc,
302-
diag::lifetime_dependence_cannot_infer_wo_ambiguous_candidate);
303-
return llvm::None;
304-
}
305-
candidateParam = param;
306-
lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex(
307-
afd, paramIndex + 1, param->getValueOwnership());
301+
if (candidateParam) {
302+
diags.diagnose(
303+
returnLoc,
304+
diag::lifetime_dependence_cannot_infer_ambiguous_candidate);
305+
return llvm::None;
308306
}
307+
candidateParam = param;
308+
lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex(
309+
afd, paramIndex + 1, param->getValueOwnership());
310+
309311
paramIndex++;
310312
}
311313
if (!candidateParam && !hasParamError) {

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ struct BufferView : ~Escapable {
2424
init(_ otherBV: consuming BufferView) {
2525
self.ptr = otherBV.ptr
2626
}
27+
// CHECK: sil hidden @$s28implicit_lifetime_dependence10BufferViewVyACSW_SaySiGhtcfC : $@convention(method) (UnsafeRawBufferPointer, @guaranteed Array<Int>, @thin BufferView.Type) -> _scope(1) @owned BufferView {
28+
init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array<Int>) {
29+
self.ptr = ptr
30+
}
2731
}
2832

2933
struct MutableBufferView : ~Escapable, ~Copyable {

0 commit comments

Comments
 (0)