A decision procedure for common Lisp'sSUBTYPEP predicate
- 18 Downloads
Common Lisp , includes a dynamic datatype system of moderate complexity, as well as predicates for checking the types of language objects. Additionally, an interesting predicate of two “type specifiers”—SUBTYPEP—is included in the language. Thissubtypep predicate provides a mechanism with which to query the Common Lisp type system regarding containment relations among the various built-in and user-defined types. Whilesubtypep is rarely needed by an applications programmer, the efficiency of a Common Lisp implementation can depend critically upon the quality of itssubtypep predicate: the run-time system typically calls uponsubtypep to decide what sort of representations to use when making arrays; the compiler calls uponsubtypep to interpret userdeclarations, on which efficient data representation and code generation decisions are based.
As might be expected due to the complexity of the Common Lisp type system, there may be type containment questions which cannot be decided. In these casessubtypep is expected to return “can't determine”, in order to avoid giving an incorrect answer. Unfortunately, most Common Lisp implementations have abused this license by answering “can't determine” in all but the most trivial cases.In particular, most Common Lisp implementations ofSUBTYPEPfail on the basic axioms of the Common Lisp type system itself . This situation is particularly embarrassing for Lisp-the premier “symbol processing language”—in which the implementation of complex symbolic logical operations should be relatively easy. Sincesubtypep was presumably included in Common Lisp to answer thehard cases of type containment, this “lazy evaluation” limits the usefulness of an important language feature.
This paper shows how those type containment relations of Common Lisp which can be decided at all, can be decided simply and quickly by a decision procedure which can dramatically reduce the number of occurrences of the “can't determine” answer fromsubtypep. This decision procedure doesnot require the conversion of a type specifier expression to conjunctive or disjunctive normal form, and therefore does not incur the exponential explosion in space and time that such a conversion would entail.
The lattice mechanism described here for decidingsubtypep is also ideal for performingtype inference ; the particular implementation developed here, however, is specific to the type system of Common Lisp .
Categories and Subject Descriptors: Lisp, dynamic typing, compiler optimization, type inference, decision procedure.
KeywordsDecision Procedure Moderate Complexity Incorrect Answer Disjunctive Normal Form Type Inference
Unable to display preview. Download preview PDF.
- 1.Aho, Alfred V., Sethi, Ravi, and Ullman, Jeffrey D.Compilers: Principles, Techniques, and Tools. Addison-Wesley, 1986.Google Scholar
- 2.Baker, Henry G.The Nimble Type Inferencer for Common Lisp-84. Submitted to ACM Trans. on Prog. Langs. and Systems.Google Scholar
- 3.Bauer, Alan M., and Saal, Harry J.Does APL really need run-time checking?. Software Practice and Experience, v.4, pp. 129–138, 1974.Google Scholar
- 4.Beer, Randall D.The compile-time type inference and type checking of Common Lisp programs: a technical summary. TR 88–116, Ctr. for Automation and Intelligent Sys. Research, Case Western Reserve Univ., May 1988.Google Scholar
- 5.Bobrow, et al.Common Lisp Object System Specification X3J13. ACM SIGPLAN Notices, v.23, Sept. 1988; also Lisp and Symbolic Computation 1, 3–4, 245–394; also X3J13 Document 88-002R, June 1988.Google Scholar
- 6.Borning, Alan H. and Ingalls, Daniel H. H.A Type Declaration and Inference System for Smalltalk. ACM POPL 9, 133–141, 1982.Google Scholar
- 7.Budd, Timothy.An APL Compiler. Springer-Verlag, NY, 1988.Google Scholar
- 8.Church, A.Introduction to Mathematical Logic. Vol. I. Princeton University Press, 1956.Google Scholar
- 9.Ferrante, J., and Rackoff, C.A decision procedure for the first order theory of real addition with order. SIAM J. Comput. 4, 1, 69–76, 1975.Google Scholar
- 10.Ferrante, J. and Geiser, J.An efficient decision procedure for the theory of rational order. Theor. Computer Sci. 4, 2, 227–234, 1977.Google Scholar
- 11.Floating-Point Working Group 754 of the Microprocessor Standards Committee. newblockA Standard for Binary Floating-Point Arithmetic. IEEE, 345 E. 47th St., New York, NY 10017, 1982.Google Scholar
- 12.Hughes, G.E., and Cresswell, M.J.An Introduction to Modal Logic. Methuen and Co., 1968.Google Scholar
- 13.Kaplan, Marc A., and Ullman, Jeffrey D.A Scheme for the Automatic Inference of Variable Types JACM 27,1, 128–145, Jan. 1980.Google Scholar
- 14.Loos, R.Computing in Algebraic Extensions In Buchberger, et al. Computer Algebra: Symbolic and Algebraic Computation, Second Edition. Springer-Verlag, New York, 173–187, 1983.Google Scholar
- 15.Ma, Kwan-Liu, and Kessler, Robert R.TICL-A Type Inference System for Common Lisp SW-Prac.&Exper. 20,6, 593–623, June 1990.Google Scholar
- 16.MacLane, Saunders and Birkhoff, and Garrett.ALGEBRA. Macmillan, 1967.Google Scholar
- 17.McAllester, David, and Zabih, Ramin.Boolean Classes. Proc. '86 OOPSLA, Sigplan Notices 21,11, 417–423, Nov. 1986.Google Scholar
- 18.Milner, Robin.A Theory of Type Polymorphism in Programming. JCSS 17, 348–375, 1978.Google Scholar
- 19.Morris, J.H.Types are Not Sets. ACM POPL, 120–124, 1973.Google Scholar
- 20.Rackoff, C.W.The complexity of theories of the monadic predicate calculus. IRIA Rep. 136, Roquencourt, France, 1975.Google Scholar
- 21.Rees, J. and Clinger, W., et al.Revised Report on the Algorithmic Language Scheme. SIGPLAN Notices 21, 12, 37–79, Dec. 1986.Google Scholar
- 22.Reference Manual for the Ada Programming Language. ANSI/MILSTD-1815A-1983, US GPO, Wash, DC, 1983.Google Scholar
- 23.Scott, D.Data types as lattices. SIAM J. Computing, 5,3, 522–587, Sept. 1976.Google Scholar
- 24.Steele, Guy L., Jr.Rabbit: A Compiler for SCHEME (A Study in Compiler Optimization) AI-TR-474, Artificial Intelligence Laboratory, MIT, May 1978.Google Scholar
- 25.Steele, Guy L., Jr.Common Lisp: The Language. Digital Press, 1984.Google Scholar
- 26.Steele, Guy L., Jr.Common Lisp: The Language, Second Edition. Digital Press, Bedford, MA, 1990.Google Scholar
- 27.Suzuki, Norihisa.Inferring Types in Smalltalk. ACM POPL 8, 187–199, 1981.Google Scholar
- 28.Tarski, A.A Decision Method for Elementary Algebra and Geometry. 2nd ed., Univ. of Cal. Press, Berkeley, 1951.Google Scholar