Active libraries and universal languages

  • Authors:
  • Andrew L. Lumsdaine;Todd L. Veldhuizen

  • Affiliations:
  • -;-

  • Venue:
  • Active libraries and universal languages
  • Year:
  • 2004

Quantified Score

Hi-index 0.02

Visualization

Abstract

Universal programming languages are an old dream. There is the computability sense of Turing-universal; Landin and others have advocated syntactically universal languages, a path leading to extensible syntax, e.g., macros. A stronger kind of universality would reduce the need for domain-specific languages—they could be replaced by ‘active libraries’ providing and safety requirements. Experience suggests that much domain-specific optimization can be realized by staging, i.e., doing computations at compile time to produce an efficient run-time. Rudimentary computability arguments show that languages with a ‘Turing-complete kernel’ can be both stage-universal and safety-universal. But making this approach practical requires compilers that find optimal programs, and this is a hard problem. Guaranteed Optimization is a proof technique for constructing compilers that find optimal programs within a decidable approximation of program equivalence. This gives us compilers whose kernels possess intuitive closure properties akin to, but stronger than, languages with explicit staging, and can meet the ‘Turing-complete kernel’ requirement to be stage- and safety-universal. To show this technique is practical we demonstrate a prototype compiler that finds optimal programs in the presence of heap operations; the proof of this is tedious but automated. The proof ensures that any code ‘lying in the kernel’ is evaluated and erased at compile-time. This opens several interesting directions for active libraries. One is staging: we can synthesize fast implementation code at compile-time by putting code-generators in the kernel. To achieve domain-specific safety checking we propose ‘proof embeddings’ in which proofs are intermingled with code and the optimizer does double-duty as a theorem prover. Proofs lying in the kernel are checked and erased at compile-time, yielding code that is both fast and safe.