Skip to content

Added temporary workaround for stack allocation optimization breaking isolated deinit tests in optimized mode #76960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime

// REQUIRES: gh76538

import Swift
import _Concurrency
import Dispatch
Expand Down Expand Up @@ -128,6 +126,14 @@ class ClassNoOp: Probe {

let tests = TestSuite("Isolated Deinit")

// Dummy global variable to suppress stack propagation
// TODO: Remove it after disabling allocation on stack for classes with isolated deinit
var x: AnyObject? = nil
func preventAllocationOnStack(_ object: AnyObject) {
x = object
x = nil
}

if #available(SwiftStdlib 5.1, *) {
tests.test("class sync fast path") {
let group = DispatchGroup()
Expand All @@ -136,7 +142,7 @@ if #available(SwiftStdlib 5.1, *) {
// FIXME: isolated deinit should be clearing task locals
await TL.$number.withValue(42) {
await AnotherActor.shared.performTesting {
_ = ClassNoOp(expectedNumber: 42, group: group)
preventAllocationOnStack(ClassNoOp(expectedNumber: 42, group: group))
}
}
}
Expand All @@ -148,7 +154,7 @@ if #available(SwiftStdlib 5.1, *) {
group.enter(1)
Task {
TL.$number.withValue(99) {
_ = ClassNoOp(expectedNumber: 0, group: group)
preventAllocationOnStack(ClassNoOp(expectedNumber: 0, group: group))
}
}
group.wait()
Expand All @@ -162,7 +168,7 @@ if #available(SwiftStdlib 5.1, *) {
TL.$number.withValue(99) {
// Despite last release happening not on the actor itself,
// this is still a fast path due to optimisation for deallocating actors.
_ = ActorNoOp(expectedNumber: 99, group: group)
preventAllocationOnStack(ActorNoOp(expectedNumber: 99, group: group))
}
}
group.wait()
Expand All @@ -174,7 +180,7 @@ if #available(SwiftStdlib 5.1, *) {
Task {
TL.$number.withValue(99) {
// Using ProxyActor breaks optimization
_ = ProxyActor(expectedNumber: 0, group: group)
preventAllocationOnStack(ProxyActor(expectedNumber: 0, group: group))
}
}
group.wait()
Expand All @@ -184,8 +190,8 @@ if #available(SwiftStdlib 5.1, *) {
let group = DispatchGroup()
group.enter(2)
Task {
_ = ActorNoOp(expectedNumber: 0, group: group)
_ = ClassNoOp(expectedNumber: 0, group: group)
preventAllocationOnStack(ActorNoOp(expectedNumber: 0, group: group))
preventAllocationOnStack(ClassNoOp(expectedNumber: 0, group: group))
}
group.wait()
}
Expand Down
18 changes: 13 additions & 5 deletions test/Concurrency/voucher_propagation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ func adopt(voucher: voucher_t?) {
os_release(voucher_adopt(os_retain(voucher)))
}

// Dummy global variable to suppress stack propagation
// TODO: Remove it after disabling allocation on stack for classes with isolated deinit
var x: AnyObject? = nil
func preventAllocationOnStack(_ object: AnyObject) {
x = object
x = nil
}

let tests = TestSuite("Voucher Propagation")

if #available(SwiftStdlib 5.1, *) {
Expand Down Expand Up @@ -436,15 +444,15 @@ if #available(SwiftStdlib 5.1, *) {
Task {
await AnotherActor.shared.performTesting {
adopt(voucher: v1)
_ = ClassWithIsolatedDeinit(expectedVoucher: v1, group: group)
preventAllocationOnStack(ClassWithIsolatedDeinit(expectedVoucher: v1, group: group))
}
await AnotherActor.shared.performTesting {
adopt(voucher: v2)
_ = ActorWithSelfIsolatedDeinit(expectedVoucher: v2, group: group)
preventAllocationOnStack(ActorWithSelfIsolatedDeinit(expectedVoucher: v2, group: group))
}
await AnotherActor.shared.performTesting {
adopt(voucher: v3)
_ = ActorWithDeinitIsolatedOnAnother(expectedVoucher: v3, group: group)
preventAllocationOnStack(ActorWithDeinitIsolatedOnAnother(expectedVoucher: v3, group: group))
}
}
group.wait()
Expand All @@ -459,11 +467,11 @@ if #available(SwiftStdlib 5.1, *) {
Task {
do {
adopt(voucher: v1)
_ = ActorWithDeinitIsolatedOnAnother(expectedVoucher: v1, group: group)
preventAllocationOnStack(ActorWithDeinitIsolatedOnAnother(expectedVoucher: v1, group: group))
}
do {
adopt(voucher: v2)
_ = ClassWithIsolatedDeinit(expectedVoucher: v2, group: group)
preventAllocationOnStack(ClassWithIsolatedDeinit(expectedVoucher: v2, group: group))
}
}
group.wait()
Expand Down