[SR-12820] No way to avoid ARC traffic for closures known not to escape #55266
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
standard library
Area: Standard library umbrella
Additional Detail from JIRA
md5: 264446cc88dffb0e861de599f03d29a2
Issue Description:
Consider a parallel `forEach`. We know the closure doesn't escape the call, but it needs to be copied to all threads. Even if we `unsafeBitCast` the type of the closure away, there's no way to call it without inducing a retain/release pair, as you can see here: https://swift.godbolt.org/z/igFqV9
Of course I realize the type aliasing is probably illegal, but it serves to illustrate the point. The function pointer in the closure uses a calling convention that matches neither
@convention(c)
nor@convention(thin)
, so there's no way to invoke it and manually pass the context pointer without generating ARC traffic. We really need some kind of callableUnmanagedFunction<F>
type or@convention(rawSwift)
to represent the raw function pointer in the closure.The text was updated successfully, but these errors were encountered: