Abstract
Metaprogramming is among the most promising candidates to solve the abstraction vs performance trade-off that plagues software engineering through specialization. Metaprogramming has been used to enable low-overhead generic programming for a long time, with C++ templates being one of the most prominent examples. But often a single, fixed pattern of specialization is not enough, and more flexibility is needed. Hence, this paper seeks to apply generic programming techniques to challenges in metaprogramming, in particular to abstract over the execution stage of individual program expressions. We thus extend the scope of generic programming into the dimension of time. The resulting notion of stage polymorphism enables novel abstractions in the design of program generators, which we develop and explore in this paper. We present one possible implementation, in Scala using the lightweight modular staging (LMS) framework, and apply it to two important case studies: convolution on images and the fast Fourier transform (FFT).
- Nada Amin, Tiark Rompf, and Martin Odersky. 2014. Foundations of path-dependent types. In OOPSLA. ACM, 233-249. Google Scholar
Digital Library
- Olav Beckmann, Alastair Houghton, Michael R. Mellor, and Paul H. J. Kelly. 2003. Runtime Code Generation in C++ as a Foundation for Domain-Specific Optimisation. In Domain-Specific Program Generation. 291-306.Google Scholar
- Julia Belyakova. 2016. Language Support for Generic Programming in Object-Oriented Languages: Peculiarities, Drawbacks, Ways of Improvement. Springer, Cham, 1-15.Google Scholar
- G. Bradski. 2000. Dr. Dobb's Journal of Software Tools (2000).Google Scholar
- Eugene Burmako. 2013. Scala macros: let our powers combine!: on how rich syntax and static types work with metaprogramming. In Proc. Workshop on Scala. Google Scholar
Digital Library
- Jacques Carette, Oleg Kiselyov, and Chung Chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19, 5 (2009), 509-543. Google Scholar
Digital Library
- K. D. Cooper, M. W. Hall, and K. Kennedy. 1992. Procedure cloning. In Proc. Computer Languages. 96-105.Google Scholar
- Keith D Cooper, MaryWHall, and Ken Kennedy. 1993. A Methodology for Procedure Cloning. Proc. Comput. Lang. 19, 2 (April 1993), 105-117. Google Scholar
Digital Library
- Paolo D'Alberto, Peter A. Milder, Aliaksei Sandryhaila, Franz Franchetti, James C. Hoe, José M. F. Moura, Markus Püschel, and Jeremy Johnson. 2007. Generating FPGA Accelerated DFT Libraries. In Proc. IEEE Symposium on Field-Programmable Custom Computing Machines (FCCM). 173-184. Google Scholar
Digital Library
- Olivier Danvy, Karoline Malmkjær, and Jens Palsberg. 1996. Eta-Expansion Does The Trick. Proc. Programming Languages and Systems (TOPLAS) 18, 6 (1996), 730-751. Google Scholar
Digital Library
- M. Frigo. 1999. A Fast Fourier Transform Compiler. In Proc. Programming Language Design and Implementation (PLDI). 169-180. Google Scholar
Digital Library
- Matteo Frigo and Steven G. Johnson. 2005. The design and implementation of FFTW3. Proceedings of the IEEE, special issue on "Program Generation, Optimization, and Adaptation" 93, 2 (2005), 216-231.Google Scholar
- Ronald Garcia, Jaakko Jarvi, Andrew Lumsdaine, Jeremy G. Siek, and Jeremiah Willcock. 2003. A Comparative Study of Language Support for Generic Programming. In Proc. Object-oriented Programming, Systems, Languages, and Applications (OOPSLA). 115-134. Google Scholar
Digital Library
- Brian Grant, Markus Mock, Matthai Philipose, Craig Chambers, and Susan J. Eggers. 2000. DyC: an expressive annotation-directed dynamic compiler for C. Theor. Comput. Sci. 248, 1-2 (2000), 147-199. Google Scholar
Digital Library
- Douglas Gregor, Jaakko Järvi, Jeremy Siek, Bjarne Stroustrup, Gabriel Dos Reis, and Andrew Lumsdaine. 2006. Concepts: Linguistic Support for Generic Programming in C++. In Proc. Object-oriented Programming Systems, Languages, and Applications (OOPSLA). 291-310. Google Scholar
Digital Library
- Fritz Henglein and Christian Mossin. 1994. Polymorphic binding-time analysis. In Proc. European Symposium on Programming Edinburg. 287-301. Google Scholar
Digital Library
- Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. 2008. Polymorphic embedding of DSLs. In Proc. Generative Programming: Concepts & Experiences (GPCE). 137-148. Google Scholar
Digital Library
- Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial evaluation and automatic program generation. Prentice-Hall, Inc., Upper Saddle River, NJ, USA. Google Scholar
Digital Library
- Ulrik Jørring and William L. Scherlis. 1986. Compilers and Staging Transformations. In Proc. Symposium on Principles of Programming Languages (POPL). 86-96. Google Scholar
Digital Library
- Oleg Kiselyov. 2014. The design and implementation of BER MetaOCaml. In Proc. Symposium on Functional and Logic Programming (ICFP). 86-102.Google Scholar
Cross Ref
- Andrei V. Klimov. 2009. A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols. In Proc. Ershov Memorial Conference. 185-192. Google Scholar
Digital Library
- Ralf Lämmel and Simon L. Peyton Jones. 2003. Scrap your boilerplate: a practical design pattern for generic programming. In Proc. Workshop on Types in languages design and implementation (TLDI). 26-37. Google Scholar
Digital Library
- Ralf Lämmel and Simon L. Peyton Jones. 2005. Scrap your boilerplate with class: extensible generic functions. In Proc. on Functional Programming (ICFP). 204-215. Google Scholar
Digital Library
- Geoffrey Mainland. 2007. Why It's Nice to Be Quoted: Quasiquoting for Haskell. In Proc. Workshop on Haskell Workshop. 73-82. Google Scholar
Digital Library
- David R. Musser and Alexander A. Stepanov. 1988. Generic Programming. In Proc. ISSAC (Lecture Notes in Computer Science), Vol. 358. Springer, 13-25. Google Scholar
Digital Library
- Martin Odersky and Tiark Rompf. 2014. Unifying functional and object-oriented programming with Scala. Commun. ACM 57, 4 (2014), 76-86. Google Scholar
Digital Library
- Georg Ofenbeck. [n. d.]. https://github.com/GeorgOfenbeck/SpaceTime. ([n. d.]). https://github.com/GeorgOfenbeck/SpaceTimeGoogle Scholar
- Georg Ofenbeck, Tiark Rompf, Alen Stojanov, Martin Odersky, and Markus Püschel. 2013. Spiral in Scala: Towards the Systematic Construction of Generators for Performance Libraries. In Proc. Generative Programming: Concepts & Experiences (GPCE). 125-134. Google Scholar
Digital Library
- Markus Püschel, Franz Franchetti, and Yevgen Voronenko. 2011. Encyclopedia of Parallel Computing. Springer, Chapter Spiral.Google Scholar
- Markus Püschel, José M. F. Moura, Jeremy Johnson, David Padua, Manuela Veloso, Bryan Singer, Jianxin Xiong, Franz Franchetti, Aca Gacic, Yevgen Voronenko, Kang Chen, Robert W. Johnson, and Nicholas Rizzolo. 2005. SPIRAL: Code Generation for DSP Transforms. Proceedings of the IEEE, special issue on "Program Generation, Optimization, and Adaptation" 93, 2 (2005), 232- 275.Google Scholar
Cross Ref
- Jonathan Ragan-Kelley, Connelly Barnes, Andrew Adams, Sylvain Paris, Frédo Durand, and Saman Amarasinghe. 2013. Halide: A Language and Compiler for Optimizing Parallelism, Locality, and Recomputation in Image Processing Pipelines. In Proc. Programming Language Design and Implementation (PLDI). ACM, 519-530. Google Scholar
Digital Library
- Tiark Rompf and Martin Odersky. 2012. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. Commun. ACM 55, 6 (2012), 121-130. Google Scholar
Digital Library
- Tiark Rompf, Arvind K. Sujeeth, Kevin J. Brown, HyoukJoong Lee, Hassan Chafi, and Kunle Olukotun. 2014. Surgical precision JIT compilers. In Proc. Programming Language Design and Implementation (PLDI). Google Scholar
Digital Library
- Henrique Nazare Santos, Pericles Alves, Igor Costa, and Fernando Magno Quintao Pereira. 2013. Just-in-time Value Specialization. In Proc. Symposium on Code Generation and Optimization (CGO). 11. Google Scholar
Digital Library
- Ulrik P. Schultz, Julia L. Lawall, and Charles Consel. 2003. Automatic Program Specialization for Java. ACM Trans. Program. Lang. Syst. 25, 4 (July 2003), 452-499. Google Scholar
Digital Library
- Amin Shali and William R. Cook. 2011. Hybrid partial evaluation. In Proc. Object-Oriented Programming Systems, Languages, and Applications (OOPSLA). Google Scholar
Digital Library
- Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. In Proc. Workshop on Haskell. 1-16. Google Scholar
Digital Library
- Jeremy G. Siek, Lie-Quan Lee, and Andrew Lumsdaine. 2002. The Boost Graph Library - User Guide and Reference Manual. Pearson / Prentice Hall. Google Scholar
Digital Library
- Alexander Slesarenko. 2012. Lightweight Polytypic Staging: a new approach to an implementation of Nested Data Parallelism in Scala. In Proc. Workshop on Scala (SCALA '13). ACM, New York, NY, USA, Article 3, 10 pages.Google Scholar
- Alexander Slesarenko, Alexander Filippov, and Alexey Romanov. 2014. First-class Isomorphic Specialization by Staged Evaluation. In Proc. Workshop on Generic Programming (WGP '14). ACM, New York, NY, USA, 35-46. Google Scholar
Digital Library
- Josef Svenningsson and Emil Axelsson. 2015. Combining deep and shallow embedding of domain-specific languages. Proc. Computer Languages, Systems & Structures 44 (2015), 143-165. Google Scholar
Digital Library
- Wouter Swierstra. 2008. Data types à la carte. Journal of Functional Programming 18, 4 (2008), 423-436. Google Scholar
Digital Library
- Walid Taha. 1999. Multi-stage programming: Its theory and applications. Ph.D. Dissertation. Oregon Graduate Institute of Science and Technology. Google Scholar
Digital Library
- Yevgen Voronenko, Frédéric de Mesmay, and Markus Püschel. 2009. Computer Generation of General Size Linear Transform Libraries. In Proc. Symposium on Code Generation and Optimization (CGO). 102-113. Google Scholar
Digital Library
- P. Wadler and S. Blott. 1989. How to Make Ad-hoc Polymorphism Less Ad Hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '89). ACM, New York, NY, USA, 60-76. Google Scholar
Digital Library
- Piotr Wendykier. 2016. JTransform. (2016). https://sites.google.com/site/piotrwendykier/software/jtransformsGoogle Scholar
- Jeremy Yallop. 2016. Staging Generic Programming. In Proc. Workshop on Partial Evaluation and Program Manipulation (PEPM '16). ACM, New York, NY, USA, 85-96. Google Scholar
Digital Library
Index Terms
Staging for generic programming in space and time
Recommendations
Staging for generic programming in space and time
GPCE 2017: Proceedings of the 16th ACM SIGPLAN International Conference on Generative Programming: Concepts and ExperiencesMetaprogramming is among the most promising candidates to solve the abstraction vs performance trade-off that plagues software engineering through specialization. Metaprogramming has been used to enable low-overhead generic programming for a long time, ...
A comparative study of language support for generic programming
OOPSLA '03: Proceedings of the 18th annual ACM SIGPLAN conference on Object-oriented programing, systems, languages, and applicationsMany modern programming languages support basic generic programming, sufficient to implement type-safe polymorphic containers. Some languages have moved beyond this basic support to a broader, more powerful interpretation of generic programming, and ...
A comparative study of language support for generic programming
Special Issue: Proceedings of the OOPSLA '03 conferenceMany modern programming languages support basic generic programming, sufficient to implement type-safe polymorphic containers. Some languages have moved beyond this basic support to a broader, more powerful interpretation of generic programming, and ...







Comments