<div dir="ltr">Great! Totally forgot to check those, even though I already skimmed them before ;). Looks like a lot of great improvements in one go!</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 22, 2016 at 9:52 AM, Dave Abrahams via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
on Thu Mar 17 2016, Patrick Pijnappel <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
<br>
> Currently, bit shifting with an amount greater than or equal to the size of<br>
> the type traps:<br>
><br>
> func foo(x: Int32) {<br>
> let y = x << 32 // Runtime trap (for any << or >> with amount >= 32)<br>
> }<br>
><br>
> I propose to make this not trap, and just end up with 0 (or ~0 in case of<br>
> right-shifting a negative number):<br>
><br>
</span>> - Unlike the traps for integer arithmetic and casts, it is obvious what<br>
<span class="">> a bitshift past the end does as fundamentally the behavior stays the same.<br>
</span>> - If the intention is to make it analogous with multiplication/division<br>
<span class="">> by 2**n, the checks don't really change anything. Right shift are still<br>
> identical to divisions by 2**n. Left shifts are like multiplication by 2**n<br>
> but with different overflow behavior, which is already the case with the<br>
> current rules (e.g. Int.max << 1 doesn't trap)<br>
</span>> - It could lead to bugs where users expect this to work, e.g. the<br>
<span class="">> following crashes when the entire buffer is consumed: buffer = buffer <<<br>
> bitsConsumed<br>
</span>> - Bitshift are often used in performance-sensitive code, and with the<br>
<span class="">> current behavior any non-constant bit shift introduces a branch.<br>
<br>
</span>This is addressed in<br>
<a href="https://github.com/apple/swift/blob/master/test/Prototypes/Integers.swift.gyb" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/test/Prototypes/Integers.swift.gyb</a><br>
which we intend to propose very soon.<br>
<br>
(negative shift amounts work too).<br>
<br>
<a href="https://github.com/apple/swift/blob/master/test/Prototypes/Integers.swift.gyb#L1628" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/test/Prototypes/Integers.swift.gyb#L1628</a><br>
<br>
For users who want to be sure they're not paying for any checks, there<br>
is a masking bitshift (&<<, &>>, &<<=, &>>=).<br>
<br>
--<br>
-Dave<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>