-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
Deinitializing an NSObject subclass with an isolated deinit from an actor other that to which the deinit is isolated to causes a runtime crash in _dispatch_assert_queue_fail
Reproduction
import Foundation
import Testing
@MainActor final class NSObjectSubclass: NSObject {
isolated deinit {
print("Deinitializing")
}
}
@Test func exampleCrash() async throws {
#expect(#isolation !== MainActor.shared, "Expected test to be run off the main thread in order to test deinitialization from a background thread.")
var object: NSObjectSubclass? = await NSObjectSubclass()
#expect(object != nil, "Expected object to be initialized")
object = nil // Crashes in _dispatch_assert_queue_fail
}Stack dump
#0 0x00000001801bbe80 in _dispatch_assert_queue_fail ()
#1 0x00000001801ee6b0 in dispatch_assert_queue$V2.cold.1 ()
#2 0x00000001801bbe08 in dispatch_assert_queue ()
#3 0x000000025849a584 in _swift_task_checkIsolatedSwift ()
#4 0x00000002584db4a4 in swift_task_isCurrentExecutorWithFlagsImpl ()
#5 0x000000025849a3a0 in _checkExpectedExecutor ()
#6 0x0000000101496820 in @objc NSObjectSubclass.__deallocating_deinit ()
#7 0x0000000101495c18 in exampleCrash() at .../IsolatedDeinitCrashDemo/Tests/IsolatedDeinitCrashDemoTests/IsolatedDeinitCrashDemoTests.swift:8
#8 0x00000001014952f0 in $s28IsolatedDeinitCrashDemoTests07exampleC04TestfMp_17Z4cffd961c2024878fMu_@Sendable () at /var/folders/sy/6zjgc33d4m7g63k0y3g8c9q40000gq/T/swift-generated-sources/@__swiftmacro_28IsolatedDeinitCrashDemoTests07exampleC04TestfMp_.swift:3
#9 0x00000001218bb8bc in (2) await resume partial function for function signature specialization <Arg[0] = Dead> of closure #1 @Sendable () async throws -> () in closure #1 () async throws -> () in closure #1 () async -> () in static Testing.Runner._runTestCase(_: Testing.Test.Case, within: Testing.Runner.Plan.Step) async throws -> () ()
#10 0x00000001218b0700 in (19) await resume partial function for closure #1 () async -> () in static Testing.Runner._runTestCase(_: Testing.Test.Case, within: Testing.Runner.Plan.Step) async throws -> () ()
#11 0x000000012181c6fc in (1) await resume partial function for partial apply forwarder for closure #1 () async throws -> sending τ_0_1 in Testing.__checkClosureCall<τ_0_0, τ_0_1 where τ_0_0: Swift.Equatable, τ_0_0: Swift.Error>(throws: τ_0_0, performing: () async throws -> τ_0_1, expression: Testing.__Expression, comments: @autoclosure () -> Swift.Array<Testing.Comment>, isRequired: Swift.Bool, sourceLocation: Testing.SourceLocation) async -> Swift.Result<(), Swift.Error> ()
#12 0x00000002584b54dc in (2) await resume partial function for Swift.TaskLocal.withValueImpl<τ_0_0>(_: __owned τ_0_0, operation: () async throws -> τ_1_0, isolation: isolated Swift.Optional<Swift.Actor>, file: Swift.String, line: Swift.UInt) async throws -> τ_1_0 ()
#13 0x00000002584b5350 in (2) await resume partial function for Swift.TaskLocal.withValue<τ_0_0>(_: τ_0_0, operation: () async throws -> τ_1_0, isolation: isolated Swift.Optional<Swift.Actor>, file: Swift.String, line: Swift.UInt) async throws -> τ_1_0 ()
#14 0x00000001218b0cdc in (2) await resume partial function for generic specialization <()> of static Testing.Test.Case.withCurrent<τ_0_0>(_: Testing.Test.Case, perform: () async throws -> τ_0_0) async throws -> τ_0_0 ()
#15 0x00000001218af228 in (2) await resume partial function for static Testing.Runner._runTestCase(_: Testing.Test.Case, within: Testing.Runner.Plan.Step) async throws -> () ()
#16 0x00000001218aeaf4 in (1) await resume partial function for closure #2 @Sendable (Testing.Test.Case) async throws -> () in static Testing.Runner._runTestCases<τ_0_0 where τ_0_0: Swift.Sequence, τ_0_0.Element == Testing.Test.Case>(_: τ_0_0, within: Testing.Runner.Plan.Step) async throws -> () ()
#17 0x000000012181c6fc in (1) await resume partial function for partial apply forwarder for closure #1 () async throws -> sending τ_0_1 in Testing.__checkClosureCall<τ_0_0, τ_0_1 where τ_0_0: Swift.Equatable, τ_0_0: Swift.Error>(throws: τ_0_0, performing: () async throws -> τ_0_1, expression: Testing.__Expression, comments: @autoclosure () -> Swift.Array<Testing.Comment>, isRequired: Swift.Bool, sourceLocation: Testing.SourceLocation) async -> Swift.Result<(), Swift.Error> ()
#18 0x00000001218b972c in (1) await resume partial function for generic not re-abstracted specialization <Testing.Test.Case, Swift.LazyFilterSequence<Swift.AnySequence<Testing.Test.Case>>> of closure #1 () async throws -> () in closure #1 (inout Swift.ThrowingTaskGroup<(), Swift.Error>) async throws -> () in static Testing.Runner._forEach<τ_0_0, τ_0_1 where τ_0_0: Swift.Sendable, τ_0_0 == τ_0_1.Element, τ_0_1: Swift.Sequence>(in: τ_0_1, _: @Sendable (τ_0_0) async throws -> ()) async throws -> () ()
#19 0x000000012181c6fc in (1) await resume partial function for partial apply forwarder for closure #1 () async throws -> sending τ_0_1 in Testing.__checkClosureCall<τ_0_0, τ_0_1 where τ_0_0: Swift.Equatable, τ_0_0: Swift.Error>(throws: τ_0_0, performing: () async throws -> τ_0_1, expression: Testing.__Expression, comments: @autoclosure () -> Swift.Array<Testing.Comment>, isRequired: Swift.Bool, sourceLocation: Testing.SourceLocation) async -> Swift.Result<(), Swift.Error> ()
Expected behavior
The deinit runs on the actor to which it is isolated, regardless of which context it was deallocated from, with no crash.
Environment
Swift 6.2
Xcode 26.0.1
Additional information
No response
grantjbutler and mtheresep
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labelsThis issue needs more specific labels