Skip to content

Fix lifetime inference with older .swiftinterface files. #80156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AST/LifetimeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class LifetimeDependenceChecker {
// TODO: remove this check once all compilers that are rev-locked to the
// stdlib print the 'copy' dependence kind in the interface (Aug '25)
if (auto *sf = afd->getParentSourceFile()) {
if (sf->Kind == SourceFileKind::SIL) {
if (sf->Kind == SourceFileKind::Interface) {
return true;
}
}
Expand Down Expand Up @@ -971,7 +971,7 @@ class LifetimeDependenceChecker {

// Infer a mutating accessor's non-Escapable 'self' dependencies.
void inferMutatingAccessor(AccessorDecl *accessor) {
if (!isImplicitOrSIL()) {
if (!isImplicitOrSIL() && !useLazyInference()) {
// Explicit setters require explicit lifetime dependencies.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/SIL/Parser/lifetime_dependence.sil
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct BufferView : ~Escapable {
@lifetime(borrow x)
func derive(_ x: borrowing BufferView) -> BufferView

@lifetime(x)
@lifetime(copy x)
func consumeAndCreate(_ x: consuming BufferView) -> BufferView

sil hidden [unsafe_nonescapable_result] @bufferviewinit1 : $@convention(method) (UnsafeRawBufferPointer, @thin BufferView.Type) -> @owned BufferView {
Expand Down
10 changes: 4 additions & 6 deletions test/Sema/lifetime_depend_infer.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// RUN: %target-swift-frontend %s -emit-sil \
// RUN: -o /dev/null \
// RUN: -verify \
// RUN: -sil-verify-all \
// RUN: -module-name test \
// RUN: %target-typecheck-verify-swift \
// RUN: -enable-experimental-feature LifetimeDependence

// REQUIRES: swift_feature_LifetimeDependence
Expand Down Expand Up @@ -312,7 +308,9 @@ struct NonescapableSelfAccessors: ~Escapable {
var ne: NE

@lifetime(immortal)
init() {}
init() {
ne = NE()
}

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