Skip to content

Commit f5a7ef2

Browse files
authored
Merge pull request #71935 from meg-gupta/fixinference
Fix lifetime dependence inference for multi-arg functions
2 parents 20021cf + a9b1de4 commit f5a7ef2

10 files changed

+15
-23
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/Parse/explicit_lifetime_dependence_specifiers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -disable-experimental-parser-round-trip -enable-experimental-feature NoncopyableGenerics -enable-builtin-module -enable-experimental-lifetime-dependence-inference
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -disable-experimental-parser-round-trip -enable-experimental-feature NoncopyableGenerics -enable-builtin-module
22
// REQUIRES: asserts
33

44
import Builtin

test/SIL/explicit_lifetime_dependence_specifiers.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// RUN: -enable-builtin-module \
44
// RUN: -enable-experimental-feature NonescapableTypes \
55
// RUN: -disable-experimental-parser-round-trip \
6-
// RUN: -enable-experimental-feature NoncopyableGenerics \
7-
// RUN: -enable-experimental-lifetime-dependence-inference | %FileCheck %s
6+
// RUN: -enable-experimental-feature NoncopyableGenerics | %FileCheck %s
87

98

109
import Builtin

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// RUN: %target-swift-frontend %s \
22
// RUN: -emit-sil \
3-
// RUN: -enable-builtin-module \
43
// RUN: -enable-experimental-feature NonescapableTypes \
54
// RUN: -disable-experimental-parser-round-trip \
6-
// RUN: -enable-experimental-feature NoncopyableGenerics \
7-
// RUN: -enable-experimental-lifetime-dependence-inference | %FileCheck %s
5+
// RUN: -enable-experimental-feature NoncopyableGenerics | %FileCheck %s
86
// REQUIRES: asserts
97

108
struct BufferView : ~Escapable {
@@ -25,7 +23,7 @@ struct BufferView : ~Escapable {
2523
self.ptr = otherBV.ptr
2624
self.c = otherBV.c
2725
}
28-
// CHECK: sil hidden @$s28implicit_lifetime_dependence10BufferViewVyACSWYls_SaySiGhtcfC : $@convention(method) (UnsafeRawBufferPointer, @guaranteed Array<Int>, @thin BufferView.Type) -> _scope(1) @owned BufferView {
26+
// CHECK: sil hidden @$s28implicit_lifetime_dependence10BufferViewVyACSW_SaySiGhYlstcfC : $@convention(method) (UnsafeRawBufferPointer, @guaranteed Array<Int>, @thin BufferView.Type) -> _scope(2) @owned BufferView {
2927
init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array<Int>) {
3028
self.ptr = ptr
3129
self.c = a.count
@@ -126,7 +124,7 @@ struct GenericBufferView<Element> : ~Escapable {
126124
let baseAddress: Pointer
127125
let count: Int
128126

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> {
127+
// 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> {
130128
init<Storage>(baseAddress: Pointer,
131129
count: Int,
132130
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,

test/SIL/lifetime_dependence_generics.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// RUN: %target-swift-frontend %s -emit-sil \
22
// RUN: -disable-experimental-parser-round-trip \
33
// RUN: -enable-experimental-feature NonescapableTypes \
4-
// RUN: -enable-experimental-feature NoncopyableGenerics \
5-
// RUN: -enable-experimental-lifetime-dependence-inference | %FileCheck %s
4+
// RUN: -enable-experimental-feature NoncopyableGenerics | %FileCheck %s
65

76

87
protocol P {

test/SILOptimizer/lifetime_dependence_borrow_fail.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// RUN: -module-name test \
66
// RUN: -disable-experimental-parser-round-trip \
77
// RUN: -enable-experimental-feature NonescapableTypes \
8-
// RUN: -Xllvm -enable-lifetime-dependence-diagnostics \
9-
// RUN: -enable-experimental-lifetime-dependence-inference
8+
// RUN: -Xllvm -enable-lifetime-dependence-diagnostics
109

1110
// REQUIRES: asserts
1211
// REQUIRES: swift_in_compiler

test/SILOptimizer/lifetime_dependence_scope_fixup.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// RUN: %target-swift-frontend %s -emit-sil -o /dev/null -verify \
2-
// RUN: -enable-builtin-module \
32
// RUN: -enable-experimental-feature NonescapableTypes \
43
// RUN: -disable-experimental-parser-round-trip \
54
// RUN: -enable-experimental-feature NoncopyableGenerics \
6-
// RUN: -enable-experimental-lifetime-dependence-inference \
75
// RUN: -Xllvm -enable-lifetime-dependence-diagnostics=true
86

97
// REQUIRES: asserts

test/Sema/explicit_lifetime_dependence_specifiers.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -disable-experimental-parser-round-trip -enable-experimental-feature NoncopyableGenerics -enable-builtin-module -enable-experimental-feature BitwiseCopyable
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NonescapableTypes -disable-experimental-parser-round-trip -enable-experimental-feature NoncopyableGenerics -enable-experimental-feature BitwiseCopyable
22
// REQUIRES: asserts
33
// REQUIRES: noncopyable_generics
4-
import Builtin
54

65
struct Container {
76
let ptr: UnsafeRawBufferPointer

test/Serialization/implicit_lifetime_dependence.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// RUN: %target-swift-frontend -module-name lifetime-dependence -emit-silgen -I %t %s \
1010
// RUN: -enable-experimental-feature NonescapableTypes \
1111
// RUN: -disable-experimental-parser-round-trip \
12-
// RUN: -enable-experimental-feature NoncopyableGenerics \
13-
// RUN: -enable-experimental-lifetime-dependence-inference | %FileCheck %s
12+
// RUN: -enable-experimental-feature NoncopyableGenerics | %FileCheck %s
1413

1514

1615

0 commit comments

Comments
 (0)