<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>FWIW, reswitch looks to me like it's really just sugar around a while loop. For example, your factorial example can be rewritten as:<br></div>
<div>&nbsp;</div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">[5, 7, 6].map {</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; var value = ($0, 1)</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; repeat {</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; switch value {</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; case (0, let n):</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return n</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; case let (n, m):</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = (n-1, m * n)</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break // or continue</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; }</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; } while true</span><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">}</span><br></div>
<div>&nbsp;</div>
<div>And breaking out of the loop can be done by attaching a label to the repeat:<br></div>
<div>&nbsp;</div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">loop: repeat {<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; switch value {<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; case .Foo:<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; &nbsp; &nbsp; break loop<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; // ...<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">&nbsp; &nbsp; }<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, &quot;courier new&quot;, monospace, sans-serif;">}</span><br></div>
<div>&nbsp;</div>
<div>All that said, I think that a proposal to add `reswitch` is actually orthogonal to whether we should remove `fallthrough`, since as I mentioned before `reswitch` doesn't actually replace some of the behavior that `fallthrough` provides. I'm strongly against removing `fallthrough`, but I'm somewhat ambivalent on `reswitch` and I'd rather it be considered separately.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard<br></div>
<div>&nbsp;</div>
<div>On Mon, Dec 7, 2015, at 12:59 PM, Alex Lew via swift-evolution wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>I like the idea of a mechanism for tail-call recursion, but agree with Colin that it's a little strange to hide it behind keywords like "switch" and "reswtich" -- it makes it less discoverable.<br></div>
<div>&nbsp;</div>
<div><div>For example, it seems like reswitch, if implemented, would become the only way to do "recursive" anonymous functions (closures):<br></div>
<div>&nbsp;</div>
<div>// calculate the factorial of each item in the list<br></div>
<div>[5, 7, 6].map {&nbsp;<br></div>
<div>&nbsp; &nbsp; &nbsp; switch ($0, 1) {<br></div>
<div>&nbsp; &nbsp; &nbsp; case (0, let n):<br></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return n<br></div>
<div>&nbsp; &nbsp; &nbsp; case let (n, m):<br></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reswitch (n-1, m * n);<br></div>
<div>&nbsp; &nbsp; &nbsp; }<br></div>
<div>}<br></div>
</div>
<div>&nbsp;</div>
<div>(Or am I missing something?) I don't feel strongly either way about this feature -- I do think it'd be neat to have -- but it would not be entirely obvious to someone wondering "how would I create a 'recursive' closure for factorial" that they should turn to switch statements.<br></div>
</div>
<div><div>&nbsp;</div>
<div><div>On Mon, Dec 7, 2015 at 3:38 PM, Colin Barrett via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex;"><div>&nbsp;</div>
<div><div>&nbsp;</div>
<blockquote type="cite"><div><span>
   On Dec 7, 2015, at 8:55 AM, Joe Groff &lt;
   <a href="mailto:jgroff@apple.com">jgroff@apple.com</a>&gt; wrote:
  </span><br></div>
<div>&nbsp;</div>
<div><blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;" type="cite"><div><span><br>On Dec 6, 2015, at 1:14 PM, Jacopo Andrea Giola via swift-evolution &lt;
     <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:
    </span></div>
<div>&nbsp;</div>
<div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><span>
      Yes, I’m aware that at this time the reswitch can be abused and maybe can be better refined to disallow such cases.
     </span><br></div>
</div>
</blockquote><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><span>
    Infinite reswitch loops seem useful. I'm thinking in particular of interpreter loops, where it's common to use GCC's computed goto extension when written in C.
   </span><br></div>
</div>
</blockquote><div>&nbsp;</div>
<div><span></span>I agree that they have useful semantics; I just wonder if it’s more clear to have explicit recursion (with TCO ;) rather than to add a looping construct that effectively does the same thing...<br></div>
</div>
<div>&nbsp;</div>
<div>Can’t lie though, given the lack of TCO in Swift, a keyword like this would probably mean fewer stack frames in code I’ve written myself (for instance, a parser combinator library).<br></div>
<div>&nbsp;</div>
<div><div>-Colin
 <br></div>
