[Review] SE-0088: Modernize libdispatch for Swift 3 naming conventions

I think this is a great idea and a great proposal. GCD is already a powerful, elegant tool available to Swift users, and this makes it feel even more Swift-like.

Feedback/questions:
- Is there a use case for user subclassing of a queue type? If not, should they be final?

Currently it’s not possible to subclass these classes in Objective C either, the metaclass symbols for the libdispatch Objective-C classes are not exported. This same restriction applies to those classes when interacting with them in swift, even though the classes themselves are not marked `final`.

- Is there a reason to use class methods rather than static methods for the queue types? I was under the impression that static methods would be preferred unless a good reason exists to dispatch upon metatype.

This detail passed me by, I will investigate.

- Nit: "DispatchWallTime" is spelled "DispatchWalltime" (lowercase 't') in the code samples.

I apologise, along with the one or two other spelling/naming issues others have pointed out. One or two of these names changed recently and I clearly didn’t catch all of them.

- Is it allowed/technically possible for non-stdlib code to use _ObjectiveCBridgable?

Similar to the Foundation mutability proposal, this will end up being an internal implementation detail of DispatchData’s struct bridging.

Regards,
M

···

On May 10, 2016, at 10:22 PM, Austin Zheng via swift-evolution <swift-evolution@swift.org> wrote:

Best,
Austin

On Tue, May 10, 2016 at 9:39 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:
Hello Swift community,

The review of "SE-0088: Modernize libdispatch for Swift 3 naming conventions" begins now and runs through May 17. The proposal is available here:

        https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

        https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

        * What is your evaluation of the proposal?
        * Is the problem being addressed significant enough to warrant a change to Swift?
        * Does this proposal fit well with the feel and direction of Swift?
        * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
        * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

        https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I'm one of the largest dispatch-on-linux users right now. In fact, I'm
reasonably sure I'm *THE* largest. I have an application in production
that uses some 400 dispatch calls.

On Linux, I'm running Swift 3 in production, essentially because
Dispatch/Linux in 2.2 does not even exist. On OSX/iOS, I compile the same
codebase with Swift 2.2, because that's the version that's released, and
using released software is a sane thing to do.

This proposal places me in the uncomfortable situation of trying to
somehow smooth out a truly MASSIVE API delta with if. And that's not
going to happen. Realistically, what I will do is create some kind of
FrankenSwift that either backports the new API to Swift 3 or the old API to
Swift 2. And that is a ton of work, really stupid work, and I would
infinitely prefer to spend that time doing something actually useful to the
world. To be clear, I don't fear migration; what I fear is the
heisenmigration, where one of my platforms must migrate, and the other ones
can't.

More broadly, I am concerned about the direction the language is going
where we do not even have working libraries yet and already we are doing
sweeping API changes to them. I suspect this is motivated by a
fundamentally incorrect premise–the premise that because it's not released
yet, we can get away with it. When actually that's backwards: we can get
away with breaking changes later, but if we do them now we will ruin
everything. Let me explain.

Right now, Linux Swift programmers exist. And they need to be able to
solve ordinary problems, like writing a string to a file, or spinning up a
background thread. And I do mean: sometime before Late 2016. No amount of
telling them "don't do that, it's not released" is going to stop this. The
only question is whether upstream is going to be the repo that solves their
problem, or whether they go to solve the problem somewhere else. Because
when they go somewhere else, they invest there.

Increasingly, because upstream is not interested in the problem, I am
seeing Linux folk go solve the problem somewhere else. Just counting the
projects I'm personally aware of, there are 3 foundation alternatives and 1
package manager alternative. All because upstream has no sane path to e.g.
reading a file on disk in the kind of timeframe working programmers
actually need to do it in.

What we *should* be doing is creating libraries that **work**, **releasing
them**, and then we can do as much API Disneyland as we want without
harassing the working programmer.

1. If we're out of bugs to fix, why not release? Then folks like me can
get off the snapshot treadmill and we won't be annoyed by massive API delta
until we can do it all at once, which is (relatively) easy.
2. If we're not out of bugs to fix, why not work on them, and then
release, and then come back to this?
3. Since Swift 3 will have a stable ABI, why not ship both libdispatch2
and libdispatch3 and let the programmer plan her own migration? I'm not
even sure the stable ABI part is relevant, since Dispatch is almost
entirely C.

All of these are saner alternatives to the proposal, and all of them
achieve the stated goal (e.g. we still end up with happy modern APIs).

I don't mean to pick on this proposal specifically, I agree with the need
to modernize the API surface area. But if we continue to do breaking
changes first and releases later I'm concerned about where the early
adopters will get pushed to.

FWIW, I believe the first Swift 3 preview branch is being created from
master tomorrow...

···

On Wed, May 11, 2016 at 1:30 AM, Drew Crawford via swift-evolution < swift-evolution@swift.org> wrote:

Drew

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

        * What is your evaluation of the proposal?

I'm generally in favor of a modernized API overlay like this (and I've written something like it myself, albeit much simpler), but I'm hoping this proposal can go through another round or two of discussion/bikeshedding/revision before approval.

