Skip to content

Commit 55153ce

Browse files
committed
Fix lifetime dependence inference for multi-arg functions
1 parent 0fc2e13 commit 55153ce

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/Sema/LifetimeDependence.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/ParameterList.h"
1919
#include "swift/AST/Type.h"
2020
#include "swift/AST/TypeRepr.h"
21+
#include "swift/Basic/Defer.h"
2122

2223
namespace swift {
2324
std::string LifetimeDependenceInfo::getString() const {
@@ -327,6 +328,9 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
327328
unsigned paramIndex = 0;
328329
bool hasParamError = false;
329330
for (auto *param : *afd->getParameters()) {
331+
SWIFT_DEFER {
332+
paramIndex++;
333+
};
330334
Type paramTypeInContext =
331335
afd->mapTypeIntoContext(param->getInterfaceType());
332336

@@ -351,8 +355,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
351355
candidateParam = param;
352356
lifetimeDependenceInfo = LifetimeDependenceInfo::getForParamIndex(
353357
afd, paramIndex + 1, param->getValueOwnership());
354-
355-
paramIndex++;
356358
}
357359
if (cd && cd->isImplicit()) {
358360
diags.diagnose(cd->getLoc(),

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct BufferView : ~Escapable {
2525
self.ptr = otherBV.ptr
2626
self.c = otherBV.c
2727
}
28-
// CHECK: sil hidden @$s28implicit_lifetime_dependence10BufferViewVyACSWYls_SaySiGhtcfC : $@convention(method) (UnsafeRawBufferPointer, @guaranteed Array<Int>, @thin BufferView.Type) -> _scope(1) @owned BufferView {
28+
// CHECK: sil hidden @$s28implicit_lifetime_dependence10BufferViewVyACSW_SaySiGhYlstcfC : $@convention(method) (UnsafeRawBufferPointer, @guaranteed Array<Int>, @thin BufferView.Type) -> _scope(2) @owned BufferView {
2929
init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array<Int>) {
3030
self.ptr = ptr
3131
self.c = a.count
@@ -126,7 +126,7 @@ struct GenericBufferView<Element> : ~Escapable {
126126
let baseAddress: Pointer
127127
let count: Int
128128

129-
// CHECK: sil hidden @$s28implicit_lifetime_dependence17GenericBufferViewV11baseAddress5count9dependsOnACyxGSVYls_Siqd__htclufC : $@convention(method) <Element><Storage> (UnsafeRawPointer, Int, @in_guaranteed Storage, @thin GenericBufferView<Element>.Type) -> _scope(1) @owned GenericBufferView<Element> {
129+
// CHECK: sil hidden @$s28implicit_lifetime_dependence17GenericBufferViewV11baseAddress5count9dependsOnACyxGSV_Siqd__hYlstclufC : $@convention(method) <Element><Storage> (UnsafeRawPointer, Int, @in_guaranteed Storage, @thin GenericBufferView<Element>.Type) -> _scope(3) @owned GenericBufferView<Element> {
130130
init<Storage>(baseAddress: Pointer,
131131
count: Int,
132132
dependsOn: borrowing Storage) {

test/SIL/lifetime_dependence_buffer_view_test.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// RUN: -disable-experimental-parser-round-trip \
33
// RUN: -enable-experimental-feature NonescapableTypes \
44
// RUN: -enable-experimental-feature NoncopyableGenerics \
5-
// RUN: -enable-experimental-lifetime-dependence-inference \
6-
// RUN: -Xllvm -enable-lifetime-dependence-diagnostics
5+
// RUN: -enable-experimental-lifetime-dependence-inference
76

87
// REQUIRES: asserts
98
// REQUIRES: swift_in_compiler
@@ -62,7 +61,7 @@ public struct BufferView<Element> : ~Escapable {
6261
let start: BufferViewIndex<Element>
6362
public let count: Int
6463
private var baseAddress: UnsafeRawPointer { start._rawValue }
65-
64+
// TODO: Enable diagnostics once this initializer's store to temporary is handled
6665
// CHECK: sil @$s31lifetime_dependence_scope_fixup10BufferViewV11baseAddress5count9dependsOnACyxGSVYls_Siqd__htclufC : $@convention(method) <Element><Owner> (UnsafeRawPointer, Int, @in_guaranteed Owner, @thin BufferView<Element>.Type) -> _scope(1) @owned BufferView<Element> {
6766
public init<Owner>(
6867
baseAddress: UnsafeRawPointer,

0 commit comments

Comments
 (0)