Open aschwaighofer opened 5 years ago
The Objective-C convention is actually fine with you stack-allocating all block arguments; it's considered the callee's responsibility to Block_copy
them. cc @rjmccall
https://clang.llvm.org/docs/BlockLanguageSpec.html
https://clang.llvm.org/docs/AutomaticReferenceCounting.html#blocks
Correct. We don't do this only because we're being cautious about lifetimes. If we had a reliable way of detecting that the copy is unnecessary, it would be a significant win.
Clang has actually implemented an optimization where it eliminates the copying logic from `noescape` blocks entirely, essentially generating them as global blocks that happen to be allocated on the stack.
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Improvement | |Assignee | None | |Priority | Medium | md5: fd60c5edf6ddc3d03a27ac1f2a14393bIssue Description:
When we pass closures to @noescape objective c block arguments the closures are allocated on the heap. We should also stack allocate them.