Staging beyond terms: prospects and challenges

Staging is a program generation paradigm with a clean, well-investigated semantics which statically ensures that the generated code is always well-typed and well-scoped. Staging is often used for specializing programs to the known properties or parts of data to improve efficiency, but so far it has been limited to generating terms. This short paper describes our ongoing work on extending staging, with its strong safety guarantees, to generation of non-terms, focusing on ML-style modules. The purpose is to map out the promises and challenges, then to pose a question to solicit the community's expertise in evaluating how essential our extensions are for the purpose of applying staging beyond the realm of terms. We demonstrate our extensions' use in specializing functor applications to eliminate its (currently large) overhead in OCaml. We explain the challenges that those extensions bring in and identify a promising line of attack. Unexpectedly, however, it turns out that we can avoid module generation altogether by representing modules, possibly containing abstract types, as polymorphic records. With the help of first-class modules, module specialization reduces to ordinary term specialization, which can be done with conventional staging. The extent to which this hack generalizes is unclear. Thus we have a question to the community: is there a compelling use case for module generation? With these insights and questions, we offer a starting point for a long-term program in the next stage of staging research.

[1]  Claudio V. Russo,et al.  F-ing modules , 2010, TLDI '10.

[2]  Jack J. Dongarra,et al.  Automatically Tuned Linear Algebra Software , 1998, Proceedings of the IEEE/ACM SC98 Conference.

[3]  John C. Mitchell,et al.  Abstract types have existential type , 1988, TOPL.

[4]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[5]  Andreas Rossberg 1ML – core and modules united (F-ing first-class modules) , 2015, ICFP.

[6]  Franz Franchetti,et al.  SPIRAL: Code Generation for DSP Transforms , 2005, Proceedings of the IEEE.

[7]  Walid Taha,et al.  Environment classifiers , 2003, POPL.

[8]  Walid Taha,et al.  Concoqtion: indexed types now! , 2007, PEPM '07.

[9]  Walid Taha,et al.  A methodology for generating verified combinatorial circuits , 2004, EMSOFT '04.

[10]  Stephen Weeks,et al.  Whole-program compilation in MLton , 2006, ML '06.

[11]  Martin Odersky,et al.  Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs , 2010, GPCE '10.

[12]  Walid Taha,et al.  Staged Notational Definitions , 2003, GPCE.

[13]  Per Martin-Löf,et al.  Intuitionistic type theory , 1984, Studies in proof theory.

[14]  Peter Morris,et al.  The gentle art of levitation , 2010, ICFP '10.

[15]  Kunle Olukotun,et al.  Optimizing data structures in high-level programs: new directions for extensible compilers based on staging , 2013, POPL.

[16]  Chung-chieh Shan,et al.  Combinators for impure yet hygienic code generation , 2014, PEPM '14.

[17]  Jim Grundy,et al.  Synthesizable high level hardware descriptions: using statically typed two-level languages to guarantee verilog synthesizability , 2008, PEPM '08.

[18]  Hongwei Xi,et al.  Applied Type System: Extended Abstract , 2003, TYPES.

[19]  Walid Taha,et al.  Reasoning about multi-stage programs* , 2016, Journal of Functional Programming.

[20]  Eelco Visser,et al.  Proceedings of the 2007 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation , 2007 .