Skip to content

Commit 6f40fc8

Browse files
committed
Dont diagnose lifetime dependence on BitwiseCopyable & ~Escapable type in Sema
rdar://123870480
1 parent f3a85b1 commit 6f40fc8

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lib/Sema/LifetimeDependence.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,20 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
178178
}
179179
}
180180

181-
if (ctx.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
182-
auto *bitwiseCopyableProtocol =
183-
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
184-
if (bitwiseCopyableProtocol && mod->checkConformance(type, bitwiseCopyableProtocol)) {
185-
diags.diagnose(loc, diag::lifetime_dependence_on_bitwise_copyable);
186-
return true;
181+
// Diagnose when we have lifetime dependence on a type that is
182+
// BitwiseCopyable & Escapable.
183+
// ~Escapable types are non-trivial in SIL and we should not raise this
184+
// error.
185+
// TODO: Diagnose ~Escapable types are always non-trivial in SIL.
186+
if (type->isEscapable()) {
187+
if (ctx.LangOpts.hasFeature(Feature::BitwiseCopyable)) {
188+
auto *bitwiseCopyableProtocol =
189+
ctx.getProtocol(KnownProtocolKind::BitwiseCopyable);
190+
if (bitwiseCopyableProtocol &&
191+
mod->checkConformance(type, bitwiseCopyableProtocol)) {
192+
diags.diagnose(loc, diag::lifetime_dependence_on_bitwise_copyable);
193+
return true;
194+
}
187195
}
188196
}
189197

test/Sema/explicit_lifetime_dependence_specifiers.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
// 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+
// REQUIRES: nonescapable_types
45

56
struct Container {
67
let ptr: UnsafeRawBufferPointer
78
}
89

10+
struct AnotherBufferView : ~Escapable, _BitwiseCopyable {
11+
let ptr: UnsafeRawBufferPointer
12+
@_unsafeNonescapableResult
13+
init(_ ptr: UnsafeRawBufferPointer) {
14+
self.ptr = ptr
15+
}
16+
}
17+
918
struct BufferView : ~Escapable {
1019
let ptr: UnsafeRawBufferPointer
1120
@_unsafeNonescapableResult
@@ -16,6 +25,10 @@ struct BufferView : ~Escapable {
1625
self.ptr = c.ptr
1726
return self
1827
}
28+
init(_ bv: borrowing AnotherBufferView) -> _borrow(bv) Self {
29+
self.ptr = bv.ptr
30+
return self
31+
}
1932
}
2033

2134
struct MutableBufferView : ~Escapable, ~Copyable {

0 commit comments

Comments
 (0)