Implicit self capturing in GCD

As async-await has brought us the special annotation, @_implicitSelfCapture, why don’t we add this annotation to DispatchQueue.async and sync? Any idea why it’s been added only for async-await?

I don’t see any reason to not do that. First, it seems that the rule about escaping closures and the explicit self is no longer actual because it is broken already when working with Task. Second, we have the same level of safety when calling DispatchQueue.main.async or UIView.animate. Moreover, developers could use this annotation in their own code when they see a closure will always be called and destroyed after some time.

I’m asking because it makes me a bit frustrated. It seems Swift and its ecosystem stick to different rules and principles. While the language declares one behaviour, some of tools follow it, and some do not. And we could at least make our tools (GCD, for instance) more convenient, I have doubts adding one annotation in several places in a library would require much time.

1 Like