The Cartesian Product Algorithm
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.
Keywordsconcrete types abstract types type inference polymorphism inheritance Self
Unable to display preview. Download preview PDF.
- 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.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.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.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.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
- 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
- 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.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.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
- 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.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.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
- 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.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.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.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
- 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
- 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