Skip to content

Commit 58c287c

Browse files
Merge pull request swiftlang#39709 from nate-chandler/lexical_lifetimes/only-give-owned-args-lexical-lifetimes
[SILGen] Only owned args get lexical lifetimes.
2 parents 3bd6716 + 88e52f8 commit 58c287c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ struct ArgumentInitHelper {
255255
SILDebugVariable varinfo(pd->isImmutable(), ArgNo);
256256
if (!argrv.getType().isAddress()) {
257257
if (SGF.getASTContext().LangOpts.EnableExperimentalLexicalLifetimes &&
258-
value->getOwnershipKind() != OwnershipKind::None) {
258+
value->getOwnershipKind() == OwnershipKind::Owned) {
259259
value =
260260
SILValue(SGF.B.createBeginBorrow(loc, value, /*isLexical*/ true));
261261
SGF.Cleanups.pushCleanup<EndBorrowCleanup>(value);

test/SILGen/lexical_lifetime.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func lexical_borrow_let_class_in_enum() {
8686

8787
// arguments:
8888

89-
// CHECK-LABEL: sil hidden [ossa] @lexical_borrow_arg_guaranteed_class : $@convention(thin) (@guaranteed C) -> () {
90-
// CHECK: {{bb[^,]+}}([[INSTANCE:%[^,]+]] : @guaranteed $C):
89+
// CHECK-LABEL: sil hidden [ossa] @lexical_borrow_arg_owned_class : $@convention(thin) (@owned C) -> () {
90+
// CHECK: {{bb[^,]+}}([[INSTANCE:%[^,]+]] : @owned $C):
9191
// CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [lexical] [[INSTANCE]]
9292
// CHECK: debug_value [[LIFETIME]]
9393
// CHECK: [[ADDR:%[^,]+]] = alloc_stack $C
@@ -98,6 +98,15 @@ func lexical_borrow_let_class_in_enum() {
9898
// CHECK: end_borrow [[LIFETIME]]
9999
// CHECK: [[RETVAL:%[^,]+]] = tuple ()
100100
// CHECK: return [[RETVAL]]
101+
// CHECK-LABEL: } // end sil function 'lexical_borrow_arg_owned_class'
102+
@_silgen_name("lexical_borrow_arg_owned_class")
103+
func lexical_borrow_arg_owned_class(_ c: __owned C) {
104+
use_generic(c)
105+
}
106+
107+
// CHECK-LABEL: sil hidden [ossa] @lexical_borrow_arg_guaranteed_class : $@convention(thin) (@guaranteed C) -> () {
108+
// CHECK: {{bb[^,]+}}([[INSTANCE:%[^,]+]] : @guaranteed $C):
109+
// CHECK-NOT: begin_borrow [lexical]
101110
// CHECK-LABEL: } // end sil function 'lexical_borrow_arg_guaranteed_class'
102111
@_silgen_name("lexical_borrow_arg_guaranteed_class")
103112
func lexical_borrow_arg_guaranteed_class(_ c: C) {

0 commit comments

Comments
 (0)