Andrew W. Keep and R. Kent Dybvig. Enabling cross-library optimization and compile-time error checking in the presence of procedural macros. Proceedings of the 2010 Workshop on Scheme and Functional Programming, 66-76, August 2010
Libraries and top-level programs are the basic units of portable code in the language defined by the Revised6 Report on Scheme. As such, they are naturally treated as compilation units, with source optimization and certain forms of compile-time error checking oc- curring within but not across library and program boundaries. This paper describes a library-group form that can be used to turn a group of libraries and optionally a top-level program into a single compilation unit, allowing whole programs to be constructed from groups of independent pieces and enabling cross-library optimiza- tion and compile-time error checking. The paper also describes the implementation, which is challenging partly because of the need to support the use of one library's run-time exports when another li- brary in the same group is compiled. The implementation does so without expanding any library in the group more than once, since doing so is expensive in some cases and, more importantly, se- mantically unsound in general. While described in the context of Scheme, the techniques presented in this paper are applicable to any language that supports both procedural macros and libraries, and might be adaptable to dependently typed languages or tem- plate meta-programming languages that provide full compile-time access to the source language.