Hostname: page-component-7479d7b7d-767nl Total loading time: 0 Render date: 2024-07-12T17:32:32.346Z Has data issue: false hasContentIssue false

Reasoning about multi-stage programs*

Published online by Cambridge University Press:  07 November 2016

JUN INOUE
Affiliation:
National Institute of Advanced Industrial Science and Technology, Ikeda, Osaka, Japan (e-mails: jun.inoue@aist.go.jp)
WALID TAHA
Affiliation:
Halmstad University, Halmstad, Halland, Sweden (e-mails: walid.taha@hh.se)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

We settle three basic questions that naturally arise when verifying code generators written in multi-stage functional programming languages. First, does adding staging to a language compromise any equalities that hold in the base language? Unfortunately it does, and more care is needed to reason about terms with free variables. Second, staging annotations, as the name “annotations” suggests, are often thought to be orthogonal to the behavior of a program, but when is this formally guaranteed to be true? We give termination conditions that characterize when this guarantee holds. Finally, do multi-stage languages satisfy useful, standard extensional properties, for example, that functions agreeing on all arguments are equivalent? We provide a sound and complete notion of applicative bisimulation, which establishes such properties or, in principle, any valid program equivalence. These results yield important insights into staging and allow us to prove the correctness of quite complicated multi-stage programs.

Type
Articles
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited.
Copyright
Copyright © Cambridge University Press 2016

Footnotes

*

This work was supported by NSF CCF 0747431 award entitled “Multi-stage programming for object-oriented languages”, NSF CSR/EHS 0720857 award entitled “Building physically safe embedded systems”, NSF CPS 1136099 award entitled “A CPS Approach to Robot Design”, and Halmstad University.

References

Abramsky, S. (1990) The lazy lambda calculus. In Research Topics in Functional Programming, Turner, D. A. (ed). Addison-Wesley, pp. 65116.Google Scholar
Arbiser, A., Miquel, A. & Ríos, A. (2006) A lambda-calculus with constructors. In Proceedings of Term Rewriting and Applications, 17th International Conference. LNCS, vol. 4098. Springer Berlin Heidelberg, pp. 181–196.CrossRefGoogle Scholar
Aydemir, B., Charguéraud, A., Pierce, B. C., Pollack, R. & Weirich, S. (2008) Engineering formal metatheory. SIGPLAN Not. 43 (1), 315.Google Scholar
Barendregt, H. P. (1984) The Lambda Calculus: Its Syntax and Semantics. Studies in Logic and The Foundations of Mathematics. Amsterdam, New York, Oxford: North-Holland Publishing Company.Google Scholar
Benaissa, Z. El-abidine, Moggi, E., Taha, W. & Sheard, T. (1999) Logical modalities and multi-stage programming. In Federated Logic Conference (FLoC) Satellite Workshop on Intuitionistic Modal Logics and Applications (IMLA).Google Scholar
Berger, M. & Tratt, L. (2015) Program logics for homogeneous generative run-time meta-programming. Log. Meth. Comput. Sci. 11 (1), 150.Google Scholar
Bondorf, A. (1992) Improving binding times without explicit CPS-conversion. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming. New York, NY, USA: ACM, pp. 1–10.Google Scholar
Brady, E. & Hammond, K. (2006) A verified staged interpreter is a verified compiler. In Proceedings of Generative Programming and Component Engineering, 5th International Conference (GPCE). New York, NY, USA: ACM, pp. 111–120.Google Scholar
Carette, J. & Kiselyov, O. (2011) Multi-stage programming with functors and monads: Eliminating abstraction overhead from generic code. Sci. Comput. Program. 76 (5), 349375.Google Scholar
Carette, J., Kiselyov, O. & Shan, C.-C. (2009) Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19 (5), 509543.Google Scholar
Choi, W., Aktemur, B., Yi, K. & Tatsuta, M. (2011) Static analysis of multi-staged programs via unstaging translation. In Proceedings of the 38th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). New York, NY, USA: ACM, pp. 81–92.Google Scholar
Cohen, A., Donadio, S., Garzaran, M.-J., Herrmann, C., Kiselyov, O. & Padua, D. (2006) In search of a program generator to implement generic transformations for high-performance computing. Sci. Comput. Program. 62 (1), 2546.Google Scholar
Dybvig, R. K. (1992) Writing Hygienic Macros in Scheme with Syntax-Case. Technical Reports TR356. Indiana University Computer Science Department.Google Scholar
Gabbay, J. M. & Pitts, M. A. (2001) A new approach to abstract syntax with variable binding. Formal Asp. Comput. 13 (3), 341363.Google Scholar
Gordon, A. D. (1999) Bisimilarity as a theory of functional programming. Theor. Comput. Sci. 228 (1–2), 547.Google Scholar
Heizmann, M., Jones, N. D. & Podelski, A. (2010) Size-change termination and transition invariants. In Proceedings of Static Analysis - 17th International Symposium (SAS). LNCS, vol. 6337. Springer Berlin Heidelberg, pp. 22–50.Google Scholar
Herrmann, C. A., & Langhammer, T. (2006) Combining partial evaluation and staged interpretation in the implementation of domain-specific languages. Sci. Comput. Program. 62 (1), 4765.Google Scholar
Howe, D. J. (1996) Proving congruence of bisimulation in functional programming languages. Inf. Comput. 124 (2), 103112.Google Scholar
Inoue, J. (2012) Reasoning about Multi-Stage Programs. Ph.D. thesis, Rice University.Google Scholar
Inoue, J. & Taha, W. (2012) Reasoning about multi-stage programs. In Proceedings of the 21st European Symposium on Programming (ESOP). LNCS, vol. 7211. Springer Berlin Heidelberg, pp. 357–376.Google Scholar
Intrigila, B. & Statman, R. (2009) The omega rule is Π1 1-complete in the λβ-calculus. Log. Meth. Comput. Sci. 5 (2), 121.Google Scholar
Jim, T. & Meyer, A. R. (1996) Full abstraction and the context lemma. SIAM J. Comput. 25 (3), 663696.Google Scholar
Kameyama, Y., Kiselyov, O. & Shan, C.-C. (2011) Shifting the stage - staging with delimited control. J. Funct. Program. 21 (6), 617662.Google Scholar
Kameyama, Y., Kiselyov, O. & Shan, C.-C. (2015) Combinators for impure yet hygienic code generation. Sci. Comput. Program. 112 (P2), 120144.CrossRefGoogle Scholar
Kim, Ik-S., Yi, K. & Calcagno, C. (2006) A polymorphic modal type system for LISP-like multi-staged languages. In Proceedings of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). New York, NY, USA: ACM, pp. 257–268.CrossRefGoogle Scholar
Kiselyov, O. & Taha, W. (2005) Relating FFTW and split-radix. In Proceedings of Embedded Software and Systems, First International Conference (ICESS). LNCS, vol. 3605. Springer Berlin Heidelberg, pp. 488–493.Google Scholar
Koutavas, V. & Wand, M. (2006) Small bisimulations for reasoning about higher-order imperative programs. In Proceedings of 2006 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation. New York, NY, USA: ACM, pp. 141152.Google Scholar
Licata, D. R., Zeilberger, N. & Harper, R. (2008) Focusing on binding and computation. In Proceedings of the 2008 23rd Annual IEEE Symposium on Logic in Computer Science. LICS '08. Washington, DC, USA: IEEE Computer Society, pp. 241–252.CrossRefGoogle Scholar
Mason, I. & Talcott, C. (1991) Equivalence in functional languages with effects. J. Funct. Program. 1 (7), 287327.Google Scholar
McCarthy, J. (1963) A basis for a mathematical theory of computation. In Computer Programming and Formal Systems, Braffort, P. & Hirschberg, D. (eds). North-Holland, pp. 3370.CrossRefGoogle Scholar
McCusker, G. (2003) On the semantics of the bad-variable constructor in Algol-like languages. Electron. notes Theor. Comput. Sci. 83, 169186.CrossRefGoogle Scholar
Milner, R. (1977) Fully abstract models of the typed lambda-calculus. Theor. Comput. Sci. 4 (1), 122.Google Scholar
Milner, R. (1989) Communication and Concurrency. Prentice-Hall.Google Scholar
Mitchell, J. C. (1993) On abstraction and the expressive power of programming languages. Sci. Comput. Program. 21 (2), 141163.Google Scholar
Muller, R. (1992) M-LISP: A representation-independent dialect of LISP with reduction semantics. ACM Trans. Program. Lang. Syst. 14 (4), 589616.Google Scholar
Nanevski, A., Pfenning, F. & Pientka, B. (2008) Contextual modal type theory. ACM Trans. Comput. Logic 9 (3), 23:1–23:49.Google Scholar
Plotkin, G. D. (1974) The λ-calculus is ω-incomplete. J. Symb. Logic 39 (2), 313317.Google Scholar
Plotkin, G. D. (1975) Call-by-name, call-by-value and the λ-calculus. Theor. Comput. Sci. 1 (2), 125159.Google Scholar
Pouillard, N. & Pottier, F. (2010) A fresh look at programming with names and binders. In Proceedings of the 15th ACM Sigplan International Conference on Functional Programming. ICFP '10. New York, NY, USA: ACM, pp. 217–228.Google Scholar
Pous, D. & Sangiorgi, D. (2011) Enhancements of the bisimulation proof method. In Advanced Topics in Bisimulation and Coinduction, Sangiorgi, D. & Rutten, J. (eds). Cambridge University Press. Cambridge Books Online, pp. 233289.Google Scholar
Reynolds, J. C. (2002) Separation logic: A logic for shared mutable data structures. In Proceedings of the 17th IEEE Symposium on Logic in Computer Science (LICS). Washington, DC, USA: IEEE Computer Society, pp. 55–74.Google Scholar
Riecke, J. G. & Subrahmanyam, R. (1994) Extensions to type systems can preserve operational equivalences. In Proceedings of Theoretical Aspects of Computer Software (TACS). LNCS, vol. 789. Springer Berlin Heidelberg, pp. 76–95.Google Scholar
Rompf, T. & Odersky, M. (2012) Lightweight modular staging: A pragmatic approach to runtime code generation and compiled DSLs. Commun. ACM 55 (6), 121130.Google Scholar
Sands, D. (1998) Improvement theory and its applications. In Higher Order Operational Techniques in Semantics, Gordon, A. D. & Pitts, A. M. (eds). Cambridge University Press, pp. 275306.Google Scholar
Sangiorgi, D., Kobayashi, N. & Sumii, E. (2011) Environmental bisimulations for higher-order languages. ACM Trans. Program. Lang. Syst. 33 (1), 5:15:69.Google Scholar
Swadi, K., Taha, W., Kiselyov, O. & Pašalić, E. (2006) A monadic approach for avoiding code duplication when staging memoized functions. In Proceedings of Symposium on Partial Evaluation and Semantics-based Program Manipulation (PEPM). New York, NY, USA: ACM, pp. 160–169.Google Scholar
Taha, W. (1999) Multistage Programming: Its Theory and Applications. Ph.D. thesis, Oregon Graduate Institute.Google Scholar
Taha, W. (2008) A gentle introduction to multi-stage programming, part II. In Proceedings of Generative and Transformational Techniques in Software Engineering II. LNCS, vol. 5235. Springer Berlin Heidelberg, pp. 260–290.CrossRefGoogle Scholar
Taha, W. & Nielsen, M. F. (2003) Environment classifiers. In Proceedings of the 30th SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). New York, NY, USA: ACM, pp. 26–37.Google Scholar
Takahashi, M. (1995) Parallel reductions in lambda-calculus. Inf. Comput. 118 (1), 120127.Google Scholar
Tsukada, T. & Igarashi, A. (2010) A logical foundation for environment classifiers. Log. Meth. Comput. Sci. 6 (4), 143.Google Scholar
Westbrook, E., Ricken, M., Inoue, J., Yao, Y., Abdelatif, T. & Taha, W. (2010) Mint: Java multi-stage programming using weak separability. In Proceedings of the 31st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). New York, NY, USA: ACM, pp. 400–411.Google Scholar
Yang, Z. (2000) Reasoning About Code-Generation in Two-Level Languages. Technical Report RS-00-46. BRICS.Google Scholar
Yuse, Y., & Igarashi, A. (2006) A modal type system for multi-level generating extensions with persistent code. In Proceedings of the 8th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP). New York, NY, USA: ACM, pp. 201–212.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.