HN
Today

A Partial Evaluator for C

Tempo, a partial evaluator for C programs, resurfaces as a fascinating artifact from the late 90s, aiming to automate program specialization for performance. This deep dive into its two-phase analysis and specialization process sparks discussion on compiler optimization evolution and C language intricacies. HN is abuzz with both nostalgic appreciation for its ambitious goals and critical examination of its vintage codebase and example quirks.

66
Score
14
Comments
#4
Highest Rank
7h
on Front Page
First Seen
Nov 23, 5:00 AM
Last Seen
Nov 23, 11:00 AM
Rank Over Time
15554457

The Lowdown

Tempo is a partial evaluator for C programs, a tool designed to automatically specialize code by pre-computing parts of a program when some inputs are known in advance. Developed in the late 1990s by researchers at IRISA / INRIA and LABRI, it promises substantial speedups across various domains.

  • What it does: Tempo takes a C program and a description of which inputs will be 'static' (known at specialization time) and which will be 'dynamic' (unknown). It then analyzes the code to propagate this knowledge.
  • Two Phases: The process is offline, involving an 'analysis' phase that uses binding-time, alias, and side-effect analyses to annotate the program. This is followed by a 'specialization' phase that generates a new, optimized program based on the annotated code and the actual values of the known inputs.
  • Specialization Types: Tempo supports both compile-time specialization (source-to-source transformation) and run-time specialization (generating optimized binary code templates on the fly).
  • Applications: It has been successfully applied to operating systems (RPC, IPC, packet filters), networking, computer graphics, scientific computation, and software engineering (DSLs, interpreters).
  • Historical Context: First made publicly available under license in 1998, with an unrestricted binary release in 2000 and a GPL source release promised "soon" at that time. The current download offered is an i386 Linux binary tested on RedHat 6.1.

Tempo represents an early, sophisticated effort in program optimization through automatic specialization, offering a glimpse into advanced compiler techniques from decades past.

The Gossip

Vintage Valor: The Age-Old Application

Many commenters immediately note the project's vintage, highlighted by the provided download being an i386 Linux binary tested on RedHat 6.1. This leads to inquiries about the availability of modern builds, current source code (despite the page's 2000 promise of a GPL release), and discussions about contemporary alternatives like LLPE, a partial evaluator for LLVM bitcode.

Code Conundrums: Critiquing C's Constructs

A significant portion of the discussion centers on a potential bug in the `miniprintf` example code provided in the article. Users meticulously dissect how `*++fmt` within the `switch` statement could lead to an out-of-bounds read if the format string ends with a single '%' or is empty. There's debate on whether `prterror()` would halt execution and if the subsequent `fmt++` would then read past the null terminator, making it a genuine bug or merely an example with undefined behavior.

Compiler's Craft: Current Code Transformations

The thread explores the relationship between partial evaluation and modern compiler optimizations. Some users observe that compilers like GCC now perform many similar optimizations, leading to questions about whether dedicated partial evaluators are still relevant. There's clarification that while compilers do constant folding and propagation, true 'Futamura Projection' style partial evaluation (generating a specialized compiler from an interpreter) is distinct. Discussions also touch on specific tools like C-Mix and LLPE as dedicated partial evaluators.