<div><div><div>&nbsp;</div>
<blockquote type="cite"><div><blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;" type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">Checking the case statement is not a problem by itself, but can be a problem if is coupled with a where clause that is not true when you fallthrought.<br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">I’ve written a really bad draft here
      <span></span> <a href="https://gist.github.com/JGiola/f735212789bf2f697847">https://gist.github.com/JGiola/f735212789bf2f697847</a><br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">If anyone wants to jump in and elaborate further is welcome. I will try to stay on par with this thread but I’m really bad at writing so every help is welcome.<br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">And if I remember correctly Daniel Jakult was the first one to made this proposal so if he wants to take on and then made the official proposal has every right to do so and I will be very glad if my gist can be a first reference :)<br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">- Jacopo<br></div>
<div>&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><blockquote type="cite"><div>On 06 Dec 2015, at 21:52, Colin Barrett &lt;
        <a href="mailto:colin@springsandstruts.com">colin@springsandstruts.com</a>&gt; wrote:<br></div>
<div>&nbsp;</div>
<div><div style="word-wrap:break-word;"><div>Apologies, Jacopo, for missing the updated proposal, and thank you for your patience in summarizing it again.<br></div>
<div>&nbsp;</div>
<div>I’ve only glanced through it but my concern here is that it introduces a whole class of new and creative “foot-guns" :) In particular, it allows this construction to loop arbitrarily and creatively, particularly in the case of associated values.<br></div>
<div>&nbsp;</div>
<div>I’m not sure why not checking the case statement is considered a problem for the fallthrough keyword. Assuming it’s impossible to fallthrough to a case that introduces binders (what would they be bound to?), and that this is statically checked (both of which seem reasonable assumptions to me, although if I’m wrong feel free to correct me), isn’t it the entire point of the fallthrough keyword that it skips checking the case statement? I can understand how that might be somewhat confusing (and perhaps it should be documented less prominently) but I’m not sure how it’s a *problem*, exactly...<br></div>
<div>&nbsp;</div>
<div>I think I’m still on the side of keeping fallthrough. What’s the downside of doing nothing? For instance in the case of ++ and -- those features complicate the design of a numerics library.<br></div>
<div>&nbsp;</div>
<div>Thanks,<br></div>
<div>-Colin<br></div>
<div>&nbsp;</div>
<div><div><div><blockquote type="cite"><div>On Dec 6, 2015, at 3:06 PM, Jacopo Andrea Giola &lt;
              <a href="mailto:swift-evolution@jacopo.giola.org">swift-evolution@jacopo.giola.org</a>&gt; wrote:<br></div>
