Skip to content

Commit f9b3f60

Browse files
authored
Merge pull request #76960 from nickolas-pohilets/mpokhylets/stack-alloc-workaround
Added temporary workaround for stack allocation optimization breaking isolated deinit tests in optimized mode
2 parents c06a9e5 + d8694db commit f9b3f60

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

test/Concurrency/Runtime/async_task_locals_isolated_deinit.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// REQUIRES: concurrency_runtime
1010
// UNSUPPORTED: back_deployment_runtime
1111

12-
// REQUIRES: gh76538
13-
1412
import Swift
1513
import _Concurrency
1614
import Dispatch
@@ -128,6 +126,14 @@ class ClassNoOp: Probe {
128126

129127
let tests = TestSuite("Isolated Deinit")
130128

129+
// Dummy global variable to suppress stack propagation
130+
// TODO: Remove it after disabling allocation on stack for classes with isolated deinit
131+
var x: AnyObject? = nil
132+
func preventAllocationOnStack(_ object: AnyObject) {
133+
x = object
134+
x = nil
135+
}
136+
131137
if #available(SwiftStdlib 5.1, *) {
132138
tests.test("class sync fast path") {
133139
let group = DispatchGroup()
@@ -136,7 +142,7 @@ if #available(SwiftStdlib 5.1, *) {
136142
// FIXME: isolated deinit should be clearing task locals
137143
await TL.$number.withValue(42) {
138144
await AnotherActor.shared.performTesting {
139-
_ = ClassNoOp(expectedNumber: 42, group: group)
145+
preventAllocationOnStack(ClassNoOp(expectedNumber: 42, group: group))
140146
}
141147
}
142148
}
@@ -148,7 +154,7 @@ if #available(SwiftStdlib 5.1, *) {
148154
group.enter(1)
149155
Task {
150156
TL.$number.withValue(99) {
151-
_ = ClassNoOp(expectedNumber: 0, group: group)
157+
preventAllocationOnStack(ClassNoOp(expectedNumber: 0, group: group))
152158
}
153159
}
154160
group.wait()
@@ -162,7 +168,7 @@ if #available(SwiftStdlib 5.1, *) {
162168
TL.$number.withValue(99) {
163169
// Despite last release happening not on the actor itself,
164170
// this is still a fast path due to optimisation for deallocating actors.
165-
_ = ActorNoOp(expectedNumber: 99, group: group)
171+
preventAllocationOnStack(ActorNoOp(expectedNumber: 99, group: group))
166172
}
167173
}
168174
group.wait()
@@ -174,7 +180,7 @@ if #available(SwiftStdlib 5.1, *) {
174180
Task {
175181
TL.$number.withValue(99) {
176182
// Using ProxyActor breaks optimization
177-
_ = ProxyActor(expectedNumber: 0, group: group)
183+
preventAllocationOnStack(ProxyActor(expectedNumber: 0, group: group))
178184
}
179185
}
180186
group.wait()
@@ -184,8 +190,8 @@ if #available(SwiftStdlib 5.1, *) {
184190
let group = DispatchGroup()
185191
group.enter(2)
186192
Task {
187-
_ = ActorNoOp(expectedNumber: 0, group: group)
188-
_ = ClassNoOp(expectedNumber: 0, group: group)
193+
preventAllocationOnStack(ActorNoOp(expectedNumber: 0, group: group))
194+
preventAllocationOnStack(ClassNoOp(expectedNumber: 0, group: group))
189195
}
190196
group.wait()
191197
}

test/Concurrency/voucher_propagation.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ func adopt(voucher: voucher_t?) {
266266
os_release(voucher_adopt(os_retain(voucher)))
267267
}
268268

269+
// Dummy global variable to suppress stack propagation
270+
// TODO: Remove it after disabling allocation on stack for classes with isolated deinit
271+
var x: AnyObject? = nil
272+
func preventAllocationOnStack(_ object: AnyObject) {
273+
x = object
274+
x = nil
275+
}
276+
269277
let tests = TestSuite("Voucher Propagation")
270278

271279
if #available(SwiftStdlib 5.1, *) {
@@ -436,15 +444,15 @@ if #available(SwiftStdlib 5.1, *) {
436444
Task {
437445
await AnotherActor.shared.performTesting {
438446
adopt(voucher: v1)
439-
_ = ClassWithIsolatedDeinit(expectedVoucher: v1, group: group)
447+
preventAllocationOnStack(ClassWithIsolatedDeinit(expectedVoucher: v1, group: group))
440448
}
441449
await AnotherActor.shared.performTesting {
442450
adopt(voucher: v2)
443-
_ = ActorWithSelfIsolatedDeinit(expectedVoucher: v2, group: group)
451+
preventAllocationOnStack(ActorWithSelfIsolatedDeinit(expectedVoucher: v2, group: group))
444452
}
445453
await AnotherActor.shared.performTesting {
446454
adopt(voucher: v3)
447-
_ = ActorWithDeinitIsolatedOnAnother(expectedVoucher: v3, group: group)
455+
preventAllocationOnStack(ActorWithDeinitIsolatedOnAnother(expectedVoucher: v3, group: group))
448456
}
449457
}
450458
group.wait()
@@ -459,11 +467,11 @@ if #available(SwiftStdlib 5.1, *) {
459467
Task {
460468
do {
461469
adopt(voucher: v1)
462-
_ = ActorWithDeinitIsolatedOnAnother(expectedVoucher: v1, group: group)
470+
preventAllocationOnStack(ActorWithDeinitIsolatedOnAnother(expectedVoucher: v1, group: group))
463471
}
464472
do {
465473
adopt(voucher: v2)
466-
_ = ClassWithIsolatedDeinit(expectedVoucher: v2, group: group)
474+
preventAllocationOnStack(ClassWithIsolatedDeinit(expectedVoucher: v2, group: group))
467475
}
468476
}
469477
group.wait()

0 commit comments

Comments
 (0)