Skip to content

Commit 2e09c17

Browse files
authored
Merge pull request #9434 from gottesmm/rdar32027013
2 parents c352f98 + 53c8044 commit 2e09c17

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ void ClosureCloner::visitLoadBorrowInst(LoadBorrowInst *LI) {
636636
// the loads get mapped to uses of the new object type argument.
637637
//
638638
// We assume that the value is already guaranteed.
639-
assert(Val.getOwnershipKind() == ValueOwnershipKind::Guaranteed
640-
&& "Expected argument value to be guaranteed");
639+
assert(Val.getOwnershipKind().isTrivialOr(ValueOwnershipKind::Guaranteed) &&
640+
"Expected argument value to be guaranteed");
641641
ValueMap.insert(std::make_pair(LI, Val));
642642
return;
643643
}
@@ -678,8 +678,8 @@ void ClosureCloner::visitLoadInst(LoadInst *LI) {
678678
// struct_extract of the new passed in value. The value should be borrowed
679679
// already.
680680
SILBuilderWithPostProcess<ClosureCloner, 1> B(this, LI);
681-
assert(B.getFunction().hasUnqualifiedOwnership()
682-
|| Val.getOwnershipKind() == ValueOwnershipKind::Guaranteed);
681+
assert(B.getFunction().hasUnqualifiedOwnership() ||
682+
Val.getOwnershipKind().isTrivialOr(ValueOwnershipKind::Guaranteed));
683683
SILValue V =
684684
B.emitStructExtract(LI->getLoc(), Val, SEAI->getField(), LI->getType());
685685
ValueMap.insert(std::make_pair(LI, V));

test/SILOptimizer/capture_promotion_ownership.sil

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sil @baz_init : $@convention(thin) (@thin Baz.Type) -> @owned Baz
3131
sil @dummy_func : $@convention(thin) (Int, Int, Int) -> Int
3232

3333
// CHECK-LABEL: sil @test_capture_promotion
34-
sil @test_capture_promotion : $@convention(thin) () -> @owned @callee_owned () -> Int {
34+
sil @test_capture_promotion : $@convention(thin) () -> @owned @callee_owned () -> (Int, Builtin.Int64) {
3535
bb0:
3636
// CHECK: [[BOX1:%.*]] = alloc_box $<τ_0_0> { var τ_0_0 } <Foo>
3737
// CHECK: [[MARKED_BOX1:%.*]] = mark_uninitialized [var] [[BOX1]]
@@ -88,17 +88,17 @@ bb0:
8888
// previously used to capture and pass the variable by reference
8989
// CHECK-NEXT: {{.*}} = partial_apply [[CLOSURE_PROMOTE]]([[LOADFOO]], [[LOADBAZ]], [[LOADINT]])
9090

91-
%17 = function_ref @closure0 : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> Int
91+
%17 = function_ref @closure0 : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> (Int, Builtin.Int64)
9292
%18 = copy_value %1ab : $<τ_0_0> { var τ_0_0 } <Foo>
9393
%19 = copy_value %6 : $<τ_0_0> { var τ_0_0 } <Baz>
9494
%20 = copy_value %11 : $<τ_0_0> { var τ_0_0 } <Int>
95-
%21 = partial_apply %17(%18, %19, %20) : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> Int
95+
%21 = partial_apply %17(%18, %19, %20) : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> (Int, Builtin.Int64)
9696

9797
destroy_value %11 : $<τ_0_0> { var τ_0_0 } <Int>
9898
destroy_value %6 : $<τ_0_0> { var τ_0_0 } <Baz>
9999
destroy_value %1ab : $<τ_0_0> { var τ_0_0 } <Foo>
100100

101-
return %21 : $@callee_owned () -> Int
101+
return %21 : $@callee_owned () -> (Int, Builtin.Int64)
102102
}
103103

104104
// CHECK-LABEL: sil @test_capture_promotion_indirect
@@ -163,7 +163,7 @@ bb0:
163163
return %21 : $@callee_owned () -> @out Int
164164
}
165165

166-
// CHECK-LABEL: sil private @_T08closure0Tf2iii_n : $@convention(thin) (@owned Foo, @owned Baz, Int) -> Int {
166+
// CHECK-LABEL: sil private @_T08closure0Tf2iii_n : $@convention(thin) (@owned Foo, @owned Baz, Int) -> (Int, Builtin.Int64) {
167167
// CHECK: bb0([[ORIGINAL_ARG0:%.*]] : @owned $Foo, [[ORIGINAL_ARG1:%.*]] : @owned $Baz, [[ARG2:%.*]] : @trivial $Int):
168168
// CHECK: [[ARG0:%.*]] = begin_borrow [[ORIGINAL_ARG0]]
169169
// CHECK: [[ARG1:%.*]] = begin_borrow [[ORIGINAL_ARG1]]
@@ -177,6 +177,7 @@ bb0:
177177
// CHECK: destroy_value [[ARG0_COPY]]
178178

179179
// CHECK: [[EXTRACT_BAZ_X:%.*]] = struct_extract [[ARG1]] : $Baz, #Baz.x
180+
// CHECK: [[EXTRACT_INT_VALUE:%.*]] = struct_extract [[ARG2]] : $Int, #Int.value
180181
// CHECK: [[RETVAL:%.*]] = apply [[DUMMY_FUNC]]([[APPLY_FOO]], [[EXTRACT_BAZ_X]], {{.*}}) : $@convention(thin) (Int, Int, Int) -> Int
181182

182183
// The release of %4 is removed because the Int type is trivial
@@ -190,10 +191,11 @@ bb0:
190191
// it is a reference type
191192
// CHECK: end_borrow [[ARG0]] from [[ORIGINAL_ARG0]]
192193
// CHECK: destroy_value [[ORIGINAL_ARG0]]
193-
// CHECK: return [[RETVAL]] : $Int
194+
// CHECK: [[RESULT:%.*]] = tuple ([[RETVAL]] : $Int, [[EXTRACT_INT_VALUE]] : $Builtin.Int64)
195+
// CHECK: return [[RESULT]] : $(Int, Builtin.Int64)
194196
// CHECK: } // end sil function '_T08closure0Tf2iii_n'
195197

196-
sil private @closure0 : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> Int {
198+
sil private @closure0 : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> (Int, Builtin.Int64) {
197199
bb0(%0 : @owned $<τ_0_0> { var τ_0_0 } <Foo>, %2 : @owned $<τ_0_0> { var τ_0_0 } <Baz>, %4 : @owned $<τ_0_0> { var τ_0_0 } <Int>):
198200
%1 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Foo>, 0
199201
%3 = project_box %2 : $<τ_0_0> { var τ_0_0 } <Baz>, 0
@@ -210,11 +212,14 @@ bb0(%0 : @owned $<τ_0_0> { var τ_0_0 } <Foo>, %2 : @owned $<τ_0_0> { var τ_0
210212
%12 = struct_element_addr %3 : $*Baz, #Baz.x
211213
%13 = load [trivial] %12 : $*Int
212214
%14 = load [trivial] %5 : $*Int
213-
%15 = apply %7(%11, %13, %14) : $@convention(thin) (Int, Int, Int) -> Int
215+
%15 = struct_element_addr %5 : $*Int, #Int.value
216+
%16 = load [trivial] %15 : $*Builtin.Int64
217+
%17 = apply %7(%11, %13, %14) : $@convention(thin) (Int, Int, Int) -> Int
214218
destroy_value %4 : $<τ_0_0> { var τ_0_0 } <Int>
215219
destroy_value %2 : $<τ_0_0> { var τ_0_0 } <Baz>
216220
destroy_value %0 : $<τ_0_0> { var τ_0_0 } <Foo>
217-
return %15 : $Int
221+
%18 = tuple(%17 : $Int, %16 : $Builtin.Int64)
222+
return %18 : $(Int, Builtin.Int64)
218223
}
219224

220225
// The closure in this function is not promotable because it mutates its argument
@@ -303,7 +308,6 @@ bb0(%0 : @owned $<τ_0_0> { var τ_0_0 } <Int>, %2 : @owned $<τ_0_0> { var τ_0
303308

304309
sil [transparent] [serialized] @_T0s1poiSiSi_SitF : $@convention(thin) (Int, Int) -> Int
305310

306-
307311
sil private @closure_indirect_result : $@convention(thin) (@owned <τ_0_0> { var τ_0_0 } <Foo>, @owned <τ_0_0> { var τ_0_0 } <Baz>, @owned <τ_0_0> { var τ_0_0 } <Int>) -> @out Int {
308312
bb0(%0: @trivial $*Int, %1 : @owned $<τ_0_0> { var τ_0_0 } <Foo>, %2 : @owned $<τ_0_0> { var τ_0_0 } <Baz>, %4 : @owned $<τ_0_0> { var τ_0_0 } <Int>):
309313
%17 = project_box %1 : $<τ_0_0> { var τ_0_0 } <Foo>, 0

0 commit comments

Comments
 (0)