ABSTRACT
Partial evaluation aims to improve the efficiency of a program by specialising it with respect to some known inputs. In this paper, we show that partial evaluation can be an effective and, unusually, easy to use technique for the efficient implementation of embedded domain-specific languages. We achieve this by exploiting dependent types and by following some simple rules in the definition of the interpreter for the domain-specific language. We present experimental evidence that partial evaluation of programs in domain-specific languages can yield efficient residual programs whose performance is competitive with their Java and C equivalents and which are also, through the use of dependent types, verifiably resource-safe. Using our technique, it follows that a verifiably correct and resource-safe program can also be an efficient program
Supplemental Material
- }}P. H. Andersen and C. K. Holst. Termination analysis for offline partial evaluation of a higher order functional language. In Proc. SAS ’96: Intl. Symp. on Static Analysis, pages 67--82. Springer, 1996. Google ScholarDigital Library
- }}L. Augustsson and M. Carlsson. An exercise in dependent types: A well-typed interpreter. In Workshop on Dependent Types in Programming, Gothenburg, 1999. Available from http://www.cs.chalmers.se/ augustss/cayenne/interp.ps.Google Scholar
- }}L. Augustsson, H. Mansell, and G. Sittampalam. Paradise: a two-stage DSL embedded in Haskell. In Proc. ICFP 2008: International Conf. on Functional Programming, pages 225--228. ACM, 2008. Google ScholarDigital Library
- }}S. Bhatti, E. Brady, K. Hammond, and J. McKinna. Domain specific languages (DSLs) for network protocols. In International Workshop on Next Generation Network Architecture (NGNA 2009), 2009. Google ScholarDigital Library
- }}H.-J. Boehm, A. J. Demers, Xerox Corporation Silicon Graphic, and Hewlett-Packard Company. A garbage collector for C and CGoogle Scholar
- }}. http://www.hpl.hp.com/personal/Hans_Boehm/gc/, 2001.Google Scholar
- }}E. Brady. Practical Implementation of a Dependently Typed Functional Programming Language. PhD thesis, University of Durham, 2005.Google Scholar
- }}E. Brady. Ivor, a proof engine. In Implementation and Application of Functional Languages 2006, volume 4449 of LNCS, pages 145--162. Springer, 2007. Google ScholarDigital Library
- }}E. Brady and K. Hammond. A verified staged interpreter is a verified compiler. In Proc. GPCE ’06: Conf. on Generative Programming and Component Engineering, 2006. Google ScholarDigital Library
- }}E. Brady, C. McBride, and J. McKinna. Inductive families need not store their indices. In S. Berardi, M. Coppo, and F. Damiani, editors, Types for Proofs and Programs 2003, volume 3085, pages 115--129. Springer, 2004.Google ScholarCross Ref
- }}J. Carette, O. Kiselyov, and C.-c. Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program., 19(5):509--543, 2009. Google ScholarDigital Library
- }}T. Coquand. An algorithm for type-checking dependent types. Science of Computer Programming, 26(1--3):167--177, 1996. Google ScholarDigital Library
- }}S. Debois. Imperative program optimization by partial evaluation. In Proc. PEPM ’04: ACM Symp. on Partial Evaluation and Semantics-Based Program Manipulation, pages 113--122. ACM, 2004. Google ScholarDigital Library
- }}B. Delaware and W. R. Cook. Generic operations and partial evaluation using models, 2009. Draft.Google Scholar
- }}C. Elliott, S. Finne, and O. De Moor. Compiling embedded languages. J. Funct. Program., 13(3):455--481, 2003. Google ScholarDigital Library
- }}S. Fogarty, E. Pasalic, J. Siek, and W. Taha. Concoqtion: indexed types now! In Proc. PEPM ’07: ACM Symp. on Partial Evaluation and Semantics-Based Program Manipulation, pages 112--121, 2007. Google ScholarDigital Library
- }}Y. Futamura. Partial evaluation of computation process --- an approach to a compiler-compiler. Systems, Comps., Controls, 2(5):45---50, 1971.Google Scholar
- }}A. Gill. Cheap deforestation for non-strict functional languages. PhD thesis, University of Glasgow, January 1996.Google Scholar
- }}P. Hancock and A. Setzer. Interactive programs in dependent type theory. In P. Clote and H. Schwichtenberg, editors, Proc. CSL 2000: 14th Ann.\ Conf.\ of EACSL, Fischbau, Germany, 21--26 Aug 2000, LNCS 1862, pages 317--331. 2000. Google ScholarDigital Library
- }}P. Hudak. Building domain-specific embedded languages. ACM Computing Surveys, 28A(4), December 1996. Google ScholarDigital Library
- }}N. Jones, C. Gomard, and P. Sestoft. Partial Evaluation and Automatic Program Generation. Prentice Hall International, 1993. Google ScholarDigital Library
- }}N. D. Jones. Challenging problems in partial evaluation and mixed computation. New Gen. Comput., 6(2--3):291--302, 1988. Google ScholarDigital Library
- }}O. Kiselyov and C.-c. Shan. Lightweight monadic regions. In Proc. Haskell ’08: ACM SIGPLAN Symp. on Haskell, pages 1--12, 2008. Google ScholarDigital Library
- }}C. Lattner. LLVM: An infrastructure for multi-stage optimization. Master’s thesis, Computer Science Dept., University of Illinois at Urbana-Champaign, December 2002.Google Scholar
- }}S. Lee, M. M. T. Chakravarty, V. Grover, and G. Keller. GPU kernels as data-parallel array computations in Haskell. In Workshop on Exploiting Parallelism using GPUs and other Hardware-Assisted Methods (EPAHM 2009), 2009.Google Scholar
- }}A. Löh, C. McBride, and W. Swierstra. A tutorial implementation of a dependently typed lambda calculus, 2010. To appear in Fundam. Inf. Google ScholarDigital Library
- }}C. McBride and J. McKinna. The view from the left. Journal of Functional Programming, 14(1):69--111, 2004. Google ScholarDigital Library
- }}N. Mitchell. Transformation and Analysis of Functional Programs. PhD thesis, University of York, June 2008.Google Scholar
- }}N. Mitchell and C. Runciman. A supercompiler for core Haskell. In Implementation and Application of Functional Languages 2007, volume 5083 of LNCS, pages 147--164. Springer, May 2008. Google ScholarDigital Library
- }}U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden, September 2007.Google Scholar
- }}W. Partain. The nofib benchmark suite of Haskell programs. In J. Launchbury and P. Sansom, editors, Functional Programming, Workshops in Computing, pages 195--202. Springer, 1992. Google ScholarDigital Library
- }}E. Pa\vsalíc, W. Taha, and T. Sheard. Tagless staged interpreters for typed languages. In Proc. 2002 International Conf. on Functional Programming (ICFP 2002). ACM, 2002. Google ScholarDigital Library
- }}S. Peyton Jones and S. Marlow. Secrets of the Glasgow Haskell Compiler inliner. Journal of Functional Programming, 12(4):393--434, September 2002. Google ScholarDigital Library
- }}T. Schrijvers, S. Peyton Jones, M. Chakravarty, and M. Sulzmann. Type checking with open type functions. In International Conf. on Functional Programming (ICFP 2008), pages 51--62, New York, NY, USA, 2008. ACM. Google ScholarDigital Library
- }}S. Seefried, M. Chakravarty, and G. Keller. Optimising embedded DSLs using Template Haskell. In Proc. GPCE ’04: Conf. Generative Prog. and Component Eng., LNCS. Springer, 2004.Google ScholarCross Ref
- }}T. Sheard and S. Peyton Jones. Template metaprogramming for Haskell. In ACM Haskell Workshop, pages 1--16, Oct. 2002. Google ScholarDigital Library
- }}K. Swadi, W. Taha, O. Kiselyov, and E. Pasalic. A monadic approach for avoiding code duplication when staging memoized functions. In Proc. PEPM ’06: ACM Symp. on Partial Evaluation and Semantics-based Program Manipulation, pages 160--169, 2006. Google ScholarDigital Library
- }}W. Taha. Multi-stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Inst. of Science and Technology, 1999. Google ScholarDigital Library
- }}W. Taha. A Gentle Introduction to Multi-stage Programming, 2003. Available from http://www.cs.rice.edu/ taha.Google Scholar
- }}W. Taha and H. Makholm. Tag elimination -- or -- type specialisation is a type indexed effect. In Subtyping and Dependent Types in Programming, APPSEM Workshop, 2000.Google Scholar
- }}W. Taha, H. Makholm, and J. Hughes. Tag elimination and jones-optimality. In PADO ’01: Proceedings of the Second Symposium on Programs as Data Objects, pages 257--275, London, UK, 2001. Springer-Verlag. Google ScholarDigital Library
- }}D. Terei. Low level virtual machine for Glasgow Haskell Compiler. Bachelor’s Thesis, Computer Science and Engineering Dept., The University of New South Wales, Sydney, Australia, 2009.Google Scholar
- }}A. van Deursen, P. Klint, and J. Visser. Domain-specific languages -- an annotated bibliography. http://homepages.cwi.nl/ arie/papers/dslbib/, 2000.Google Scholar
- }}P. Wadler. Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science, 73:231--248, 1990. Google ScholarDigital Library
Index Terms
- Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation
Recommendations
A verified staged interpreter is a verified compiler
GPCE '06: Proceedings of the 5th international conference on Generative programming and component engineeringDependent types and multi-stage programming have both been used, separately, in programming language design and implementation. Each technique has its own advantages --- with dependent types, we can verify aspects of interpreters and compilers such as ...
Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation
ICFP '10Partial evaluation aims to improve the efficiency of a program by specialising it with respect to some known inputs. In this paper, we show that partial evaluation can be an effective and, unusually, easy to use technique for the efficient ...
Towards a jitting VM for prolog execution
PPDP '10: Proceedings of the 12th international ACM SIGPLAN symposium on Principles and practice of declarative programmingMost Prolog implementations are implemented in low-level languages such as C and are based on a variation of the WAM instruction set, which enhances their performance but makes them hard to write. In addition, many of the more dynamic features of Prolog ...
Comments