<div>&nbsp;</div>
<div><div style="word-wrap:break-word;"><div>&nbsp;Hi Colin,<br></div>
<div>&nbsp;</div>
<div>the initial proposal was indeed to remove entirely the `fallthrough` keyword but many people expressed your similar concern and from that point the discussion was steered through an "enhancement" and better refinement of the keyword.<br></div>
<div>&nbsp;</div>
<div>The new idea is to substitute the old keyword with "reswitch" passing the desired new value on which the switch is applied.<br></div>
<div>So something like this:<br></div>
<div>&nbsp;</div>
<div>switch (enum) {<br></div>
<div><span style="white-space:pre-wrap;"></span>case .One:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something<br></div>
<div><span style="white-space:pre-wrap;"></span>reswitch .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>case .Two:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something else<br></div>
<div><span style="white-space:pre-wrap;"></span>default:<br></div>
<div><span style="white-space:pre-wrap;"></span>// and so one<br></div>
<div>}<br></div>
<div>&nbsp;</div>
<div>This new behaviour, IMO, is better suited for Swift because is more declarative of the developer intent and doesn't carry over unintentional misbehaviour.<br></div>
<div>Is more declarative because you are forced to state in which case you want to go, and even if the order of the switch’ cases will change in the future, you don't fall in the wrong case by mistake.<br></div>
<div>&nbsp;</div>
<div><div>switch (enum) {<br></div>
<div><span style="white-space:pre-wrap;"></span>case .One:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something<br></div>
<div><span style="white-space:pre-wrap;"></span>reswitch .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>case .OneAndAHalf<br></div>
<div><span style="white-space:pre-wrap;"></span>// maybe this change is not made by you but by a messed up merge<br></div>
<div><span style="white-space:pre-wrap;"></span>case .Two:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something else<br></div>
<div><span style="white-space:pre-wrap;"></span>default:<br></div>
<div><span style="white-space:pre-wrap;"></span>// and so one<br></div>
<div>}<br></div>
</div>
<div>&nbsp;</div>
<div>In this case if you are using the fallthrough keyboard your code is now broken by accident, and depending on what are you trying to do inside the cases you can have a hidden bug that your tests are not seeing right away.&nbsp;<br></div>
<div>&nbsp;</div>
<div>Another advantage is that in this way you can made more cases&nbsp;fallthrough in the same one even if they are not one over each other<br></div>
<div>&nbsp;</div>
<div><div>switch (enum) {<br></div>
<div><span style="white-space:pre-wrap;"></span>case .One:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something<br></div>
<div><span style="white-space:pre-wrap;"></span>reswitch .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>case .OneAndAHalf<br></div>
<div><span style="white-space:pre-wrap;"></span>// so something that you don’t want to do for .One<br></div>
<div><span style="white-space:pre-wrap;"></span>reswitch .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>case .Two:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something else that you may want to do for .One and .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>default:<br></div>
<div><span style="white-space:pre-wrap;"></span>// and so one<br></div>
<div>}<br></div>
</div>
<div>&nbsp;</div>
<div>I must say that this is a side effect that can be used to messed up the code flow in a way that is not intended, but is a new behaviour that gives more power to the switch statement.<br></div>
<div>&nbsp;</div>
<div>The reswitch keyword in addition is not a mere&nbsp;fallthrough on the new case without doing the optional checking attached to it, but is intended to be a new call and all the check are executed.<br></div>
<div>&nbsp;</div>
<div><div><div>switch (enum) {<br></div>
<div><span style="white-space:pre-wrap;"></span>case .One:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something<br></div>
<div><span style="white-space:pre-wrap;"></span>x = 0;<br></div>
<div><span style="white-space:pre-wrap;"></span>reswitch .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>case .OneAndAHalf<br></div>
<div><span style="white-space:pre-wrap;"></span>// so something that you don’t want to do for .One<br></div>
<div><span style="white-space:pre-wrap;"></span>reswitch .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>case .Two where x &gt; 0:<br></div>
<div><span style="white-space:pre-wrap;"></span>// do something else that you may want to do for .One and .Two<br></div>
<div><span style="white-space:pre-wrap;"></span>element =&nbsp;array[x]<br></div>
<div><span style="white-space:pre-wrap;"></span>default:<br></div>
<div><span style="white-space:pre-wrap;"></span>// and so one<br></div>
<div>}<br></div>
<div>(I’m going by memory and by writing this snippets in the mail app directly, so the code must be incorrect in the syntax and for this I’m sorry).<br></div>
<div>&nbsp;</div>
<div>In this case if enum is .One the only case that is executed is case .One and the code doesn’t&nbsp;fallthrough in the .Two case because we are made the where invalid by changing the x to a value less than 1.<br></div>
<div>&nbsp;</div>
<div>Now I don’t remember who was the first one who mede this proposal, and I don’t know if he is working on a first draft to lay down the things better, but for me this can be a nice improvement and a neat break with the C-switch behaviour that Swift has trying to change from the very first beta disallowing the implicit fallthrough.<br></div>
<div>&nbsp;</div>
<div>I can be completely wrong but I see the `fallthrough`keyword as a “temporary” implementation for ease the transition from Obj-C to Swift and is time to improve it and made the switch statement even more powerful.<br></div>
<div>&nbsp;</div>
</div>
</div>
<div><div>- Jacopo
                <br></div>
