Closed
Bug 881579
Opened 13 years ago
Closed 12 years ago
Avoid multiple-inclusions of headers where possible
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla24
People
(Reporter: n.nethercote, Assigned: n.nethercote)
References
Details
Attachments
(1 file)
If you have a canonical #ifndef wrapper in a header file, e.g.:
#ifndef FOO_H__
...
#endif
clang and GCC will avoid re-including the header if FOO_H__ is defined. But
for this to work the #ifndef wrapper must have the above form (|#if
defined(FOO_H__)| is also allowed, and there can't be any tokens before or
afterwards (but whitespace and comments are ok).
(See
http://gcc.gnu.org/onlinedocs/cpp/Once_002dOnly-Headers.html#Once_002dOnly-Headers
and http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html for details.)
SpiderMonkey has numerous header files that violate this, and so get
multiply-included unnecessarily.
| Assignee | ||
Comment 1•13 years ago
|
||
This patch fixes all the easy ones. I've used the -H option to confirm the
relevant files are singly-included. It reduces the number of files #include
during an SM build from 103,666 to 99,074.
There are some cases not yet fixed:
- Some inlines.h/-inl.h files are still multiply-included. I think this is
because jsinferinlines has all its #includes *before* the #ifndef wrapper!
Fixing this is non-trivial.
- More importantly, all the $OBJDIR/dist/system_wrappers_js/*.h files lack an
#ifndef wrapper. I tried adding one but it caused compile errors. I also
tried #pragma once but that caused different compile errors. I'm not sure
what this means.
It would be good to fix this one because some of these files are #included
many times. Furthermore, on my system some system headers don't have a
canonical #ifndef wrapper (d'oh) and if the system_wrappers_js/*.h files were
fixed that would prevent those system headers being multiply-included.
Attachment #760682 -
Flags: review?(jorendorff)
| Assignee | ||
Comment 3•12 years ago
|
||
Comment on attachment 760682 [details] [diff] [review]
Use the canonical #ifndef wrapper form in SpiderMonkey headers so that GCC and clang can avoid including them more than once per compilation unit.
Review of attachment 760682 [details] [diff] [review]:
-----------------------------------------------------------------
No good deed goes unpunished...
Attachment #760682 -
Flags: review?(jorendorff) → review?(benjamin)
Comment 4•12 years ago
|
||
Comment on attachment 760682 [details] [diff] [review]
Use the canonical #ifndef wrapper form in SpiderMonkey headers so that GCC and clang can avoid including them more than once per compilation unit.
Review of attachment 760682 [details] [diff] [review]:
-----------------------------------------------------------------
I see our naming convention of these defines is inconsistent.
gc/StoreBuffer.h -> jsgc_storebuffer_h___
ion/BaselineCompiler.h -> jsion_baseline_compiler_h__
vm/Stack.h -> Stack_h__
For bonus points, you could standardize that.
Attachment #760682 -
Flags: review?(benjamin) → review+
| Assignee | ||
Comment 5•12 years ago
|
||
> For bonus points, you could standardize that.
I'll do it as a follow-up. I've emailed the JS internals list to get consensus on the exact form.
(Nb: A cursory inspection finds that gc/FindSCCs-inl.h doesn't even have a #ifndef wrapper! Yuk. Bring on bug 880088.
| Assignee | ||
Comment 6•12 years ago
|
||
Comment 7•12 years ago
|
||
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
You need to log in
before you can comment on or make changes to this bug.
Description
•