skip to main content
article

Sound type-dependent syntactic language extension

Published:11 January 2016Publication History
Skip Abstract Section

Abstract

Syntactic language extensions can introduce new facilities into a programming language while requiring little implementation effort and modest changes to the compiler. It is typical to desugar language extensions in a distinguished compiler phase after parsing or type checking, not affecting any of the later compiler phases. If desugaring happens before type checking, the desugaring cannot depend on typing information and type errors are reported in terms of the generated code. If desugaring happens after type checking, the code generated by the desugaring is not type checked and may introduce vulnerabilities. Both options are undesirable. We propose a system for syntactic extensibility where desugaring happens after type checking and desugarings are guaranteed to only generate well-typed code. A major novelty of our work is that desugarings operate on typing derivations instead of plain syntax trees. This provides desugarings access to typing information and forms the basis for the soundness guarantee we provide, namely that a desugaring generates a valid typing derivation. We have implemented our system for syntactic extensibility in a language-independent fashion and instantiated it for a substantial subset of Java, including generics and inheritance. We provide a sound Java extension for Scala-like for-comprehensions.

References

  1. E. Burmako. Scala macros: Let our powers combine!: On how rich syntax and static types work with metaprogramming. In Proceedings of the 4th Workshop on Scala, SCALA ’13, pages 3:1–3:10. ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. Charguéraud. The locally nameless representation. Journal of Automated Reasoning, 49(3):363–408, 2012.Google ScholarGoogle ScholarCross RefCross Ref
  3. J. Cheney and C. Urban. Nominal logic programming. ACM Transactions on Programming Languages and Systems, 30(5):26:1–26:47, Sept. 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. R. Cox, T. Bergan, A. T. Clements, F. Kaashoek, and E. Kohler. Xoc, an extension-oriented compiler for systems programming. In Proceedings of the 13th International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS XIII, pages 244–254. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. D. de Rauglaudre. Camlp4 reference manual, 2003.Google ScholarGoogle Scholar
  6. S. Erdweg, T. Rendel, C. Kästner, and K. Ostermann. SugarJ: librarybased syntactic language extensibility. In Proceedings of the 2011 ACM International Conference on Object-oriented Programming, Systems, Languages, and Applications, OOPSLA ’11, pages 391–406. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. S. Erdweg, P. G. Giarrusso, and T. Rendel. Language composition untangled. In Proceedings of the Twelfth Workshop on Language Descriptions, Tools, and Applications, LDTA ’12, pages 7:1–7:8. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. M. Felleisen, R. B. Findler, and M. Flatt. Semantics Engineering with PLT Redex. MIT Press, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. D. Fisher and O. Shivers. Building language towers with Ziggurat. Journal of Functional Programming, 18(5–6):707–780, Sept. 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. M. Flatt. Creating languages in Racket. Communications of the ACM, 55(1):48–56, Jan. 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. S. Ganz, A. Sabry, and W. Taha. Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In Proceedings of the 6th ACM SIGPLAN International Conference on Functional Programming, ICFP ’01, pages 74–85. ACM, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. G. Giorgidze and H. Nilsson. Embedding a functional hybrid modelling language in Haskell. In Proceedings of the 20th International Conference on Implementation and Application of Functional Languages, IFL ’08, pages 138–155. Springer, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. J. Gosling, B. Joy, G. L. Steele, Jr., G. Bracha, and A. Buckley. The Java R Language Specification – Java SE 8 Edition. Oracle America, Inc., 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. S. Grewe, S. Erdweg, P. Wittmann, and M. Mezini. Type systems for the masses: Deriving soundness proofs and e fficient checkers. In Proceedings of Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, Onward! 2015. ACM, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. to appear.Google ScholarGoogle Scholar
  16. R. Harper. Practical Foundations for Programming Languages. Cambridge University Press, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. R. Harper and D. R. Licata. Mechanizing metatheory in a logical framework. Journal of Functional Programming, 17(4-5):613–673, July 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. D. Herman. A Theory of Typed Hygienic Macros. PhD thesis, Northeastern University, Boston, Massachusetts, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. F. Lorenzen and S. Erdweg. Modular and automated type-soundness verification for language extensions. In Proceedings of 18th International Conference on Functional Programming, ICFP ’13, pages 331–342. ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. G. Mainland. Why it’s nice to be quoted: quasiquoting for Haskell. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell ’07, pages 73–82. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. G. Mainland. Explicitly heterogeneous metaprogramming with metahaskell. In Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming, ICFP ’12, pages 311–322. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Marlow, Simon. Haskell 2010 – language report, June 2010.Google ScholarGoogle Scholar
  23. M. Odersky, L. Spoon, and B. Venners. Programming in Scala: A Comprehensive Step-by-step Guide. Artima Incorporation, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. C. Omar, D. Kurilova, L. Nistor, B. Chung, A. Potanin, and J. Aldrich. Safely composable type-specific languages. In R. Jones, editor, ECOOP 2014 – Object-Oriented Programming, volume 8586 of Lecture Notes in Computer Science, pages 105–130. Springer, 2014.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. B. C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. C. Schürmann and F. Pfenning. Automated theorem proving in a simple meta-logic for LF. In Proceedings of International Conference on Automated Deduction, volume 1421 of LNCS, pages 286–300. Springer, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. T. Sheard and S. L. Peyton Jones. Template metaprogramming for Haskell. In Proceedings of the ACM Workshop on Haskell, Haskell ’02, pages 1–16. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. M. R. Shinwell, A. M. Pitts, and M. J. Gabbay. FreshML: Programming with binders made simple. In Proceedings of the 8th ACM SIGPLAN International Conference on Functional Programming, ICFP ’03, pages 263–274. ACM, Aug. 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. P. Stansifer and M. Wand. Romeo: A system for more flexible binding-safe programming. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming, ICFP ’14, pages 53–65. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. E. Visser. Syntax Definition for Language Prototyping. PhD thesis, University of Amsterdam, 1997.Google ScholarGoogle Scholar
  31. E. Visser, Z.-E.-A. Benaissa, and A. Tolmach. Building program optimizers with rewriting strategies. In Proceedings of the 3rd ACM SIGPLAN International Conference on Functional Programming, ICFP ’98, pages 13–26. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. H. Xi and C. Schürmann. CPS transform for Dependent ML (abstract). Logic Journal of IGPL, 9(5):739–754, Sept. 2001.Google ScholarGoogle Scholar

Index Terms

  1. Sound type-dependent syntactic language extension

              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

              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!