Skip to content

Commit afdd141

Browse files
committed
Ban lifetime dependence specifiers on tuple result
1 parent 68e3488 commit afdd141

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7849,6 +7849,8 @@ ERROR(lifetime_dependence_cannot_infer_implicit_init, none,
78497849
"cannot infer lifetime dependence on implicit initializer of ~Escapable"
78507850
" type, define an initializer with explicit lifetime dependence"
78517851
" specifiers", ())
7852+
ERROR(lifetime_dependence_cannot_be_applied_to_tuple_elt, none,
7853+
"lifetime dependence specifiers cannot be applied to tuple elements", ())
78527854

78537855
//===----------------------------------------------------------------------===//
78547856
// MARK: Transferring

lib/Sema/TypeCheckType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,6 +5048,11 @@ TypeResolver::resolveResultDependsOnTypeRepr(ResultDependsOnTypeRepr *repr,
50485048

50495049
NeverNullType TypeResolver::resolveLifetimeDependentReturnTypeRepr(
50505050
LifetimeDependentReturnTypeRepr *repr, TypeResolutionOptions options) {
5051+
if (options.is(TypeResolverContext::TupleElement)) {
5052+
diagnoseInvalid(repr, repr->getSpecifierLoc(),
5053+
diag::lifetime_dependence_cannot_be_applied_to_tuple_elt);
5054+
return ErrorType::get(getASTContext());
5055+
}
50515056
if (!options.is(TypeResolverContext::FunctionResult)) {
50525057
diagnoseInvalid(
50535058
repr, repr->getSpecifierLoc(),

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,9 @@ struct GenericBufferView<Element> : ~Escapable {
160160
}
161161
}
162162
}
163+
164+
// CHECK: sil hidden @$s28implicit_lifetime_dependence23tupleLifetimeDependenceyAA10BufferViewV_ADtADYlsF : $@convention(thin) (@guaranteed BufferView) -> _scope(1) (@owned BufferView, @owned BufferView) {
165+
func tupleLifetimeDependence(_ x: borrowing BufferView) -> (BufferView, BufferView) {
166+
return (BufferView(x.ptr, x.c), BufferView(x.ptr, x.c))
167+
}
168+

test/Sema/explicit_lifetime_dependence_specifiers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// 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
2+
// REQUIRES: asserts
23
// REQUIRES: noncopyable_generics
34
import Builtin
45

@@ -97,6 +98,10 @@ func invalidSpecifierPosition2(_ x: borrowing BufferView) -> BufferView {
9798
return BufferView(y.ptr)
9899
}
99100

101+
func invalidTupleLifetimeDependence(_ x: inout BufferView) -> (_mutate(x) BufferView, BufferView) { // expected-error{{lifetime dependence specifiers cannot be applied to tuple elements}}
102+
return (BufferView(x.ptr), BufferView(x.ptr))
103+
}
104+
100105
struct Wrapper : ~Escapable {
101106
let view: BufferView
102107
init(_ view: consuming BufferView) {

0 commit comments

Comments
 (0)