Skip to content

assumeIsolated doesn't work for actors with Dispatch executors #74626

@wadetregaskis

Description

@wadetregaskis

Description

assumeIsolated apparently doesn't understand custom executors, at all. So it lies, in essence, by crashing when in fact the code is executing isolated to the actor.

Reproduction

import Dispatch

actor Example {
    final class DispatchQueueExecutor: SerialExecutor {
        private let queue: DispatchQueue

        init(queue: DispatchQueue) {
            self.queue = queue
        }

        func enqueue(_ job: UnownedJob) {
            self.queue.async {
                job.runSynchronously(on: self.asUnownedSerialExecutor())
            }
        }

        func asUnownedSerialExecutor() -> UnownedSerialExecutor {
            UnownedSerialExecutor(ordinary: self)
        }
    }

    private let executor: DispatchQueueExecutor

    init(queue: DispatchQueue) {
        self.executor = DispatchQueueExecutor(queue: queue)
    }

    func bridge() {
        print("Sadly, I never get my moment.")
    }

    nonisolated var unownedExecutor: UnownedSerialExecutor {
        executor.asUnownedSerialExecutor()
    }
}

let queue = DispatchQueue(label: "Example")
let example = Example(queue: queue)

queue.sync {
    example.assumeIsolated {
        $0.bridge()
    }
}

Expected behavior

Not crashing.

Environment

Swift 6 (swiftlang-6.0.0.3.300 clang-1600.0.20.10).

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language features

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions