Capture-Avoiding and Hygienic Program Transformations
Abstract
Program transformations in terms of abstract syntax trees compromise referential integrity by introducing variable capture. Variable capture occurs when in the generated program a variable declaration accidentally shadows the intended target of a variable reference. Existing transformation systems either do not guarantee the avoidance of variable capture or impair the implementation of transformations.
We present an algorithm called name-fix that automatically eliminates variable capture from a generated program by systematically renaming variables. name-fix is guided by a graph representation of the binding structure of a program, and requires name-resolution algorithms for the source language and the target language of a transformation. name-fix is generic and works for arbitrary transformations in any transformation system that supports origin tracking for names. We verify the correctness of name-fix and identify an interesting class of transformations for which name-fix provides hygiene. We demonstrate the applicability of name-fix for implementing capture-avoiding substitution, inlining, lambda lifting, and compilers for two domain-specific languages.
Keywords
State Machine Target Language Abstract Syntax Source Program Program TransformationPreview
Unable to display preview. Download preview PDF.
Supplementary material
References
- 1.Barzilay, E., Culpepper, R., Flatt, M.: Keeping it clean with syntax parameters. In: Scheme (2011)Google Scholar
- 2.Bawden, A., Rees, J.: Syntactic closures. In: LFP, pp. 86–95. ACM (1988)Google Scholar
- 3.Clinger, W., Rees, J.: Macros that work. In: POPL, pp. 155–162. ACM (1991)Google Scholar
- 4.Czarnecki, K., Helsen, S.: Feature-based survey of model transformation approaches. IBM Systems Journal 45(3), 621–645 (2006)CrossRefGoogle Scholar
- 5.de Bruijn, N.G.: Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagationes Mathematicae 75(5), 381–392 (1972)CrossRefzbMATHGoogle Scholar
- 6.de Jonge, M., Visser, E.: A language generic solution for name binding preservation in refactorings. In: LDTA. ACM (2012)Google Scholar
- 7.Dybvig, R.K., Hieb, R., Bruggeman, C.: Syntactic abstraction in scheme. Lisp and Symbolic Computation 5(4), 295–326 (1992)CrossRefGoogle Scholar
- 8.Erdweg, S.: Extensible Languages for Flexible and Principled Domain Abstraction. PhD thesis, Philipps-Universität Marburg (2013)Google Scholar
- 9.Erdweg, S., van der Storm, T., Dai, Y.: Capture-avoiding and hygienic program transformations (incl. proofs). CoRR, abs/1404.5770 (2014)Google Scholar
- 10.Erdweg, S., et al.: The state of the art in language workbenches. In: Erwig, M., Paige, R.F., Van Wyk, E. (eds.) SLE 2013. LNCS, vol. 8225, pp. 197–217. Springer, Heidelberg (2013)CrossRefGoogle Scholar
- 11.Herman, D.: A Theory of Typed Hygienic Macros. PhD thesis, Northeastern University, Boston, Massachusetts (2012)Google Scholar
- 12.Izmaylova, A., Klint, P., Shahi, A., Vinju, J.: M3: An open model for measuring source code artifacts. arXiv:1312.1188, BENEVOL 2013 (2013)Google Scholar
- 13.Johnsson, T.: Lambda lifting: Transforming programs to recursive equations. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 190–203. Springer, Heidelberg (1985)CrossRefGoogle Scholar
- 14.Klint, P., van der Storm, T., Vinju, J.: Rascal: A domain-specific language for source code analysis and manipulation. In: SCAM, pp. 168–177 (2009)Google Scholar
- 15.Kohlbecker, E., Friedman, D.P., Felleisen, M., Duba, B.: Hygienic macro expansion. In: LFP, pp. 151–161. ACM (1986)Google Scholar
- 16.Lee, B., Grimm, R., Hirzel, M., McKinley, K.S.: Marco: Safe, expressive macros for any language. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 589–613. Springer, Heidelberg (2012)CrossRefGoogle Scholar
- 17.B.C.: d. S. Oliveira and A. Löh. Abstract syntax graphs for domain specific languages. In: PEPM, pp. 87–96. ACM (2013)Google Scholar
- 18.Paige, R.F., Kolovos, D.S., Polack, F.A.C.: Metamodelling for grammarware researchers. In: Czarnecki, K., Hedin, G. (eds.) SLE 2012. LNCS, vol. 7745, pp. 64–82. Springer, Heidelberg (2013)CrossRefGoogle Scholar
- 19.Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: PLDI, pp. 199–208. ACM (1988)Google Scholar
- 20.Reps, T., Teitelbaum, T., Demers, A.: Incremental context-dependent analysis for language-based editors. TOPLAS 5(3), 449–477 (1983)CrossRefGoogle Scholar
- 21.Schäfer, M., Ekman, T., de Moor, O.: Sound and extensible renaming for Java. In: OOPSLA, pp. 227–294. ACM (2008)Google Scholar
- 22.Sheard, T.: Accomplishments and research challenges in meta-programming. In: Taha, W. (ed.) SAIG 2001. LNCS, vol. 2196, pp. 2–44. Springer, Heidelberg (2001)CrossRefGoogle Scholar
- 23.Shinwell, M.R., Pitts, A.M., Gabbay, M.J.: FreshML: Programming with binders made simple. In: ICFP, pp. 263–274. ACM (2003)Google Scholar
- 24.Macko, M., Batory, D.: Scoping constructs for software generators. In: Czarnecki, K. (ed.) GCSE 1999. LNCS, vol. 1799, pp. 65–78. Springer, Heidelberg (2000)CrossRefGoogle Scholar
- 25.Valdera, P.I., van der Storm, T., Erdweg, S.: Tracing model transformations with string origins. In: ICMT. Springer (to appear, 2014)Google Scholar
- 26.van den Bos, J., van der Storm, T.: Bringing domain-specific languages to digital forensics. In: ICSE, pp. 671–680. ACM (2011)Google Scholar
- 27.van Deursen, A., Klint, P., Tip, F.: Origin tracking. Symbolic Computation 15, 523–545 (1993)CrossRefzbMATHGoogle Scholar
- 28.Wachsmuth, G., Konat, G.D.P., Vergu, V.A., Groenewegen, D.M., Visser, E.: A language independent task engine for incremental name and type analysis. In: Erwig, M., Paige, R.F., Van Wyk, E. (eds.) SLE 2013. LNCS, vol. 8225, pp. 260–280. Springer, Heidelberg (2013)CrossRefGoogle Scholar