Skip to content

Commit 44b0d5d

Browse files
authored
Merge pull request #80156 from atrick/fix-interface
Fix lifetime inference with older .swiftinterface files.
2 parents 1ba7b6a + 8895224 commit 44b0d5d

File tree

6 files changed

+464
-20
lines changed

6 files changed

+464
-20
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class LifetimeDependenceChecker {
334334
// TODO: remove this check once all compilers that are rev-locked to the
335335
// stdlib print the 'copy' dependence kind in the interface (Aug '25)
336336
if (auto *sf = afd->getParentSourceFile()) {
337-
if (sf->Kind == SourceFileKind::SIL) {
337+
if (sf->Kind == SourceFileKind::Interface) {
338338
return true;
339339
}
340340
}
@@ -971,7 +971,7 @@ class LifetimeDependenceChecker {
971971

972972
// Infer a mutating accessor's non-Escapable 'self' dependencies.
973973
void inferMutatingAccessor(AccessorDecl *accessor) {
974-
if (!isImplicitOrSIL()) {
974+
if (!isImplicitOrSIL() && !useLazyInference()) {
975975
// Explicit setters require explicit lifetime dependencies.
976976
return;
977977
}

test/SIL/Parser/lifetime_dependence.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct BufferView : ~Escapable {
1818
@lifetime(borrow x)
1919
func derive(_ x: borrowing BufferView) -> BufferView
2020

21-
@lifetime(x)
21+
@lifetime(copy x)
2222
func consumeAndCreate(_ x: consuming BufferView) -> BufferView
2323

2424
sil hidden [unsafe_nonescapable_result] @bufferviewinit1 : $@convention(method) (UnsafeRawBufferPointer, @thin BufferView.Type) -> @owned BufferView {

test/Sema/lifetime_depend_infer.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// RUN: %target-swift-frontend %s -emit-sil \
2-
// RUN: -o /dev/null \
3-
// RUN: -verify \
4-
// RUN: -sil-verify-all \
5-
// RUN: -module-name test \
1+
// RUN: %target-typecheck-verify-swift \
62
// RUN: -enable-experimental-feature LifetimeDependence
73

84
// REQUIRES: swift_feature_LifetimeDependence
@@ -312,7 +308,9 @@ struct NonescapableSelfAccessors: ~Escapable {
312308
var ne: NE
313309

314310
@lifetime(immortal)
315-
init() {}
311+
init() {
312+
ne = NE()
313+
}
316314

317315
var neComputed: NE {
318316
get { // expected-error{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@lifetime(borrow self)' or '@lifetime(copy self)'}}

0 commit comments

Comments
 (0)