Abstract
AbstractWe 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.
Highlights
Multi-stage programming (MSP) allows programmers to write generic code without sacrificing performance
Few formal studies have considered verifying generators written with MSP, and MSP research has predominantly focused on applications that confirm performance benefits and on type systems (Taha & Nielsen, 2003; Kim et al, 2006; Yuse & Igarashi, 2006; Tsukada & Igarashi, 2010; Westbrook et al, 2010; Kameyama et al, 2011)
In general, do we prove equivalences of the form e ≈ t? It is known that hygienic, purely functional MSP satisfies intensional equalities like β (Taha, 1999), but those equalities are too weak to prove such properties as extensionality
Summary
Multi-stage programming (MSP) allows programmers to write generic code without sacrificing performance. Tagless final encodings (Carette et al, 2009), and the lightweight modular staging framework (Rompf & Odersky, 2012) inspired by that technique, give a different approach to metaprogramming than MetaOCaml-style MSP They offer data types that represent code, like bracketed expressions do in MetaOCaml, but can be interpreted by any semantics of the user’s choosing. The semantics may evaluate the code, print the code, or perform a post-generation-pass optimization and emit some intermediate representation These frameworks are not limited to staging (separating a program into multiple execution phases, or stages) but rather support general-purpose metaprogramming (writing programs that manipulate other programs in arbitrary ways). Our approach may still be relevant when the machinery is used for staging
Talk to us
Join us for a 30 min session where you can share your feedback and ask us any queries you have
Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.