Compiling polymorphism using intensional type analysis

Traditional techniques for implementing polymorphism use a universal representation for objects of unknown type. Often, this forces a compiler to use universal representations even if the types of objects are known. We examine an alternative approach for compiling polymorphism where types are passed as arguments to polymorphic routines in order to determine the representation of an object. This approach allows monomorphic code to use natural, efficient representations, supports separate compilation of polymorphic definitions and, unlike coercion-based implementations of polymorphism, natural representations can be used for mutable objects such as refs and arrays. We are particularly interested in the typing properties of an intermediate language that allows run-time type analysis to be coded within the language. This allows us to compile many representation transformations and many language features without adding new primitive operations to the language. In this paper, we provide a core target language where type-analysis operators can be coded within the language and the types of such operators can be accurately tracked. The target language is powerful enough to code a variety of useful features, yet type checking remains decidable. We show how to translate an ML-like language into the target language so that primitive operators can analyze types to produce efficient representations. We demonstrate the power of the “user-level” operators by coding flattened tuples, marshalling, type classes, and a form of type dynamic within the language.

[1]  Xavier Leroy,et al.  The ZINC experiment : an economical implementation of the ML language , 1990 .

[2]  A. K. Wmght Polymorphism for imperative languages without imperative types , 1993 .

[3]  H. Friedman Equality between functionals , 1975 .

[4]  Per Martin-Löuf About Models for Intuitionistic Type Theories and the Notion of Definitional Equality , 1975 .

[5]  Brian Cantwell Smith,et al.  Reflection and semantics in LISP , 1984, POPL.

[6]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[7]  Mark P. Jones,et al.  ML Typing, Explicit Polymorphism and Qualified Types , 1994, TACS.

[8]  Xavier Leroy,et al.  Unboxed objects and polymorphic typing , 1992, POPL '92.

[9]  Matthias Felleisen,et al.  Abstract models of memory management , 1995, FPCA '95.

[10]  Carl A. Gunter,et al.  Computing ML Equality Kinds Using Abstract Interpretation , 1993, Inf. Comput..

[11]  Von Kurt Gödel,et al.  ÜBER EINE BISHER NOCH NICHT BENÜTZTE ERWEITERUNG DES FINITEN STANDPUNKTES , 1958 .

[12]  John C. Mitchell,et al.  On the type structure of standard ML , 1993, TOPL.

[13]  Kazuhiko Kato,et al.  Semantics for communication primitives in a polymorphic language , 1993, POPL '93.

[14]  Alexander Aiken,et al.  Soft typing with conditional types , 1994, POPL '94.

[15]  Robert L. Constable,et al.  The Type Theory of PL/CV 3 , 1981, Logic of Programs.

[16]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[17]  John C. Reynolds,et al.  Types, Abstraction and Parametric Polymorphism , 1983, IFIP Congress.

[18]  Zhong Shao,et al.  Compiling standard ML for efficient execution on modern machines , 1994 .

[19]  Mark Philip Jones Qualified types: theory and practice (ordering relation) , 1992 .

[20]  Atsushi Ohori,et al.  A compilation method for ML-style polymorphic record calculi , 1992, POPL '92.

[21]  Robert Cartwright,et al.  A practical soft type system for scheme , 1997, TOPL.

[22]  Satish R. Thatte Semantics of type classes revisited , 1994, LFP '94.

[23]  Simon L. Peyton Jones,et al.  Report on the programming language Haskell: a non-strict, purely functional language version 1.2 , 1992, SIGP.

[24]  J. Girard Une Extension De ĽInterpretation De Gödel a ĽAnalyse, Et Son Application a ĽElimination Des Coupures Dans ĽAnalyse Et La Theorie Des Types , 1971 .

[25]  Thierry Coquand,et al.  Inheritance as Implicit Coercion , 1991, Inf. Comput..

[26]  Simon L. Peyton Jones,et al.  Unboxed Values as First Class Citizens in a Non-Strict Functional Language , 1991, FPCA.

[27]  Richard Statman,et al.  Completeness, invariance and λ-definability , 1982, Journal of Symbolic Logic.

[28]  Guy E. Blelloch,et al.  Implementation of a portable nested data-parallel language , 1993, PPOPP '93.

[29]  Mark Lillibridge,et al.  Polymorphic type assignment and CPS conversion , 1993, LISP Symb. Comput..

[30]  John C. Mitchell,et al.  Higher-order modules and the phase distinction , 1989, POPL '90.

[31]  Robin Milner,et al.  Definition of standard ML , 1990 .

[32]  Robert L. Constable,et al.  The Type Theory of PL/CV3 , 1984, TOPL.

[33]  Mark P. Jones A system of constructor classes: overloading and implicit higher-order polymorphism , 1993, FPCA '93.

[34]  Andrew P. Tolmach Tag-free garbage collection using explicit type parameters , 1994, LFP '94.

[35]  William W. Tait,et al.  Intensional interpretations of functionals of finite type I , 1967, Journal of Symbolic Logic.

[36]  Nevin Heintze,et al.  Set-based analysis of ML programs , 1994, LFP '94.

[37]  Mark P. Jones Qualified Types: Theory and Practice , 1994 .

[38]  Robert Cartwright,et al.  Soft typing , 2004, SIGP.

[39]  Andrew W. Appel,et al.  A critique of Standard ML , 1993, Journal of Functional Programming.

[40]  John C. Mitchell,et al.  Abstract types have existential type , 1988, TOPL.

[41]  Martín Abadi,et al.  Dynamic typing in a statically-typed language , 1989, POPL '89.

[42]  Mark P. Jones Coherence for Qualiied Types , 1993 .

[43]  R. L. Constable Intensional analysis of functions and types , 1982 .

[44]  Dominique Clément,et al.  A simple applicative language: mini-ML , 1986, LFP '86.

[45]  Sören Stenlund Combinators, λ-Terms and Proof Theory , 2011 .

[46]  Satish R. Thatte Quasi-static typing , 1989, POPL '90.

[47]  WadlerPhilip,et al.  Report on the programming language Haskell , 1992 .

[48]  Richard C. H. Connor,et al.  An ad hoc approach to the implementation of polymorphism , 1991, TOPL.

[49]  Luca Cardelli,et al.  Typeful Programming , 1989, Formal Description of Programming Concepts.

[50]  John Launchbury,et al.  Unboxed values as first class citizens , 1991 .

[51]  Lennart Augustsson,et al.  Implementing Haskell overloading , 1993, FPCA '93.

[52]  Robert L. Constable,et al.  The semantics of reflected proof , 1990, [1990] Proceedings. Fifth Annual IEEE Symposium on Logic in Computer Science.

[53]  Fritz Henglein,et al.  Formally optimal boxing , 1994, POPL '94.

[54]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[55]  Richard Statman,et al.  Logical Relations and the Typed lambda-Calculus , 1985, Inf. Control..

[56]  John C. Reynolds,et al.  Towards a theory of type structure , 1974, Symposium on Programming.

[57]  Luca Cardelli,et al.  Phase Distinctions in Type Theory , 1988 .

[58]  John C. Mitchell,et al.  The essence of ML , 1988, POPL '88.