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.
Details
Diff Detail
- Repository
- rC Clang
Event Timeline
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. |
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. |
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–8 | Spurious change that can be reverted? | |
31–33 | Spurious change that can be reverted? | |
clang/test/SemaObjC/attr-objc-non-lazy.m | ||
35 ↗ | (On Diff #181692) | Please add a newline to the end of this file. |
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. |
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?