<div>Sent from my iPad<br></div>
</div>
<div><div>&nbsp;</div>
<div>On 06 Dec 2015, at 19:57, Colin Barrett via swift-evolution &lt;
                <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:
                <br></div>
<div>&nbsp;</div>
</div>
<blockquote type="cite"><div><div><div>tl;dr The fallthrough keyword, as far as I am aware, isn’t costing us anything; and has at least minimal utility, as I try to demonstrate.<br></div>
</div>
<div>&nbsp;</div>
<div>Apologies for jumping into this thread at an awkward point, but I’ve only just now subscribed to this list.<br></div>
<div>&nbsp;</div>
<div>I think the fallthrough keyword is useful in certain circumstances. I’ve also yet to see an example of where it creates a negative impact, either in code, optimization, or what have you. Other than “It’s like something in C, and C is old and busted” I’m unsure of the rationale for removing it. (Feel free to point me in the right direction.)<br></div>
<div>&nbsp;</div>
<div>Consider the Planet enum from the documentation. One of the simplest way to define the number of a planet (i.e. its 1-based index in the ordering of planets wrt. distance from the sun) is using a switch and fall-through:<br></div>
<div>&nbsp;</div>
<div><a href="https://gist.github.com/cbarrett/23b24a9fe76efdf006df">https://gist.github.com/cbarrett/23b24a9fe76efdf006df</a><br></div>
<div>&nbsp;</div>
<div>This technique is very extensible — for instance imagine computing the force induced by the gravity of the other planets on a particular planet. All that would need to change is the case statements.<br></div>
<div>&nbsp;</div>
<div>Yes, you could write this by putting the planets into a list and mapping or folding (or looping) over that, but unless the compiler can “unroll” that construct, you’re paying for an allocation simply bc of your choice of control flow. But in fact, you could imagine generalizing this construct into the implementation of fold for the Planet type — low-overhead folds for monomorphic types seems like a pretty compelling an natural use case for fallthrough to me.<br></div>
<div>&nbsp;</div>
<div>Thanks,<br></div>
<div>-Colin<br></div>
<div><div>&nbsp;</div>
<div><blockquote type="cite"><div>On Dec 6, 2015, at 4:52 AM, Jacopo Andrea Giola via swift-evolution &lt;
                     <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div>&nbsp;</div>
<div><div><div>+1 for this idea, but I will prefer the reswitch keyword instead of overloading continue with a new syntax.<br></div>
<div>&nbsp;</div>
<div>If this proposal is accepted, it must be coupled with a compiler check that the reswitch statements don't introduce an infinite "switch" loop.<br></div>
<div><div>&nbsp;</div>
<div>Sent from my iPad<br></div>
</div>
<div><div>&nbsp;</div>
<div>On 06 Dec 2015, at 00:23, Steve Canon via swift-evolution &lt;
                       <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:
                       <br></div>
<div>&nbsp;</div>
</div>
<blockquote type="cite"><div><div>Very much thinking out loud and not really the implications, I wonder if we might just use "continue" instead of "reswitch".<br></div>
<div>&nbsp;</div>
<div><div>I very much like specifying what case to fall through into, no matter how we spell it.
                         <br></div>
<div>&nbsp;</div>
<div>- Steve<br></div>
</div>
<div><div>&nbsp;</div>
<div>On Dec 5, 2015, at 4:45 PM, John McCall via swift-evolution &lt;
                         <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:
                         <br></div>
<div>&nbsp;</div>
</div>
<blockquote type="cite"><div><div><blockquote type="cite"><div>On Dec 5, 2015, at 1:31 PM, John McCall via swift-evolution &lt;
                             <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div><div style="word-wrap:break-word;"><div><blockquote type="cite"><div>On Dec 4, 2015, at 11:37 PM, John Calsbeek &lt;
                                 <a href="mailto:john.calsbeek+lists@gmail.com">john.calsbeek+lists@gmail.com</a>&gt; wrote:<br></div>
