fix: Remove excessive CF_NOESCAPE and NS_NOESCAPE#76
Merged
jdtsmith merged 1 commit intojdtsmith:emacs-mac-30_1_expfrom Aug 11, 2025
Merged
Conversation
Closed
jdtsmith
reviewed
Aug 10, 2025
| - (void)enumerateChildWindowsUsingBlock:(NS_NOESCAPE void | ||
| (^)(NSWindow *child, BOOL *stop))block; | ||
| - (void)enumerateChildWindowsUsingBlock:(void | ||
| (NS_NOESCAPE ^)(NSWindow *child, BOOL *stop))block; |
Owner
There was a problem hiding this comment.
Is this just for consistency or does the order of the caret matter?
Contributor
Author
There was a problem hiding this comment.
That's right, this is for consistency only, the order doesn't matter.
Details
In a context of this gist.
I compiled a small example (just most important bits):
#define MY_NOESCAPE __attribute__ ((noescape))
void queue_block_1(void (^ MY_NOESCAPE block) (void)) {...}
void queue_block_2(void (MY_NOESCAPE ^block) (void)) {...}
void queue_block_3(MY_NOESCAPE void (^block) (void)) {...}
void queue_1(const char* arg)
{
queue_block_1(^{
printf("block_1: %s\n", arg);
});
}
void queue_2(const char* arg)
{
queue_block_2(^{
printf("block_2: %s\n", arg);
});
}
void queue_3(const char* arg)
{
queue_block_3(^{
printf("block_3: %s\n", arg);
});
}with $(brew --prefix llvm)/bin/clang -g -framework CoreFoundation -o reproducer_123 reproducer.m and then:
(lldb) dis -n queue_1
reproducer_123`queue_1:
[...]
reproducer_123[0x100000828] <+32>: mov w8, #-0x2f800000 ; =-796917760
[...]
(lldb) dis -n queue_2
reproducer_123`queue_2:
[...]
reproducer_123[0x1000008c4] <+32>: mov w8, #-0x2f800000 ; =-796917760
(lldb) dis -n queue_3
reproducer_123`queue_3:
[...]
reproducer_123[0x100000960] <+32>: mov w8, #-0x2f800000 ; =-796917760
jdtsmith
reviewed
Aug 11, 2025
| static void mac_within_gui_allowing_inner_lisp (void (^ CF_NOESCAPE) (void)); | ||
| static void mac_within_lisp (void (^ CF_NOESCAPE) (void)); | ||
| static void mac_within_gui_and_here (void (^) (void), | ||
| void (CF_NOESCAPE ^) (void)); |
Owner
There was a problem hiding this comment.
Here the idea is that block_here is executed locally, and so does not escape?
Contributor
Author
There was a problem hiding this comment.
Exactly that.
This is the only usage of block_here
206f229 to
b71c4e9
Compare
These annotations direct the compiler to optimize block allocation assuming the function to which it is passed calls it locally, and does not retain the block beyond the function body. Analyzed all occurrences of CF_NOESCAPE and NS_NOESCAPE and removed locations where the annotation seemed to be excessive, for example when the annotated block has been enqueued in a queue to execute in another loop. Such a block may have a an optimized placement as `NSConcreteGlobalBlock' on the stack on a callee side. This happen on non-Apple clang Apple at least from version 7 (see [1]). This tries to preserve as many of the NOESCAPES which serve a purpose; see [2], [3], and [4]. * src/macappkit.m (mac_within_gui, mac_within_lisp, mac_within_gui_and_here, mac_within_gui_allowing_inner_lisp): Remove excessive CF_NOESCAPE annotations, for blocks that are passed and executed in other threads or saved on queues. * src/macterm.h (mac_within_gui) : Remove excessive CF_NOESCAPE, for blocks that are passed and executed in other threads. * src/macappkit.h (enumerateChildWindowsUsingBlock): Harmonize NS_NOESCAPE placement. * src/macappkit.m (enumerateChildWindowsUsingBlock): Harmonize CF_NOESCAPE placement. [1] NixOS/nixpkgs#127902 (comment) [2] jdtsmith#43 [3] jdtsmith#48 [4] jdtsmith#69
b71c4e9 to
c3f3ce5
Compare
Owner
|
Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Analysed all occurrences of CF_NOESCAPE and NS_NOESCAPE and removed
where the annotation seemed to be excessive, for example when the
annotated block has been enqueued in a queue to execute in another loop.
Such a block, may have a an optimised placement as
NSConcreteGlobalBlockon stack on a callee side. This happen onnon-Apple clang Apple at least in version 7 (see [1]).
This is slightly different than fully disabling the blocks (see [2],
[3], and [4]), while trying to preserve as much of the NOESCAPES where
it seems to server a purpose.
mac_within_gui_and_here, mac_within_gui_allowing_inner_lisp): Remove
excessive CF_NOESCAPE, for blocks that are passed and executed in
other threads.
blocks that are passed and executed in other threads.
NS_NOESCAPE placement.
CF_NOESCAPE placement.
[1] NixOS/nixpkgs#127902 (comment)
[2] #43
[3] #48
[4] #69