This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PCH, and more generally C++ parser performance
Geoff Keating <geoffk@cygnus.com> writes:
| Zack Weinberg <zack@wolery.cumb.org> writes:
|
| > Look over at the conversation I've been having with Mark Mitchell. He
| > thinks we can't get away with lazy parsing of anything in C++, and has
| > some solid arguments for it.
Yes, I'm also of the opinion that you can't simply do lazy parsing in
C++, unless you have indeed a very very sophisticated scheme to get
name resolution right, especially to get the two-phase name lookup in
templates (see 14.6 of the C++ Standard). You also need to keep
track of points of instantiation.
| That's why my preferred scheme uses lazy _loading_, keyed by
| identifier names.
|
| I claim (and I'd be interested to know if anyone has a counterexample)
| that if an identifier is never used other than to be declared or
| defined, then program behaviour is the same as if those declarations
| were never made.
How exactly do you determine that an identifier is never used other
than to be declared or defined given separate compilation? Consider
the nifty_counter idiom popular in the C++ community for consistent
initialization of global variables across different translation units:
// nifty_counter.H
class nifty_counter {
public:
nifty_counter();
~nifty_counter();
private:
static int count;
};
static nifty_counter counter;
Every translation unit that #includes "nifty_counter.H" defines an
instance of nifty_counter -- at first glance there is no other use.
Actually, the constructor and destructor will be responsible for
incrementing and decrementing nifty_counter::count for proper
initialization of globals across different translation units.
That idiom is, for example, used to initialize the global stream
objects in the C++ Standard Library.
The idea is generalized into the idiom "resource acquisition is
initialization". And we need to support it correctly, whether we like
it or not.
| So, for instance, if we have something like
|
| #include <everything.h>
| int foo (int bar)
| {
| bar = f(g(i<3>));
| }
|
| then during parsing, everything relating to "foo", "bar", "f", "g",
| "i" gets loaded from a pre-compiled header file, as are their types
| and so on.
Given that name lookup is not that simple in C++, I would like you be
more precise here: how do you handle names found by unqualified name
lookup?
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com