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

David P Grove groved at us.ibm.com
Wed Mar 9 17:14:46 CST 2016


I've made some progress on getting libdispatch types like dispatch_queue_t
to implement the Swift object model and be imported as Swift classes.  As
Joe suggested last week, I am attempting to implement the Swift object
model in libdispatch (and get the importer to realize that).

To simplify things, I created a tiny simulation of libdispatch [1] and used
it to explore options.   I think I've ended up in a reasonable point, but
before actually making the changes for real in libdispatch and submitting
pull requests I want to get a sanity check on the approach.

Summary of the changes:
	1. In the ClangImporter, I added more Dispatch types to
MappedTypes.def and a new value, MappedCTypeKind::SwiftClass.

	2. In the simulated libdispatch, I define DISPATCH_RETURNS_RETAINED
to be __attribute__((cf_returns_retained)) instead of
__attribute__((__ns_returns_retained__))

	3. In the simulated libdispatch, I wired
dispatch_retain/dispatch_release to swift_retain/release.  I used
swift_allocObject to create instances of dispatch_queue_t, etc.

	4. In Dispatch.swift I define stub classes DispatchObject,
DispatchQueue, etc. in a class hierarchy.   I use the compiler-generated
metadata for these classes when calling swift_allocObject for the isa
pointer.


The changes to ClangImporter can be browsed at [2].

thanks for any feedback,

--dave

[1] https://github.com/dgrove-oss/swift-object-model-experiments
[2] https://github.com/dgrove-oss/swift/tree/dispatch-import-exploration

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160309/21530bb9/attachment.html>


More information about the swift-dev mailing list