This is an archive of the discontinued LLVM Phabricator instance.

[Clang][ObjC] Add optionality to property attribute strings.
AcceptedPublic

Authored by al45tair on Oct 5 2022, 8:33 AM.

Details

Summary

Add a new attribute, "?", to the property attribute string for properties of protocols that are declared @optional.

Diff Detail

Event Timeline

al45tair created this revision.Oct 5 2022, 8:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 8:33 AM
al45tair requested review of this revision.Oct 5 2022, 8:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 8:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ahatanak accepted this revision.Oct 7 2022, 7:44 PM

This LGTM for apple's runtime assuming it knows how to handle the new string.

clang/lib/AST/ASTContext.cpp
7857

You can omit braces here.

clang/test/CodeGenObjC/objc-asm-attribute-test.m
20

Do you need this change?

72

Can you use regular expression for the two globals above and check they are referenced in @"_OBJC_$_PROP_LIST_MySecretNamespace.Protocol2?

This revision is now accepted and ready to land.Oct 7 2022, 7:44 PM
al45tair updated this revision to Diff 476387.Nov 18 2022, 2:09 AM
al45tair marked 2 inline comments as done.

Updated following comments from @ahatanak.

al45tair marked an inline comment as done.Nov 18 2022, 2:10 AM
al45tair added inline comments.
clang/test/CodeGenObjC/objc-asm-attribute-test.m
20

No, I think this is left-over from an earlier revision. I'll get rid of it.

@theraven Any chance you could glance over this and reassure us that it isn't going to break the GNU runtime if we do this? (We're adding an extra attribute in the property attribute string so that we can detect @optional properties in ObjC protocols at runtime.)

@theraven Any chance you could glance over this and reassure us that it isn't going to break the GNU runtime if we do this? (We're adding an extra attribute in the property attribute string so that we can detect @optional properties in ObjC protocols at runtime.)

It shouldn't, we ignore any unknown property attributes. I'd be more concerned about code outside the runtime. Lots of things parse encoding strings badly, but the property APIs make it much easier to query known attributes and so I think that's a lot lower risk than changing anything in encoding strings. It's a shame to use ?, since that is unknown type in type encodings and that may confuse some parsers..

@theraven Any chance you could glance over this and reassure us that it isn't going to break the GNU runtime if we do this? (We're adding an extra attribute in the property attribute string so that we can detect @optional properties in ObjC protocols at runtime.)

It shouldn't, we ignore any unknown property attributes. I'd be more concerned about code outside the runtime. Lots of things parse encoding strings badly, but the property APIs make it much easier to query known attributes and so I think that's a lot lower risk than changing anything in encoding strings. It's a shame to use ?, since that is unknown type in type encodings and that may confuse some parsers..

I don't think using ? is really an issue here; anyone parsing types from these strings already has to stop for the , character, since the string is defined to be a ,-separated list of attributes, the first of which is the type attribute T<type encoding>. If they were going to be confused by the ?, then they'd already get confused by the other attribute characters, many of which are also valid in a type encoding.