Concept-Based Component Libraries and Optimizing Compilers S. Schupp, D. P. Gregor, B. Osman, D. R. Musser Rensselaer Polytechnic Institute schupp,gregord,osman,musser @cs.rpi.edu J. G. Siek, L.-Q. Lee, A. Lumsdaine Indiana University jsiek,llee,lums @cs.indiana.edu Abstract This paper discusses concept lattices and some of their applications in component library development and com- piler optimizations. Ongoing work on concept-based user- extensible simplification (type-based optimizer generators) and library transformations is first reviewed, then a new application—categorization of algorithms via precise de- scriptions of their performance characteristics—is outlined, with Standard Template Library and Boost Graph Library algorithm concept lattices as examples. 1 Introduction A concept is a set of abstractions that all satisfy a com- mon set of requirements. More formally: Definition: A concept is a set of requirements together with a set of abstractions, such that an abstraction is in- cluded in if and only if it satisfies all of the requirements in . A technical definition of “abstraction” will not be given here, but relevant examples are (abstract data) types, algo- rithms, and simplification rules. Concept refinement means adding more requirements, which means fewer abstractions in the subconcept, but each is more specialized. This refine- ment relation yields a concept lattice [19, 20] or hierarchy. Perhaps the most widely known example among software developers is the use of concept lattices in the C++ Stan- dard Template Library (STL) documentation developed at SGI [1, 17]. There, concepts are used to classify container, iterator, and functor type abstractions so that one can doc- ument precisely which types one can pass to the generic algorithms in the library and be guaranteed of correct and efficient execution. Concepts are so much a part of generic programming [11, 12] that generic programming is some- times called “programming with concepts.” The main application of generic programming is in the area of library design. Especially in C++, the principles of This work was supported by NSF grant EIA-0131354. generic programming have become widely accepted after the STL became part of the language standard [4]. Many recent libraries adopt, extend, or carry over concept-based programming to, e.g., scientific programming [6, 16, 18], graph libraries [2, 8, 15], domain-specific applications in bioinformatics or partial differential equations, but also low-level tasks like multi-threading [5]. In designing and documenting both the Matrix Template Library [16] and the Boost Graph Library [15] we have used concept lattices ex- tensively to describe matrix and graph structures; see Fig- ures 1 and 2. Most importantly for scientific software, programming with concepts can be accomplished without sacrificing per- formance. This is made possible by static polymorphism, i.e., compile-time function dispatch based on argument types. Since the dispatch is determined at compile time, these polymorphic functions have the same overhead as nor- mal functions and can be optimized just as any normal func- tion. Although it is possible for generic programs to obtain levels of performance comparable to non-generic programs, many of the optimizations must be incorporated manually (although there are techniques that can be used to provide certain degrees of automation using the C++ template sys- tem). We have been developing mechanisms for allowing the compiler to optimize user-defined ADTs and basic data types in a unified fashion as well as to incorporate user- defined optimizations. This approach opens up new opti- mization opportunities that are not available to optimiza- tions by hand. In Section 2, we briefly summarize our ap- proach, concept-based optimization, as manifested in user- extensible simplification (type-based optimizer generators) and library transformations. In Section 3 we outline a new application of concept lat- tices, algorithm concepts, with emphasis on their use in specifying precise performance requirements. Despite the fact that generic library component design starts from algo- rithms [10], there has been little prior development of clas- sifications and documentation of algorithms in concept lat- tices. Nevertheless, such algorithm concepts appear to be an excellent means of documenting algorithms for end-users. 1 0-7695-1573-8/02/$17.00 (C) 2002 IEEE