<div><div style="word-wrap:break-word;"><div><div>`fallthrough` is conceptually similar to `goto` in that both allow natural expression of concepts that exist at the instruction level but are otherwise difficult to express with nested control structures. `fallthrough` is perhaps slightly less objectionable because control flow remains local, but it has a similar role.<br></div>
<div>&nbsp;</div>
<div>It is not particularly natural to write `switch` statements with `fallthrough` in the reverse order that can be seen in Duff’s Device and similar constructs (case 7 falls through to 6 which falls through to 5, etc.). It’s just because you know for certain that all the code in case 6 would be duplicated in case 7, so 7 can transfer into 6 without a jump instruction. Communicating that to the compiler without `fallthrough` requires deeply nested `if`s.<br></div>
</div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>Right.&nbsp; One idea that I’ve always had for “fallthrough” is that we might parameterize it in the future; parameterized it would mean “repeat the switch with this new value”, so that unparameterized fallthrough would mean “repeat the switch with a notional value that ends up in the next case”.&nbsp; There’s a very common pattern in switches of deferring to another case that I’ve always found very awkward to write in C, and while sometimes there’s no choice but to extract a helper function, there’s a still-fairly-structural code pattern here that I think we can sensibly support.<br></div>
</div>
<div>&nbsp;</div>
<div>On the other hand, there’s an argument that this is an inappropriate extension for “fallthrough” specifically, which is one reason we’ve never pursued it.<br></div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>Oh, I see that Joe already brought this up, spelled “reswitch”.<br></div>
</div>
<div>&nbsp;</div>
<div>John.<br></div>
<div><div>&nbsp;</div>
<blockquote type="cite"><div><div style="word-wrap:break-word;"><div>&nbsp;</div>
<div>John.<br></div>
<div><div>&nbsp;</div>
<blockquote type="cite"><div><div style="word-wrap:break-word;"><div><div>&nbsp;</div>
<div>One defense comes to mind: there is talk of Swift aiming at systems programming. Is writing a threaded interpreter loop within the potential scope of Swift? That’s a use case that could make use of both `fallthrough` and `goto` (computed goto, really).<br></div>
<div>&nbsp;</div>
<div>switch op {<br></div>
<div>case LOAD_INDIRECT:<br></div>
<div>&nbsp; &nbsp;in0 = memory[in1]<br></div>
<div>&nbsp; &nbsp;fallthrough<br></div>
<div>case LOAD:<br></div>
<div>&nbsp; &nbsp;out0 = memory[in0]<br></div>
<div>//...<br></div>
<div>}<br></div>
<div>&nbsp;</div>
<div>I am personally interested in the prospect of a language that can scale up to high-level concepts and down to “portable assembler,” but I don’t know if that is the right direction for Swift’s evolution.<br></div>
<div>&nbsp;</div>
<div>Cheers,<br></div>
<div>John<br></div>
</div>
<div>&nbsp;</div>
<div><blockquote type="cite"><div>On Dec 4, 2015, at 2:42 PM, John McCall &lt;
                                     <a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>&gt; wrote:<br></div>
<div>&nbsp;</div>
<div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><blockquote type="cite"><div>On Dec 4, 2015, at 2:33 PM, Kevin Ballard &lt;
                                        <a href="mailto:kevin@sb.org">kevin@sb.org</a>&gt; wrote:<br></div>
<div><div><div>It's not actually Duff's Device. Duff's Device relies on the fact that C switch statements don't actually introduce a new scope, and so it overlaps a switch with a do-while loop. This lets it only test the number of bytes once, to jump into the middle of the loop, and then it switches over to a while loop that decrements a counter every 8 instructions. Basically, it's a trick for manual loop unrolling that deals with non-multiple-of-8 counts efficiently.
                                          <br></div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>To be pedantic, C switch statements do introduce a new scope.&nbsp; What Duff’s Device exploits is that switch is allowed to jump into (almost) arbitrary scopes, and cases can appear anywhere recursively inside a switch.<br></div>
