A Refactoring Library for Scala Compiler Extensions

Part of the Lecture Notes in Computer Science book series (LNCS, volume 9031)

Abstract

Compiler plugins enable languages to be extended with new functionality by adding compiler passes that perform additional static checking, code generation, or code transformations. However, compiler plugins are often difficult to build. A plugin can perform arbitrary code transformations, easily allowing a developer to generate incorrect code. Moreover, the base compiler assumes many complex, sometimes undocumented invariants, requiring plugin developers to acquire intimate knowledge of the design and implementation of the compiler. To address these issues in the context of the Scala compiler plugin framework, we introduce Piuma. Piuma is a library that provides, first, an API to perform many common refactoring tasks needed by plugin writers, and, second, a DSL to eliminate much of the boilerplate code required for plugin development. We demonstrate the usefulness of our library by implementing five diverse compiler plugins. We show that, using Piuma, plugins require less code and are easier to understand than plugins developed using the base Scala compiler plugin API.

Keywords

Scala compiler extensions refactoring 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Acar, U.A.: Self-adjusting computation (an overview). In: Proceedings of the 2009 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2009, pp. 1–6. ACM, New York (2009)Google Scholar
  2. 2.
    Apache Foundation: Apache Avro Records, http://avro.apache.org/
  3. 3.
    Bastin, C., Ureche, V., Odersky, M.: ScalaDyno: Making Name Resolution and Type Checking Fault-tolerant. In: Proceedings of the Fifth Annual Scala Workshop, SCALA 2014, pp. 1–5. ACM, New York (2014)CrossRefGoogle Scholar
  4. 4.
    Bentley, J.: Programming pearls: little languages. Commun. ACM 29(8), 711–721 (1986)CrossRefMathSciNetGoogle Scholar
  5. 5.
    Bloch, J.: JSR 175: A metadata facility for the Java programming langauges (2004), http://jcp.org/en/jsr/detail?id=175
  6. 6.
    Bracha, G.: Pluggable type systems. In: OOPSLA 2004 Workshop on Revival of Dynamic Languages (2004)Google Scholar
  7. 7.
    Burmako, E.: Scala Macros: Let Our Powers Combine! In: 4th Annual Workshop Scala 2013 (2013)Google Scholar
  8. 8.
    Burmako, E.: Macro annotations (2014), http://docs.scala-lang.org/overviews/macros/annotations.html
  9. 9.
    Charles, P., Grothoff, C., Saraswat, V., Donawa, C., Kielstra, A., Ebcioglu, K., von Praun, C., Sarkar, V.: X10: An object-oriented approach to non-uniform cluster computing. In: Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2005, pp. 519–538. ACM, New York (2005)CrossRefGoogle Scholar
  10. 10.
    Danial, A.: Cloc, http://cloc.sourceforge.net/
  11. 11.
    Dietl, W., Dietzel, S., Ernst, M.D., Muslu, K., Schiller, T.W.: Building and Using Pluggable Type-Checkers. In: Software Enginnering in Practice Track, International Conference on Software Engineering (ICSE) (May 2011)Google Scholar
  12. 12.
    Dybvig, R., Hieb, R., Bruggeman, C.: Syntactic abstraction in Scheme. LISP and Symbolic Computation 5(4), 295–326 (1993)CrossRefGoogle Scholar
  13. 13.
    Ekman, T., Hedin, G.: The JastAdd extensible Java compiler. In: Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems and Applications, OOPSLA 2007, pp. 1–18. ACM, New York (2007)CrossRefGoogle Scholar
  14. 14.
    Ernst, M.: JSR 308: Annotations on Java Types (2004), https://jcp.org/en/jsr/detail?id=308
  15. 15.
    Flanagan, D., Matsumoto, Y.: The Ruby Programming Language, 1st edn. O’Reilly (2008)Google Scholar
  16. 16.
    Foundation, N.: NET compiler platform (“roslyn”), https://github.com/dotnet/roslyn/ (2014)
  17. 17.
    Futamura, Y.: Partial evaluation of computation process–an approach to a compiler-compiler. Higher-Order and Symbolic Computation 12(4), 381–391 (1999)CrossRefMATHGoogle Scholar
  18. 18.
    Gosling, J., Joy, B., Steele, G., Bracha, G.: Java(TM) Language Specification, 3rd edn. (Java (Addison-Wesley)). Addison-Wesley Professional (2005)Google Scholar
  19. 19.
    Haller, P., Odersky, M.: Capabilities for uniqueness and borrowing. In: D’Hondt, T. (ed.) ECOOP 2010. LNCS, vol. 6183, pp. 354–378. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  20. 20.
    Hammer, M.A., Acar, U.A., Chen, Y.: CEAL: A C-based language for self-adjusting computation. In: Proceedings of the 30th ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 25–37 (2009)Google Scholar
  21. 21.
    Hejlsberg, A., Wiltamuth, S., Golde, P.: C# Language Specification. Addison-Wesley Longman Publishing Co., Inc.,, Boston (2003)Google Scholar
  22. 22.
    Hudak, P.: Modular domain specific languages and tools. In: The Fifth International Conference on Software Reuse (ICSR) (1998)Google Scholar
  23. 23.
    Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Inc., Upper Saddle River (1993)MATHGoogle Scholar
  24. 24.
    Jovanovic, V., Nikolaev, V., Pham, N.D., Ureche, V., Stucki, S., Koch, C., Odersky, M.: Yin-Yang: Transparent Deep Embedding of DSLs. Technical report, EPFL (2013), http://infoscience.epfl.ch/record/185832
  25. 25.
    Klint, P., van der Storm, T., Vinju, J.: Rascal: A domain specific language for source code analysis and manipulation. In: Ninth IEEE International Working Conference on Source Code Analysis and Manipulation, SCAM 2009, pp. 168–177. IEEE (2009)Google Scholar
  26. 26.
    Kohlbecker, E., Friedman, D.P., Felleisen, M., Duba, B.: Hygienic macro expansion. In: Proceedings of the 1986 ACM Conference on LISP and Functional Programming, pp. 151–161. ACM (1986)Google Scholar
  27. 27.
    Konat, G.D.P., Vergu, V.A., Kats, L.C.L., Wachsmuth, G., Visser, E.: The Spoofax Name Binding Language. In: SPLASH, pp. 79–80. ACM (2012)Google Scholar
  28. 28.
    Li, H., Thompson, S., Orosz, G., et al.: Refactoring with Wrangler: Data and process refactorings, and integration with Eclipse. In: Proceedings of the Seventh ACM SIGPLAN Erlang Workshop (September 2008)Google Scholar
  29. 29.
    Markstrum, S., Marino, D., Esquivel, M., Millstein, T., Andreae, C., Noble, J.: JavaCOP: Declarative Pluggable Types for Java. ACM Trans. Program. Lang. Syst. 32(2), 4:1–4:37 (2010)Google Scholar
  30. 30.
    Moors, A., Rompf, T., Haller, P., Odersky, M.: Scala-virtualized. In: Proceedings of the ACM SIGPLAN 2012 Workshop on Partial Evaluation and Program Manipulation, PEPM 2012, pp. 117–120. ACM, New York (2012)Google Scholar
  31. 31.
    Nystrom, N.: Harmless Compiler Plugins. In: Proceedings of the 13th Workshop on Formal Techniques for Java-Like Programs, FTfJP 2011, pp. 4:1–4:6. ACM, New York (2011)Google Scholar
  32. 32.
    Nystrom, N., Clarkson, M.R., Myers, A.C.: Polyglot: An Extensible Compiler Framework for Java. In: Hedin, G. (ed.) CC 2003. LNCS, vol. 2622, pp. 138–152. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  33. 33.
    Odersky, M., et al.: The Scala programming language (2006-2013), http://www.scala-lang.org
  34. 34.
    Peyton Jones, S.L.: Haskell 98 language and libraries: the revised report. Cambridge University Press (2003), http://www.haskell.org/definition/haskell98-report.pdf
  35. 35.
    Rompf, T., Maier, I., Odersky, M.: Implementing first-class polymorphic delimited continuations by a type-directed selective cps-transform. ACM Sigplan Notices 44(9), 317–328 (2009)CrossRefGoogle Scholar
  36. 36.
    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
  37. 37.
    Rompf, T., Sujeeth, A.K., Amin, N., Brown, K.J., Jovanovic, V., Lee, H., Jonnalagedda, M., Olukotun, K., Odersky, M.: Optimizing data structures in high-level programs: New directions for extensible compilers based on staging. In: Giacobazzi, R., Cousot, R. (eds.) POPL, pp. 497–510. ACM (2013)Google Scholar
  38. 38.
  39. 39.
    Shabalin, D., Burmako, E., Odersky, M.: Quasiquotes for Scala. Technical report, EPFL (2013), http://infoscience.epfl.ch/record/185242
  40. 40.
    Shali, A., Cook, W.R.: Hybrid Partial Evaluation. In: Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA 2011, pp. 375–390. ACM, New York (2011)Google Scholar
  41. 41.
    Steele, G.L., Gabriel, R.P.: The evolution of Lisp. In: The Second ACM SIGPLAN Conference on History of Programming Languages, HOPL-II, pp. 231–270. ACM, New York (1993)CrossRefGoogle Scholar
  42. 42.
    Stocker, M., Sommerlad, P.: Scala Refactoring. Master’s thesis, University of Applied Sciences Rapperswil (2010)Google Scholar
  43. 43.
    Sujeeth, A.K., Lee, H., Brown, K.J., Rompf, T., Chafi, H., Wu, M., Atreya, A.R., Odersky, M., Olukotun, K.: OptiML: An Implicitly Parallel Domain-Specific Language for Machine Learning. In: Getoor, L., Scheffer, T. (eds.) ICML, pp. 609–616. Omnipress (2011)Google Scholar
  44. 44.
    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
  45. 45.
    Tu, S., et al.: A Scala compiler plugin for Avro records (2011), http://code.google.com/p/avro-scala-compiler-plugin
  46. 46.
    Ureche, V., Talau, C., Odersky, M.: Miniboxing: improving the speed to code size tradeoff in parametric polymorphism translations. In: Proceedings of the 2013 ACM SIGPLAN International Conference on Object Oriented Programming Systems Languages & Applications, pp. 73–92. ACM (2013)Google Scholar
  47. 47.
    Vaziri, M., Tip, F., Dolby, J., Hammer, C., Vitek, J.: Type System for Data-Centric Synchronization. In: D’Hondt, T. (ed.) ECOOP 2010. LNCS, vol. 6183, pp. 304–328. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  48. 48.
    Zenger, M., Odersky, M.: Independently extensible solutions to the expression problem. In: 12th International Workshop on Foundations of Object-Oriented Languages (2005)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2015

Authors and Affiliations

  • Amanj Sherwany
    • 1
  • Nosheen Zaza
    • 1
  • Nathaniel Nystrom
    • 1
  1. 1.Faculty of InformaticsUniversità della Svizzera italiana (USI)LuganoSwitzerland

Personalised recommendations