(Small note: I'm really happy about the strong-typed-ness of the Source subclasses, e.g. how mergeData is only available for Add/Or.)

In no particular order, here are some things on which I'm unclear, or not-so-+1:

- synchronously()'s block parameter should be @noescape. Perhaps more arguably, it should have a generic return type and rethrows, like autoreleasepool now does.

Both of these are present in the changes I have for this proposal. The former point is a mistake in my proposal text, the latter is an unfortunate oversight on my part in putting together the proposal document.

- The names asynchronously(execute:) and synchronously(execute:) don't seem to fit with any API guidelines I'm aware of. Did you consider including the verb in the method name?

We did. Of the number of names that we discussed, none of them were perfect. sync/async are common in other languages but don’t fit the general direction of the Swift 3 naming conventions. Using `dispatchAsynchronously` is an extremely long method name, even more so than `asynchronously`. `perform` does not capture the sync/async nature of the calls particularly well, compared to DispatchWorkItem where `perform` immediately executes the block.

(And I'm guessing that "func synchronously(work:...)" is meant to be "func synchronously(execute work:...)”?)

Right.

As another bikeshed-item, I'd vote for "Data.init(withoutCopying:...)" rather than "(bytesNoCopy:...)", and perhaps whenDone() instead of notify().

Here the init() functions closely mirror Data from Foundation, the Objective-C class is toll-free bridged to NSData and we desired a close match to the Foundation Swift API. `notify` is Dispatch-only API though, I’ll go think over that one.

- Are DispatchWorkItemFlags meant to overlay dispatch_block_flags? It would be nice to explicitly list these in the proposal.

The dispatch_block_* API is completely superseded by DispatchWorkItem in the proposal. DispatchWorkItemFlags is the equivalent to dispatch_block_flags.

- Are functions like dispatch_barrier_sync totally gone in favor of passing a .barrier flag? It would be nice to explicitly state this in the proposal.

Yes, you can supply .barrier to either `synchronously` or `asynchronously`, or create a DispatchWorkItem as a barrier item. Where possible the multiple variants of a class (dispatch_async, dispatch_barrier_async, etc) are collapsed into a single method with default arguments.

- I echo Austin's concerns about subclassability. I think it would be dangerously misleading if the classes were subclassable from user code, even if it didn't work properly.

Building at compile time will fail. So you wouldn’t get very far trying to use them, I plan to investigate adding `final` here (it’s only absent for technical reasons, as the classes originate from Objective-C).

- What of the APIs provided on Semaphore and Group objects? I'd like to see these before I vote for the proposal.

These would be transformed similarly, I will include them when updating the proposal.

class DispatchSemaphore : DispatchObject {

  init(value: Int)

  func wait(timeout: DispatchTime = default) -> Int

  func wait(walltime timeout: DispatchWalltime) -> Int

  func signal() -> Int

}

class DispatchGroup : DispatchObject {

  init()

  func wait(timeout: DispatchTime = default) -> Int

  func wait(walltime timeout: DispatchWalltime) -> Int

  func notify(queue: DispatchQueue, block: () -> Void)

  func enter()

  func leave()

}

- What will dispatch_set_target_queue's replacement look like look like?

extension DispatchObject {

  func setTargetQueue(queue: DispatchQueue?)

}

- What about dispatch_once?

Removed. Swift already has lazy initialisation at the language level, dispatch_once is neither needed nor safe in Swift.

- Why use class funcs for the Source initializers, rather than an init on each individual subclass?

Implementation limitations. The “subclasses" are protocols would be introduced in order to attain a level of type safety around DispatchSource. We felt this was a significant enough improvement that it was worth including even with this implementation wart.

- Since DispatchSpecificKey is an object now, is there any concern with the object being allocated at the same address as an old, since-deallocated, object? (This might cause user confusion if both were used as "different" keys.)

The intention, though something that cannot be enforced, is that DispatchSpecificKey would be a global static object. I’d be interested if anyone has a pattern that more throughly enforces the allocation pattern required by the underlying API.

···

On May 10, 2016, at 11:52 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org> wrote:

        * Is the problem being addressed significant enough to warrant a change to Swift?

Yes.

        * Does this proposal fit well with the feel and direction of Swift?

Getting there.

        * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Medium-quick reading of this proposal. I've thought about this issue a good deal in the past, though.

Jacob

On Tue, May 10, 2016 at 9:39 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:
Hello Swift community,

The review of "SE-0088: Modernize libdispatch for Swift 3 naming conventions" begins now and runs through May 17. The proposal is available here:

        https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

        https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

More information about the Swift evolution process is available at

        https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Hey Jacob,

I agree with you that there are some unanswered questions and areas we would need some more polish on, but libdispatch was a bit unwieldy in Objective-C already and when used as is in Swift code it looks to be even less user friendly and not because it has to, but because of a lack of proper improvements such as the one described here.

I strongly hope we can get this in time for Swift 3... (not given up on cleaner dispatching rules for protocols and protocol extensions, but that's another story :)).

···

Sent from my iPhone

On 11 May 2016, at 07:52, Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org> wrote:

        * What is your evaluation of the proposal?

I'm generally in favor of a modernized API overlay like this (and I've written something like it myself, albeit much simpler), but I'm hoping this proposal can go through another round or two of discussion/bikeshedding/revision before approval.

(Small note: I'm really happy about the strong-typed-ness of the Source subclasses, e.g. how mergeData is only available for Add/Or.)

In no particular order, here are some things on which I'm unclear, or not-so-+1:

- synchronously()'s block parameter should be @noescape. Perhaps more arguably, it should have a generic return type and rethrows, like autoreleasepool now does.

- The names asynchronously(execute:) and synchronously(execute:) don't seem to fit with any API guidelines I'm aware of. Did you consider including the verb in the method name? (And I'm guessing that "func synchronously(work:...)" is meant to be "func synchronously(execute work:...)"?) As another bikeshed-item, I'd vote for "Data.init(withoutCopying:...)" rather than "(bytesNoCopy:...)", and perhaps whenDone() instead of notify().

- Are DispatchWorkItemFlags meant to overlay dispatch_block_flags? It would be nice to explicitly list these in the proposal.

- Are functions like dispatch_barrier_sync totally gone in favor of passing a .barrier flag? It would be nice to explicitly state this in the proposal.

- I echo Austin's concerns about subclassability. I think it would be dangerously misleading if the classes were subclassable from user code, even if it didn't work properly.

- What of the APIs provided on Semaphore and Group objects? I'd like to see these before I vote for the proposal.

- What will dispatch_set_target_queue's replacement look like look like?

- What about dispatch_once?

- Why use class funcs for the Source initializers, rather than an init on each individual subclass?

- Since DispatchSpecificKey is an object now, is there any concern with the object being allocated at the same address as an old, since-deallocated, object? (This might cause user confusion if both were used as "different" keys.)

        * Is the problem being addressed significant enough to warrant a change to Swift?

Yes.

        * Does this proposal fit well with the feel and direction of Swift?

Getting there.

        * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Medium-quick reading of this proposal. I've thought about this issue a good deal in the past, though.

Jacob

On Tue, May 10, 2016 at 9:39 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:
Hello Swift community,

The review of "SE-0088: Modernize libdispatch for Swift 3 naming conventions" begins now and runs through May 17. The proposal is available here:

        https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

        https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

More information about the Swift evolution process is available at

        https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

My main piece of feedback is that the method names synchronously() and asynchronously() don’t conform to Swift 3 naming conventions for functions and methods:

I agree.

dispatchAsynch()
dispatchSynch()

I prefer something like this. It feels more Swifty. As it is, they aren't any longer than asynchronously(), if name length is a concern.

Jacob Bandes-Storch suggested:

synchronously(execute work: …)

So maybe that will conform to the API naming guideline? Or would the verb have to be in the base name of the func?

Or perhaps:

synchronously(dispatch work: …)
asynchronously(dispatch work: …)

···

On May 11, 2016, at 9:32 AM, James Dempsey via swift-evolution <swift-evolution@swift.org> wrote:

The method names

  synchronously()
  asynchronously()

are both adverbs, not noun phrases or verb phrases.
These methods have side effects, so each name should have a verb in it to make it a verb phrase.

Since these are the methods where you actually dispatch a block into a queue

dispatchSynchronously()
dispatchAsynchronously()

would include the verb in the name of the methods.

I completely disagree with what you said. It sounds extreme to me to release a v1 of a library without giving yourself the flexibility to iterate on it beforehand.

···

On 11 May 2016, at 08:30, Drew Crawford via swift-evolution <swift-evolution@swift.org> wrote:

I'm one of the largest dispatch-on-linux users right now. In fact, I'm reasonably sure I'm THE largest. I have an application in production that uses some 400 dispatch calls.

On Linux, I'm running Swift 3 in production, essentially because Dispatch/Linux in 2.2 does not even exist. On OSX/iOS, I compile the same codebase with Swift 2.2, because that's the version that's released, and using released software is a sane thing to do.

This proposal places me in the uncomfortable situation of trying to somehow smooth out a truly MASSIVE API delta with if. And that's not going to happen. Realistically, what I will do is create some kind of FrankenSwift that either backports the new API to Swift 3 or the old API to Swift 2. And that is a ton of work, really stupid work, and I would infinitely prefer to spend that time doing something actually useful to the world. To be clear, I don't fear migration; what I fear is the heisenmigration, where one of my platforms must migrate, and the other ones can't.

More broadly, I am concerned about the direction the language is going where we do not even have working libraries yet and already we are doing sweeping API changes to them. I suspect this is motivated by a fundamentally incorrect premise–the premise that because it's not released yet, we can get away with it. When actually that's backwards: we can get away with breaking changes later, but if we do them now we will ruin everything. Let me explain.

Right now, Linux Swift programmers exist. And they need to be able to solve ordinary problems, like writing a string to a file, or spinning up a background thread. And I do mean: sometime before Late 2016. No amount of telling them "don't do that, it's not released" is going to stop this. The only question is whether upstream is going to be the repo that solves their problem, or whether they go to solve the problem somewhere else. Because when they go somewhere else, they invest there.

Increasingly, because upstream is not interested in the problem, I am seeing Linux folk go solve the problem somewhere else. Just counting the projects I'm personally aware of, there are 3 foundation alternatives and 1 package manager alternative. All because upstream has no sane path to e.g. reading a file on disk in the kind of timeframe working programmers actually need to do it in.

What we *should* be doing is creating libraries that *work*, *releasing them*, and then we can do as much API Disneyland as we want without harassing the working programmer.

1. If we're out of bugs to fix, why not release? Then folks like me can get off the snapshot treadmill and we won't be annoyed by massive API delta until we can do it all at once, which is (relatively) easy.
2. If we're not out of bugs to fix, why not work on them, and then release, and then come back to this?
3. Since Swift 3 will have a stable ABI, why not ship both libdispatch2 and libdispatch3 and let the programmer plan her own migration? I'm not even sure the stable ABI part is relevant, since Dispatch is almost entirely C.

All of these are saner alternatives to the proposal, and all of them achieve the stated goal (e.g. we still end up with happy modern APIs).

I don't mean to pick on this proposal specifically, I agree with the need to modernize the API surface area. But if we continue to do breaking changes first and releases later I'm concerned about where the early adopters will get pushed to.

Drew
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

You do make some good points; we have a variety of important areas that are completely unimplemented across any platforms, besides the feature parity across platforms.

I also wonder why this can’t be provided as a new library on top of (rather than as a replacement for) the existing libDispatch C interface. I have my own DispatchQueue class that does a lot of what this proposal suggests but it doesn’t replace the dispatch_* calls so it doesn’t break anything.

We are starting to accumulate a massive number of breaking changes. Yes there are fix-its but you still have problems with branches and coordinating the upgrade.

I’m also sympathetic to the fact that any changes we want to make will only get more difficult with time and the longer we wait to refactor APIs, rename things, etc the less likely it will even be possible. I think part of the rush for these kinds of changes is the fact that Swift 3 wants to focus on ABI stability and a lot of people are interpreting that as “this is our last chance to fix everything we don’t like!”, though ABI stability != API stability. Might just be me though.

Russ

···

On May 10, 2016, at 11:30 PM, Drew Crawford via swift-evolution <swift-evolution@swift.org> wrote:

I'm one of the largest dispatch-on-linux users right now. In fact, I'm reasonably sure I'm THE largest. I have an application in production that uses some 400 dispatch calls.

On Linux, I'm running Swift 3 in production, essentially because Dispatch/Linux in 2.2 does not even exist. On OSX/iOS, I compile the same codebase with Swift 2.2, because that's the version that's released, and using released software is a sane thing to do.

This proposal places me in the uncomfortable situation of trying to somehow smooth out a truly MASSIVE API delta with if. And that's not going to happen. Realistically, what I will do is create some kind of FrankenSwift that either backports the new API to Swift 3 or the old API to Swift 2. And that is a ton of work, really stupid work, and I would infinitely prefer to spend that time doing something actually useful to the world. To be clear, I don't fear migration; what I fear is the heisenmigration, where one of my platforms must migrate, and the other ones can't.

More broadly, I am concerned about the direction the language is going where we do not even have working libraries yet and already we are doing sweeping API changes to them. I suspect this is motivated by a fundamentally incorrect premise–the premise that because it's not released yet, we can get away with it. When actually that's backwards: we can get away with breaking changes later, but if we do them now we will ruin everything. Let me explain.

Right now, Linux Swift programmers exist. And they need to be able to solve ordinary problems, like writing a string to a file, or spinning up a background thread. And I do mean: sometime before Late 2016. No amount of telling them "don't do that, it's not released" is going to stop this. The only question is whether upstream is going to be the repo that solves their problem, or whether they go to solve the problem somewhere else. Because when they go somewhere else, they invest there.

Increasingly, because upstream is not interested in the problem, I am seeing Linux folk go solve the problem somewhere else. Just counting the projects I'm personally aware of, there are 3 foundation alternatives and 1 package manager alternative. All because upstream has no sane path to e.g. reading a file on disk in the kind of timeframe working programmers actually need to do it in.

What we *should* be doing is creating libraries that *work*, *releasing them*, and then we can do as much API Disneyland as we want without harassing the working programmer.

1. If we're out of bugs to fix, why not release? Then folks like me can get off the snapshot treadmill and we won't be annoyed by massive API delta until we can do it all at once, which is (relatively) easy.
2. If we're not out of bugs to fix, why not work on them, and then release, and then come back to this?
3. Since Swift 3 will have a stable ABI, why not ship both libdispatch2 and libdispatch3 and let the programmer plan her own migration? I'm not even sure the stable ABI part is relevant, since Dispatch is almost entirely C.

All of these are saner alternatives to the proposal, and all of them achieve the stated goal (e.g. we still end up with happy modern APIs).

I don't mean to pick on this proposal specifically, I agree with the need to modernize the API surface area. But if we continue to do breaking changes first and releases later I'm concerned about where the early adopters will get pushed to.

Drew
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Sorry, instead of saying this I meant to say fall into the pit of success with concurrency and QOS. (http://blog.codinghorror.com/falling-into-the-pit-of-success/\)
The Foundation APIs such as -[NSData writeToURL:atomically:] are easy to find yet synchronous, and might be a newcomer’s first choice. A new API built on top of libdispatch might make doing the right thing the first choice.

···

On 11 May 2016, at 3:41 PM, Patrick Smith <pgwsmith@gmail.com> wrote:

that get have concurrency and compatible with QOS by default.

+1 I’d also vote for dispatchAsync and dispatchSync. For reference, c# is also a language with fairly verbose conventions like Swift and it has adopted the Async convention for their “async” methods.

···

On 11 May 2016, at 20:08, Darren Mo via swift-evolution <swift-evolution@swift.org> wrote:

Great, this is the libdispatch API that I’ve been dreaming about! I think it meshes well with the rest of Swift.

I am concerned about one thing though: the naming of the DispatchGroup methods synchronously/asynchronously.

They are hard to type correctly and ugly to look at.
sync/async are already well-established abbreviations in the tech industry.
They are adjectives without verbs, which goes against the API Design Guidelines.

I suggest sticking with the naming from the C API. For example:

let queue = …
queue.dispatchAsync {
  …
}

Cheers,
Darren

> Hello Swift community,
>
> The review of "SE-0088: Modernize libdispatch for Swift 3 naming conventions" begins now and runs through May 17. The proposal is available here:
>
> https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md
>
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
>
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> or, if you would like to keep your feedback private, directly to the review manager.
>
> What goes into a review?
>
> The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
>
> * What is your evaluation of the proposal?
> * Is the problem being addressed significant enough to warrant a change to Swift?
> * Does this proposal fit well with the feel and direction of Swift?
> * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
>
> More information about the Swift evolution process is available at
>
> https://github.com/apple/swift-evolution/blob/master/process.md
>
> Thank you,
>
> -Chris Lattner
> Review Manager
>
>
>
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

1. What is your evaluation of the proposal?
+1 I think this is a big win for readability.

2. Is the problem being addressed significant enough to warrant a change to Swift?
Yes. dispatch is used nearly everywhere so many many projects would benefit from it.

3. Does this proposal fit well with the feel and direction of Swift?
Making the API more “swift" and feel more natural definitely is the direction Swift libraries are / should be going in.

4. If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Unfortunately not.

5. How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Read the proposal twice.

A little nitpick:

let item = DispatchWorkItem(qos: .qosUserInitiated) {
    print("Hello World")
}

I’d change the enum case from .qosUserInitiated to .userInitiated (maybe that’s just a typo since in the code example before uses .unspecified).

I think it is a typo, only default needs to be qosDefault because default is a keyword, and asking all users to back-tick it isn’t really good either.
(also no one should really specify qos class default anyway).

···

On May 11, 2016, at 9:02 AM, Dennis Weissmann via swift-evolution <swift-evolution@swift.org> wrote:

- Dennis

On May 11, 2016, at 6:39 AM, Chris Lattner <clattner@apple.com <mailto:clattner@apple.com>> wrote:

Hello Swift community,

The review of "SE-0088: Modernize libdispatch for Swift 3 naming conventions" begins now and runs through May 17. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution-announce mailing list
swift-evolution-announce@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution-announce

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

<https://github.com/apple/swift-evolution/blob/master/proposals/
0088-libdispatch-for-swift3.md>

## Type Names

I was going to suggest unprefixed type names, but having to qualify both
`Dispatch.Data` and `Foundation.Data` would be an issue. If libdispatch
had originally been part of Foundation, you'd need prefixes anyway:

* DispatchQueue
* NotificationQueue
* OperationQueue

## Quality of Service

Should argument labels and type names match those in Foundation?

* qos: => qualityOfService:
* DispatchQoS => DispatchQualityOfService

Could there be a shared `Swift.QualityOfService` enum?

* QOS_CLASS_DEFAULT = 0x15
* NSQualityOfServiceDefault = -1

The `.unspecified` QoS is not defined in NSQualityOfService.
Would an optional QoS parameter (defaulting to nil) be better?

## Time

The `dispatch_time` function uses a nanoseconds delta, so the operator
overloads taking `seconds: Double` might be ambiguous at the call site.
You could try changing the associated value types of your enum.

enum DispatchTimeInterval {
   case      seconds(Double) // changed from `Int`
   case milliseconds(Int64)  // changed from `Int`
   case microseconds(Int64)  // changed from `Int`
   case  nanoseconds(Int64)  // changed from `Int`
}

let _ = DispatchTime.now + 3.5 // ambiguous?

Are you talking about ambiguity at a compiler level, or in human-reading? The other four examples are an addition with an enum type, the first one is a double. There’s no compiler ambiguity here.

let a = DispatchTime.now + .seconds(3.5)
let b = DispatchTime.now + .milliseconds(3_500)
let c = DispatchTime.now + .microseconds(3_500_000)
let d = DispatchTime.now + .nanoseconds(3_500_000_000)


Is the \`DispatchTime\.now\` in your example a type property?

DispatchTime.now() is a function that returns the current time. The subsequent examples are typos (now() became a method quite late in the proposal’s development) and I’ll fix it up before pushing a v2 proposal that’s fixed up a lot of the typos that arose from late changes.

···

On May 12, 2016, at 7:00 AM, Ben Rimmington via swift-evolution <swift-evolution@swift.org> wrote:

## Data

Should the `DispatchData.append` methods have `contentsOf:` labels?
Or could it conform to the RangeReplaceableCollection protocol?

## Queues

My suggestions for the async/sync methods:

* enqueue(...)
* enqueueAndWaitUntilFinished(...)

-- Ben

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

On First, this is a huge breaking change, and it doesn’t really have to be one. The current SPM convention is to prefix C libraries with Lib. Following this convention, Dispatch (which is the C version) would be renamed to LibDispatch, and this new wrapper library would be called just Dispatch. With this setup, the old C api would still be there (under the module LibDispatch), which makes migration much easier. In the proposal, this issue is not addressed at all and it even says that all code using libdispatch would be affected. As it stands, that is not ok.

Separating existing dispatch from a new SwiftDispatch is a great idea. It would give the opportunity to really spend time working on the right approach for concurrency in swift without affecting existing production code and the hundreds of dispatch wrappers out there.

While we're on the subject: Dispatch Queues are 'queues' ... Isn't the right verb append (for asynchronous dispatch)?

DispatchQueue.main.append {
  print("Hello Swift")
}

After all, asyncDispatch or dispatchAsync imply you are dispatching a synchronously - which you are not. The dispatch (sending for execution) is always synchronous, it's the execution which is asynchronous.

DispatchQueue.main.dispatchForAsynchronousExecution {
  print("Help, I have repetitive strain injury")
}

Just my 2¢
Andrew.

<https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md&gt;

Are you talking about ambiguity at a compiler level, or in human-reading?

I meant ambiguous for people familiar with libdispatch. For example, the `interval`, `leeway`, and `delta` parameters of the following are all in nanoseconds:

* dispatch_io_set_interval
* dispatch_source_set_timer
* dispatch_time
* dispatch_walltime

_ = DispatchTime.now() + 3_500_000_000 // 3.5 seconds or 111 years?
_ = DispatchTime.now() + .seconds(3.5) // OK

The other associated value types were changed (from Int to Int64) to support 32-bit platforms.

DISPATCH_TIME_FOREVER can also be represented as an optional parameter:

func wait(timeout: DispatchTime? = nil)

Is it possible to eliminate the DispatchWalltime type?

public struct DispatchTime {

    private let _value: dispatch_time_t

    public init() {
        _value = dispatch_time(DISPATCH_TIME_NOW, 0)
    }

    public init(walltime: UnsafePointer<timespec>?) {
        _value = dispatch_walltime(walltime, 0)
    }
}

-- Ben

···

On 12 May 2016, at 19:03, Matt Wright <mww@apple.com> wrote:

[Apologies for the weird threading, I missed the original email to the list so I can’t reply to it directly]

I just wanted to let the list know that I updated proposal SE-0088 to fix the typos and include a more complete listing of the Dispatch module after the transformations in the proposal have been applied. Additionally, I’ve been keeping up with some of the feedback in this review thread and looking to see which ones would be best applied to the proposal. Though it should be made clear, this particular update only covers fixing the inconsistencies in my original proposal and providing a more complete overview of the module layout.

Similar to the changes in Foundation that are proposed on swift-evolution, I don’t expect all of the changes in libdispatch will be able to go through this process. As this is a large change (and, hopefully, a step forwards) to libdispatch I believe it is important to bring it to the swift-evolution list and take away your feedback for inclusion in future iterations of the module.

Thanks again for your continued feedback,
Matt

···

On Tue, May 10, 2016 at 9:39 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:
Hello Swift community,

The review of "SE-0088: Modernize libdispatch for Swift 3 naming conventions" begins now and runs through May 17. The proposal is available here:

        https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

        https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

        * What is your evaluation of the proposal?
        * Is the problem being addressed significant enough to warrant a change to Swift?
        * Does this proposal fit well with the feel and direction of Swift?
        * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
        * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

        https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

  * What is your evaluation of the proposal?

+1 conceptually, some quibbles.

I agree with a few others that `synchronously` and `asynchronously` aren’t ideal; `dispatchSynchronously` or `dispatchSync` (or `performSync` or `performSynchronously`) all seem more-appropriate.

I understand the impetus behind having fewer core methods, but IMHO the `dispatch_barrier_sync` and `dispatch_barrier_async` calls ought to have direct equivalents here (even if they are just sodlib-supplied conveniences that call through to the unified method).

I don’t see having barrier as separate methods as a particularly good fit for Swift. Given that there are other options surrounding how a block operates when it is executed, it makes more sense as default parameters to the same methods. This avoids having to have variants of the block submission methods for both barrier, QoS, both, etc.

I also don’t see `dispatch_apply` here anywhere; intentional? Ideally it’d be @noescape, but handling `throw` / `rethrow` for that function in this case seems complicated.

This is here in the updated version, though I agree it’s not simple to handle throwing out of the block as multiple threads are executing the same code at once.

This next one is subjective, but I find the placement of the group-related methods somewhat backwards vis-a-vis how I think of them in terms of the C-API.

I suspect this can go either way but the block is still being executed on a given queue, you’re just associating the execution of that block with a given group. In my mind that lives on the queue, as the execution will still occur there. Contrasting this to notify, which requests that the group itself submits the notify block to the queue when the group itself is empty.

EG: I think of `dispatch_group_async` as a “method” on a `dispatch_group`, so would’ve expected this:

class DispatchGroup : DispatchObject {

// (actual name should match chosen name convention)
func asynchronouslyDispatch(to queue: DispatchQueue, work: @convention(block) () -> Void)

// (actual name should match chosen name convention)
func notify(on queue: DispatchQueue, using block: @convention(block) () -> Void)

}

…(and presumably the API would have manual enter/leave/wait methods and so on exposed).

I don’t feel strongly here but bring it up in case others feel similarly.

I’m a little confused about the `DispatchSpecificKey<T>` class; is it anything more than a way to "smuggle in” a generic type parameter for the associated value?

I think it’s a little stronger than “smuggle in” here, it allows the compiler to enforce that you have the same type going into setSpecific that you get out of getSpecific (or DispatchQueue.getSpecific) for a given key. The C API here forces you to cast away from void* and I think this is a good example of how the Swift equivalent API is helping make things safer.

Also on queue-specifics, what is our expected story if we have custom destructors? Subclass `DispatchSpecificKey`?

The value supplied to setSpecific is boxed inside a class that’s then retained. When the queue is deallocated, or the value is replaced then the box is released and normal Swift semantics for memory management will kick in on your boxed value. That way the API is still flexible enough to consume non-objects, like Ints, but also capable of taking references to classes too.

For things like `Int` specifics, I assume this API is storing auto-boxed values…? Is there any way to side-step if we use want to store an unsafe pointer? It’s not a big deal for me if we can’t under this API, TBH, but I’d at least like to see this API’s implementation and costs spelled-out more explicitly.

For `DispatchData`, is there a principled reason there isn’t something like this defined:

struct DispatchDataSegment {
let bytes: UnsafeBufferPointer<UInt8>
let byteIndex: Int
}

extension DispatchData {

/// Returns a sequence that enumerates the contiguous chunks,
/// e.g. a sequence with elements of type `DispatchDataSegment`.
///
/// Sequence-based eplacement-for `enumerateBytes(_:)`
var segmentSequence: DispatchDataSegmentSequence { get }

}

This is a good path to investigate in future improvements here.

…or something analogous (instead of the proposed use dispatch_data_apply?)?

I don’t see any API yet for setting target queues, or getting queue labels. I know the proposal isn’t documenting the APIs in full but it’s hard to evaluate in that absence.

I don’t see basic API on dispatch sources yet for things like setting event handlers, (etc.); again I know the APIs aren’t fully specified here but it’s hard to evaluate something that’s not fully specified.

These should be present in today’s updated module listing.

···

On May 13, 2016, at 9:29 AM, plx via swift-evolution <swift-evolution@swift.org> wrote:

  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Excellent, thanks for answering my questions!

If the classes should/can not be subclassed, they should probably be marked
as 'final' in order to make this clear to consumers, regardless of
performance or correctness implications.

Austin

···

On Tue, May 10, 2016 at 11:12 PM, Matt Wright <mww@apple.com> wrote:

> On May 10, 2016, at 10:22 PM, Austin Zheng via swift-evolution < > swift-evolution@swift.org> wrote:
>
> I think this is a great idea and a great proposal. GCD is already a
powerful, elegant tool available to Swift users, and this makes it feel
even more Swift-like.
>
> Feedback/questions:
> - Is there a use case for user subclassing of a queue type? If not,
should they be final?

Currently it’s not possible to subclass these classes in Objective C
either, the metaclass symbols for the libdispatch Objective-C classes are
not exported. This same restriction applies to those classes when
interacting with them in swift, even though the classes themselves are not
marked `final`.

> - Is there a reason to use class methods rather than static methods for
the queue types? I was under the impression that static methods would be
preferred unless a good reason exists to dispatch upon metatype.

This detail passed me by, I will investigate.

> - Nit: "DispatchWallTime" is spelled "DispatchWalltime" (lowercase 't')
in the code samples.

I apologise, along with the one or two other spelling/naming issues others
have pointed out. One or two of these names changed recently and I clearly
didn’t catch all of them.

> - Is it allowed/technically possible for non-stdlib code to use
_ObjectiveCBridgable?

Similar to the Foundation mutability proposal, this will end up being an
internal implementation detail of DispatchData’s struct bridging.

Regards,
M

>
> Best,
> Austin
>
>
> On Tue, May 10, 2016 at 9:39 PM, Chris Lattner via swift-evolution < > swift-evolution@swift.org> wrote:
> Hello Swift community,
>
> The review of "SE-0088: Modernize libdispatch for Swift 3 naming
conventions" begins now and runs through May 17. The proposal is available
here:
>
>
https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md
>
> Reviews are an important part of the Swift evolution process. All
reviews should be sent to the swift-evolution mailing list at
>
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> or, if you would like to keep your feedback private, directly to the
review manager.
>
> What goes into a review?
>
> The goal of the review process is to improve the proposal under review
through constructive criticism and contribute to the direction of Swift.
When writing your review, here are some questions you might want to answer
in your review:
>
> * What is your evaluation of the proposal?
> * Is the problem being addressed significant enough to warrant a
change to Swift?
> * Does this proposal fit well with the feel and direction of
Swift?
> * If you have used other languages or libraries with a similar
feature, how do you feel that this proposal compares to those?
> * How much effort did you put into your review? A glance, a
quick reading, or an in-depth study?
>
> More information about the Swift evolution process is available at
>
> https://github.com/apple/swift-evolution/blob/master/process.md
>
> Thank you,
>
> -Chris Lattner
> Review Manager
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

Did not see this proposal coming down the pipeline, but a more Swift-like
GCD will be fantastic. In terms of painting the bike shed, I'm not quite
sure about having adverbs "synchronously" and "asynchronously" as method
names. Conveniently, "sync" and "async" avoid the issue entirely, and they
are pretty widespread and acceptable as terms of art, no?

One more nit: "DispatchSourceMachRecv" in the table, but
"DispatchSourceMachReceive" in the code sample.

···

On Wed, May 11, 2016 at 12:24 AM, Austin Zheng via swift-evolution < swift-evolution@swift.org> wrote:

I also think that this proposal highlights a reason why the stdlib should
have some sort of 'indigenous' binary data capability, given that both
Foundation and libdispatch would theoretically be able to leverage such a
feature.

Austin

On Tue, May 10, 2016 at 10:22 PM, Austin Zheng <austinzheng@gmail.com> > wrote:

I think this is a great idea and a great proposal. GCD is already a
powerful, elegant tool available to Swift users, and this makes it feel
even more Swift-like.

Feedback/questions:
- Is there a use case for user subclassing of a queue type? If not,
should they be final?
- Is there a reason to use class methods rather than static methods for
the queue types? I was under the impression that static methods would be
preferred unless a good reason exists to dispatch upon metatype.
- Nit: "DispatchWallTime" is spelled "DispatchWalltime" (lowercase 't')
in the code samples.
- Is it allowed/technically possible for non-stdlib code to use
_ObjectiveCBridgable?

Best,
Austin

On Tue, May 10, 2016 at 9:39 PM, Chris Lattner via swift-evolution < >> swift-evolution@swift.org> wrote:

Hello Swift community,

The review of "SE-0088: Modernize libdispatch for Swift 3 naming
conventions" begins now and runs through May 17. The proposal is available
here:

https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md

Reviews are an important part of the Swift evolution process. All
reviews should be sent to the swift-evolution mailing list at

        https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the
review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review
through constructive criticism and contribute to the direction of Swift.
When writing your review, here are some questions you might want to answer
in your review:

        * What is your evaluation of the proposal?
        * Is the problem being addressed significant enough to warrant a
change to Swift?
        * Does this proposal fit well with the feel and direction of
Swift?
        * If you have used other languages or libraries with a similar
feature, how do you feel that this proposal compares to those?
        * How much effort did you put into your review? A glance, a
quick reading, or an in-depth study?

More information about the Swift evolution process is available at

        https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Dispatch is already released (on two platforms). So that ship sailed in 2010. The question in front of us is whether we're going to focus in getting the Linux port to parity with Darwin or whether we're going off an an API design adventure before seriously addressing that goal.

It seems prudent to point out that "API design" appears last on our list of Swift 3 goals, while "Portability <https://github.com/apple/swift-evolution&gt;&quot; is in the top three. So I don't know why my position would be "extreme", as it is more consistent with what we are on paper supposed to be doing in this release.

It also seems prudent to point out that we are going to do the first preview branch tomorrow. Obviously none of us really know what to expect, but the official guidance includes such statements as "only changes that align with the core goals of the release will be considered" and "Source-breaking changes to the language will be considered on a case-by-case basis." I think we should consider whether rewriting the entire Dispatch API surface area is something that would clear that bar.

I agree with all the individual API changes. They're great. I just think the timing is wrong. We should get to Darwin parity, and then we'll be in a position to pull the trigger on this.

Drew

···

On May 11, 2016, at 6:34 AM, David Hart <david@hartbit.com> wrote:

It sounds extreme to me to release a v1 of a library without giving yourself the flexibility to iterate on it beforehand.

So maybe that will conform to the API naming guideline? Or would the verb have to be in the base name of the func?

It seems from the guidelines that the intent is for the verb to be in the base name of the func, especially since there is another set of guidelines for naming function parameters.

In general the other methods in the proposal are verbs (perform(), notify(), wait(), cancel(), etc.)

At least for me, not including a verb makes the API read like the sentence “The dog quickly”. This wasn’t so bad in the C API, because you could read the word ‘dispatch’ as the verb.

Looking at the current GDC API, it does seem like dispatching synchronously is the rare and special case.

Could there be just a single dispatch() method, with async as a flag with a default value of true?

It might be a little ugly because most of the other parameters of the proposed asynchronously() method would not apply in the sync case.

James

···

On May 11, 2016, at 7:14 AM, Ricardo Parada <rparada@mac.com> wrote:

Jacob Bandes-Storch suggested:

synchronously(execute work: …)

So maybe that will conform to the API naming guideline? Or would the verb have to be in the base name of the func?

Or perhaps:

synchronously(dispatch work: …)
asynchronously(dispatch work: …)

On May 11, 2016, at 9:32 AM, James Dempsey via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

The method names

  synchronously()
  asynchronously()

are both adverbs, not noun phrases or verb phrases.
These methods have side effects, so each name should have a verb in it to make it a verb phrase.

Since these are the methods where you actually dispatch a block into a queue

dispatchSynchronously()
dispatchAsynchronously()

would include the verb in the name of the methods.