</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">But your point that Swift’s switch requires cases to be at the top level within a switch and thus prevents the use of Duff’s Device is 100% correct.<br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">John.<br></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><div>&nbsp;</div>
<blockquote type="cite"><div><div><div>&nbsp;</div>
<div>Steve's code is also an example of manual loop unrolling that deals with non-multiple-of-8 counts, but it has calculate the number of bytes on every iteration instead of once. It's a good example of one of the uses of `fallthrough`, it's just not Duff's Device. It's impossible to use Duff's Device in Swift.
                                          <br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard<br></div>
<div>&nbsp;</div>
<div>On Fri, Dec 4, 2015, at 02:16 PM, Greg Titus wrote:
                                          <br></div>
<blockquote type="cite"><div>Streza’s source code is an example of Duff’s Device, which is a big place where switch fallthrough is arguably the cleanest way to do things and the reason why I’d personally prefer to keep it as part of the language.
                                           <br></div>
<div>&nbsp;</div>
<div><blockquote type="cite"><div>On Dec 4, 2015, at 2:12 PM, Erica Sadun &lt;
                                             <a href="mailto:erica@ericasadun.com">erica@ericasadun.com</a>&gt; wrote:
                                             <br></div>
<div>&nbsp;</div>
<div><div style="word-wrap:break-word;"><div>Oh let it die, let it die. Any time I use fallthrough I find myself re-factoring to stop using it.&nbsp;
                                               <br></div>
<div>&nbsp;</div>
<div><b>True fact</b>: On all of
                                               <span></span> <a href="http://gist.github.com/">gist.github.com</a>, there are only 22 gist results for "fallthrough language:swift".
                                               <br></div>
<div>Half of those are people just testing out the feature. Most of the remaining ones are just complex cases:
                                               <br></div>
<div><i>case .Enum1, .Enum2:</i> <br></div>
<div>expressed as&nbsp;
                                               <br></div>
<div><i>case .Enum1: fallthrough</i> <br></div>
<div><i>case .Enum2:</i> <br></div>
<div>&nbsp;</div>
<div>And then there's streza: &nbsp;
                                               <a href="https://gist.github.com/stevestreza/2557dc5ec9e7c694d7ea">https://gist.github.com/stevestreza/2557dc5ec9e7c694d7ea</a> <span></span>&nbsp; I'm pretty sure that ponies were harmed in the production of whatever that last bit is.
                                               <br></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><blockquote type="cite"><div>On Dec 4, 2015, at 3:05 PM,
                                                 <span></span> <a href="mailto:jalkut@red-sweater.com">jalkut@red-sweater.com</a> <span></span>wrote:
                                                 <br></div>
<div>&nbsp;</div>
<div><div><div>In the spirit of some other proposals that remove C or C++ style artifacts, what do folks think about the possibility of removing the "fallthrough" keyword from the language?
                                                   <br></div>
<div>&nbsp;</div>
<div>My understanding is this keyword is only used for the archaic seeming purpose of perpetuating C-style fallthrough from one switch statement to the subsequent one. The documentation hedges the use of this keyword in forbidding terms that make it clear its use is not encouraged. The presence of the keyword, while an improvement over C’s implicit fallthrough, is a mark of inelegance on an otherwise well-designed, opinionated implementation of swtich statements.
                                                   <br></div>
<div>&nbsp;</div>
<div>The ugliness of fallthrough’s C-style behavior even demands a caveat in the documentation:
                                                   <br></div>
<div>&nbsp;</div>
<div>"The fallthrough keyword does not check the case conditions for the switch case that it causes execution to fall into. The fallthrough keyword simply causes code execution to move directly to the statements inside the next case (or default case) block, as in C’s standard switch statement behavior."
                                                   <br></div>
<div>&nbsp;</div>
<div>To my mind, the caveat explains just what is wrong with fallthrough, both in C or Swift: coded that is clearly labeled with deliberate conditions can nonetheless be reached.
                                                   <br></div>
<div>&nbsp;</div>
<div>I quipped about this on Twitter, and the most common pushback I got seemed to be from people who either did not know about Swift’s support for comma-separated case statements, or harbored an aesthetic preference for clustering such cases together with fallthrough statements.
                                                   <br></div>
