Constraint-Based Type Inference and Parametric Polymorphism
نویسنده
چکیده
Constraint-based analysis is a technique for inferring implementation types. Traditionally it has been described using mathematical formalisms. We explain it in a different and more intuitive way as a flow problem. The intuition is facilitated by a direct correspondence between run-time and analysis-time concepts. Precise analysis of polymorphism is hard; several algorithms have been developed to cope with it. Focusing on parametric polymorphism and using the flow perspective, we analyze and compare these algorithms, for the first time directly characterizing when they succeed and fail. Our study of the algorithms lead us to two conclusions. First, designing an algorithm that is either efficient or precise is easy, but designing an algorithm that is efficient and precise is hard. Second, to achieve efficiency and precision simultaneously, the analysis effort must be actively guided towards the areas of the program with the highest pay-off. We define a general class of algorithms that do this: the adaptive algorithms. The two most powerful of the five algorithms we study fall in this class.
منابع مشابه
Precise Constraint-Based Type Inference for Java
Precise type information is invaluable for analysis and optimization of object-oriented programs. Some forms of polymorphism found in object-oriented languages pose significant difficulty for type inference, in particular data polymorphism. Agesen’s Cartesian Product Algorithm (CPA) can analyze programs with parametric polymorphism in a reasonably precise and efficient manner, but CPA loses pre...
متن کاملType inference for MLj
MLj is an extension of the Standard ML language which allows interoperation with Java. It has a type system which combines ML’s parametric polymorphism and type inference with Java’s subtyping (class hierarchy) and arbitrary overloading of methods. In this paper, we discuss some of the difficulties in implementing type inference for MLj and outline our progress on the implementation. In particu...
متن کاملType Inference with Inequalities
Type inference can be phrased as constraint-solving over types. We consider an implicitly typed language equipped with recursive types, multiple inheritance, 1st order parametric polymorphism, and assignments. Type correctness is expressed as satisfiability of a possibly infinite collection of (monotonic) inequalities on the types of variables and expressions. A general result about systems of ...
متن کاملAn Interval-Based Inference of Variant Parametric Types
Variant parametric types represent the successful integration of subtype and parametric polymorphism to support a more flexible subtyping for Javalike languages. A key feature that helps strengthen this integration is the use-site variance. Depending on how the fields are used, each variance denotes a covariant, a contravariant, an invariant or a bivariant subtyping. By annotating variance prop...
متن کاملFPH: First-class Polymorphism for Haskell Declarative, Constraint-free Type Inference for Impredicative Polymorphism
Languages supporting polymorphism typically have ad-hoc restrictions on where polymorphic types may occur. Supporting “firstclass” polymorphism, by lifting those restrictions, is obviously desirable, but it is hard to achieve this without sacrificing type inference. We present a new type system for higher-rank and impredicative polymorphism that improves on earlier proposals: it is an extension...
متن کامل