Page MenuHomePhabricator

Add Attribute to define nonlazy objc classes
Needs ReviewPublic

Authored by joedaniels29 on Thu, Jan 10, 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.Thu, Jan 10, 1:21 PM
vsk added a subscriber: vsk.Thu, Jan 10, 3:11 PM
aaron.ballman requested changes to this revision.Fri, Jan 11, 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.Fri, Jan 11, 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
39–40

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?

31–32

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.