Currently on Linux, the various libdispatch types (dispatch_object_t,
dispatch_queue_t, etc.) are imported into Swift as COpaquePointer on Linux.
This causes a number of problems including:
(a) The intended subtyping relationships are lost, resulting in some
of the dispatch APIs not being usable (https://bugs.swift.org/browse/SR-737
(b) The libdispatch types can't be used in Swift where AnyObject is
(c) In Swift code that manipulates values coming from libdispatch,
the expected retain/release operations are not generated by the compiler on
I can see two obvious ways to tackle these issues (and perhaps other
problems with the same root cause I haven't encountered yet).
(1) Stay with the current C-level code of libdispatch where
dispatch_object_t et al. simulate enough of the Objective-C object model
that they can masquerade as Objective-C objects. Convince the Swift
compiler to import them as Objective-C types on Linux even though there is
not an Objective-C runtime (just the stubbed out bits of it that are in
(2) Change the current C-level code of libdispatch so that on Linux
dispatch_object_t et al. simulate/implement enough of the Swift object
model that they can masquerade as Swift objects. Convince the Swift
compiler to import them as Swift types.
My gut is that (2) is the more desirable path to pursue. The main downside
I see is that it will likely make libdispatch.so dependent on
libswiftCore.so (to avoid replicating object model implementation
Before seriously starting down either path, I'd like to get some guidance
on what experts think the desired outcome should be and if I've overlooked
a better option.