[swift-evolution] [Proposal] [Discussion] Explicit Toll-Free Conversions
phausler at apple.com
Thu Mar 23 12:47:31 CDT 2017
> On Mar 23, 2017, at 10:14 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>> On Mar 23, 2017, at 09:05, Joe Groff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On Mar 22, 2017, at 10:41 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> On Mar 22, 2017, at 10:35 PM, Robert Widmann via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> Alternatives considered
>>>> Do nothing and continue to accept this implicit conversion.
>>> One alternative would be to import CFArray as a typealias for NSArray, etc, erasing the distinction between the two types completely. I did suggest this to Jordan at one point and he pointed out some problems, but I don’t remember them now. Hopefully Jordan can chime in.
>> I'd prefer this solution as well, especially since toll-free bridged CF types are nearly indistinguishable from their NS counterparts at runtime, so trying to maintain the distinction for dynamic casts or reflection has historically been problematic. Part of the problem is that, as Charlie noted, CFArray/Dictionary/Set can take an arbitrary set of retain/release callbacks, in which case the resulting container isn't fully NSArray-compatible. I'm not sure that happens often enough with CF containers in the SDKs that accounting for that case is worth the burden of separating the types.
> [adding Philippe, who has also thought about this problem]
> The abstract problems I know of are:
> (1) custom callbacks
> (2) it's legal to import CF without importing Foundation
> (3) CF types will not get generics
> In practice, (1) is both exceedingly rare (only one public API that I know of) and something that can be worked around by using the CF APIs on the array—that is, we can keep CFArrayGetValueAtIndex around and just have it take an NSArray. (2) is something we can deprecate and/or fix. (3) just means we have to import the CFArray as NSArray rather than Array.
> We would have to be very sure that all toll-free bridged CF types are marked as such; adding toll-free bridging would not be a backwards-compatible change since it would conflate two types into one. This leads us to a fourth problem: this is a source-breaking change if anyone has overloads for both CFArray and NSArray, or adds a protocol to CFArray that NSArray already has. We probably already need to solve the latter in some way, and could try to cross our fingers about the former.
I think there are a bit more ramifications that are under the hood here; we should consider the full extent of what changing the behavior between CF types and NS types a bit more deeply than just a cursory proposal. Additionally as with any change to Foundation and CoreFoundation this should be passed around internally to the appropriate stakeholders that will be in charge of providing long term support for any sort of change this would apply to.
As an initial gut reaction; I would say that this is well past our stage for changes for Foundation and I would hate to see something be pushed out last minute that takes away development time from other important tasks on the table.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution