Skip to content

Commit bc01d97

Browse files
committed
Add a begin_borrow canonicalization test case.
Canonicalization should be able to convert a nested borrow to a borrow. In this case, the coroutine was a nested borrow and becomes a borrow.
1 parent cead6a5 commit bc01d97

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/SILOptimizer/mandatory_combiner_opt.sil

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -mandatory-combine -sil-mandatory-combine-enable-canon-and-simple-dce %s | %FileCheck %s
1+
// RUN: %target-sil-opt -optimized-mandatory-combine -sil-mandatory-combine-enable-canon-and-simple-dce %s | %FileCheck %s
22

33
// Tests for when the mandatory combiner is running with optimizations
44
// enabled. Only put tests here for functionality that only occurs when the
@@ -106,3 +106,32 @@ bb0(%0 : @guaranteed $Klass):
106106
%9999 = tuple()
107107
return %9999 : $()
108108
}
109+
110+
// -----------------------------------------------------------------------------
111+
// Test removal of redundant borrow scopes for owned-to-guaranteed
112+
// coroutine arguments.
113+
class C {
114+
@_hasStorage var float: Builtin.Int64 { get set }
115+
init(_ float: Builtin.Int64)
116+
}
117+
118+
// CHECK-LABEL: sil hidden [ossa] @testCoroutineBorrow : $@convention(thin) (@owned C, Builtin.Int64) -> () {
119+
// CHECK-LABEL: bb0(%0 : @owned $C, %1 : $Builtin.Int64):
120+
// CHECK-NOT: borrow
121+
// CHECK: class_method %0 : $C, #C.float!modify : (C) -> () -> (), $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
122+
// CHECK: begin_apply %{{.*}}(%0) : $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
123+
// CHECK-NOT: borrow
124+
// CHECK: destroy_value %0 : $C
125+
// CHECK-LABEL: } // end sil function 'testCoroutineBorrow'
126+
sil hidden [ossa] @testCoroutineBorrow : $@convention(thin) (@owned C, Builtin.Int64) -> () {
127+
bb0(%0 : @owned $C, %1 : $Builtin.Int64):
128+
%14 = begin_borrow %0 : $C
129+
%15 = class_method %14 : $C, #C.float!modify : (C) -> () -> (), $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
130+
(%16, %17) = begin_apply %15(%14) : $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
131+
store %1 to [trivial] %16 : $*Builtin.Int64
132+
end_apply %17
133+
end_borrow %14 : $C
134+
destroy_value %0 : $C
135+
%23 = tuple ()
136+
return %23 : $()
137+
}

0 commit comments

Comments
 (0)