Partial Evaluation and Residual Programs

Specialize a program on known inputs and identify which work and effects must remain in the residual program.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Separate values known now from values supplied later
  2. Preserve the stage at which behavior is visible

Separate values known now from values supplied later

Suppose a general polynomial evaluator receives coefficients and a number \(x\). When coefficients are known but \(x\) is not, specialization can produce a residual expression in \(x\). For coefficients \(2,3,4\), Horner’s rule produces \((2x+3)x+4\). There is no need at runtime to loop over this already-fixed coefficient list. The residual program still performs arithmetic involving its unknown input.

Preserve the stage at which behavior is visible

Moving an effect from runtime to specialization can alter how many times it happens and who observes it. A specializer also needs to avoid unbounded unfolding on recursive calls. Treating an expression as static requires a justification about both data availability and its evaluation. Constant propagation simplifies known values inside ordinary compilation. Advanced partial evaluation relates binding times to staged languages and compiler generation.[1]

References

  1. Neil D. Jones, Carsten K. Gomard and Peter Sestoft, Partial Evaluation and Automatic Program Generation ↩