10.1145/3372884.3373160acmconferencesArticle/Chapter ViewAbstractPublication PagespepmConference Proceedings
research-article

Module generation without regret

ABSTRACT

Modules are an indispensable mechanism for providing abstraction to programming languages. To reduce the abstraction overhead in the usage of modules, Watanabe et al. proposed a language for generating and manipulating code of modules, and implemented it via a translation to plain MetaOCaml. Unfortunately, their solution has a serious problem of code explosion if functors are repeatedly applied to modules. Another problem in their solution is that it does not allow nested modules.

This paper proposes a refined translation for a two-stage typed language with module generation where nested modules are allowed. Our translation does not suffer from the code-duplication problem. The key idea is to use the genlet operator in latest MetaOCaml, which performs let insertion at the code-generation time to allow sharing of code fragments. To our knowledge, our work is the first to apply genlet to code generation for modules. We conduct an experiment using a microbenchmark, and the result shows that our method is effective to reduce the size of generated code that would have been exponentially large.

References

  1. 1997. MLton, a whole program optimizing compiler for Standard ML. http://www.mlton.org. (1997).Google ScholarGoogle Scholar
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. Olivier Danvy. 1996. Pragmatic Aspects of Type-Directed Partial Evaluation. Technical Report. BRICS Report Series RS-96-15. 27 pages.Google ScholarGoogle Scholar
  4. Olivier Danvy and Andrzej Filinski. 1990. Abstracting Control. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming, LFP 1990, Nice, France, 27-29 June 1990. 151-160. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Rowan Davies. 1996. A Temporal-Logic Approach to Binding-Time Analysis. In Proceedings, 11th Annual IEEE Symposium on Logic in Computer Science, New Brunswick, New Jersey, USA, July 27-30, 1996. 184-195. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Xavier Leroy et al. 2019. Chapter 21. Optimisation with Flambda. The OCaml system release 4.09. (2019). https://caml.inria.fr/pub/docs/manual-ocaml/flambda.html.Google ScholarGoogle Scholar
  7. Jun Inoue, Oleg Kiselyov, and Yukiyoshi Kameyama. 2016. Staging beyond terms: prospects and challenges. In Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, St. Petersburg, FL, USA, January 20 - 22, 2016. 103-108. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Yukiyoshi Kameyama, Oleg Kiselyov, and Chung-chieh Shan. 2011. Shifting the stage - Staging with delimited control. J. Funct. Program. 21, 6 (2011), 617-662. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Oleg Kiselyov. 2012. Delimited control in OCaml, abstractly and concretely. Theor. Comput. Sci. 435 (2012), 56-76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Oleg Kiselyov. 2015. Generating Code with Polymorphic let: A Ballad of Value Restriction, Copying and Sharing. In Proceedings ML Family / OCaml Users and Developers workshops, ML Family/OCaml 2015, Vancouver, Canada, 3rd & 4th September 2015. 1-22.Google ScholarGoogle Scholar
  11. Oleg Kiselyov. 2017. Let-insertion as a primitive. (2017). http://okmij.org/ftp/ML/MetaOCaml.html#genlet.Google ScholarGoogle Scholar
  12. Xavier Leroy. 2000. A modular module system. J. Funct. Program. 10, 3 (2000), 269-303. http://journals.cambridge.org/action/displayAbstract?aid=54525. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Gabriel Radanne, Thomas Gazagnaire, Anil Madhavapeddy, Jeremy Yallop, Richard Mortier, Hannes Mehnert, Mindy Preston, and David J. Scott. 2019. Programming Unikernels in the Large via Functor Driven Development. CoRR abs/1905.02529 (2019). arXiv:1905.02529 http://arxiv.org/abs/1905.02529.Google ScholarGoogle Scholar
  14. Tiark Rompf, Kevin J. Brown, HyoukJoong Lee, Arvind K. Sujeeth, Manohar Jonnalagedda, Nada Amin, Georg Ofenbeck, Alen Stojanov, Yannis Klonatos, Mohammad Dashti, Christoph Koch, Markus Püschel, and Kunle Olukotun. 2015. Go Meta! A Case for Generative Programming and DSLs in Performance Critical Systems. In 1st Summit on Advances in Programming Languages, SNAPL 2015, May 3-6, 2015, Asilomar, California, USA. 238-261.Google ScholarGoogle Scholar
  15. Kenichi Suzuki, Oleg Kiselyov, and Yukiyoshi Kameyama. 2016. Finally, safely-extensible and efficient language-integrated query. In Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, St. Petersburg, FL, USA, January 20 - 22, 2016. 37-48. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Takahisa Watanabe. 2017. Program Generation for ML Modules. (2017). http://logic.cs.tsukuba.ac.jp/~takahisa/module-generation.html.Google ScholarGoogle Scholar
  17. Takahisa Watanabe and Yukiyoshi Kameyama. 2018. Program generation for ML modules (short paper). In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, Los Angeles, CA, USA, January 8-9, 2018. 60-66. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Jeremy Yallop. 2016. Staging generic programming. In Proceedings of the 2016 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2016, St. Petersburg, FL, USA, January 20 - 22, 2016. 85-96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Jeremy Yallop and Oleg Kiselyov. 2019. Generating mutually recursive definitions. In Proceedings of the 2019 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, [email protected] 2019, Cascais, Portugal, January 14-15, 2019. 75-81. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Jeremy Yallop and Leo White. 2015. Modular macros. OCaml Users and Developers Workshop. (2015).Google ScholarGoogle Scholar

Index Terms

  1. Module generation without regret

      Comments

      Login options

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

      Sign in

      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!