diff --git a/lib/AST/FeatureSet.cpp b/lib/AST/FeatureSet.cpp index d1b0fc4936a..cc63e5296e9 100644 --- a/lib/AST/FeatureSet.cpp +++ b/lib/AST/FeatureSet.cpp @@ -254,13 +254,15 @@ static bool usesFeatureLifetimeDependence(Decl *decl) { if (decl->getAttrs().hasAttribute()) { return true; } - auto *afd = dyn_cast(decl); - if (!afd) { - return false; - } - return afd->getInterfaceType() + if (auto *afd = dyn_cast(decl)) { + return afd->getInterfaceType() ->getAs() ->hasLifetimeDependencies(); + } + if (auto *varDecl = dyn_cast(decl)) { + return !varDecl->getTypeInContext()->isEscapable(); + } + return false; } UNINTERESTING_FEATURE(DynamicActorIsolation) diff --git a/test/ModuleInterface/Inputs/lifetime_dependence.swift b/test/ModuleInterface/Inputs/lifetime_dependence.swift index 9214b151695..418724522f5 100644 --- a/test/ModuleInterface/Inputs/lifetime_dependence.swift +++ b/test/ModuleInterface/Inputs/lifetime_dependence.swift @@ -54,3 +54,24 @@ public func deriveThisOrThat(_ this: consuming BufferView, _ that: consuming Buf return BufferView(that._ptr, that._count) } +@_unsafeNonescapableResult +@_transparent +@lifetime(borrow source) +internal func _overrideLifetime( + _ dependent: consuming T, borrowing source: borrowing U) -> T { + dependent +} + +public struct Container { + var buffer: UnsafeRawBufferPointer + var object: AnyObject +} + +extension Container { + public var storage: BufferView { + get { + let view = BufferView(buffer, 1) + return _overrideLifetime(view, borrowing: self) + } + } +} diff --git a/test/ModuleInterface/lifetime_dependence_test.swift b/test/ModuleInterface/lifetime_dependence_test.swift index ca2673dd48f..0813c15ade3 100644 --- a/test/ModuleInterface/lifetime_dependence_test.swift +++ b/test/ModuleInterface/lifetime_dependence_test.swift @@ -35,3 +35,9 @@ import lifetime_dependence // CHECK: @lifetime(this, that) // CHECK-NEXT: @inlinable public func deriveThisOrThat(_ this: consuming lifetime_dependence.BufferView, _ that: consuming lifetime_dependence.BufferView) -> lifetime_dependence.BufferView { + +// Check that an implicitly dependent variable accessor is guarded by LifetimeDependence. +// +// CHECK: extension lifetime_dependence.Container { +// CHECK-NEXT: #if compiler(>=5.3) && $NonescapableTypes && $LifetimeDependence +// CHECK-NEXT: public var storage: lifetime_dependence.BufferView {