[swift-dev] feedback on alternatives for importing libdispatch types into Swift on Liunx

Joe Groff jgroff at apple.com
Fri Feb 26 13:11:39 CST 2016


> On Feb 25, 2016, at 3:34 PM, David P Grove via swift-dev <swift-dev at swift.org> wrote:
> 
> 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 <https://bugs.swift.org/browse/SR-737>)
> (b) The libdispatch types can't be used in Swift where AnyObject is expected (https://bugs.swift.org/browse/SR-740 <https://bugs.swift.org/browse/SR-740>)
> (c) In Swift code that manipulates values coming from libdispatch, the expected retain/release operations are not generated by the compiler on Linux.
> 
> 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 libdispatch).
> (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 functions). 
> 
> 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.
> 

I agree that (2) is preferable; it'd be great if the entire corelibs platform could avoid needing to support multiple object models. You'll probably also have problems with blocks, which also aren't Swift-refcountable. We might be able to also customize the blocks runtime to use Swift refcounting as well. There's some trickiness there since global and stack blocks are ABI emitted by Clang, so swift-clang would need changes to match.

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160226/7edfa7cf/attachment.html>


More information about the swift-dev mailing list