This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Idea for export Implemnation
- To: egcs at cygnus dot com
- Subject: Idea for export Implemnation
- From: Kevin Atkinson <kevinatk at home dot com>
- Date: Tue, 01 Dec 1998 05:25:51 -0500
Idea for export Implementation
Here is my idea for implanting the export keyword. I am I bit foggy of
how it works so please bear with me if I overlook something.
The basic idea is to have the template code (either parsed or raw) as
data blocks in the object files and have the linker compile them as
necessary.
For example:
// foo.hh
template <class T> class Foo {
Foo *data;
public:
double average_data();
};
// foo.cc
export template <class T>
Foo Foo<T>::average_data() {
//...
}
// main.cc
int main() {
Foo<int> grades;
/* ... */
int = average_data();
}
# Makefile
main: main.o foo.o
main.o: main.cc foo.hh
foo.o: foo.cc foo.hh
--end--
g++ -c main.cc: object code for main gets stored in main.o
g++ -c foo.cc: actual c++ code for Foo<T>::average_data() get stored in
foo.o
g++ main.o foo.o -o main
Now things get interesting. Where should the compiler store the new
code needed for Foo<int>::average_data() the most logical place for it
would be foo.o. So now foo.o contains the c++ code for
Foo<T>::average_data() and the object code for Foo<int>::average_data().
When every foo.cc gets recompiled by the user. All the object code for
template installations gets purged. It will be recompiled again when it
is needed and not before. This way foo.o will not get unnecessary large
with unused instationations.
With this approach approach a large database is totally unneeded. Thus
avaling all the problems of maininging one.
Now the questions comes what to do with libraries and object files which
are not modified. Things are sligtly more diffacult. As I see it
there are two options.
1) Put template instantiations for the read-only library or object file
in a special file in the place where the compiler can find it. When
ever the read-only library is changed purge the file and recompile
template instantiation as needed.
2) Put the template instantiations in the object file where they are
used and remove duplicates by the same means duplicates are removed
now. When the object file is recreated only recompile the instantiation
the read-only library has changed.
The biggest problem with #1 is where to put the file. And the biggest
problem with #2 is dealing with an object file that can not be bluntly
over written.
So what do you think. I am sure there are issues I am overlooking but
hopefully It is enough to get the ball rolling so that the very valuable
export keyword can find its way into egcs. Quite frankly compiling code
that makes heavy user of the STL takes 10 times longer than it needs to.
--
Kevin Atkinson
kevinatk@home.com
http://metalab.unc.edu/kevina/