Implement __attribute__((objc_direct)), __attribute__((objc_direct_me… #328
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.
…mbers))
attribute((objc_direct)) is an attribute on methods declaration, and
attribute((objc_direct_members)) on implementation, categories or
extensions.
A
direct
property specifier is added (@Property(direct) type name)These attributes / specifiers cause the method to have no associated
Objective-C metadata (for the property or the method itself), and the
calling convention to be a direct C function call.
The symbol for the method has enforced hidden visibility and such direct
calls are hence unreachable cross image. An explicit C function must be
made if so desired to wrap them.
The implicit
self
and_cmd
arguments are preserved, however tomaintain compatibility with the usual
objc_msgSend
semantics,3 fundamental precautions are taken:
for instance methods,
self
is nil-checked. On arm64 backends thistypically adds a single instruction (cbz x0, ) to the
codegen, for the vast majority of the cases when the return type is a
scalar.
for class methods, because the class may not be realized/initialized
yet, a call to
[self self]
is emitted. When the proper deploymenttarget is used, this is optimized to
objc_opt_self(self)
.However, long term we might want to emit something better that the
optimizer can reason about. When inlining kicks in, these calls
aren't optimized away as the optimizer has no idea that a single call
is really necessary.
the calling convention for the
_cmd
argument is changed: the callerleaves the second argument to the call undefined, and the selector is
loaded inside the body when it's referenced only.
As far as error reporting goes, the compiler refuses:
interface isn't (the other way around is allowed, as the direct
attribute is inherited from the declaration),
id
with a direct method,As warnings:
@selector() or messaging is used,
Lastly an
objc_direct_members
attribute is added that can decorate@implementation
blocks and causes methods only declared there (and inno
@interface
) to be automatically direct. When decorating an@interface
then all methods and properties declared in this block aremarked direct.
Radar-ID: rdar://problem/2684889
Differential Revision: https://reviews.llvm.org/D69991
Reviewed-By: John McCall