skip to main content
article
Open Access

Polymorphic specialization for ML

Published:01 July 2004Publication History
Skip Abstract Section

Abstract

We present a framework for offline partial evaluation for call-by-value functional programming languages with an ML-style typing discipline. This includes a binding-time analysis which is (1) polymorphic with respect to binding times; (2) allows the use of polymorphic recursion with respect to binding times; (3) is applicable to a polymorphically typed term; and (4) is proven correct with respect to a novel small-step specialization semantics.The main innovation is to build the analysis on top of the region calculus of Tofte and Talpin [1994], thus leveraging the tools and techniques developed for it. Our approach factorizes the binding-time analysis into region inference and a subsequent constraint analysis. The key insight underlying our framework is to consider binding times as properties of regions.Specialization is specified as a small-step semantics, building on previous work on syntactic-type soundness results for the region calculus. Using similar syntactic proof techniques, we prove soundness of the binding-time analysis with respect to the specializer. In addition, we prove that specialization preserves the call-by-value semantics of the region calculus by showing that the reductions of the specializer are contextual equivalences in the region calculus.

References

  1. Abadi, M., Banerjee, A., Heintze, N., and Riecke, J. 1999. A core calculus of dependency. In Proceedings of the 1999 ACM SIGPLAN Symposium on Principles of Programming Languages (San Antonio, Tex). ACM, New York, 147--160.]] Google ScholarGoogle Scholar
  2. Banerjee, A., Heintze, N., and Riecke, J. 1999. Region analysis and the polymorphic lambda calculus. In proceedings of the 14th Annual Symposium on Logic in Computer Science, LICS'99 (Trento, Italy). IEEE Computer Society Press, Los Alamitos, Calif., 88--97.]] Google ScholarGoogle Scholar
  3. Birkedal, L. and Tofte, M. 2001. A constraint-based region inference algorithm. Theoret. Comput. Sci. 58, 299--392.]] Google ScholarGoogle Scholar
  4. Birkedal, L. and Welinder, M. 1993. Partial evaluation of Standard ML. Rapport 93/22, DIKU, University of Copenhagen.]]Google ScholarGoogle Scholar
  5. Birkedal, L. and Welinder, M. 1994. Binding-time analysis for Standard-ML. In Proceedings of the 1994 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (Orlando, Fla), 61--71. (Technical Report 94/9, Department of Computer Science.)]]Google ScholarGoogle Scholar
  6. Bondorf, A. and Jørgensen, J. 1993. Efficient analyses for realistic off-line partial evaluation. J. Funct. Prog. 3, 3 (July), 315--346.]]Google ScholarGoogle Scholar
  7. Bulyonkov, M. 1993. Extracting polyvariant binding time analysis from polyvariant specializer. In Proceedings of the 1993 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (Copenhagen, Denmark), D. Schmidt, Ed. ACM, New York, 59--65.]] Google ScholarGoogle Scholar
  8. Calcagno, C. 2001. Stratified operational semantics for safety and correctness of the region calculus. In Proceedings of the 2001 ASM SIGPLAN Symposium on Principles of Programming Languages (London, England), H. R. Nielson, Ed. ACM, New York, 155--165.]] Google ScholarGoogle Scholar
  9. Calcagno, C., Helsen, S., and Thiemann, P. 2002. Syntactic type soundness results for the region calculus. Inf. Comput. 173, 2, 199--221.]] Google ScholarGoogle Scholar
  10. Consel, C. 1989. Analyse de programmes, evaluation partielle et génération de compilateurs. Ph.D. dissertation, Université de Paris VI, Paris, France.]]Google ScholarGoogle Scholar
  11. Consel, C. 1990. Binding time analysis for higher order untyped functional languages. In Proceedings of the 1990 ACM Conference on Lisp and Functional Programming (Nice, France). ACM, New York, 264--272.]] Google ScholarGoogle Scholar
  12. Consel, C. 1993a. Polyvariant binding-time analysis for applicative languages. In Proceedings of the 1993 ACM SIGPLAN Workshop on Partial Evalution and Semantics-Based Program Manipulation (Copenhagen, Denmark), D. Schmidt, Ed. ACM, New York, 66--77.]] Google ScholarGoogle Scholar
  13. Consel, C. 1993b. A tour of Schism. In Proceedings of the 1993 ACM SIGPLAN Workshop on Partial Evalution and Semantics-Based Program Manipulation (Copenhagen, Denmark), D. Schmidt, Ed. ACM, New York, 134--154.]] Google ScholarGoogle Scholar
  14. Consel, C. and Danvy, O. 1991. For a better support of static data flow. In Functional Prgramming Languages and Computer Architecture (Cambridge, Mass.), J. Hughes, Ed. Lecture Notes in Computer Science, vol. 523. Springer-Verlag, New York, 496--519.]] Google ScholarGoogle Scholar
  15. Consel, C. and Danvy, O. 1993. Tutorial notes on partial evaluation. In Proceedings of the 1993 ACM SIGPLAN Symposium on Principles of Programming Languages (Charleston, S.C.). ACM, New York, 493--501.]] Google ScholarGoogle Scholar
  16. Consel, C., Jouvelot, P., and Ørbæk, P. 1994. Separate polyvariant binding-time reconstruction. Tech. Rep. CRI-A/261, Ecole des Mines, Paris. Oct.]]Google ScholarGoogle Scholar
  17. Danvy, O., Malmkjær, K., and Palsberg, J. 1995. The essence of eta-expansion in partial evaluation. LISP Symb. Comput. 8, 3 (July), 209--227.]] Google ScholarGoogle Scholar
  18. Danvy, O., Malmkjær, K., and Palsberg, J. 1996. Eta-expansion does The Trick. ACM Trans. Prog. Lang. Syst. 18, 6 (Nov.), 730--751.]] Google ScholarGoogle Scholar
  19. Dussart, D., Heldal, R., and Hughes, J. 1997. Module-sensitive program specialisation. In Proceedings of the 1997 Conference on Programming Language Design and Implementation (Las Vegas, Nev.). ACM, New York, 206--214.]] Google ScholarGoogle Scholar
  20. Dussart, D., Henglein, F., and Mossin, C. 1995. Polymorphic recursion and subtype qualifications: Polymorphic binding-time analysis in polynomial time. In Proceedings of the 1995 International Static Analysis Symposium (Glasgow, Scotland), A. Mycroft, Ed. Lecture Notes in Computer Science, vol. 983, Springer-Verlag, New York, 118--136.]] Google ScholarGoogle Scholar
  21. Gengler, M., and Rytz, B. 1992. A polyvariant binding time analysis handling partially known values. In Proceedings of the 2nd Workshop on Static Analysis. Bigre Journal, vol. 81--82. IRISA, Rennes, France, 322--330.]]Google ScholarGoogle Scholar
  22. Gifford, D. and Lucassen, J. 1986. Integrating functional and imperative programming. In Proceedings of the 1986 ACM Conference on LISP and Functional Programming. ACM, New York, 28--38.]] Google ScholarGoogle Scholar
  23. Glenstrup, A. J. and Jones, N. D. 1996. BTA algorithms to ensure termination of offline partial evaluation. In PSA-96: Andrei Ershov Second International Memorial Conference, Perspectives of System Informatics (Novosibirsk, Russia), Lecture Notes in Computer Science, vol. 1181. Springer-Verlag, New York, 273--284.]] Google ScholarGoogle Scholar
  24. Glynn, K., Stuckey, P., Sulzmann, M., and Søndergaard, H. 2001. Boolean constraints for binding-time analysis. In Programs as Data Objects II (Aarhus, Denmark). Lecture Notes in Computer Science, vol. 2053. Springer-Verlag, New York, 39--62.]] Google ScholarGoogle Scholar
  25. Harper, R. 1994. A simplified account of polymorphic references. Inf. Proc. Lett. 51, 4 (Aug.), 201--206. (See also note {Harper 1996}.)]] Google ScholarGoogle Scholar
  26. Harper, R. 1996. A note on: "A simplified account of polymorphic references". Inf. Proc. Lett. 57, 1 (Jan.), 15--16. (See also {Harper 1994}.)]] Google ScholarGoogle Scholar
  27. Hatcliff, J. and Danvy, O. 1997. A computational formalization for partial evaluation. Math. Struct. Comput. Sci. 7, 5, 507--542.]] Google ScholarGoogle Scholar
  28. Heldal, R. 2001. The treatment of polymorphism and modules in a partial evaluator. Ph.D. dissertation. Chalmers University of Technology.]]Google ScholarGoogle Scholar
  29. Heldal, R. and Hughes, J. 2000. Extending a partial evaluator which supports separate compilation. Theoret. Comput. Sci. 248, 99--145.]] Google ScholarGoogle Scholar
  30. Heldal, R. and Hughes, J. 2001. Binding-time analysis for polymorphic types. In PSI-01: Andrei Ershov Fourth International Conference, Perspectives of System Informatics (Novosibirsk, Russia), Lecture Notes in Computer Science, vol. 2244. Springer-Verlag, New York, 191--204.]] Google ScholarGoogle Scholar
  31. Helsen, S. 2002. Region-based program specialization---An operational approach to polymorphic offline partial evaluation for ML-like languages. Ph.D. dissertation, Unversität Freiburg, Germany. Available from http://www.freidok.uni-freiburg.de/volltexte/538/.]]Google ScholarGoogle Scholar
  32. Helsen, S. 2004. Bisimilarity for the region calculus. Higher-Order and Symbolic Computation. 17, 4.]] Google ScholarGoogle Scholar
  33. Helsen, S. and Thiemann, P. 2000a. Fragmental specialization. In Semantics, Applications and Implementation of Program Generation (SAIG'00) (Montreal, Ont., Canada), W. Taha, Ed. Lecture Notes in Computer Science, vol. 1927. Springer-Verlag, New York, 51--71.]] Google ScholarGoogle Scholar
  34. Helsen, S. and Thiemann, P. 2000b. Syntactic type soundness for the region calculus. In ACM Workshop on Higher Order Operational Techniques in Semantics (HOOTS) (Montreal, Ont., Canada). A. Jeffrey, Ed. Electronic Notes in Theoretical Computer Science, vol. 41(3). Elsevier Science, Amsterdam, The Netherlands 1--20.]]Google ScholarGoogle Scholar
  35. Henglein, F. 1991. Efficient type interference for higher-order binding-time analysis. In Functional Programming Languages and Computer Architecture (Cambridge, Mass.), J. Hughes, Ed. Lecture Notes in Computer Science, vol. 523. Springer-Verlag, New York, 448--472.]] Google ScholarGoogle Scholar
  36. Henglein, F., and Mossin, C. 1994. Polymorphic binding-time analysis. In Proceedings of European Symposium on Programming, D. Sannella, Ed. Lecture Notes in Computer Science, vol. 788. Springer-Verlag, New York 287--301.]] Google ScholarGoogle Scholar
  37. Hornof, L., and Noyè, J. 2000. Accurate binding-time analysis for imperative languages: Flow, context, and return sensitivity. Theoret. Comput. Sci. 248, 1--2 (Oct.), 3--27.]] Google ScholarGoogle Scholar
  38. Jones, N., Gomard, C., and Sestoft, P. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs, N.J.]] Google ScholarGoogle Scholar
  39. Jouvelot, P. and Gifford, D. 1991. Algebraic reconstruction of types and effects. In Proceedings of the 1991 ACM SIGPLAN Symposium on Principles of Programming Languages (Orlando, Florida), ACM New York, 303--310.]] Google ScholarGoogle Scholar
  40. Lassen, S. 1998. Relational reasoning about contexts. In Higher Order Operational Techniques in Semantics (HOOTS), A. Gordon and A. Pitts, Eds. Publications of the Newton Institute. Cambridge University Press, 91--136.]] Google ScholarGoogle Scholar
  41. Launchbury, J. and Holst, C. K. 1991. Handwriting cogen to avoid problems with static typing. In Draft Proceedings, Fourth Annual Glasgow Workshop on Functional Programming. Glasgow University, Skye, Scotland, 210--218.]]Google ScholarGoogle Scholar
  42. Lawall, J. and Thiemann, P. 1997. Sound specialization in the presence of computational effects. In Proceedings of the Theoretical Aspects of Computer Software (Sendai, Japan), Lecture Notes in Computer Science, vol. 1284 Springer-Verlag, New York, 165--190.]] Google ScholarGoogle Scholar
  43. Lee, C. S. 2002a. Finiteness analysis in polynomial time. In Static Analysis: 9th International Symposium, SAS 2002, M. Hermenegildo and G. Puebla, Eds. Lecture Notes in Computer Science, vol. 2477. Springer-Verlag, New York, 493--508.]] Google ScholarGoogle Scholar
  44. Lee, C. S. 2002b. Program termination analysis in polynomial time. In Generative Programming and Component Engineering: ACM SIGPLAN/SIGSOFT Conference, GPCE 2002, D. Batory, C. Consel, and W. Taha, Eds. Lecture Notes in Computer Science, vol. 2487. Springer-Verlag, New York, 218--235.]] Google ScholarGoogle Scholar
  45. Lee, C. S., Jones, N. D., and Ben-Amram, A. M. 2001. The size-change principle for program termination. In Proceedings of the 2001 ACM SIGPLAN Symposium on Principles of Programming Languages (London, England), H. R. Nielson, Ed. ACM New York, 81--92.]] Google ScholarGoogle Scholar
  46. Milner, R. 1978. A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17, 348--375.]]Google ScholarGoogle Scholar
  47. Milner, R., Tofte, M., Harper, R., and MacQueen, D. 1997. The Definition of Standard ML (Revised). MIT Press, Cambridge, Mass.]] Google ScholarGoogle Scholar
  48. Mogensen, T. 1989. Binding time analysis for polymorphically typed higher order languages. In TAPSOFT '89 (Barcelona, Spain), J. Díaz and F. Orejas, Eds. Lecture Notes in Computer Science, vol. 351 and 352. Springer-Verlag, New York, 298--312.]] Google ScholarGoogle Scholar
  49. Moggi, E. 1991. Notions of computations and monads. Inf. Comput. 93, 55--92.]] Google ScholarGoogle Scholar
  50. Morris, J. 1968. Lambda calculus models of programming languages. Ph.D. dissertation. MIT Press, Cambridge, Mass.]]Google ScholarGoogle Scholar
  51. Nielson, F., and Nielson, H. R. 1988. Automatic binding-time analysis for a typed lambda calculus. Sci. Comput. Prog. 10, 139--176.]] Google ScholarGoogle Scholar
  52. Nielson, F. and Nielson, H. R. 1992. Two-Level Functional Languages. Cambridge Tracts in Theoretical Computer Science, vol. 34. Cambridge University Press, Cambridge, Mass.]] Google ScholarGoogle Scholar
  53. Odersky, M., Sulzmann, M., and Wehr, M. 1999. Type inference with constrained types. Theory Pract. Obj. Syst. 5, 1, 35--55.]] Google ScholarGoogle Scholar
  54. Plotkin, G. 1975. Call-by-name, call-by-value and the λ-calculus. Theoret. Comput. Sci. 1, 125--159.]]Google ScholarGoogle Scholar
  55. Plotkin, G. 1981. A structural approach to operational semantics. Tech. Rep. DAIMI FN-19. Aarhus University, Denmark.]]Google ScholarGoogle Scholar
  56. Rytz, B. and Gengler, M. 1992. A polyvariant binding time analysis. In Proceedings of the 1992 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, C. Consel, Ed. Yale University, San Francisco, CA, 21--28. Report YALEU/DCS/RR-909.]]Google ScholarGoogle Scholar
  57. Talpin, J.-P. and Jouvelot, P. 1992. Polymorphic type, region and effect inference. J. Funct. Prog. 2, 3 (July), 245--272.]]Google ScholarGoogle Scholar
  58. Thiemann, P. 1996. Implementing memoization for partial evaluation. In International Symposium on Programming Languages, Implementations, Logics and Programs (PLILP '96) (Aachen, Germany), H. Kuchen and D. Swierstra, Eds. Lecture Notes in Computer Science, vol. 1140. Springer-Verlag, New York, 198--212.]] Google ScholarGoogle Scholar
  59. Thiemann, P. 1997a. Correctness of a region-based binding-time analysis. In Proceedings of the 1997 Conference on Mathematical Foundations of Programming Semantics. Electronic Notes in Theoretical Computer Science, vol. 6. Carnegie Mellon University, Pittsburgh, Pa. Elsevier Science, BV, Amsterdam, The Netherlands. URL: http://www.elsevier.nl/ locate/entcs/volume6.html.]]Google ScholarGoogle Scholar
  60. Thiemann, P. 1997b. A unified framework for binding-time analysis. In TAPSOFT '97: Theory and Practice of Software Development, M. Bidoit and M. Dauchet, Eds. Number 1214 in Lecture Notes in Computer Science. Springer-Verlag, Lille, France, 742--756.]] Google ScholarGoogle Scholar
  61. Thiemann, P. 1998. A generic framework for specialization. In Proceedings of the 7th European Symposium on Programming (Lisbon, Portugal), C. Hankin, Ed. Lecture Notes in Computer Science, vol 1381. Springer-Verlag, New York, 267--281.]] Google ScholarGoogle Scholar
  62. Thiemann, P. 1999a. Combinators for program generation. J. Funct. Prog. 9, 5 (Sept.), 483--525.]] Google ScholarGoogle Scholar
  63. Thiemann, P. 1999b. Interpreting specialization in type theory. In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation PEPM '99 (San Antonio, Tex.), O. Danvy, Ed. ACM, New York, 30--43. BRICS Notes Series NS-99-1.]]Google ScholarGoogle Scholar
  64. Thiemann, P. 2000. The PGG System--User Manual. Universität Freiburg, Freiburg, Germany. Available from http://www.informatik.uni-freiburg.de/proglang/software/pgg/.]]Google ScholarGoogle Scholar
  65. Thiemann, P. 2001. Enforcing safety properties using type specialization. In Proceedings of the 2001 European Symposium on Programming (Genova,Italy), D. Sands, Ed. Lecture Notes in Computer Science. Springer-Verlag, New York.]] Google ScholarGoogle Scholar
  66. Thiemann, P. 2002. A prototype dependency calculus. In Proceedings of the 11th European Symposium on Programming (Grenoble, France), D. L. Metayèr, Ed. Lecture Notes in Computer Science, vol. 2305. Springer-Verlag, New York, 228--242.]] Google ScholarGoogle Scholar
  67. Thiemann, P. and Dussart, D. 1997. Partial evaluation for higher-order languages with state. Berichte des Wilhelm-Schickard-Instituts WSI-97-XX, Universität Tübingen. Apr.]]Google ScholarGoogle Scholar
  68. Tofte, M. and Birkedal, L. 1998. A region inference algorithm. ACM Trans. Prog. Lang. Syst. 20, 5, 724--767.]] Google ScholarGoogle Scholar
  69. Tofte, M. and Birkedal, L. 2000. Unification and polymorphism in region inference. In Proof, Language, and Interaction: Essays in Honour of Robin Milner. MIT Press, Cambridge Mass.]] Google ScholarGoogle Scholar
  70. Tofte, M., Birkedal, L., Elsman, M., Hallenberg, N., Olensen, T., and Sestoft, P. 2001. Programming with Regions in the ML Kit, Version 4.0.0. Available from http://www.it.edu/research/ mlkit/dist/mlkit-4.0.0.pdf.]]Google ScholarGoogle Scholar
  71. Tofte, M. and Talpin, J.-P. 1994. Implementation of the typed call-by-value λ-calculus using a stack of regions. In Proceedings of the 1994 ACM SIGPLAN Symposium on Principles of Programming Languages (Portland, Ore). ACM, New York, 188--201.]] Google ScholarGoogle Scholar
  72. Tofte, M. and Talpin, J.-P. 1997. Region-based memory management. Inf. Comput. 132, 2, 109--176.]] Google ScholarGoogle Scholar
  73. Wright, A. and Felleisen, M. 1994. A syntactic approach to type soundness. Inf. Comput. 115, 1, 38--94.]] Google ScholarGoogle Scholar

Index Terms

  1. Polymorphic specialization for ML

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM Transactions on Programming Languages and Systems
              ACM Transactions on Programming Languages and Systems  Volume 26, Issue 4
              July 2004
              157 pages
              ISSN:0164-0925
              EISSN:1558-4593
              DOI:10.1145/1011508
              Issue’s Table of Contents

              Copyright © 2004 ACM

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 1 July 2004
              Published in toplas Volume 26, Issue 4

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader