Skip to content

Commit 1b0691f

Browse files
committed
[SILGen] Used move_value for lexical lets.
Instead of using begin_borrow [lexical] + copy_value.
1 parent ff9e2aa commit 1b0691f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+329
-238
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,14 @@ class LetValueInitialization : public Initialization {
843843
}
844844

845845
// Otherwise, if we do not have a no implicit copy variable, just follow
846-
// the "normal path": perform a lexical borrow if the lifetime is lexical.
847-
return SGF.B.createBeginBorrow(
848-
PrologueLoc, value,
849-
/*isLexical=*/SGF.F.getLifetime(vd, value->getType()).isLexical(),
850-
/*hasPointerEscape=*/false, /*fromVarDecl=*/true);
846+
// the "normal path".
847+
848+
auto isLexical = SGF.F.getLifetime(vd, value->getType()).isLexical();
849+
850+
if (value->getOwnershipKind() == OwnershipKind::Owned)
851+
return SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ isLexical, /*hasPointerEscape=*/false, /*fromVarDecl=*/true);
852+
853+
return SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ isLexical, /*hasPointerEscape=*/false, /*fromVarDecl=*/true);
851854
}
852855

853856
void bindValue(SILValue value, SILGenFunction &SGF, bool wasPlusOne,
@@ -2173,6 +2176,11 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21732176
return;
21742177
}
21752178

2179+
if (auto *mvi = dyn_cast<MoveValueInst>(Val.getDefiningInstruction())) {
2180+
B.emitDestroyValueOperation(silLoc, mvi);
2181+
return;
2182+
}
2183+
21762184
if (auto *mvi = dyn_cast<MarkUnresolvedNonCopyableValueInst>(
21772185
Val.getDefiningInstruction())) {
21782186
if (mvi->hasMoveCheckerKind()) {

stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ public func reflect<T: Error>(error: T) {
508508
let error: Error = error
509509
let errorPointerValue = unsafeBitCast(error, to: UInt.self)
510510
reflect(instanceAddress: errorPointerValue, kind: .ErrorExistential)
511+
withExtendedLifetime(error) {}
511512
}
512513

513514
// Like reflect<T: Error>(error: T), but calls projectExistentialAndUnwrapClass
@@ -523,6 +524,7 @@ public func reflectUnwrappingClassExistential<T: Error>(error: T) {
523524
kind: .ErrorExistential,
524525
shouldUnwrapClassExistential: true)
525526
anyPointer.deallocate()
527+
withExtendedLifetime(error) {}
526528
}
527529

528530
// Reflect an `Enum`

test/AutoDiff/SILGen/autodiff_builtins.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ func test_context_builtins_with_type<T>(t: T) {
9797
// CHECK-LABEL: sil{{.*}}@test_context_builtins_with_type : $@convention(thin) <T> (@in_guaranteed T) -> () {
9898
// CHECK: bb0({{%.*}} : $*T):
9999
// CHECK: [[CTX:%.*]] = builtin "autoDiffCreateLinearMapContextWithType"<T>({{%.*}} : $@thick T.Type) : $Builtin.NativeObject // users: {{.*}}
100-
// CHECK: [[BORROWED_CTX:%.*]] = begin_borrow [lexical] [var_decl] [[CTX]] : $Builtin.NativeObject // users: {{.*}}
100+
// CHECK: [[CTX_LIFETIME:%.*]] = move_value [lexical] [[CTX]]
101+
// CHECK: [[BORROWED_CTX:%.*]] = begin_borrow [[CTX_LIFETIME]]
101102
// CHECK: [[BUF:%.*]] = builtin "autoDiffProjectTopLevelSubcontext"([[BORROWED_CTX]] : $Builtin.NativeObject) : $Builtin.RawPointer // users: {{.*}}
103+
// CHECK: [[BORROWED_CTX:%.*]] = begin_borrow [[CTX_LIFETIME]]
102104
// CHECK: [[BUF:%.*]] = builtin "autoDiffAllocateSubcontextWithType"<T>([[BORROWED_CTX]] : $Builtin.NativeObject, {{.*}} : $@thick T.Type) : $Builtin.RawPointer // users: {{.*}}
103105
// CHECK: destroy_value [[CTX]]

test/DebugInfo/guard-let-scope3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class S {
1515
// CHECK: debug_value {{.*}} : $Optional<C>, let, name "x", {{.*}}, scope [[X1]]
1616
// CHECK: debug_value {{.*}} : $C, let, name "x", {{.*}}, scope [[X2]]
1717
// FIXME: This source location is a little wild.
18-
// CHECK-NEXT: strong_retain{{.*}}:[[@LINE+4]]:12, scope [[X2]]
18+
// CHECK-NEXT: release_value{{.*}}:[[@LINE+5]]:3, scope [[X2]]
1919
throw MyError()
2020
// CHECK: function_ref {{.*}}MyError{{.*}}:[[@LINE-1]]:13, scope [[GUARD]]
2121
}

test/SILGen/cf_members.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public func foo(_ x: Double) {
6868
// CHECK: [[ZVAL:%.*]] = load [trivial] [[READ]]
6969
// CHECK: [[THUNK:%.*]] = function_ref @$s10cf_members3fooyySdFSo10IAMStruct1VSdcADcfu0_ : $@convention(thin) (Struct1) -> @owned @callee_guaranteed (Double) -> Struct1
7070
// CHECK: [[C:%.*]] = apply [[THUNK]]([[ZVAL]])
71-
// CHECK: [[BORROWED_C:%.*]] = begin_borrow [lexical] [var_decl] [[C]]
71+
// CHECK: [[C_MOVE:%.*]] = move_value [lexical] [var_decl] [[C]]
72+
// CHECK: [[BORROWED_C:%.*]] = begin_borrow [[C_MOVE]]
7273
// CHECK: [[C_COPY:%.*]] = copy_value [[BORROWED_C]]
7374
// CHECK: [[BORROWED_C2:%.*]] = begin_borrow [[C_COPY]]
7475
let c: (Double) -> Struct1 = z.translate(radians:)
@@ -102,7 +103,8 @@ public func foo(_ x: Double) {
102103
// CHECK: [[ZVAL:%.*]] = load [trivial] [[READ]]
103104
// CHECK: [[THUNK:%.*]] = function_ref @$s10cf_members3fooyySdFSo10IAMStruct1VSdcADcfu4_ : $@convention(thin) (Struct1) -> @owned @callee_guaranteed (Double) -> Struct1
104105
// CHECK: [[F:%.*]] = apply [[THUNK]]([[ZVAL]])
105-
// CHECK: [[BORROWED_F:%.*]] = begin_borrow [lexical] [var_decl] [[F]]
106+
// CHECK: [[MOVED_F:%.*]] = move_value [lexical] [var_decl] [[F]]
107+
// CHECK: [[BORROWED_F:%.*]] = begin_borrow [[MOVED_F]]
106108
// CHECK: [[F_COPY:%.*]] = copy_value [[BORROWED_F]]
107109
// CHECK: [[BORROWED_F2:%.*]] = begin_borrow [[F_COPY]]
108110
let f = z.scale

test/SILGen/closures.swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,15 @@ class SuperSub : SuperBase {
494494
// CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:\$s8closures8SuperSubC1c[_0-9a-zA-Z]*]] : $@convention(thin) (@guaranteed SuperSub) -> ()
495495
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
496496
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [[INNER]]([[SELF_COPY]])
497-
// CHECK: [[BORROWED_PA:%.*]] = begin_borrow [lexical] [var_decl] [[PA]]
498-
// CHECK: [[PA_COPY:%.*]] = copy_value [[BORROWED_PA]]
499-
// CHECK: [[B:%.*]] = begin_borrow [[PA_COPY]]
500-
// CHECK: apply [[B]]()
497+
// CHECK: [[MOVED_PA:%.*]] = move_value [lexical] [var_decl] [[PA]]
498+
// CHECK: [[B:%.*]] = begin_borrow [[MOVED_PA]]
499+
// CHECK: [[B_COPY:%.*]] = copy_value [[B]]
500+
// CHECK: [[B2:%.*]] = begin_borrow [[B_COPY]]
501+
// CHECK: apply [[B2]]()
502+
// CHECK: end_borrow [[B2]]
503+
// CHECK: destroy_value [[B_COPY]]
501504
// CHECK: end_borrow [[B]]
502-
// CHECK: destroy_value [[PA_COPY]]
503-
// CHECK: end_borrow [[BORROWED_PA]]
504-
// CHECK: destroy_value [[PA]]
505+
// CHECK: destroy_value [[MOVED_PA]]
505506
// CHECK: } // end sil function '$s8closures8SuperSubC1cyyF'
506507
func c() {
507508
// CHECK: sil private [ossa] @[[INNER_FUNC_1]] : $@convention(thin) (@guaranteed SuperSub) -> ()
@@ -526,14 +527,15 @@ class SuperSub : SuperBase {
526527
// CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:\$s8closures8SuperSubC1d[_0-9a-zA-Z]*]] : $@convention(thin) (@guaranteed SuperSub) -> ()
527528
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
528529
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [[INNER]]([[SELF_COPY]])
529-
// CHECK: [[BORROWED_PA:%.*]] = begin_borrow [lexical] [var_decl] [[PA]]
530-
// CHECK: [[PA_COPY:%.*]] = copy_value [[BORROWED_PA]]
531-
// CHECK: [[B:%.*]] = begin_borrow [[PA_COPY]]
532-
// CHECK: apply [[B]]()
533-
// CHECK: end_borrow [[B]]
534-
// CHECK: destroy_value [[PA_COPY]]
535-
// CHECK: end_borrow [[BORROWED_PA]]
536-
// CHECK: destroy_value [[PA]]
530+
// CHECK: [[MOVED_PA:%.*]] = move_value [lexical] [var_decl] [[PA]]
531+
// CHECK: [[B:%.*]] = begin_borrow [[MOVED_PA]]
532+
// CHECK: [[PA_COPY:%.*]] = copy_value [[B]]
533+
// CHECK: [[B2:%.*]] = begin_borrow [[PA_COPY]]
534+
// CHECK: apply [[B2]]()
535+
// CHECK: end_borrow [[B2]]
536+
// CHECK: destroy_value [[B_COPY]]
537+
// CHECK: end_borrow [[B]]
538+
// CHECK: destroy_value [[MOVED_PA]]
537539
// CHECK: } // end sil function '$s8closures8SuperSubC1dyyF'
538540
func d() {
539541
// CHECK: sil private [ossa] @[[INNER_FUNC_1]] : $@convention(thin) (@guaranteed SuperSub) -> () {
@@ -569,14 +571,15 @@ class SuperSub : SuperBase {
569571
// CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_NAME2:\$s8closures8SuperSubC1e.*]] : $@convention(thin)
570572
// CHECK: [[ARG_COPY:%.*]] = copy_value [[ARG]]
571573
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [[INNER]]([[ARG_COPY]])
572-
// CHECK: [[BORROWED_PA:%.*]] = begin_borrow [lexical] [var_decl] [[PA]]
573-
// CHECK: [[PA_COPY:%.*]] = copy_value [[BORROWED_PA]]
574-
// CHECK: [[B:%.*]] = begin_borrow [[PA_COPY]]
575-
// CHECK: apply [[B]]() : $@callee_guaranteed () -> ()
576-
// CHECK: end_borrow [[B]]
577-
// CHECK: destroy_value [[PA_COPY]]
578-
// CHECK: end_borrow [[BORROWED_PA]]
579-
// CHECK: destroy_value [[PA]]
574+
// CHECK: [[MOVED_PA:%.*]] = move_value [lexical] [var_decl] [[PA]]
575+
// CHECK: [[B:%.*]] = begin_borrow [[MOVED_PA]]
576+
// CHECK: [[PA_COPY:%.*]] = copy_value [[B]]
577+
// CHECK: [[B2:%.*]] = begin_borrow [[PA_COPY]]
578+
// CHECK: apply [[B2]]()
579+
// CHECK: end_borrow [[B2]]
580+
// CHECK: destroy_value [[B_COPY]]
581+
// CHECK: end_borrow [[B]]
582+
// CHECK: destroy_value [[MOVED_PA]]
580583
// CHECK: } // end sil function '[[INNER_FUNC_NAME1]]'
581584
func e1() {
582585
// CHECK: sil private [ossa] @[[INNER_FUNC_NAME2]] : $@convention(thin)
@@ -601,7 +604,8 @@ class SuperSub : SuperBase {
601604
// CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:\$s8closures8SuperSubC1fyyFyycfU_]] : $@convention(thin) (@guaranteed SuperSub) -> ()
602605
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
603606
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] [[INNER]]([[SELF_COPY]])
604-
// CHECK: destroy_value [[PA]]
607+
// CHECK: [[MOVED_PA:%.*]] = move_value [lexical] [var_decl] [[PA]]
608+
// CHECK: destroy_value [[MOVED_PA]]
605609
// CHECK: } // end sil function '$s8closures8SuperSubC1fyyF'
606610
func f() {
607611
// CHECK: sil private [ossa] @[[INNER_FUNC_1]] : $@convention(thin) (@guaranteed SuperSub) -> () {

test/SILGen/collection_upcast.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func testArrayUpcast(_ array: [BridgedObjC]) {
4747
// CHECK: [[ARRAY_COPY:%.*]] = copy_value [[ARRAY]]
4848
// CHECK: [[UPCAST_FN:%[0-9]+]] = function_ref @$ss15_arrayForceCast{{.*}}F : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
4949
// CHECK: [[RESULT:%.*]] = apply [[UPCAST_FN]]<BridgedObjC, AnyObject>([[ARRAY_COPY]]) : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
50-
// CHECK: destroy_value [[RESULT]]
50+
// CHECK: [[RESULT_LIFETIME:%.*]] = move_value [var_decl] [[RESULT]]
51+
// CHECK: destroy_value [[RESULT_LIFETIME]]
5152
// CHECK-NOT: destroy_value [[ARRAY]]
5253
let anyObjectArr: [AnyObject] = array
5354
}
@@ -59,7 +60,8 @@ func testArrayUpcastBridged(_ array: [BridgedSwift]) {
5960
// CHECK: [[ARRAY_COPY:%.*]] = copy_value [[ARRAY]]
6061
// CHECK: [[BRIDGE_FN:%[0-9]+]] = function_ref @$ss15_arrayForceCast{{.*}}F : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
6162
// CHECK: [[RESULT:%.*]] = apply [[BRIDGE_FN]]<BridgedSwift, AnyObject>([[ARRAY_COPY]]) : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
62-
// CHECK: destroy_value [[RESULT]]
63+
// CHECK: [[RESULT_LIFETIME:%.*]] = move_value [var_decl] [[RESULT]]
64+
// CHECK: destroy_value [[RESULT_LIFETIME]]
6365
// CHECK-NOT: destroy_value [[ARRAY]]
6466
let anyObjectArr = array as [AnyObject]
6567
}
@@ -71,7 +73,8 @@ func testDictionaryUpcast(_ dict: Dictionary<BridgedObjC, BridgedObjC>) {
7173
// CHECK: [[DICT_COPY:%.*]] = copy_value [[DICT]]
7274
// CHECK: [[UPCAST_FN:%[0-9]+]] = function_ref @$ss17_dictionaryUpCast{{.*}}F : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
7375
// CHECK: [[RESULT:%.*]] = apply [[UPCAST_FN]]<BridgedObjC, BridgedObjC, NSObject, AnyObject>([[DICT_COPY]]) : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
74-
// CHECK: destroy_value [[RESULT]]
76+
// CHECK: [[RESULT_LIFETIME:%.*]] = move_value [var_decl] [[RESULT]]
77+
// CHECK: destroy_value [[RESULT_LIFETIME]]
7578
// CHECK-NOT: destroy_value [[DICT]]
7679
let anyObjectDict: Dictionary<NSObject, AnyObject> = dict
7780
}
@@ -82,7 +85,8 @@ func testDictionaryUpcastBridged(_ dict: Dictionary<BridgedSwift, BridgedSwift>)
8285
// CHECK: [[DICT_COPY:%.*]] = copy_value [[DICT]]
8386
// CHECK: [[BRIDGE_FN:%[0-9]+]] = function_ref @$ss17_dictionaryUpCast{{.*}}F
8487
// CHECK: [[RESULT:%.*]] = apply [[BRIDGE_FN]]<BridgedSwift, BridgedSwift, NSObject, AnyObject>([[DICT_COPY]]) : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
85-
// CHECK: destroy_value [[RESULT]]
88+
// CHECK: [[RESULT_LIFETIME:%.*]] = move_value [var_decl] [[RESULT]]
89+
// CHECK: destroy_value [[RESULT_LIFETIME]]
8690
// CHECK-NOT: destroy_value [[DICT]]
8791
let anyObjectDict = dict as Dictionary<NSObject, AnyObject>
8892
}
@@ -93,7 +97,8 @@ func testSetUpcast(_ dict: Set<BridgedObjC>) {
9397
// CHECK: [[SET_COPY:%.*]] = copy_value [[SET]]
9498
// CHECK: [[BRIDGE_FN:%[0-9]+]] = function_ref @$ss10_setUpCast{{.*}}F : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Set<τ_0_1>
9599
// CHECK: [[RESULT:%.*]] = apply [[BRIDGE_FN]]<BridgedObjC, NSObject>([[SET_COPY]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Set<τ_0_1>
96-
// CHECK: destroy_value [[RESULT]]
100+
// CHECK: [[RESULT_LIFETIME:%.*]] = move_value [var_decl] [[RESULT]]
101+
// CHECK: destroy_value [[RESULT_LIFETIME]]
97102
// CHECK-NOT: destroy_value [[SET]]
98103
let anyObjectSet: Set<NSObject> = dict
99104
}
@@ -104,7 +109,8 @@ func testSetUpcastBridged(_ set: Set<BridgedSwift>) {
104109
// CHECK: [[SET_COPY:%.*]] = copy_value [[SET]]
105110
// CHECK: [[BRIDGE_FN:%[0-9]+]] = function_ref @$ss10_setUpCast{{.*}}F
106111
// CHECK: [[RESULT:%.*]] = apply [[BRIDGE_FN]]<BridgedSwift, NSObject>([[SET_COPY]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Hashable, τ_0_1 : Hashable> (@guaranteed Set<τ_0_0>) -> @owned Set<τ_0_1>
107-
// CHECK: destroy_value [[RESULT]]
112+
// CHECK: [[RESULT_LIFETIME:%.*]] = move_value [var_decl] [[RESULT]]
113+
// CHECK: destroy_value [[RESULT_LIFETIME]]
108114
// CHECK-NOT: destroy_value [[SET]]
109115
let anyObjectSet = set as Set<NSObject>
110116
}

test/SILGen/consume_operator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ protocol P {
88

99
// CHECK-LABEL: sil hidden [ossa] @$s7consume15testLoadableLetyyF : $@convention(thin) () -> () {
1010
// CHECK: [[ORIG_VALUE:%.*]] = apply {{%.*}}({{%.*}}) : $@convention(method) (@thick Klass.Type) -> @owned Klass
11-
// CHECK: [[BORROWED_VALUE:%.*]] = begin_borrow [lexical] [var_decl] [[ORIG_VALUE]]
11+
// CHECK: [[MOVED_VALUE:%.*]] = move_value [lexical] [var_decl] [[ORIG_VALUE]]
12+
// CHECK: [[BORROWED_VALUE:%.*]] = begin_borrow [[MOVED_VALUE]]
1213
// CHECK: [[COPY:%.*]] = copy_value [[BORROWED_VALUE:%.*]]
1314
// CHECK: move_value [allows_diagnostics] [[COPY]]
1415
// CHECK: } // end sil function '$s7consume15testLoadableLetyyF'

test/SILGen/copy_expr.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ struct ContainKlass {
2525

2626
// CHECK-LABEL: sil hidden [ossa] @$s9copy_expr22testCopyLoadableRValueyyF : $@convention(thin) () -> () {
2727
// CHECK: [[X:%.*]] = apply {{%.*}}({{%.*}}) : $@convention(method) (@thin ContainKlass.Type) -> @owned ContainKlass
28-
// CHECK: [[BORROW:%.*]] = begin_borrow [lexical] [var_decl] [[X]]
28+
// CHECK: [[MOVE:%.*]] = move_value [lexical] [var_decl] [[X]]
29+
// CHECK: [[BORROW:%.*]] = begin_borrow [[MOVE]]
2930
// CHECK: [[COPY_BORROW:%.*]] = copy_value [[BORROW]]
3031
// CHECK: explicit_copy_value [[COPY_BORROW]]
3132
// CHECK: } // end sil function '$s9copy_expr22testCopyLoadableRValueyyF'
@@ -114,7 +115,8 @@ func testCopyAddressOnlyLValueArg<T : P>(_ x: inout T) {
114115

115116
// CHECK-LABEL: sil hidden [ossa] @$s9copy_expr31testCallMethodOnLoadableLetCopyyyF : $@convention(thin) () -> () {
116117
// CHECK: [[ORIG_X:%.*]] = apply {{%.*}}({{%.*}}) : $@convention(method) (@thin ContainKlass.Type) -> @owned ContainKlass
117-
// CHECK: [[X:%.*]] = begin_borrow [lexical] [var_decl] [[ORIG_X]]
118+
// CHECK: [[MOVE:%.*]] = move_value [lexical] [var_decl] [[ORIG_X]]
119+
// CHECK: [[X:%.*]] = begin_borrow [[MOVE]]
118120
//
119121
// Calling consumeFunc.
120122
// CHECK: [[COPY_X:%.*]] = copy_value [[X]]
@@ -124,6 +126,7 @@ func testCopyAddressOnlyLValueArg<T : P>(_ x: inout T) {
124126
// CHECK: destroy_value [[COPY_X]]
125127
//
126128
// Calling borrowingFunc.
129+
// CHECK: [[X:%.*]] = begin_borrow [[MOVE]]
127130
// CHECK: [[COPY_X:%.*]] = copy_value [[X]]
128131
// CHECK: [[EXPLICIT_COPY_X:%.*]] = explicit_copy_value [[COPY_X]]
129132
// CHECK: [[FUNC:%.*]] = function_ref @$s9copy_expr12ContainKlassV13borrowingFuncyyF : $@convention(method) (@guaranteed ContainKlass) -> ()
@@ -132,6 +135,7 @@ func testCopyAddressOnlyLValueArg<T : P>(_ x: inout T) {
132135
// CHECK: destroy_value [[COPY_X]]
133136
//
134137
// Calling computedK. It is borrowed.
138+
// CHECK: [[X:%.*]] = begin_borrow [[MOVE]]
135139
// CHECK: [[COPY_X:%.*]] = copy_value [[X]]
136140
// CHECK: [[EXPLICIT_COPY_X:%.*]] = explicit_copy_value [[COPY_X]]
137141
// CHECK: [[BORROW_EXPLICIT_COPY_X:%.*]] = begin_borrow [[EXPLICIT_COPY_X]]
@@ -142,6 +146,7 @@ func testCopyAddressOnlyLValueArg<T : P>(_ x: inout T) {
142146
// CHECK: destroy_value [[COPY_X]]
143147
//
144148
// Calling computed getter.
149+
// CHECK: [[X:%.*]] = begin_borrow [[MOVE]]
145150
// CHECK: [[COPY_X:%.*]] = copy_value [[X]]
146151
// CHECK: [[EXPLICIT_COPY_X:%.*]] = explicit_copy_value [[COPY_X]]
147152
// CHECK: [[BORROW_EXPLICIT_COPY_X:%.*]] = begin_borrow [[EXPLICIT_COPY_X]]

test/SILGen/errors.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ func dont_return<T>(_ argument: T) throws -> T {
107107

108108
// Catch HomeworkError.CatAteIt.
109109
// CHECK: [[MATCH]]([[T0:%.*]] : @owned $Cat):
110-
// CHECK-NEXT: [[BORROWED_T0:%.*]] = begin_borrow [lexical] [var_decl] [[T0]]
111-
// CHECK-NEXT: debug_value [[BORROWED_T0]] : $Cat
110+
// CHECK-NEXT: [[MOVED_T0:%.*]] = move_value [lexical] [var_decl] [[T0]]
111+
// CHECK-NEXT: debug_value [[MOVED_T0]] : $Cat
112+
// CHECK-NEXT: [[BORROWED_T0:%.*]] = begin_borrow [[MOVED_T0]]
112113
// CHECK-NEXT: [[T0_COPY:%.*]] = copy_value [[BORROWED_T0]]
113114
// CHECK-NEXT: end_borrow [[BORROWED_T0]]
114-
// CHECK-NEXT: destroy_value [[T0]]
115+
// CHECK-NEXT: destroy_value [[MOVED_T0]]
115116
// CHECK-NEXT: dealloc_stack [[DEST_TEMP]]
116117
// CHECK-NEXT: destroy_addr [[SRC_TEMP]]
117118
// CHECK-NEXT: dealloc_stack [[SRC_TEMP]]
@@ -314,10 +315,9 @@ func all_together_now_four(_ flag: Bool) throws -> Cat? {
314315

315316
// Catch HomeworkError.CatAteIt.
316317
// CHECK: [[MATCH_ATE]]([[T0:%.*]] : @owned $Cat):
317-
// CHECK-NEXT: [[T0_BORROW:%.*]] = begin_borrow [lexical] [var_decl] [[T0]]
318-
// CHECK-NEXT: [[T0_COPY:%.*]] = copy_value [[T0_BORROW]]
319-
// CHECK-NEXT: end_borrow [[T0_BORROW]]
320-
// CHECK-NEXT: destroy_value [[T0]]
318+
// CHECK-NEXT: [[MOVED_T0:%.*]] = move_value [lexical] [var_decl] [[T0]]
319+
// CHECK-NEXT: [[T0_COPY:%.*]] = copy_value [[MOVED_T0]]
320+
// CHECK-NEXT: destroy_value [[MOVED_T0]]
321321
// CHECK-NEXT: dealloc_stack [[DEST_TEMP]]
322322
// CHECK-NEXT: destroy_addr [[SRC_TEMP]]
323323
// CHECK-NEXT: dealloc_stack [[SRC_TEMP]]
@@ -326,10 +326,9 @@ func all_together_now_four(_ flag: Bool) throws -> Cat? {
326326

327327
// Catch HomeworkError.CatHidIt.
328328
// CHECK: [[MATCH_HID]]([[T0:%.*]] : @owned $Cat):
329-
// CHECK-NEXT: [[T0_BORROW:%.*]] = begin_borrow [lexical] [var_decl] [[T0]]
330-
// CHECK-NEXT: [[T0_COPY:%.*]] = copy_value [[T0_BORROW]]
331-
// CHECK-NEXT: end_borrow [[T0_BORROW]]
332-
// CHECK-NEXT: destroy_value [[T0]]
329+
// CHECK-NEXT: [[MOVED_T0:%.*]] = move_value [lexical] [var_decl] [[T0]]
330+
// CHECK-NEXT: [[T0_COPY:%.*]] = copy_value [[MOVED_T0]]
331+
// CHECK-NEXT: destroy_value [[MOVED_T0]]
333332
// CHECK-NEXT: dealloc_stack [[DEST_TEMP]]
334333
// CHECK-NEXT: destroy_addr [[SRC_TEMP]]
335334
// CHECK-NEXT: dealloc_stack [[SRC_TEMP]]

0 commit comments

Comments
 (0)