Topic: implementation of export'ed templates


Author: "Dave Martin XXIII" <xxiii@cyberdude.com>
Date: 1998/07/15
Raw View
Having just discovered this feature, and searching dejanews for info,
and not finding much about implementation, i'm wondering how its done.

I see a couple of scenarios; the compiler silently generates "super"
classes for types used with templates and passes this info to the
precompiled templates.  The "super" classes contain enough information
for the templates to be "instantiated" at runtime.  The overhead
potential in this seems enourmous, not to mention a lot of
optimizations cannot be applied, and even a few pessimizations may be
required.

Or, the compiler only partially compiles and tokenizes templates, and
the linker recursively invokes the compiler as necessary to finish
instantiating the templates and it feeds the output directly back into
the linker.

Any other options?  Am I missing something obvious?

<*> - Know Future



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jkanze@otelo.ibmmail.com
Date: 1998/07/16
Raw View
In article <000101bdaf96$e3427320$0100000a@bryce>,
  "Dave Martin XXIII" <xxiii@cyberdude.com> wrote:
> Having just discovered this feature, and searching dejanews for info,
> and not finding much about implementation, i'm wondering how its done.
>
> I see a couple of scenarios; the compiler silently generates "super"
> classes for types used with templates and passes this info to the
> precompiled templates.  The "super" classes contain enough information
> for the templates to be "instantiated" at runtime.  The overhead
> potential in this seems enourmous, not to mention a lot of
> optimizations cannot be applied, and even a few pessimizations may be
> required.
>
> Or, the compiler only partially compiles and tokenizes templates, and
> the linker recursively invokes the compiler as necessary to finish
> instantiating the templates and it feeds the output directly back into
> the linker.
>
> Any other options?  Am I missing something obvious?

The standard explicitly allows the implementation to require that the
exported template implementations be compiled before any code that uses
them.  I expect that this is to allow the compiler to simply copy the
template implementations, perhaps stripping comments, compressing, or
partially tokenizing them, into a repository, and otherwise proceed as
it does with normal templates today.

The problem with link time instantiation isn't so much the template
implementation, but the context of instantiation, which must be somehow
transmitted to the linker.  If link times are to be reasonable, it is also
necessary for the linker to somehow be able to detect when it must rebuild
the instantiations.  This is less evident than you think; you can change
almost everything in the instantiation context, and still not have to
rebuild vector< int >, for example, but even a small change may require
the rebuilding of a user template.

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
        +49 (0)69 66 45 33 10    mailto: jkanze@otelo.ibmmail.com
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient   e objet --
              -- Beratung in objektorientierter Datenverarbeitung

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]