A List of Successes That Can Change the World pp 318-335

Part of the Lecture Notes in Computer Science book series (LNCS, volume 9600) | Cite as

The Essence of Multi-stage Evaluation in LMS

Chapter

Abstract

Embedded domain-specific languages (DSLs) are the subject of wide-spread interest, and a variety of implementation techniques exist. Some of them have been invented, and some of them discovered. Many are based on a form of generative or multi-stage programming, where the host language program builds up DSL terms during its evaluation. In this paper, we examine the execution model of LMS (Lightweight Modular Staging), a framework for embedded DSLs in Scala, and link it to evaluation in a two-stage lambda calculus. This clarifies the semantics of certain ad-hoc implementation choices, and provides guidance for implementing similar multi-stage evaluation facilities in other languages.

Keywords

Multi-stage programming Scala Domain-specific languages LMS (Lightweight Modular Staging) Partial evaluation 

References

  1. 1.
    Ager, M.S., Danvy, O., Rohde, H.K.: Fast partial evaluation of pattern matching in strings. ACM Trans. Program. Lang. Syst. 28(4), 696–714 (2006)CrossRefGoogle Scholar
  2. 2.
    Amarasinghe, S.P.: Petabricks: a language and compiler based on autotuning. In: Katevenis, M., Martonosi, M., Kozyrakis, C., Temam, O. (eds.) Proceedings of the 6th International Conference on High Performance Embedded Architectures and Compilers, HiPEAC 2011, Heraklion, Crete, Greece, 24–26 January 2011, p. 3. ACM (2011)Google Scholar
  3. 3.
    Axelsson, E., Claessen, K., Sheeran, M., Svenningsson, J., Engdal, D., Persson, A.: The design and implementation of feldspar: an embedded language for digital signal processing. In: Hage, J., Morazán, M.T. (eds.) IFL. LNCS, vol. 6647, pp. 121–136. Springer, Heidelberg (2011)CrossRefGoogle Scholar
  4. 4.
    Beckmann, O., Houghton, A., Mellor, M.R., Kelly, P.H.J.: Runtime code generation in C++ as a foundation for domain-specific optimisation. In: Lengauer, C., Batory, D., Blum, A., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 291–306. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  5. 5.
    Boehm, H., Flanagan, C. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle, WA, USA, 16–19 June 2013. ACM (2013)Google Scholar
  6. 6.
    Bondorf, A.: Self-applicable partial evaluation. Ph.D. thesis, DIKU, Department of Computer Science, University of Copenhagen (1990)Google Scholar
  7. 7.
    Brown, K.J., Sujeeth, A.K., Lee, H., Rompf, T., Chafi, H., Odersky, M., Olukotun, K.: A heterogeneous parallel framework for domain-specific languages. In: PACT (2011)Google Scholar
  8. 8.
    Bulyonkov, M.A.: Polyvariant mixed computation for analyzer programs. Acta Inf. 21, 473–484 (1984)MathSciNetCrossRefMATHGoogle Scholar
  9. 9.
    Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using ASTs, gensym, and reflection. In: Pfenning, F., Macko, M. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  10. 10.
    Carette, J., Kiselyov, O., Shan, C.C.: Finally tagless, partially evaluated: tagless staged interpreters forsimpler typed languages. J. Funct. Program. 19(5), 509–543 (2009)MathSciNetCrossRefMATHGoogle Scholar
  11. 11.
    Catanzaro, B., Garland, M., Keutzer, K.: Copperhead: compiling an embedded data parallel language. In: Proceedings of the 16th ACM Symposium on Principles and Practice of Parallel Programming, PPoPP, pp. 47–56. ACM, New York (2011)Google Scholar
  12. 12.
    Chafi, H., DeVito, Z., Moors, A., Rompf, T., Sujeeth, A.K., Hanrahan, P., Odersky, M., Olukotun, K.: Language virtualization for heterogeneous parallel computing. In: Onward! (2010)Google Scholar
  13. 13.
    Cheney, J., Lindley, S., Wadler, P.: A practical theory of language-integrated query. In: Morrisett, G., Uustalu, T. (eds.) ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, Boston, MA, USA, 25–27 September 2013, pp. 403–416. ACM (2013)Google Scholar
  14. 14.
    Click, C., Cooper, K.D.: Combining analyses, combining optimizations. ACM Trans. Program. Lang. Syst. 17, 181–196 (1995)CrossRefGoogle Scholar
  15. 15.
    Consel, C., Danvy, O.: Partial evaluation of pattern matching in strings. Inf. Process. Lett. 30(2), 79–86 (1989)CrossRefGoogle Scholar
  16. 16.
    Consel, C., Khoo, S.-C.: Parameterized partial evaluation. ACM Trans. Program. Lang. Syst. 15(3), 463–493 (1993)MathSciNetCrossRefGoogle Scholar
  17. 17.
    Danvy, O.: Type-directed partial evaluation. In: Hatcliff, J., Mogensen, T.Æ., Thiemann, P. (eds.) DIKU 1998. LNCS, vol. 1706, pp. 367–411. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  18. 18.
    DeVito, Z., Hegarty, J., Aiken, A., Hanrahan, P., Vitek, J.: Terra: a multi-stage language for high-performance computing. In: Boehm, H., Flanagan, C. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle, WA, USA, 16–19 June 2013, pp. 105–116. ACM (2013)Google Scholar
  19. 19.
    DeVito, Z., Ritchie, D., Fisher, M., Aiken, A., Hanrahan, P.: First-class runtime generation of high-performance types using exotypes. In: O’Boyle, M.F.P., Pingali, K. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2014, Edinburgh, United Kingdom, 09–11 June 2014, p. 11. ACM (2014)Google Scholar
  20. 20.
    Elliott, C., Finne, S., de Moor, O.: Compiling embedded languages. J. Funct. Program. 13(3), 455–481 (2003)CrossRefMATHGoogle Scholar
  21. 21.
    Filinski, A.: Representing monads. In: Boehm, H., Lang, B., Yellin, D.M. (eds.) 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Conference Record of POPL 1994, Portland, Oregon, USA, 17–21 January 1994, pp. 446–457. ACM Press (1994)Google Scholar
  22. 22.
    Filinski, A.: Normalization by evaluation for the computational Lambda-Calculus. In: Abramsky, S. (ed.) TLCA 2001. LNCS, vol. 2044, pp. 151–165. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  23. 23.
    Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: Cartwright, R. (ed.) Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation (PLDI), Albuquerque, New Mexico, USA, 23–25 June 1993, pp. 237–247. ACM (1993)Google Scholar
  24. 24.
    Frigo, M.: A fast fourier transform compiler. In: PLDI, pp. 169–180 (1999)Google Scholar
  25. 25.
    Gill, A.: Domain-specific languages and code synthesis using haskell. Queue 12(4), 30:30–30:43 (2014)Google Scholar
  26. 26.
    Grant, B., Mock, M., Philipose, M., Chambers, C., Eggers, S.J.: Dyc: an expressive annotation-directed dynamic compiler for c. Theoret. Comput. Sci. 248(1–2), 147–199 (2000)CrossRefMATHGoogle Scholar
  27. 27.
    Hanger, M., Johansen, T.A., Mykland, G.K., Skullestad, A.: Dynamic model predictive control allocation using CVXGEN. In: 9th IEEE International Conference on Control and Automation, ICCA 2011, Santiago, Chile, 19–21 December 2011, pp. 417–422. IEEE (2011)Google Scholar
  28. 28.
    Hatcliff, J., Danvy, O.: A computational formalization for partial evaluation. Math. Struct. Comput. Sci. 7(5), 507–541 (1997)MathSciNetCrossRefMATHGoogle Scholar
  29. 29.
    Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of DSLs. In: Smaragdakis, Y., Siek, J.G. (eds.) GPCE, pp. 137–148. ACM (2008)Google Scholar
  30. 30.
    Hudak, P.: Building domain-specific embedded languages. ACM Comput. Surv. 28, 196 (1996)CrossRefGoogle Scholar
  31. 31.
    Hudak, P.: Modular domain specific languages and tools. In: Proceedings of Fifth International Conference on Software Reuse, pp. 134–142, June 1998Google Scholar
  32. 32.
    Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall Inc., Upper Saddle River (1993)MATHGoogle Scholar
  33. 33.
    Kiselyov, O., Swadi, K.N., Taha, W.: A methodology for generating verified combinatorial circuits. In: Buttazzo, G.C. (ed.) EMSOFT, pp. 249–258. ACM (2004)Google Scholar
  34. 34.
    Klimov, A.V.: A Java supercompiler and its application to verification of cache-coherence protocols. In: Pnueli, A., Virbitskaite, I., Voronkov, A. (eds.) PSI 2009. LNCS, vol. 5947, pp. 185–192. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  35. 35.
    Krishnamurthi, S.: Linguistic reuse. Ph.D. thesis, Computer Science, Rice University, Houston (2001)Google Scholar
  36. 36.
    Landin, P.J.: The next 700 programming languages. Commun. ACM 9(3), 157–166 (1966)CrossRefMATHGoogle Scholar
  37. 37.
    Lawall, J.L., Thiemann, P.: Sound specialization in the presence of computational effects. In: Abadi, M., Ito, T. (eds.) TACS 1997. LNCS, vol. 1281, pp. 165–190. Springer, Heidelberg (1997)CrossRefGoogle Scholar
  38. 38.
    Lee, H., Brown, K.J., Sujeeth, A.K., Chafi, H., Rompf, T., Odersky, M., Olukotun, K.: Implementing domain-specific languages for heterogeneous parallel computing. IEEE Micro 31(5), 42–53 (2011)CrossRefGoogle Scholar
  39. 39.
    Leijen, D., Meijer, E.: Domain specific embedded compilers. In: DSL, pp. 109–122 (1999)Google Scholar
  40. 40.
    Lindley, S.: Normalisation by evaluation in the compilation of typed functional programming languages (2005)Google Scholar
  41. 41.
    Mainland, G., Morrisett, G.: Nikola: embedding compiled GPU functions in Haskell. In: Proceedings of the Third ACM Haskell Symposium on Haskell, Haskell 2010, pp. 67–78. ACM, New York (2010)Google Scholar
  42. 42.
    McDonell, T.L., Chakravarty, M.M., Keller, G., Lippmeier, B.: Optimising purely functional GPU programs. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, pp. 49–60. ACM, New York (2013)Google Scholar
  43. 43.
    Mogensen, T.A.: Partially static structures in a self-applicable partial evaluator (1988)Google Scholar
  44. 44.
    Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991)MathSciNetCrossRefMATHGoogle Scholar
  45. 45.
    Najd, S., Lindley, S., Svenningsson, J., Wadler, P.: Everything old is new again: quoted domain specific languages. Technical report, University of Edinburgh (2015)Google Scholar
  46. 46.
    Nielson, F., Nielson, H.R.: Code generation from two-level denotational meta-languages. In: Ganzinger, H., Jones, N.D. (eds.) Programs as Data Objects. LNCS, vol. 217, pp. 192–205. Springer, Heidelberg (1986)CrossRefGoogle Scholar
  47. 47.
    Nielson, F., Nielson, H.R.: Multi-level Lambda-Calculi: an algebraic description. In: Danvy, O., Glück, R., Thiemann, P. (eds.) Partial Evaluation. LNCS, vol. 1110, pp. 338–354. Springer, Heidelberg (1996)CrossRefGoogle Scholar
  48. 48.
    Nystrom, N., White, D., Das, K.: Firepile: run-time compilation for GPUs in scala. In: Proceedings of the 10th ACM International Conference on Generative Programming and Component Engineering, GPCE, pp. 107–116. ACM, NewYork (2011)Google Scholar
  49. 49.
    Püschel, M., Moura, J.M.F., Singer, B., Xiong, J., Johnson, J., Padua, D.A., Veloso, M.M., Johnson, R.W.: Spiral: a generator for platform-adapted libraries of signal processing alogorithms. IJHPCA 18(1), 21–45 (2004)Google Scholar
  50. 50.
    Ragan-Kelley, J., Adams, A., Paris, S., Levoy, M., Amarasinghe, S.P., Durand, F.: Decoupling algorithms from schedules for easy optimization of image processing pipelines. ACM Trans. Graph. 31(4), 32 (2012)CrossRefGoogle Scholar
  51. 51.
    Ragan-Kelley, J., Barnes, C., Adams, A., Paris, S., Durand, F., Amarasinghe, S.P.: Halide: a language and compiler for optimizing parallelism, locality, and recomputation in image processing pipelines. In: Boehm, H., Flanagan, C. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle, WA, USA, 16–19 June 2013, pp. 519–530. ACM (2013)Google Scholar
  52. 52.
    Reynolds, J.: User-defined types and procedural data structures as complementary approaches to data abstraction (1975)Google Scholar
  53. 53.
    Rompf, T.: Lightweight Modular Staging and Embedded Compilers: Abstraction Without Regret for High-Level High-Performance Programming. Ph.D. thesis, EPFL (2012)Google Scholar
  54. 54.
    Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. Commun. ACM 55(6), 121–130 (2012)CrossRefGoogle Scholar
  55. 55.
    Rompf, T., Sujeeth, A.K., Amin, N., Brown, K., Jovanovic, V., Lee, H., Jonnalagedda, M., Olukotun, K., Odersky, M.: Optimizing data structures in high-level programs. In: POPL (2013)Google Scholar
  56. 56.
    Rompf, T., Sujeeth, A.K., Lee, H., Brown, K.J., Chafi, H., Odersky, M., Olukotun, K.: Building-blocks for performance oriented DSLs. In: DSL (2011)Google Scholar
  57. 57.
    Schultz, U.P., Lawall, J.L., Consel, C.: Automatic program specialization for java. ACM Trans. Program. Lang. Syst. 25(4), 452–499 (2003)CrossRefGoogle Scholar
  58. 58.
    Shali, A., Cook, W.R.: Hybrid partial evaluation. In: OOPSLA, pp. 375–390 (2011)Google Scholar
  59. 59.
    Sørensen, M.H., Glück, R., Jones, N.D.: A positive supercompiler. J. Funct. Program. 6(6), 811–838 (1996)CrossRefMATHGoogle Scholar
  60. 60.
    Sperber, M., Thiemann, P.: Realistic compilation by partial evaluation. In: PLDI, pp. 206–214 (1996)Google Scholar
  61. 61.
    Sperber, M., Thiemann, P.: Generation of LR parsers by partial evaluation. ACM Trans. Program. Lang. Syst. 22(2), 224–264 (2000)CrossRefGoogle Scholar
  62. 62.
    Steele, G.: Growing a language. High.-Order Symbolic Comput. 12(3), 221–236 (1999)CrossRefGoogle Scholar
  63. 63.
    Sujeeth, A.K., Rompf, T., Brown, K.J., Lee, H., Chafi, H., Popic, V., Wu, M., Prokopec, A., Jovanovic, V., Odersky, M., Olukotun, K.: Composition and reuse with compiled domain-specific languages. In: Castagna, G. (ed.) ECOOP 2013. LNCS, vol. 7920, pp. 52–78. Springer, Heidelberg (2013)CrossRefGoogle Scholar
  64. 64.
    Svensson, B.J., Sheeran, M., Newton, R.: Design exploration through code-generating DSLs. Queue 12(4), 40:40–40:52 (2014)Google Scholar
  65. 65.
    Taha, W., Sheard, T.: MetaML and multi-stage programming with explicit annotations. Theoret. Comput. Sci. 248(1–2), 211–242 (2000)CrossRefMATHGoogle Scholar
  66. 66.
    Thiemann, P.: Partially static operations. In: Albert, E., Mu, S.-C. (eds.) PEPM, pp. 75–76. ACM (2013)Google Scholar
  67. 67.
    Thiemann, P., Dussart, D.: Partial evaluation for higher-order languages with state. Technical report (1999)Google Scholar
  68. 68.
    Tobin-Hochstadt, S., St-Amour, V., Culpepper, R., Flatt, M., Felleisen, M.: Languages as libraries. In: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2011, pp. 132–141. ACM, New York (2011)Google Scholar
  69. 69.
    Turchin, V.F.: The concept of a supercompiler. ACM Trans. Program. Lang. Syst. 8(3), 292–325 (1986)MathSciNetCrossRefMATHGoogle Scholar
  70. 70.
    Whaley, R.C., Petitet, A., Dongarra, J.: Automated empirical optimizations of software and the ATLAS project. Parallel Comput. 27(1–2), 3–35 (2001)CrossRefMATHGoogle Scholar

Copyright information

© Springer International Publishing Switzerland 2016

Authors and Affiliations

  1. 1.Purdue UniversityWest LafayetteUSA

Personalised recommendations