Visualizing partial evaluation

syntax records manipulated by the partial evaluator contain source file and position information collected by the lexical analyzer and maintained during parsing and expansion of syntactic extensions [Dybvig et al. 1993]. Transformations within the partial evaluator and all subsequent compiler passes preserve this source file information. Because source information is contained within abstract-syntax records, that information is automatically preserved when code is replicated during specialization. Other transformations may collapse an abstract-syntax tree into a single node in the residual program. In such cases we select an appropriate source annotation for the residual code from among the source annotations in the input expression. For example, the residual form produced via copy propagation is annotated with the source information from the variable reference it replaces. Similarly, the residual form produced by constant folding is annotated with the source information from the primitive application it replaces. The viewer displays the source program and a pretty-printed form of the residual program in separate windows. To facilitate pretty-printing, the residual program is first converted to list structure. To enhance readability of the residual program, the conversion process reverses the expansion of common syntactic extensions, e.g., let, and, and or. Directives embedded within the resulting list structure cause the pretty-printer to correlate the current output position with the source information contained in the abstract-syntax record. When pretty-printing is complete, we have constructed tables that correlate the position of each source program expression with the positions of zero or more residual program expressions and the position of each residual program expression with the position of at most one source program expression. These tables are consulted when the user selects an expression in the source or residual program window and the corresponding expressions, if any, are marked in both windows as shown in Figure 1. The partial evaluator can be instantiated with different functions for annotating Visualizing Partial Evaluation · 3 Fig. 1. The user has instructed the viewer to display calls where constant folding took place with a light gray background. The user has also selected a let expression in the residual program and the viewer has displayed the corresponding source and residual program expressions in boldface. residual code with source information. For production use, residual code is annotated as described earlier. An alternative instantiation records additional details such as the transformation that produced each residual form. The viewer supports both forms of source annotation and uses the additional information, if available, to enrich the display. For example, the viewer may use the additional information to mark points in the source program where procedures were inlined. Another instantiation of the partial evaluator is configured to trigger a data breakpoint when processing selected input forms. These breakpoints can be set or cleared by selecting expressions in the source file viewer. An implementor can use this feature to examine the processing of a particular source expression in detail.