[swift-evolution] [Returned for Revision] SE-0095: Replace protocol<P1, P2> syntax with Any<P1, P2>

L Mihalkovic laurent.mihalkovic at gmail.com
Fri Jun 10 09:51:00 CDT 2016


> On Jun 10, 2016, at 4:20 PM, L. Mihalkovic <laurent.mihalkovic at gmail.com> wrote:
> 
> I noticed that the "impacted" section was not updated to the new syntax.

apologies, I was looking at the last reference to Any, and it is indeed correct as it is. 


as for the grammar, I guess it is just a matter of removing the reference to protocol<> and swapping in the new & operator in composition types:
GRAMMAR OF A PROTOCOL COMPOSITION TYPE

 <>protocol-composition-type → protocol­<­protocol-identifier-list <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier-list>­opt­>­
 <>protocol-identifier-list → protocol-identifier <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier>­  protocol-identifier <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier>­,­protocol-identifier-list <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier-list>­
 <>protocol-identifier → type-identifier <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/type-identifier>­
GRAMMAR OF A PROTOCOL COMPOSITION TYPE

 <>protocol-composition-type → protocol-identifier-list <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier-list>­
 <>protocol-identifier-list → protocol-identifier <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier>­  protocol-identifier <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier>­&­protocol-identifier-list <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/protocol-identifier-list>­
 <>protocol-identifier → type-identifier <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/type-identifier>­
In this form there is the problem of the degenerate case where protocol-identifier-list is empty which is required for Any.  The syntax I have been playing with for generalized existential would degenerate fine for covering this gap.

https://gist.github.com/lmihalkovic/8aa66542f5cc4592e967bade260477ef


> Additionally it might be useful to show the impact on the grammar.
> Regards
> (From mobile)
> On Jun 2, 2016, at 7:42 AM, Austin Zheng via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> Excellent.
>> 
>> I put together a PR with a revised proposal containing the core team's recommended approach. If anyone is curious they can see it here: https://github.com/austinzheng/swift-evolution/blob/ef6adbe0fe09bff6c44c6aa9d73ee407629235ce/proposals/0095-any-as-existential.md <https://github.com/austinzheng/swift-evolution/blob/ef6adbe0fe09bff6c44c6aa9d73ee407629235ce/proposals/0095-any-as-existential.md>
>> 
>> Since this is the de-facto second round discussion thread, I'll start with my personal opinion (which is *not* reflected in the PR): the '&' separators in lieu of commas are a good idea, but I would still prefer the types to be wrapped in "Any<>", at least when being used as existentials.
>> 
>> My reasons:
>> 
>> - Jordan Rose brought up a good point in one of the discussion threads today: a resilience goal is to allow a library to add an associated type to a protocol that had none and not have it break user code. If this is true whatever syntax is used for existentials in Swift 3 should be a valid subset of the generalized existential syntax used to describe protocol compositions with no associated types.
>> 
>> - I would rather have "Any<>" be used consistently across all existential types eventually than have it only be used for (e.g.) existential types with `where` constraints, or allowing two different representations of the same existential type (one with Any, and one without).
>> 
>> - I think any generalized existential syntax without delimiting markers (like angle braces) is harder to read than syntax with such markers, so I would prefer a design with those markers.
>> 
>> Best,
>> Austin
>> 
>>> On Jun 1, 2016, at 10:17 PM, Chris Lattner <clattner at apple.com <mailto:clattner at apple.com>> wrote:
>>> 
>>> 
>>>> On Jun 1, 2016, at 9:53 PM, Austin Zheng <austinzheng at gmail.com <mailto:austinzheng at gmail.com>> wrote:
>>>> 
>>>> This was indeed a very thorough review by the core team. I'll prepare a v2 proposal with this feedback taken into account so we can continue moving things along.
>>>> 
>>>> One quick question - is making whatever syntax is chosen for Swift 3 "forward-compatible" with a future generalized existential feature a concern?
>>> 
>>> Yes it is a concern, but we assume that the “X & Y” syntax will always be accepted going forward, as sugar for the more general feature that is yet to be designed.
>>> 
>>> -Chris
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/ebfa44a3/attachment.html>


More information about the swift-evolution mailing list