[PATCH] D75574: RFC: Implement objc_direct_protocol attribute to remove protocol metadata

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 24 11:57:38 PDT 2020


rjmccall added a comment.

Okay, the result of internal review is that we're comfortable with this feature.

Reviewers brought up the point that it would be interesting to add some way to ensure unique emission of a protocol, so that protocols that can't be non-runtime could avoid bloating binary sizes outside the defining module.  Maybe this could be deployment-gated so that builds targeting iOS 21 can take advantage of NSMoveOnlyType being exported but builds targeting iOS 20 still have to emit their own copy.  But that's a separable improvement and doesn't need to block this work.



================
Comment at: clang/include/clang/Basic/AttrDocs.td:4505
+intend to use protocols to implement compile time behaviors then the metadata is
+uneeded overhead.
+  }];
----------------
Suggestion:

  The ``objc_non_runtime_protocol`` attribute can be used to mark that an
  Objective-C protocol is only used during static type-checking and doesn't
  need to be represented dynamically.  This avoids several small code-size
  and run-time overheads associated with handling the protocol's metadata.
  A non-runtime protocol cannot be used as the operand of a ``@protocol``
  expression, and dynamic attempts to find it with ``objc_getProtocol`` will fail.

  If a non-runtime protocol inherits from any ordinary protocols, classes and
  derived protocols that declare conformance to the non-runtime protocol
  will dynamically list their conformance to those base protocols.


================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1062
+  "non_runtime_protocol attribute on protocol %0 ignored (not implemented by this Objective-C runtime)">,
+  InGroup<IgnoredAttributes>;
 def err_objc_direct_dynamic_property : Error<
----------------
This is dead now.


================
Comment at: clang/lib/CodeGen/CGObjC.cpp:466
+  for (; begin != end; ++begin)
+    AppendFirstRuntimeProtocols(*begin, PDs);
+
----------------
Should this make an effort to avoid declaring redundant bases?  e.g.

```
@protocol Base @end
@protocol NonRuntime<Base> @end
@protocol Runtime<Base> @end
@interface MyClass <Runtime, NonRuntime> @end
@implementation MyClass @end
```

Ideally `MyClass` only declares conformance to `Runtime` rather than redundantly declaring conformance to `Base`, which I think you'd naturally get from this algorithm.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75574/new/

https://reviews.llvm.org/D75574



More information about the cfe-commits mailing list