[swift-corelibs-dev] Proposal: add `noescape` attribute to public API (particularly libdispatch)

Jacob Bandes-Storch jtbandes at gmail.com
Sat Dec 5 14:53:05 CST 2015

There are several functions in public API, such as dispatch_sync and
dispatch_apply, which do not allow their block parameters to escape the
function call.

However, they are not currently exposed to Swift as @noescape, meaning that
users are required to specify "self." or "[weak self]" in their closures.

The instances I can think of:

- dispatch_sync
- dispatch_barrier_sync
- dispatch_apply
- dispatch_block_perform (thanks to Pierre Habouzit for pointing this out)

I provided a preliminary implementation at
https://github.com/apple/swift-corelibs-libdispatch/pull/6, but it needs
refinement. Tony Parker mentioned commented that there might be similar
changes to make for the swift-corelibs-foundation project.


Question: does __attribute__((noescape)) have the same meaning when applied
to C function pointers? Namely, does Swift understand @noescape as it
applies to @convention(c)?

Jacob Bandes-Storch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20151205/dbc5556a/attachment.html>

More information about the swift-corelibs-dev mailing list