Skip to main content
Log in

A Hybrid Approach to Online and Offline Partial Evaluation

  • Published:
Higher-Order and Symbolic Computation

Abstract

This article presents a hybrid method of partial evaluation (PE), which is exactly as precise as naive online PE and nearly as efficient as state-of-the-art offline PE, for a statically typed call-by-value functional language.

PE is a program transformation that specializes a program with respect to a subset of its input by reducing the program and leaving a residual program. Online PE makes the reduction/residualization decision during specialization, while offline PE makes it before specialization by using a static analysis called binding-time analysis. Compared to offline PE, online PE is more precise in the sense that it finds more redexes, but less efficient in the sense that it takes more time.

To solve this dilemma, we begin with a naive online partial evaluator, and make it efficient without sacrificing its precision. To this end, we (1) use state (instead of continuations) for let-insertion, (2) take a so-called cogen approach (instead of self-application), and (3) remove unnecessary let-insertion, unnecessary tags, and unnecessary values/expressions by using a type-based representation analysis, which subsumes various monovariant binding-time analyses.

We implemented and compared our method and existing methods—both online and offline—in a subset of Standard ML. Experiments showed that (1) our method produces as fast residual programs as online PE and (2) it does so at least twice as fast as other methods (including a cogen approach to offline PE with a polyvariant binding-time analysis) that produce comparable residual programs.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Appel, A.W. Compiling with Continuations. Cambridge University Press, Cambridge, UK, 1992.

    Google Scholar 

  2. Appel, A.W. and Shao, Z. An empirical and analytic study of stack vs. heap cost for languages with closures. Journal of Functional Programming, 6(1) (1996) 47–74.

    Google Scholar 

  3. Asai, K. Binding-time analysis for both static and dynamic expressions. In Static Analysis Symposium. Lecture Notes in Computer Science, Vol. 1694, 1999, pp. 117–133.

  4. Ashley, J.M. The effectiveness of flow analysis for inlining. In Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming, 1997, pp. 99–111.

  5. Berger, U. and Schwichtenberg, H. An inverse of the evaluation functional for typed lambda-calculus. In Sixth Annual IEEE Symposium on Logic in Computer Science, 1991, pp. 203–211.

  6. Birkedal, L. and Harper, R. Relational interpretations of recursive types in an operational setting. Information and Computation, 155(1/2) (1999) 3–63.

    Google Scholar 

  7. Birkedal, L. and Welinder, M. Partial evaluation of standard ML. Master's Thesis, Department of Computer Science, University of Copenhagen, 1993. Available at http://www.cs.cmu.edu/afs/cs/user/birkedal/pub/smlmix.ps.gz.

  8. Bondorf, A. Self-applicable partial evaluation. Technical Report 90/17, Department of Computer Science, University of Copenhagen, 1990. Ph.D. Thesis (Revised Version).

  9. Bondorf, A. Improving binding times without explicit CPS-conversion. In Proceedings of the Conference on LISP and Functional Programming, 1992, pp. 1–10.

  10. Bondorf, A. and Danvy, O. Automatic autoprojection of recursive equations with global variables and abstract data types. Science of Computer Programming, 16(2) (1991) 151–195.

    Google Scholar 

  11. Cartwright, R. and Fagan, M. Soft typing. In Proceedings of the ACM SIGPLAN '91 Conference on Programming Language Design and Implementation, 1991, pp. 278–292. In ACM SIGPLAN Notices, 26(6) (1991).

  12. Consel, C. Polyvariant binding-time analysis for applicative languages. In Proceedings of the ACMSIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, 1993, pp. 66–77.

  13. Consel, C. and Danvy, O. Tutorial notes on partial evaluation. In Proceedings of the 20th ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, 1993, pp. 493–501.

  14. Danvy, O. Type-directed partial evaluation. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1996, pp. 242–257.

  15. Danvy, O. Online type-directed partial evaluation. Technical Report RS–97–53, Basic research in computer science. Available at http://www.brics.dk/RS/97/53/. Extended version of an article that appeared in Proceedings of the Third Fuji International Symposium on Functional and Logic Programming. Masahiko Sato and Yoshihito Toyama (Eds.). World Scientific, 1998.

  16. Danvy, O. Type-directed partial evaluation. In Partial Evaluation-Practice and Theory. Lecture Notes in Computer Science, Vol. 1706, 1999, pp. 367–411.

    Google Scholar 

  17. Danvy, O. and Filinski, A. A functional abstraction of typed contexts. Technical Report 89/12, Institute of Datalogy, University of Copenhagen, 1989.

  18. Danvy, O. and Filinski, A. Abstracting control. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming, 1990, pp. 151–160.

  19. Filinski, A. Representing monads. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1994, pp. 446–457.

  20. Filinski, A. Controlling effects. Ph.D. Thesis, School of Computer Science, Carnegie Mellon University, 1996. Available at http://www.brics.dk/~andrzej/papers/CE.ps.gz.

  21. Filinski, A. Normalization by evaluation for the computational lambda-calculus. In Typed Lambda Calculi and Applications, 5th International Conference, TLCA 2001, Lecture Notes in Computer Science, Vol. 2044, 2001, pp. 151–165.

    Google Scholar 

  22. Futamura, Y. Partial evaluation of computation process-an approach to a compiler-compiler. Systems, Computers, Controls, 2(5) (1971) 45–50. Reprinted in Higher-Order and Symbolic Computation, 12(4) (1999) 381–391.

    Google Scholar 

  23. Hatcliff, J. and Danvy, O. A computational formalization for partial evaluation (extended version). Technical Report RS–96–34, Basic Research in Computer Science, 1996. Available at http://www.brics.dk/RS/96/34/. Extended version of an article that appeared in Mathematical Structures in Computer Science, 7(5) (1997) 507–541.

    Google Scholar 

  24. Henglein, F. Efficient type inference for higher-order binding-time analysis. In Proceedings of the Fifth International Conference on Functional Programming Languages and Computer Architecture. Lecture Notes in Computer Science, Vol. 523, 1991, pp. 448–472.

    Google Scholar 

  25. Henglein, F. and Mossin, C. Polymorphic binding-time analysis. In 5th European Symposium on Programming, Lecture Notes in Computer Science, Vol. 788, 1994, pp. 287–301.

    Google Scholar 

  26. Jones, N.D., Gomard, C.K., Bondorf, A., Danvy, O., and Mogensen, T.Æ . A self-applicable partial evaluator for the lambda calculus. In 1990 International Conference on Computer Languages, 1990, pp. 49–58.

  27. Jones, N.D., Gomard, C.K., and Sestoft, P. Partial Evaluation and Automatic Program Generation. Prentice Hall, 1993.

  28. Kobayashi, N. Type-based useless variable elimination. Technical Report, Department of Information Science, Faculty of Science, University of Tokyo, 1999. Available at http://www.yl.is.s.u-tokyo.ac.jp/members/koba/pub/UVE-full.ps.gz. A summary appeared in Proceedings of the 2000 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation.

  29. Launchbury, J. A Strongly-typed self-applicable partial evaluator. In Proceedings of the Fifth International Conference on Functional Programming Languages and Computer Architecture, 1991, pp. 145–164.

  30. Lawall, J.L. and Danvy, O. Continuation-based partial evaluation. In Proceedings of the 1994 ACM Conference on LISP and Functional Programming, ACM SIGPLAN Lisp Pointers, Vol. VII, 1994, pp. 227–238.

    Google Scholar 

  31. Lawall, J. and Thiemann, P. Sound specialization in the presence of computational effects. In Theoretical Aspects of Computer Software. Lecture Notes in Computer Science, Vol. 1281, 1997, pp. 165–190.

    Google Scholar 

  32. Milner, R. The polyadic π-calculus: A tutorial. In Logic and Algebra of Specification. F.L. Bauer, W. Brauer, and H. Schwichtenberg (Eds.). Springer-Verlag, 1993. Available at http://www.dcs.ed.ac.uk/home/lfcsreps/EXPORT/91/ECS-LFCS–91–180/.

  33. Moggi, E. Notions of computation and monads. Information and Computation, 93(1) (1991) 55–92.

    Google Scholar 

  34. Pfenning, F. and Elliott, C. Higher-order abstract syntax. In Proceedings of the ACM SIGPLAN '88 Conference on Programming Language Design and Implementation, 1988, pp. 199–208.

  35. Ruf, E. Topics in online partial evaluation. Ph.D. Thesis, Stanford University, 1993. Available at http://research.microsoft.com/~daniel/fuse-memos/FUSE-MEMO–93–14.ps.

  36. Sperber, M. Self-applicable online partial evaluation. In Partial Evaluation. Lecture Notes in Computer Science, Vol. 1110, 1996, pp. 465–480.

    Google Scholar 

  37. Sumii, E. and Kobayashi, N. Online type-directed partial evaluation for dynamically-typed languages. Computer Software, 17(3) (2000) 38–62.

    Google Scholar 

  38. Talpin, J.-P. and Jouvelot, P. The type and effect discipline. Information and Computation, 111(2) (1994) 245–296.

    Google Scholar 

  39. Thiemann, P. Combinators for program generation. Journal of Functional Programming, 9(5) (1999) 483–525.

    Google Scholar 

  40. Thiemann, P. and Dussart, D. Partial evaluation for higher-order languages with state, 1997. Available at http://www.informatik.uni-freiburg.de/~thiemann/papers/mlpe.ps.gz.

  41. Turner, D.N., Wadler, P., and Mossin, C. Once upon a type. In Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, 1995, pp. 1–11.

  42. Wadler, P. Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science, 73(2) (1990) 231–248.

    Google Scholar 

  43. Yang, Z. Encoding types in ML-like languages. In Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming, 1998, pp. 289–300.

Download references

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

About this article

Cite this article

Sumii, E., Kobayashi, N. A Hybrid Approach to Online and Offline Partial Evaluation. Higher-Order and Symbolic Computation 14, 101–142 (2001). https://doi.org/10.1023/A:1012984529382

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1023/A:1012984529382

Navigation