Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/567532.567553acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
Article
Free access

Inferring types in Smalltalk

Published: 26 January 1981 Publication History

Abstract

Smalltalk is an object-oriented language designed and implemented by the Learning Research (Group of the Xerox Palo Alto Research Center [2, 5, 14]. Some features of this language are: abstract data classes, information inheritance by a superclass-subclass mechanism, message passing semantics, extremely late binding no type declarations, and automatic storage management. Experience has shown that large complex systems can be written in Smalltalk in quite a short period of time; it is also used to teach programming to children quite effectively. Object-oriented languages like Smalltalk have begun to be accepted as friendly languages for novice programmers on personal computers.
However, Smalltalk has some drawbacks, too. Smalltalk programs are inefficient compared with Lisp or Pascal Late binding is a major reason of this inefficiency; every time a procedure is called, its implementation in the current context has to be found.
Because of late binding, whether there is an implementation of a procedure call or not can only be found at run-time. This may be convenient in the early stages of system development; one can run a partially completed system, and when he discovers a run-time error caused by an unimplemented procedure, he can write the procedure body and proceed the computation from the point where the error was discovered. However, there is no way to guarantee that there will be no run-time errors. We found many "completed" systems which still had such run-time errors.
Another problem is that it is hard for a novice to read Smalltalk programs written by other people. The fact that there are no type declarations and the fact that the bindings are late are major causes of unreadability. All the Smalltalk procedures are so called generic procedures. Each procedure name is associated with several procedure bodies declared in different classes. Depending on the classes of the arguments of a procedure call different procedure bodies are invoked. Since the classes of the arguments may differ according to the context, it is impossible to statically predict the behavior of the procedure calls.
We observed that both inefficiency and unreadability are attributed to late binding; however, early binding can be effectively accomplished if we can tell the classes of the procedure arguments at compile time. In the long run probably Smalltalk needs to have "type" declarations---probably not rigid declarations of Pascal but rather in the form of hints to compilers and programmers. Even without changing the language it would be nice to have a tool that supplies "type" declarations to current Smalltalk or partially specified Smalltalk. This will also lead to efficient compilation.
We thus concluded that we need to introduce "types" to Smalltalk. The introduction of types is more promising in Smalltalk than in similarly declarationless language Lisp, since Smalltalk has a rich user-defined abstract classes. Therefore, the most straightforward approach to introduce types is to associate types of variables to classes that variables denote and to associate types of procedures to mappings from classes to classes. Since a variable may denote objects of different classes, we define the type of a variable to be a union of classes that the variable will ever denote.
The aim of this research is not to implement compilers for Smalltalk with type declarations. We intend to design tools to supply type declarations to current Smalltalk programs. Complete type determination is neither possible nor desirable; people do write Smalltalk programs that take advantage of late bindings. We are, therefore, interested in finding a relatively efficient method that can find types of expressions in a large number of cases.
The problem of statically assigning types to type-declarationless programs is called type-inference problem. We can find a number of work on type inference [3, 4, 7, 9, 11, 15]; these techniques are, however, either too restrictive or too inefficient for our purpose. The only technique implemented, proven to work for non-trivial cases, and used extensively was developed by Milner [7] to determine types for ML language of LCF. Even though ML language is much simpler than Smalltalk, the fact that there exists an efficient, versatile algorithm encouraged us to investigate whether we can extend the method.
The LCF type checker produces a set of equations from procedure declarations and solves them by unification [12], to obtain the types of the procedures; it can run in linear time due to a fast unification algorithm invented recently [10]. We extended Milner's method so that we can treat unions of types; in our method,we create a set of equations and inequalities and solve them by unification and a transitive closure algorithm. This technique is general and can be applied to other data-flow problems.
The advantage of Milner's method and our method is that it reduces the problems to purely mathematical domain so that we can apply various formula manipulation algorithms, without considering the execution order or side-effects. Another advantage is that these methods can handle functions with polymorphic types.
In section 2 we review earlier work on type inference. The brief introduction of the syntax and the semantics of Smalltalk is done in section 3. Then we introduce the "types" into Smalltalk in section 4. We discuss the first part of our algorithm, how to extend LCF type checking algorithm for liberal unions of types, in section 5. Then in section 6 the whole algorithm is presented. Section 7 is concerned with the implementation and experience.
Smalltalk has four major different versions of the language and implementations. The version we used for our experiments is Smalltalk-76.

References

[1]
DAHL, O.-J., NYGAARD, K. Simula---an Algol-Based Simulation Language. Comm. of the ACM, Vol.9. No.9, pp.671-678.
[2]
INGALLS, D. H. H. The Smalltalk-76 Programming System Design and Implementation. Conf. Rec. Fifth ACM Symp. on Principles of Programming Languages, Tucson, Arizona, 1978, pp.9-16.
[3]
JONES, N. D., AND MUCHNICK, S. Binding time optimization in programming languages. Conf. Rec. Third ACM Symp. on Principles of Programming Languages, Atlanta, Ga., 1976, pp.77-94.
[4]
KAPLAN, M., AND ULLMAN, J. D. A Scheme for the automatic inference of variable types, Journal of the ACM, No.1, Vol.27, pp.128-145, 1980.
[5]
KAY, A. C. Microelectronics and the Personal Computer. Scientific American, 237, No.3, pp230-244, September 1977.
[6]
KILDALL, G. A. A Unified Approach to Global Program Optimization. Conf. Rec. ACM Symp. on Principles of Programming Languages, Boston, Mass., 1973, pp.194-206.
[7]
MILNER, R. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17, 348-375 (1978).
[8]
MITCHELL, J. G. The Design and Construction of Flexible and Efficient Interactive Programming Systems. Ph.D. thesis, Carnegie-Mellon University, 1970. Reprinted in Outstanding Dissertations in the Computer Sciences series, Garland Publishing Co., N.Y., 1980.
[9]
MORRIS, J. H. Lambda-Calculus Models of Programming Languages, Ph.D. Thesis, MAC-TR-57, MIT, 1968.
[10]
PATERSON, M. S. & WEGMAN, M. N. Linear Unification. Proc. Eighth ACM Symp. on Theory of Comp., Hershey, Pa., 1976, pp.181-186.
[11]
REYNOLDS, J. C. Automatic Computation of Data Set Definitions. Information Processing 68, pp.456-461, North-Holland Publishing Company, Amsterdam, 1969.
[12]
ROBINSON, J. A. A machine-oriented logic based on the resolution principle, Journal of the ACM, No.1, Vol.12, pp.23-41, 1965.
[13]
ROSEN, B. K. Data flow analysis for procedural languages, Journal of the ACM, No.2, Vol. 26, pp.322-344, 1979.
[14]
GOLDBERG, A., ROBSON, D., INGALLS, D., & TESLER, L. Dreams & Schemes, Part One: The Language & its Implementation. To be published.
[15]
TENNENBAUM, A. Type determination for very high level languages. Rep. NSO-3, Courant Inst. Math. Sci., New York U., New York, 1974.
[16]
WEIHL, W. E. Interprocedural Data Flow Analysis in the Presence of Pointers, Procedure Variables, and Label Variables. Conf. Rec. Seventh ACM Symp. on Principles of Programming Languages, Las Vegas, Nevada, 1980, pp.83-94.

Cited By

View all
  • (2022)DepMiner: Automatic Recommendation of Transformation Rules for Method DeprecationReuse and Software Quality10.1007/978-3-031-08129-3_2(22-37)Online publication date: 10-Jun-2022
  • (2019)VM support for live typingCompanion Proceedings of the 3rd International Conference on the Art, Science, and Engineering of Programming10.1145/3328433.3328443(1-3)Online publication date: 1-Apr-2019
  • (2018)A spectrum of type soundness and performanceProceedings of the ACM on Programming Languages10.1145/32367662:ICFP(1-32)Online publication date: 30-Jul-2018
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Conferences
POPL '81: Proceedings of the 8th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
January 1981
230 pages
ISBN:089791029X
DOI:10.1145/567532
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 26 January 1981

Permissions

Request permissions for this article.

Check for updates

Qualifiers

  • Article

Acceptance Rates

POPL '81 Paper Acceptance Rate 24 of 121 submissions, 20%;
Overall Acceptance Rate 824 of 4,130 submissions, 20%

Upcoming Conference

POPL '25

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)94
  • Downloads (Last 6 weeks)15
Reflects downloads up to 22 Sep 2024

Other Metrics

Citations

Cited By

View all
  • (2022)DepMiner: Automatic Recommendation of Transformation Rules for Method DeprecationReuse and Software Quality10.1007/978-3-031-08129-3_2(22-37)Online publication date: 10-Jun-2022
  • (2019)VM support for live typingCompanion Proceedings of the 3rd International Conference on the Art, Science, and Engineering of Programming10.1145/3328433.3328443(1-3)Online publication date: 1-Apr-2019
  • (2018)A spectrum of type soundness and performanceProceedings of the ACM on Programming Languages10.1145/32367662:ICFP(1-32)Online publication date: 30-Jul-2018
  • (2016)A Case Study on Type Hints in Method Argument Names in Pharo Smalltalk Projects2016 IEEE 23rd International Conference on Software Analysis, Evolution, and Reengineering (SANER)10.1109/SANER.2016.41(283-292)Online publication date: Mar-2016
  • (2015)Measuring polymorphism in python programsACM SIGPLAN Notices10.1145/2936313.281671751:2(114-128)Online publication date: 21-Oct-2015
  • (2015)Measuring polymorphism in python programsProceedings of the 11th Symposium on Dynamic Languages10.1145/2816707.2816717(114-128)Online publication date: 21-Oct-2015
  • (2013)TeJaSACM SIGPLAN Notices10.1145/2578856.250817049:2(1-16)Online publication date: 28-Oct-2013
  • (2013)TeJaSProceedings of the 9th symposium on Dynamic languages10.1145/2508168.2508170(1-16)Online publication date: 28-Oct-2013
  • (2012)Progressive typesProceedings of the ACM international symposium on New ideas, new paradigms, and reflections on programming and software10.1145/2384592.2384599(55-66)Online publication date: 19-Oct-2012
  • (2011)Type harvestingProceedings of the 2011 ACM Symposium on Applied Computing10.1145/1982185.1982464(1282-1289)Online publication date: 21-Mar-2011
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media