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
- 1997. MLton, a whole program optimizing compiler for Standard ML. http://www.mlton.org. (1997).Google Scholar
- 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
- Olivier Danvy. 1996. Pragmatic Aspects of Type-Directed Partial Evaluation. Technical Report. BRICS Report Series RS-96-15. 27 pages.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Oleg Kiselyov. 2012. Delimited control in OCaml, abstractly and concretely. Theor. Comput. Sci. 435 (2012), 56-76. Google Scholar
Digital Library
- 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 Scholar
- Oleg Kiselyov. 2017. Let-insertion as a primitive. (2017). http://okmij.org/ftp/ML/MetaOCaml.html#genlet.Google Scholar
- Xavier Leroy. 2000. A modular module system. J. Funct. Program. 10, 3 (2000), 269-303. http://journals.cambridge.org/action/displayAbstract?aid=54525. Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Takahisa Watanabe. 2017. Program Generation for ML Modules. (2017). http://logic.cs.tsukuba.ac.jp/~takahisa/module-generation.html.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Jeremy Yallop and Leo White. 2015. Modular macros. OCaml Users and Developers Workshop. (2015).Google Scholar
Index Terms
Module generation without regret





Comments