<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 17, 2017, at 7:13 PM, Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">on Tue Jan 17 2017, Jonathan Hull <</span><a href="http://jhull-at-gbis.com/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">jhull-AT-gbis.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Bringing it back towards the initial post, what if there was a<br class="">separation from true needs-to-take-down-the-entire-system trapping and<br class="">things like out-of-bounds and overflow errors which could stop at<br class="">thread/actor bounds (or in some cases even be recovered)?<br class=""><br class="">The latter were the ones I was targeting with my proposal. They live<br class="">in this grey area, because honestly, they should be throwing errors if<br class="">not for the performance overhead and usability issues. <br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I fundamentally disagree with that statement. There is value in</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">declaring certain program behaviors illegal, and in general for things</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">like out-of-bounds access and overflow no sensible recovery (where</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">“recovery” means something that would allow the program to continue</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">reliably) is possible. </span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>I think we do fundamentally disagree. I know I come from a very different background (Human-Computer Interaction & Human Factors) than most people here, and I am kind of the odd man out, but I have never understood this viewpoint for anything but the most severe cases where the system itself is in danger of being compromised (certainly not for an index out of bounds). In my mind “fail fast” is great for iterating in development builds, but once you are deploying, the user’s needs should come ahead of the programmer’s.</div><div><br class=""></div><div>Shouldn’t a system be as robust as possible and try to minimize the fallout from any failure point? I don’t consider crashing and losing all of the user’s data minimal. It used to be that something like dividing by zero took down the entire machine. Now we mimic that by crashing the application, even though it isn’t strictly necessary. Wouldn’t it be even better if we only took down the current operation, notified the user about what happened and continue on?</div><div><br class=""></div><div>Swift does a great job of using forcing functions (like optionals) to make some errors impossible, and this is literally the opposite of that. This requires the programmer to remember to add a check that the number is within certain bounds, but there is no reminder for them to do that. The failure is silent (i.e. there isn’t a ‘!’ or ’try' to mark that it is a possibility), at runtime, under certain conditions and not others. It is a recipe for bugs which cause a crash for the user.</div><div><br class=""></div><div>If we wanted fool-proof arrays, then the subscript would return an optional, forcing the programmer to think about and deal with the possibility of out-of-bounds failure (that is how we handle dictionary lookups after all). If I remember correctly, we don’t do that because of performance. Instead we ask the programmer to remember to check against the array count first, just like we used to ask the programmer to remember to check for nil pointers in C++.</div><div><br class=""></div><div>The idea that a programmer can or should be perfect is a lovely fantasy… My CS teachers always talked about how it would encourage bad programming if there wasn’t punishment for making these types of mistakes.</div><div><br class=""></div><div>I don’t see the value in punishing the user for the programmer’s mistake, and I have rarely seen a case where sensible recovery wouldn’t be possible (given Swift’s error handling). In most real-world applications, you would just end up cancelling whatever operation was happening, reverting to the state before it, and notifying the user of the problem. The programming languages which get into trouble are the ones which treat everything as valid, so they just keep barreling on, overwriting data or something like that. We don’t have that problem though, since we have sensible error handling that can be used to fail an operation and get things back to a previous state (or better yet, avoiding overwriting the state until after the operation has succeeded). We should aim for robustness, and crashing isn’t robust.</div><div><br class=""></div><div>Please note: I am not saying we allow memory access out of bounds. We are still triggering an error state when these things happen (either returning nil or throwing an error), we’re just not crashing the entire program because of it.</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">My solution was to give the compiler a way to know that this was the<br class="">desired behavior and optimize the throwing away unless it was<br class="">explicitly requested.<br class=""><br class="">I guess another option would be to introduce a new concept for this<br class="">grey type of error. Maybe instead of ‘fatalError’ you have something<br class="">with a different name saying “this should only take down the current<br class="">actor”… and then you add a well defined process for cleanup.<br class=""><br class="">I would still really like to see the ability to turn this type of<br class="">thing into normal throwing error handling, so maybe something like<br class="">‘fatalThrow’ which takes the same information as ‘throw’, so that it<br class="">can be converted to a standard throw by the caller, but otherwise<br class="">traps and takes down the actor. That would make certain types of<br class="">algorithms much simpler for me.<br class=""><br class="">Thanks,<br class="">Jon<br class=""><br class=""><blockquote type="cite" class="">On Jan 17, 2017, at 11:49 AM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><br class="">on Mon Jan 16 2017, Chris Lattner <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Jan 16, 2017, at 3:57 PM, David Waite via swift-evolution<br class=""></blockquote><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><blockquote type="cite" class=""><br class="">My interpretation is that he was advocating a future where a<br class="">precondition’s failure killed less than the entire process. Instead,<br class="">shut down some smaller portion like a thread, actor, or container<br class=""></blockquote><br class=""><blockquote type="cite" class="">like .Net's app domains (which for those more familiar with<br class="">Javascript could be loosely compared with Web Workers).<br class=""><br class="">Today - if you wanted a Swift server where overflowing addition<br class="">didn’t interrupt your service for multiple users, you would need to<br class="">use something like a pre-fork model (with each request handled by a<br class="">separate swift process)<br class=""><br class="">That's the difference between CLI and desktop apps where the process<br class="">is providing services for a single user, and a server where it may<br class="">be providing a service for thousands or millions of users.<br class=""></blockquote><br class="">Agreed, I’d also really like to see this some day. It seems like a<br class="">natural outgrowth of the concurrency model, if it goes the direction<br class="">of actors. <br class=""><br class="">If you’re interested, I speculated on this direction in this talk:<br class=""><a href="http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf" class="">http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf</a><br class=""><<a href="http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf" class="">http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf</a><br class=""><<a href="http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf" class="">http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf</a>>><br class=""></blockquote><br class="">I totally support the idea of emergency shutown measures<br class="">(e.g. save document for recovery),<span class="Apple-converted-space"> </span><br class=""><br class="">In general, though, when a precondition is violated, it means your<br class="">program state is compromised in an arbitrarily bad way. Unfortunately,<br class="">that applies equally across process boundaries as it does across thread<br class="">boundaries, if there's some kind of static guarantee of safety as might<br class="">be provided by actors. This means you need a way to make decisions<br class="">about which kinds of precondition violations should be considered<br class="">recoverable as long as you're willing to abandon the job, and which<br class="">really do need to be fatal for the whole process... and I don't know if<br class="">anyone's really ever figured that problem out. It'd be cool if Swift<br class="">could solve it.<br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">-Dave<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class=""></blockquote></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-Dave</span></div></blockquote></div><br class=""></body></html>