The Cartesian Product Algorithm

Simple and Precise Type Inference of Parametric Polymorphism
  • Ole Agesen
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 952)

Abstract

Concrete types and abstract types are different and serve different purposes. Concrete types, the focus of this paper, are essential to support compilation, application delivery, and debugging in object-oriented environments. Concrete types should not be obtained from explicit type declarations because their presence limits polymorphism unacceptably. This leaves us with type inference. Unfortunately, while polymorphism demands the use of type inference, it has also been the hardest challenge for type inference.

We review previous type inference algorithms that analyze code with parametric polymorphism and then present a new one: the cartesian product algorithm. It improves precision and efficiency over previous algorithms and deals directly with inheritance, rather than relying on a preprocessor to expand it away. Last, but not least, it is conceptually simple.

The cartesian product algorithm has been used in the Self system since late 1993. We present measurements to document its performance and compare it against several previous algorithms.

Keywords

concrete types abstract types type inference polymorphism inheritance Self 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Agesen, O., Constraint-Based Type Inference and Parametric Polymorphism. In SAS’94, First International Static Analysis Symposium, p. 78–100, Namur, Belgium, Sept. 1994. Springer-Verlag, LNCS 864.Google Scholar
  2. 2.
    Agesen, O., L. Bak, C. Chambers, B.W. Chang, U. Hölzle, I. Maloney, R.B. Smith, D. Ungar, M. Wolczko. How to use Self 3.0 & The Self 3.0 Programmer’s Reference Manual. 1993. Sun Microsystems Laboratories, 2550 Garcia Avenue, Mountain View, CA 94043, USA. Available by anon. ftp from self.stanford.edu or www: http://self.stanford.edu/.
  3. 3.
    Agesen, O., J. Palsberg, and M.I. Schwartzbach, Type Inference of Self: Analysis of Objects with Dynamic and Multiple Inheritance. In ECOOP’93, Seventh European Conference on Object-Oriented Programming, p. 247–267, Kaiserslautern, Germany, July 1993. Springer-Verlag, LNCS 707.Google Scholar
  4. 4.
    Agesen, O. and D. Ungar, Sifting Out the Gold: Delivering Compact Applications from an Exploratory Object-Oriented Programming Environment. In OOPSLA’ 94, Object-Oriented Programming Systems, Languages and Applications, p. 355–370, Portland, Oregon, Oct. 1994.Google Scholar
  5. 5.
    Bobrow, D.G., K. Kahn, G. Kiczales, L. Masinter, M. Stefik, and F. Zdybel, Common-Loops: Merging Lisp and Object-Oriented Programming. In OOPSLA’ 86 Object-Oriented Programming Systems, Languages and Applications, p. 17–29, Portland, Oregon, Sept. 1986.Google Scholar
  6. 6.
    Chambers, C., Object-Oriented Multi-Methods in Cecil. In ECOOP’92, Sixth European Conference on Object-Oriented Programming, p. 33–56, June 1992, Utrecht, The Netherlands. Springer-Verlag, LNCS 615.CrossRefGoogle Scholar
  7. 7.
    Chambers, C., D. Ungar, Making Pure Object-Oriented Languages Practical. In OOPSLA’ 91, Sixth Annual Conference on Object-Oriented Programming Systems, Languages and Applications, p. 1–15, Phoenix, Arizona, Oct. 1991.Google Scholar
  8. 8.
    Chambers, C., D. Ungar, and E. Lee, An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes. Lisp and Symbolic Computation 4(3), p. 243–281, Kluwer Academic Publishers, June 1991. (Originally published in Proc. OOPSLA’89).CrossRefGoogle Scholar
  9. 9.
    Cousot, P. and R. Cousot, Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints. In Conference Record of the Fourth ACM Symposium on Principles of Programming Languages, p. 238–252, Jan. 1977.Google Scholar
  10. 10.
    Graver, J.O., Type-Checking and Type-Inference for Object-Oriented Programming Languages, Ph.D. thesis, University of Illinois at Urbana-Champaign, 1989.Google Scholar
  11. 11.
    Graver, J.O. and R.E. Johnson, A Type System for Smalltalk. In Conference Record of the Seventeenth Annual ACM Symposium on Principles of Programming Languages, p. 136–150, San Francisco, California, Jan. 1990.Google Scholar
  12. 12.
    Hunt, J.W. and T.G. Szymanski, A Fast Algorithm for Computing Longest Common Subsequences, Communications of the ACM, 20(5), p. 350–353, May 1977.MATHCrossRefMathSciNetGoogle Scholar
  13. 13.
    Hölzle, U., Why Static Typing is not Important for Efficiency. In: J. Palsberg & M.I. Schwartzbach (eds.) Types, Inheritance, and Assignment, Technical Report, Daimi PB-357, Computer Science Department, Aarhus University, Denmark, June 1991.Google Scholar
  14. 14.
    Hölzle, U. and D. Ungar, Optimizing Dynamically-Dispatched Calls with Run-time Type Feedback. In PLDI’94, Conference on Programming Language Design and Implementation, p. 326–336, Orlando, Florida, June 1994.Google Scholar
  15. 15.
    Johnson, R.E., Type-Checking Smalltalk. In OOPSLA’86 Object-Oriented Programming Systems, Languages and Applications, p. 315–321, Portland, Oregon, Sept. 1986.Google Scholar
  16. 16.
    Milner, R., A Theory of Type Polymorphism in Programming. Journal of Computer and System Sciences, 17, p. 348–375, 1978.MATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    Oxhøj, N., J. Palsberg, and M.I. Schwartzbach, Making Type Inference Practical. In ECOOP’92, Sixth European Conference on Object-Oriented Programming, p. 329–349, Utrecht, The Netherlands, June 1992, Springer-Verlag, LNCS 615.CrossRefGoogle Scholar
  18. 18.
    Palsberg, J. and M.I. Schwartzbach, Object-Oriented Type Inference. In OOPSLA’91 Object-Oriented Programming Systems, Languages and Applications, p. 146–161, Phoenix, Arizona, Oct. 1991.Google Scholar
  19. 19.
    Phillips, G. and T. Shepard, Static Typing Without Explicit Types. Technical Report, Dept. of Electrical and Computer Engineering, Royal Military College of Canada, Kingston, Ontario, Canada, 1994.Google Scholar
  20. 20.
    Plevyak, J. and A.A. Chien, Precise Concrete Type Inference for Object-Oriented Languages. In OOPSLA’ 94, Object-Oriented Programming Systems, Languages and Applications, p. 324–340, Portland, Oregon, Oct. 1994.Google Scholar
  21. 21.
    Plevyak, J., X. Zhang, and A.A. Chien, Obtaining Sequential Efficiency in Concurrent Object-Oriented Programs. In Conference Record of the 22nd Symposium on Principles of Programming Languages, p. 311–321, San Francisco, California, Jan. 1995Google Scholar
  22. 22.
    Sanella, M., J. Maloney, B. Freeman-Benson, A. Borning, Multi-way versus One-way Constraints in User Interfaces: Experience with the DeltaBlue Algorithm. Software — Practice and Experience, 23(5), p. 529–566, May 1993.CrossRefGoogle Scholar
  23. 23.
    Suzuki, N., Inferring Types in Smalltalk, In Conference Record of the Eighth Annual ACM Symposium on Principles of Programming Languages, p. 187–199, Williamsburg, Virginia, Jan. 1981.Google Scholar
  24. 24.
    Ungar, D. and R.B. Smith, SELF: The Power of Simplicity. Lisp and Symbolic Computing, 4(3), p. 187–205, Kluwer Academic Publishers, June 1991. (Originally published in Proc. OOPSLA’87).CrossRefGoogle Scholar
  25. 25.
    Vitek, J., N. Horspool, and J.S. Uhl, Compile-Time Analysis of Object-Oriented Programs. In Compiler Construction 4th International Conference, CC’92, p. 236–250, Paderborn, Germany, Oct. 1992, Springer-Verlag LNCS 641.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1995

Authors and Affiliations

  • Ole Agesen
    • 1
  1. 1.Computer Science DepartmentStanford UniversityStanford

Personalised recommendations