Indiana University Bloomington

Luddy School of Informatics, Computing, and Engineering

Technical Report TR543:
Five Compilation Models for C++ Templates

Todd Veldhuizen
(Aug 2000), 11 pages pages
Abstract:
This paper proposes an alternate structure for C++ compilers. Type analysis is removed from the compiler and replaced with a type system library which is treated as source code by the compiler. Type computations are embedded in the intermediate language of the compiler, and partial evaluation is used to drive type analysis and template instantiation. By making simple changes to the behavior of the partial evaluator, a wide range of compilation models is achieved, each with a distinct tradeoff of compile time, code size, and code speed. These models range from pure dynamic typing -- ideal for scripting C++ -- to profile-directed template instantiation. This approach may solve several serious problems in compiling C++: it achieves separate compilation of templates, allows template code to be distributed in binary form by deferring template instantiation until run time, and reduces the code bloat associated with templates.

Available as: