aschwaighofer has a pull request for stack-allocating Swift closures.

Slava Pestov:

Short history of non-escaping functions:

- Swift 4.1 and earlier: type checker enforcement; same ABI as escaping

- Swift 4.2: new ABI - the context is a trivial pointer and not ref-counted like with escaping

- now: non-escaping contexts allocated on stack

The ABI change was key here - Arnold frontloaded the changes before we started locking down, now stack-allocation is “just” an optimization

And ancient pre-history for those who weren’t around at the time:

- Swift 2.2 and earlier: all function values escaping by default, opt-in @noescape attribute for parameter types

- Swift 3: @noescape becomes default for function parameters, @escaping added to opt-in

More trivia: In ancient Swift the accepted idiom to turn a non-escaping function into an escaping one was unfortunately an unsafeBitCast(). The compiler added a special withoutActuallyEscaping form and started screaming about casts in 4.0 so that we could stage in the ABI change