Extending functionality of -frepo

Noe Aljaz ITICMN noe@iskratel.si
Mon Sep 5 07:09:00 GMT 2005


Hi!

Has anyone considered extending the functionality of the -frepo compiler
switch in the following way:

1. In the .rpo file, also include implicit template instantiations that
WOULD be instantiated if their definitions were included,

2. Define macro NO_TEMPLATE_INSTANTIATION during normal compilation and
un-define it when g++ is called by collect2,

and making this accessible via some new compiler option (e.g. -frepo2)?

Why would this be good? Because it would enable something like this:

File: bar.h
-----------
#ifndef INCLUDE_GUARD_bar_h
#define INCLUDE_GUARD_bar_h

template<class T>
class bar
{
public:
    void f();
};

#ifndef NO_TEMPLATE_INSTANTIATION
#include "bar.tpp"
#endif

#endif // #ifndef INCLUDE_GUARD_bar_h



File: bar.tpp
-------------
#include "bar.h"
#include "big_header.h"

template<class T>
void A::f()
{
    function_declared_in_big_header();
}


File: foo.cpp
-------------
#include "bar.h"

void foo()
{
    bar<int> x;
    x.f();
}



Benefits:

1. Code in foo.cpp normally compiles without including big_header.h
(from bar.tpp). This makes it impossible for foo.cpp to become
inadvertently dependant on the code from big_header.h.

2. Compilation of foo.cpp and every source file that includes bar.h is
much faster since the implementation of bar.tpp is not seen by the
compiler.

3. Definitions for the bar class template and the big_header are only
compiled by collect2 during template instantiations. If bar<int> is
commonly used in the code, compilation times would be significantly
reduced.

4. If the -frepo2 switch is not used and macro NO_TEMPLATE_INSTANTIATION
is not defined, everything still works as before using the Borland
template instantiation model.



Potential problems:

1. If big_header.h makes something funny (macros) that changes the
meaning of code in foo.cpp, all bets are off.

2. Implementation of the -frepo2 switch may be difficult in g++. I can't
comment on this, since I have no experience in writing a compiler.

3. Something else, I did not think of.



Comments are appreciated.



Aljaz



More information about the Gcc mailing list