Skip to content

Commit 627a799

Browse files
committed
[Test] Add caller of modify.
1 parent 9ceaa77 commit 627a799

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/SILGen/coroutine_accessors.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,53 @@ public var irm: Int {
8989
// CHECK-LABEL: } // end sil function '$s19coroutine_accessors1SV3irmSivM'
9090
} // public var irm
9191

92+
// CHECK-LABEL: sil {{.*}}[ossa] @$s19coroutine_accessors1SV6update3irmS2i_tKF :
93+
// CHECK-SAME: $@convention(method)
94+
// CHECK-SAME: (Int, @inout S)
95+
// CHECK-SAME: ->
96+
// CHECK-SAME: (Int, @error any Error)
97+
// CHECK-SAME: {
98+
// CHECK: bb0(
99+
// CHECK-SAME: [[NEW_VALUE:%[^,]+]] :
100+
// CHECK-SAME: [[SELF:%[^,]+]] :
101+
// CHECK-SAME: ):
102+
// CHECK: [[OLD_VALUE_ADDR:%[^,]+]] = alloc_stack $Int
103+
// CHECK: [[NEW_VALUE_ADDR:%[^,]+]] = alloc_stack $Int
104+
// CHECK: store [[NEW_VALUE:%[^,]+]] to [trivial] [[NEW_VALUE_ADDR]]
105+
// CHECK: [[SELF_ACCESS:%[^,]+]] = begin_access [modify] [unknown] [[SELF]]
106+
// CHECK: [[MODIFY_ACCESSOR:%[^,]+]] = function_ref @$s19coroutine_accessors1SV3irmSivx
107+
// CHECK: ([[VALUE_ADDR:%[^,]+]], [[TOKEN:%[^,]+]]) = begin_apply [[MODIFY_ACCESSOR]]([[SELF_ACCESS]])
108+
// CHECK: [[UPDATE:%[^,]+]] = function_ref @$s19coroutine_accessors6update2at2toxxz_xtKSQRzlF
109+
// CHECK: try_apply [[UPDATE:%[^,]+]]<Int>([[OLD_VALUE_ADDR]], [[VALUE_ADDR]], [[NEW_VALUE_ADDR]])
110+
// CHECK: bb1
111+
// CHECK: end_apply [[TOKEN]] as $()
112+
// CHECK: end_access [[SELF_ACCESS]]
113+
// CHECK: dealloc_stack [[NEW_VALUE_ADDR]]
114+
// CHECK: [[OLD_VALUE:%[^,]+]] = load [trivial] [[OLD_VALUE_ADDR]]
115+
// CHECK: dealloc_stack [[OLD_VALUE_ADDR]]
116+
// CHECK: return [[OLD_VALUE]]
117+
// CHECK: bb2([[ERROR:%[^,]+]] : @owned $any Error):
118+
// CHECK: abort_apply [[TOKEN]]
119+
// CHECK: end_access [[SELF_ACCESS]]
120+
// CHECK: dealloc_stack [[NEW_VALUE_ADDR]]
121+
// CHECK: dealloc_stack [[OLD_VALUE_ADDR]]
122+
// CHECK: throw [[ERROR]]
123+
// CHECK-LABEL: } // end sil function '$s19coroutine_accessors1SV6update3irmS2i_tKF'
124+
mutating func update(irm newValue: Int) throws -> Int {
125+
try coroutine_accessors.update(at: &irm, to: newValue)
126+
}
127+
92128
} // public struct S
129+
130+
enum E : Error {
131+
case e
132+
}
133+
134+
func update<T : Equatable>(at location: inout T, to newValue: T) throws -> T {
135+
let oldValue = location
136+
if oldValue == newValue {
137+
throw E.e
138+
}
139+
location = newValue
140+
return oldValue
141+
}

0 commit comments

Comments
 (0)