@@ -4122,6 +4122,104 @@ overheads associated with defining and calling such a method.
4122
4122
}];
4123
4123
}
4124
4124
4125
+ def ObjCDirectDocs : Documentation {
4126
+ let Category = DocCatDecl;
4127
+ let Content = [{
4128
+ The ``objc_direct`` attribute can be used to mark an Objective-C method as
4129
+ being *direct*. A direct method is treated statically like an ordinary method,
4130
+ but dynamically it behaves more like a C function. This lowers some of the costs
4131
+ associated with the method but also sacrifices some of the ordinary capabilities
4132
+ of Objective-C methods.
4133
+
4134
+ A message send of a direct method calls the implementation directly, as if it
4135
+ were a C function, rather than using ordinary Objective-C method dispatch. This
4136
+ is substantially faster and potentially allows the implementation to be inlined,
4137
+ but it also means the method cannot be overridden in subclasses or replaced
4138
+ dynamically, as ordinary Objective-C methods can.
4139
+
4140
+ Furthermore, a direct method is not listed in the class's method lists. This
4141
+ substantially reduces the code-size overhead of the method but also means it
4142
+ cannot be called dynamically using ordinary Objective-C method dispatch at all;
4143
+ in particular, this means that it cannot override a superclass method or satisfy
4144
+ a protocol requirement.
4145
+
4146
+ Because a direct method cannot be overridden, it is an error to perform
4147
+ a ``super`` message send of one.
4148
+
4149
+ Although a message send of a direct method causes the method to be called
4150
+ directly as if it were a C function, it still obeys Objective-C semantics in other
4151
+ ways:
4152
+
4153
+ - If the receiver is ``nil``, the message send does nothing and returns the zero value
4154
+ for the return type.
4155
+
4156
+ - A message send of a direct class method will cause the class to be initialized,
4157
+ including calling the ``+initialize`` method if present.
4158
+
4159
+ - The implicit ``_cmd`` parameter containing the method's selector is still defined.
4160
+ In order to minimize code-size costs, the implementation will not emit a reference
4161
+ to the selector if the parameter is unused within the method.
4162
+
4163
+ Symbols for direct method implementations are implicitly given hidden
4164
+ visibility, meaning that they can only be called within the same linkage unit.
4165
+
4166
+ It is an error to do any of the following:
4167
+
4168
+ - declare a direct method in a protocol,
4169
+ - declare an override of a direct method with a method in a subclass,
4170
+ - declare an override of a non-direct method with a direct method in a subclass,
4171
+ - declare a method with different directness in different class interfaces, or
4172
+ - implement a non-direct method (as declared in any class interface) with a direct method.
4173
+
4174
+ If any of these rules would be violated if every method defined in an
4175
+ ``@implementation`` within a single linkage unit were declared in an
4176
+ appropriate class interface, the program is ill-formed with no diagnostic
4177
+ required. If a violation of this rule is not diagnosed, behavior remains
4178
+ well-defined; this paragraph is simply reserving the right to diagnose such
4179
+ conflicts in the future, not to treat them as undefined behavior.
4180
+
4181
+ Additionally, Clang will warn about any ``@selector`` expression that
4182
+ names a selector that is only known to be used for direct methods.
4183
+
4184
+ For the purpose of these rules, a "class interface" includes a class's primary
4185
+ ``@interface`` block, its class extensions, its categories, its declared protocols,
4186
+ and all the class interfaces of its superclasses.
4187
+
4188
+ An Objective-C property can be declared with the ``direct`` property
4189
+ attribute. If a direct property declaration causes an implicit declaration of
4190
+ a getter or setter method (that is, if the given method is not explicitly
4191
+ declared elsewhere), the method is declared to be direct.
4192
+
4193
+ Some programmers may wish to make many methods direct at once. In order
4194
+ to simplify this, the ``objc_direct_members`` attribute is provided; see its
4195
+ documentation for more information.
4196
+ }];
4197
+ }
4198
+
4199
+ def ObjCDirectMembersDocs : Documentation {
4200
+ let Category = DocCatDecl;
4201
+ let Content = [{
4202
+ The ``objc_direct_members`` attribute can be placed on an Objective-C
4203
+ ``@interface`` or ``@implementation`` to mark that methods declared
4204
+ therein should be considered direct by default. See the documentation
4205
+ for ``objc_direct`` for more information about direct methods.
4206
+
4207
+ When ``objc_direct_members`` is placed on an ``@interface`` block, every
4208
+ method in the block is considered to be declared as direct. This includes any
4209
+ implicit method declarations introduced by property declarations. If the method
4210
+ redeclares a non-direct method, the declaration is ill-formed, exactly as if the
4211
+ method was annotated with the ``objc_direct`` attribute. ``objc_direct_members``
4212
+ cannot be placed on the primary interface of a class, only on category or class
4213
+ extension interfaces.
4214
+
4215
+ When ``objc_direct_members`` is placed on an ``@implementation`` block,
4216
+ methods defined in the block are considered to be declared as direct unless
4217
+ they have been previously declared as non-direct in any interface of the class.
4218
+ This includes the implicit method definitions introduced by synthesized
4219
+ properties, including auto-synthesized properties.
4220
+ }];
4221
+ }
4222
+
4125
4223
def SelectAnyDocs : Documentation {
4126
4224
let Category = DocCatDecl;
4127
4225
let Content = [{
0 commit comments