<div>&nbsp;</div>
<div>In my opinion, unless somebody can think of a strong defense for supporting intentional fallthrough in Swift, removing the keyword would be a move in the direction of minimizing the language’s complexity while also discouraging poor coding style in switch statements.
                                                   <br></div>
<div>&nbsp;</div>
<div>Thoughts?
                                                   <br></div>
<div>&nbsp;</div>
<div>Daniel
                                                   <br></div>
<div>&nbsp;</div>
<div>_______________________________________________
                                                   <br></div>
<div>swift-evolution mailing list
                                                   <br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</div>
</div>
</blockquote></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
</div>
<div>_______________________________________________
                                              <br></div>
<div>swift-evolution mailing list
                                              <br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><u>_______________________________________________</u> <br></div>
<div>swift-evolution mailing list
                                           <br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</blockquote><div>&nbsp;</div>
</div>
<div>_______________________________________________
                                        <br></div>
<div>swift-evolution mailing list
                                        <br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
<div> <span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"><span></span>_______________________________________________</span></span> <br></div>
<div> <span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">swift-evolution mailing list</span></span> <br></div>
<div> <a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div> <a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;" href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
</div>
<div>_______________________________________________
                                 <br></div>
<div>swift-evolution mailing list
                                 <br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
</div>
<div>_______________________________________________
                             <br></div>
<div>swift-evolution mailing list
                             <br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
</div>
</blockquote><blockquote type="cite"><div><div><span>_______________________________________________</span> <br></div>
<div> <span>swift-evolution mailing list</span> <br></div>
<div> <span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span> <br></div>
<div> <span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span> <br></div>
</div>
</blockquote></div>
</blockquote><blockquote type="cite"><div><div><span>_______________________________________________</span> <br></div>
<div> <span>swift-evolution mailing list</span> <br></div>
<div> <span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span> <br></div>
<div> <span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span> <br></div>
</div>
</blockquote></div>
<div>_______________________________________________
                     <br></div>
<div>swift-evolution mailing list
                     <br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a> <br></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
</div>
</div>
</blockquote><blockquote type="cite"><div><div><span>_______________________________________________</span> <br></div>
<div> <span>swift-evolution mailing list</span> <br></div>
<div> <span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span> <br></div>
<div> <span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span> <br></div>
</div>
</blockquote></div>
</div>
</blockquote></div>
<div>&nbsp;</div>
</div>
</div>
</div>
</div>
</blockquote></div>
<div>&nbsp;</div>
<div> <span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"></span></span> <span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">_______________________________________________</span></span> <br></div>
<div> <span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">swift-evolution mailing list</span></span> <br></div>
<div> <a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> <br></div>
<div> <a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;" href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
</blockquote></div>
</div>
</div>
<div>&nbsp;</div>
<div style="margin-top:10px;font-size:12px;font-family:Helvetica, Arial;color:rgb(153, 153, 153);">Untracked with 
 <a href="https://trackbuster.com/?sig" style="color:rgb(153, 153, 153);">Trackbuster</a><br></div>
<div>&nbsp;</div>
<div>_______________________________________________<br></div>
<div>
swift-evolution mailing list<br></div>
<div> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
<div>&nbsp;</div>
</blockquote></div>
</div>
<div><img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/372e47bd196a2bc45e9ec7943a07d03cf3ef1c936438d22b2eb7a08178e3ee6d/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e4157784f49377d223644305b475177427c697f677c46674a796631673f433145597252325248344746607b635b4138483167775a4a59563167374a703d685675516977457057697e6d4a494559685d63317e635e403758765d633d223649343940715f4b66485275685267397c44435754783a734b416436523d41513a423258703e6654335277505554313658694333305965534473546d2232426d2236495d22324e614376353471737a5f6d22364a707d22364e6e635149334d223240317744754958736569407238505076514338315d23344d23344/open"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div>&nbsp;</div>
</body>
</html>