I think it would be a good idea to remove the covariance of Array since it is compiler magic and that would clear the way for a more general solution. <br><br>On Friday, 26 February 2016, Radek Pietruszewski via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Interesting. Two Qs:<br>
<br>
- when you say "moving in the direction of encouraging the use of abstract AnyCollection values", do you mean in general? To encourage people to use AnyCollection<T> instead of [T] in their code?<br>
- how could covariant collection casting look like in this world?<br>
<br>
Sent from my iPhone<br>
<br>
> On 25 Feb 2016, at 20:12, Joe Groff <<a href="javascript:;" onclick="_e(event, 'cvml', 'jgroff@apple.com')">jgroff@apple.com</a>> wrote:<br>
><br>
><br>
>> On Feb 25, 2016, at 9:07 AM, Jordan Rose via swift-evolution <<a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')">swift-evolution@swift.org</a>> wrote:<br>
>><br>
>> I think there are two things going on here:<br>
>><br>
>> - The compiler allows a memory-corrupting cast, which should be rejected (a bug).<br>
>> - But it's a useful thing to do (a language change).<br>
>><br>
>> I'm actually surprised about the bug, since we get plenty of questions about why the compiler doesn't allow it, implying that the compiler is indeed rejecting it. The answer is that protocol values and class values don't have the same representation, so converting between [Eatable] and [Burger] is an O(N) operation that requires allocating a new array. But that may not be a good enough reason not to allow it—conversions from NSArray to Array can do the same thing if the NSArray was mutable.<br>
><br>
> I've overheard discussion of removing the covariant container conversions altogether, since they're inconsistent with the rest of the language, lead to a lot of type-checker and runtime dynamic cast complexity, and have unpredictable performance if generalized, and moving in the direction of encouraging the use of abstract AnyCollection values instead of concrete Arrays, that would free us to make covariant conversions cheaper by wrapping instead of eagerly mapping the array representation.<br>
><br>
> -Joe<br>
><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote><br><br>-- <br>-- Howard.<br>