[swift-evolution] Generic Subscripts
Ben Cohen
ben_cohen at apple.com
Fri Jan 13 11:29:41 CST 2017
> On Jan 12, 2017, at 1:37 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org> wrote:
>
>> Before I submit it, could someone let me know if adding generics to subscripts would influence the ABI? ( still feel pretty clueless in that area).
>
> It won’t change the ABI of existing subscript calls, but if the standard library introduces new generic subscripts that replace older non-generic subscripts, it will impact ABI.
>
Specifically, we currently have to have a _Hashable protocol that has a _toAnyHashable() method in order to implement Dictionary<AnyHashable,*> subscripting using concrete types as keys. A replacement subscript that was generic over all Hashable types would solve this more neatly, and would be source-compatible, but affects the ABI of the stdlib.
https://github.com/apple/swift/blob/master/stdlib/public/core/Hashable.swift#L16
Generic subscripts would also make it easier to implement one-sided ranges e.g.
myCollection[i...] // slice from i to the end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170113/2d870fe7/attachment.html>
More information about the swift-evolution
mailing list