This is an archive of the discontinued LLVM Phabricator instance.

Add Attribute to define nonlazy objc classes
ClosedPublic

Authored by joedaniels29 on Jan 10 2019, 1:21 PM.

Details

Summary

Currently to get a nonlazy class in objective c, you need to define a +load method.
Because we do other work when we realize a class, other than just call that load method, it would be ideal to have an attribute to mark a class as nonlazy.
libdispatch, libtrace, objc, Foundation all define empty +load methods, simply to make certain classes nonlazy. This is done during process initialization which causes code pages to be faulted in that shouldn't be and increase the code side working set that is needed only for the sake of creating a process.

Diff Detail

Repository
rC Clang

Event Timeline

joedaniels29 created this revision.Jan 10 2019, 1:21 PM
vsk added a subscriber: vsk.Jan 10 2019, 3:11 PM
aaron.ballman requested changes to this revision.Jan 11 2019, 5:41 AM
aaron.ballman added a subscriber: aaron.ballman.

The patch is missing SemaObjC tests that ensure the attribute only appertains to the expected subjects, accepts no args, etc.

clang/include/clang/Basic/Attr.td
1696

No new undocumented attributes, please.

Does this attribute make sense when compiling a non-ObjC compiland? e.g., should this also have a let LangOpts = [ObjC]; as well?

clang/lib/Sema/SemaDeclAttr.cpp
6377–6379

Formatting is incorrect here -- you should run the patch through clang-format.

This revision now requires changes to proceed.Jan 11 2019, 5:41 AM

Tried to fix Aaron Ballman's feedback. Thanks Aaron!

It's still missing the tests in SemaObjC -- you can use clang\test\SemaObjC\attr-root-class.m as an example of what I'm talking about.

clang/include/clang/Basic/Attr.td
1697

You need to hook this up to ObjCNonLazyClassDocs.

clang/test/CodeGenObjC/non-lazy-classes.m
37–38

The formatting is incorrect here.

joedaniels29 marked 2 inline comments as done.

Hopefully addressed Aaron's comments. Thanks again Aaron.

never mind, I didnt address

It's still missing the tests in SemaObjC -- you can use clang\test\SemaObjC\attr-root-class.m as an example of what I'm talking about.

On second thought, I have addressed everything, I think.

clang/test/SemaObjC/attr-objc-non-lazy.m

Aaron, would you mind taking another look? Thanks a bunch.

In terms of implementation, the attribute code looks pretty close (just a few nits). However, someone more familiar with Obj-C should chime in with whether the attribute semantics make sense and whether the documentation will be sufficiently clear for an Objective-C user.

clang/include/clang/Basic/AttrDocs.td
3506

Add backticks around objc_init() because it should be in code font.

clang/test/CodeGenObjC/non-lazy-classes.m
6–7

Spurious change that can be reverted?

30–31

Spurious change that can be reverted?

clang/test/SemaObjC/attr-objc-non-lazy.m
35

Please add a newline to the end of this file.

rjmccall added inline comments.Jan 31 2019, 10:26 AM
clang/include/clang/Basic/AttrDocs.td
3506

I don't think "objc_init() time" is a widely-recognized concept. How about:

A non-lazy class will be initialized eagerly when the Objective-C runtime is loaded.  This is required for certain system classes which have instances allocated in non-standard ways, such as the classes for blocks and constant strings.  Adding this attribute is essentially equivalent to providing a trivial `+load` method but avoids the (fairly small) load-time overheads associated with defining and calling such a method.
joedaniels29 marked 4 inline comments as done.

Docs changes, formatting.

Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2019, 8:07 PM
rjmccall accepted this revision.Jan 31 2019, 8:18 PM

Thanks! I'd like Aaron to sign off as well before we commit this.

This revision is now accepted and ready to land.Feb 1 2019, 5:57 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2019, 3:32 PM