skip to main content
research-article

Incremental type-checking for type-reflective metaprograms

Published:10 October 2010Publication History
Skip Abstract Section

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.

References

  1. }}1} David Abrahams and Aleksey Gurtovoy. C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Addison-Wesley Professional, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}Andrei Alexandrescu. Modern C++ design: generic programming and design patterns applied. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}Krzysztof Czarnecki and Ulrich W. Eisenecker. Generative programming: methods, tools, and applications. ACM Press/Addison-Wesley, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. }}Tim Sheard and Simon Peyton Jones. Template metaprogramming for Haskell. In ACM SIGPLAN Haskell Workshop 02, pages 1--16, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}Ronald Garcia. Static Computation and Reflection. PhD thesis, Indiana University, September 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}Taha Walid. Multi-stage programming: Its theory and applications. Technical report, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}Guy L. Steele, Jr. Common LISP: the language (2nd ed.). Digital Press, Newton, MA, USA, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}Jeremy G. Siek and Manish Vachharajani. Gradual typing with unification-based inference. In Dynamic Languages Symposium, July 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}Jeremy Siek and Walid Taha. Typing for objects. In European Conference on Object-Oriented Programming, 2007.Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. }}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 ScholarGoogle Scholar
  14. }}Ian Lynagh. Typing template haskell: Soft types. In GPCE W2: Second MetaOCaml Workshop, 2005.Google ScholarGoogle Scholar
  15. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. }}Hongwei Xi. Applied type system. In post-workshop Proceedings of TYPES, Lecture Notes in Computer Science, 3085, 2004.Google ScholarGoogle Scholar
  18. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. }}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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Incremental type-checking for type-reflective metaprograms

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 46, Issue 2
          GPCE '10
          Febuary 2011
          185 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/1942788
          Issue’s Table of Contents
          • cover image ACM Conferences
            GPCE '10: Proceedings of the ninth international conference on Generative programming and component engineering
            October 2010
            198 pages
            ISBN:9781450301541
            DOI:10.1145/1868294
            • General Chair:
            • Eelco Visser,
            • Program Chair:
            • Jaakko Järvi

          Copyright © 2010 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 10 October 2010

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!