<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="">On Dec 7, 2015, at 3:18 PM, Mark Lacey <<a href="mailto:mark.lacey@apple.com" class="">mark.lacey@apple.com</a>> wrote:<br class=""><div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;">It seems like this could also be handled by passing continuations that should be run on the return paths of callees. The continuation a function passes to its callee would wrap the continuation passed to it by its caller, so they would get executed in the original order. That’s an ABI change though, and a potentially expensive one.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;">We’ve considered doing something like this as an optimization to enable more proper tail calls in other cases (e.g. for the ARC case where you release after return). This would be done by cloning callees, and adding a new parameter. It’s not clear how worthwhile it would be to pursue this, and how expensive it would be in terms of code bloat.</div></div></div></div></blockquote><br class=""></div><div class="">Why not just make “tail” a modifier on return that guarantees you’ll either get a tail call, or a compile time error?</div><div class=""><br class=""></div><div class="">Use of “tail return foo()” in a context with a defer in flight could/should just produce that compile time error then. This would provide the predictable programming model that people are seeking, and can provide good QoI so people know how to solve the problem if they really want the tail call (remove or change the defer).</div></div></div></blockquote><div class=""><br class=""></div>If you really don’t want to support defer in functions that have tail calls, I think what you're suggesting is the right approach. As Joe pointed out the optimization I had in mind wouldn’t be necessary if we had support for just transferring ownership at the point of these tail calls (as opposed to the retain/release we emit around the call for these arguments today).</div></div></blockquote><br class=""></div><div>I would really prefer that a “tail return” not change the semantics of the function, it merely is an assertion that the tail call is guaranteed. This means that defer cannot be used, but we can exploit the “early destroy’s are ok” aspect of ARC to solve its issues.</div><div><br class=""></div><div>I agree that this isn’t enough to solve the calling convention issue, an attribute or magic for self recursion seems fine to me.</div><div><br class=""></div><div>-Chris</div><br class=""></body></html>