[swift-dev] No return functions and program exit

Greg Parker gparker at apple.com
Tue Feb 7 06:22:31 CST 2017

> On Feb 6, 2017, at 9:48 AM, Michael Gottesman via swift-dev <swift-dev at swift.org> wrote:
> One thing that is an issue that has come up with ownership is that at the SIL level we do not distinguish in between exceptional noreturn functions and exceptional return functions.
> This is important since in the non-exceptional case, we would like to clean up all of the values used in the current function before calling the no-return function. An example of such a function is dispatch_main from libdispatch. In the exceptional case though, we are ok with leaking since the program will be exiting. Beyond reducing code size (I guess?), the argument I have heard for this is that this will allow for people to examine values in the debugger since we will not have cleaned things up before the abort is called.
> From what I can tell, if we are going to distinguish in between these cases, then we need a distinction in between the two baked into the compiler. Thoughts? I have code written that will enable either case to be handled as long as I can distinguish in between them at the SIL level.

How important is it to actually clean up in the non-exceptional cases? Historically whatever work is performed before dispatch_main() or NSApplicationMain() just leaks a little and nobody cares. 

(I suppose pthread_exit() is a non-exceptional exit that ought to do its best to clean up first.)

Avoiding cleanups before exceptional exits is important. We don't want to increase the code size of assert() and abort(). We also don't want to introduce additional potential crash points if the program's state is broken and it is merely trying to print a helpful error message on its way out. 

Greg Parker     gparker at apple.com     Runtime Wrangler

More information about the swift-dev mailing list