Abstract
Garcia introduces a calculus for type-reflective metaprogramming that provides much of the power and flexibility of C++ templates and solves many of its problems. However, one of the problems that remains is that the residual program is not type checked until after meta computation is complete. Ideally, one would like the type system of the metaprogram to also guarantee that the residual program will type check, as is the case in MetaML. However, in a language with type-reflective metaprogramming, type expressions in the residual program may be the result of meta computation, making the MetaML guarantee next to impossible to achieve.
In this paper we offer an approach to detecting errors earlier without sacrificing flexibility: we incrementally type check code fragments as they are created and spliced together during meta computation. The incremental type system is a variant of the gradual type system of Siek and Taha, in which we use type variables to represent type expressions that are not yet normalized and a new dynamic variation on existential types to represent residual code fragments. A type error in a code fragment is treated as a run-time error of the meta computation. We show that the incremental type checker can be implemented efficiently and we prove that if a well-typed metaprogram generates a residual program, then the residual program is also well-typed.
- }}1} David Abrahams and Aleksey Gurtovoy. C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Addison-Wesley Professional, 2004. Google Scholar
Digital Library
- }}Andrei Alexandrescu. Modern C++ design: generic programming and design patterns applied. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2001. Google Scholar
Digital Library
- }}Krzysztof Czarnecki and Ulrich W. Eisenecker. Generative programming: methods, tools, and applications. ACM Press/Addison-Wesley, 2000. Google Scholar
Digital Library
- }}Walid Taha and Tim Sheard. Multi-stage programming with explicit annotations. In PEPM '97: Proceedings of the 1997 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation, pages 203--217, New York, NY, USA, 1997. ACM Press. Google Scholar
Digital Library
- }}Tim Sheard and Simon Peyton Jones. Template metaprogramming for Haskell. In ACM SIGPLAN Haskell Workshop 02, pages 1--16, 2002. Google Scholar
Digital Library
- }}Ronald Garcia and Andrew Lumsdaine. Toward foundations for type-reflective metaprogramming. In GPCE '09: Proceedings of the eighth international conference on Generative programming and component engineering, pages 25--34, New York, NY, USA, 2009. ACM. Google Scholar
Digital Library
- }}Ronald Garcia. Static Computation and Reflection. PhD thesis, Indiana University, September 2008. Google Scholar
Digital Library
- }}Taha Walid. Multi-stage programming: Its theory and applications. Technical report, 1999. Google Scholar
Digital Library
- }}Walid Taha and Michael Florentin Nielsen. Environment classifiers. In POPL '03: Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 26--37, New York, NY, USA, 2003. ACM Press. Google Scholar
Digital Library
- }}Guy L. Steele, Jr. Common LISP: the language (2nd ed.). Digital Press, Newton, MA, USA, 1990. Google Scholar
Digital Library
- }}Jeremy G. Siek and Manish Vachharajani. Gradual typing with unification-based inference. In Dynamic Languages Symposium, July 2008. Google Scholar
Digital Library
- }}Jeremy Siek and Walid Taha. Typing for objects. In European Conference on Object-Oriented Programming, 2007.Google Scholar
Digital Library
- }}Philip Wadler and Robert Bruce Findler. Well-typed programs can't be blamed. In In workshop on Scheme and functional programming, pages 15--26, 2007.Google Scholar
- }}Ian Lynagh. Typing template haskell: Soft types. In GPCE W2: Second MetaOCaml Workshop, 2005.Google Scholar
- }}Lennart Augustsson. Cayenne - a language with dependent types. In ICFP '98: Proceedings of the third ACM SIGPLAN international conference on Functional programming, New York, NY, USA. ACM. Google Scholar
Digital Library
- }}Hongwei Xi and Frank Pfenning. Dependent types in practical programming. In Proceedings of the 26th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 214--227, 1999. Google Scholar
Digital Library
- }}Hongwei Xi. Applied type system. In post-workshop Proceedings of TYPES, Lecture Notes in Computer Science, 3085, 2004.Google Scholar
- }}Seth Fogarty, Emir Pasalic, Jeremy Siek, and Walid Taha. Concoqtion: indexed types now. In Workshop on Partial Evaluation and Semantics-Based Program Manipulation, 2007. Google Scholar
Digital Library
- }}Hongwei Xi, Chiyan Chen, and Gang Chen. Guarded recursive datatype constructors. In Proceedings of the 30th ACM SIGPLAN Symposium on Principles of Programming Languages, pages 224--235, New Orleans, January 2003. Google Scholar
Digital Library
- }}Khoo Yit Phang, Bor-Yuh Evan Chang, and Jeffrey S. Foster. Mixing type checking and symbolic execution. In ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, 2010. Google Scholar
Digital Library
Index Terms
Incremental type-checking for type-reflective metaprograms
Recommendations
Incremental type-checking for type-reflective metaprograms
GPCE '10: Proceedings of the ninth international conference on Generative programming and component engineeringGarcia introduces a calculus for type-reflective metaprogramming that provides much of the power and flexibility of C++ templates and solves many of its problems. However, one of the problems that remains is that the residual program is not type checked ...
Early detection of type errors in C++ templates
PEPM '14: Proceedings of the ACM SIGPLAN 2014 Workshop on Partial Evaluation and Program ManipulationCurrent C++ implementations typecheck templates in two phases: Before instantiation, those parts of the template are checked that do not depend on template parameters, while the checking of the remaining parts is delayed until template instantiation ...
The gradualizer: a methodology and algorithm for generating gradual type systems
POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesMany languages are beginning to integrate dynamic and static typing. Siek and Taha offered gradual typing as an approach to this integration that provides a coherent and full-span migration between the two disciplines. However, the literature lacks a ...







Comments