Simple polymorphic usage analysis

Implementations of lazy functional languages ensure that computations are performed only when they are needed, and save the results so that they are not repeated. This frees the programmer to describe solutions at a high level, leaving details of control flow to the compiler. This freedom however places a heavy burden on the compiler; measurements show that over 70% of these saved results are never used again. A usage analysis that could statically detect values used at most once would enable these wasted updates to be avoided, and would be of great benefit. However, existing usage analyses either give poor results or have been applied only to prototype compilers or toy languages. This thesis presents a sound, practical, type-based usage analysis that copes with all the language features of a modern functional language, including type polymorphism and user-defined algebraic data types, and addresses a range of problems that have caused difficulty for previous analyses, including poisoning, mutual recursion, separate compilation, and partial application and usage dependencies. In addition to well-typing rules, an inference algorithm is developed, with proofs of soundness and a complexity analysis. In the process, the thesis develops simple polymorphism, a novel approach to polymorphism in the presence of subtyping that attempts to strike a balance between pragmatic concerns and expressive power. This thesis may be considered an extended experiment into this approach, worked out in some detail but not yet conclusive. The analysis described was designed in parallel with a full implementation in the Glasgow Haskell Compiler, leading to informed design choices, thorough coverage of language features, and accurate measurements of its potential and effectiveness when used on real code. The latter demonstrate that the analysis yields moderate benefit in practice.

[1]  B. Jacobs,et al.  A tutorial on (co)algebras and (co)induction , 1997 .

[2]  Karl-Philip Faxén Analysing, transforming and compiling lazy functional programs , 1997 .

[3]  Johan Nordlander,et al.  Polymorphic subtyping in O'Haskell , 2002, Sci. Comput. Program..

[4]  Clement A. Baker-Finch,et al.  Usage Analysis with Natural Reduction Types , 1993, WSA.

[5]  Erik Barendsen,et al.  A derivation system for uniqueness typing , 1995, Electron. Notes Theor. Comput. Sci..

[6]  John E. Hopcroft,et al.  An n log n algorithm for minimizing states in a finite automaton , 1971 .

[7]  Richard S. Bird,et al.  Nested Datatypes , 1998, MPC.

[8]  Luca Cardelli,et al.  Subtyping recursive types , 1991, POPL '91.

[9]  Simon L. Peyton Jones,et al.  Once upon a polymorphic type , 1999, POPL '99.

[10]  T. Jim,et al.  Type inference in systems of recursive types with subtyping , 1997 .

[11]  Richard E. Jones,et al.  Tail recursion without space leaks , 1992, Journal of Functional Programming.

[12]  J. Tiuryn Subtyping over a lattice , 1997 .

[13]  Christopher Strachey,et al.  Fundamental Concepts in Programming Languages , 2000, High. Order Symb. Comput..

[14]  Philip Wadler EDITORIAL: A HOT opportunity , 1997 .

[15]  Rafael Dueire Lins,et al.  Benchmarking implementations of functional languages with ‘Pseudoknot’, a float-intensive benchmark , 1996, Journal of Functional Programming.

[16]  Scott F. Smith,et al.  Subtyping Constrained Types , 1996, SAS.

[17]  Jeffrey D. Ullman,et al.  Introduction to Automata Theory, Languages and Computation , 1979 .

[18]  Erik Barendsen,et al.  Conventional and Uniqueness Typing in Graph Rewrite Systems , 1993, FSTTCS.

[19]  Simon Peyton Jones,et al.  Henk: a typed intermediate language , 1997 .

[20]  J. Dekker,et al.  Some theorems on classes of recursively enumerable sets , 1958 .

[21]  Jens Palsberg,et al.  Optimal Representations of Polymorphic Types with Subtyping (Extended Abstract) , 1997, TACS.

[22]  Luca Cardelli An implementation of F , 1993 .

[23]  Peter J. Stuckey,et al.  Boolean Constraints for Binding-Time Analysis , 2001, PADO.

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

[25]  François Pottier,et al.  Type Inference in the Presence of Subtyping: from Theory to Practice , 1998 .

[26]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[27]  John Launchbury,et al.  Zip Fusion with Hyperfunctions , 2000 .

[28]  Simon Peyton Jones,et al.  Type classes: an exploration of the design space , 1997 .

[29]  Luca Cardelli,et al.  Basic Polymorphic Typechecking , 1987, Sci. Comput. Program..

[30]  Jörgen Gustavsson A type based sharing analysis for update avoidance and optimisation , 1998, ICFP '98.

[31]  Peter Lee,et al.  TIL: A Type-Directed Optimizing Compiler , 1996 .

[32]  Chris Okasaki,et al.  Purely functional data structures , 1998 .

[33]  Andrew W. Appel,et al.  A type-based compiler for standard ML , 1995, PLDI '95.

[34]  B. Pierce,et al.  Datatypes and SubtypingHaruo , 2007 .

[35]  Rod M. Burstall,et al.  HOPE: An experimental applicative language , 1980, LISP Conference.

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

[37]  David Wright Linear, Strictness and Usage Logics , 1996 .

[38]  Pavel Curtis Constrained qualification in polymorphic type analysis , 1990 .

[39]  Simon Marlow Update Avoidance Analysis by Abstract Interpretation , 1993, Functional Programming.

[40]  Henk Barendregt,et al.  The Lambda Calculus: Its Syntax and Semantics , 1985 .

[41]  Mads Tofte,et al.  Implementation of the typed call-by-value λ-calculus using a stack of regions , 1994, POPL '94.

[42]  Thomas P. Jensen,et al.  Conjunctive Type Systems and Abstract Interpretation of Higher-Order Functional Programs , 1995, J. Log. Comput..

[43]  Benjamin C. Pierce,et al.  Recursive subtyping revealed: (functional pearl) , 2000, ICFP '00.

[44]  Robert E. Tarjan,et al.  Efficiency of a Good But Not Linear Set Union Algorithm , 1972, JACM.

[45]  Fritz Henglein,et al.  Coinductive Axiomatization of Recursive Type Equality and Subtyping , 1998, Fundam. Informaticae.

[46]  Jan van Leeuwen,et al.  Worst-case Analysis of Set Union Algorithms , 1984, JACM.

[47]  Trevor Jim What are principal typings and what are they good for? , 1996, POPL '96.

[48]  Chris Okasaki,et al.  Catenable double-ended queues , 1997, ICFP '97.

[49]  Jean-Yves Girard,et al.  On the Unity of Logic , 1993, Ann. Pure Appl. Log..

[50]  François Pottier,et al.  A Versatile Constraint-Based Type Inference System , 2000, Nord. J. Comput..

[51]  Thomas Johnsson,et al.  The GRIN Project: A Highly Optimising Back End for Lazy Functional Languages , 1996, Implementation of Functional Languages.

[52]  John C. Mitchell,et al.  Foundations for programming languages , 1996, Foundation of computing series.

[53]  P. J. Landin,et al.  The next 700 programming languages , 1966, CACM.

[54]  Andrew M. Pitts,et al.  A First Order Theory of Names and Binding , 2001 .

[55]  Benjamin C. Pierce,et al.  Higher-Order Subtyping , 1994, Theor. Comput. Sci..

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

[57]  Robert Cartwright,et al.  Soft typing , 1991, PLDI '91.

[58]  Alberto Martelli,et al.  An Efficient Unification Algorithm , 1982, TOPL.

[59]  Eric S. Raymond,et al.  The New Hacker's Dictionary , 1991 .

[60]  J. B. Wells Typability and type checking in the second-order Λ-calculus are equivalent and undecidable (Preliminary Draft) , 1993 .

[61]  Josef Svenningsson,et al.  A Usage Analysis with Bounded Usage Polymorphism and Subtyping , 2000, IFL.

[62]  Jörgen Gustavsson Space-Safe Transformations and Usage Analysis for Call-by-Need Languages , 2001 .

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

[64]  Marinus J. Plasmeijer,et al.  Language report Concurrent Clean , 1998 .

[65]  S. Abramsky The lazy lambda calculus , 1990 .

[66]  H. Rice Classes of recursively enumerable sets and their decision problems , 1953 .

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

[68]  John Hughes,et al.  Why Functional Programming Matters , 1989, Comput. J..

[69]  Martin Odersky,et al.  Call-by-name, call-by-value, call-by-need and the linear lambda calculus , 1995, MFPS.

[70]  Mike Fagan,et al.  Soft typing: an approach to type checking for dynamically typed languages , 1992 .

[71]  S. Jones,et al.  A Transformation-Based Optimiser for Haskell , 1998, Sci. Comput. Program..

[72]  S. Hawking A Brief History of Time: From the Big Bang to Black Holes , 1988 .

[73]  John Hughes,et al.  Report on the Programming Language Haskell 98 , 1999 .

[74]  Paul Hudak,et al.  Code optimizations for lazy evaluation , 1988, LISP Symb. Comput..

[75]  Marinus J. Plasmeijer,et al.  High Level Specification of I/O in Functional Languages , 1992, Functional Programming.

[76]  Philip Wadler,et al.  Is there a use for linear logic? , 1991, PEPM '91.

[77]  Peter Sestoft,et al.  Analysis and efficient implementation of functional programs , 1991 .

[78]  John C. Mitchell,et al.  Type inference with simple subtypes , 1991, Journal of Functional Programming.

[79]  Hanne Riis Nielson,et al.  Programming Languages and Systems — ESOP '96 , 1996, Lecture Notes in Computer Science.

[80]  Benjamin C. Pierce,et al.  Local type inference , 1998, POPL '98.

[81]  Martin Sulzmann,et al.  Hindley/Milner style type systems in constraint form , 1999 .

[82]  Davide Sangiorgi,et al.  Typing and subtyping for mobile processes , 1993, [1993] Proceedings Eighth Annual IEEE Symposium on Logic in Computer Science.

[83]  Bart Jacobs,et al.  Semantics of Weakening and Contraction , 1994, Ann. Pure Appl. Log..

[84]  Suresh Jagannathan,et al.  Polymorphic splitting: an effective polyvariant flow analysis , 1998, TOPL.

[85]  Andrew Barber,et al.  Dual Intuitionistic Linear Logic , 1996 .

[86]  Simon Peyton Jones,et al.  Measuring the effectiveness of a simple strictness analyser , 1993, Functional Programming.

[87]  Simon L. Peyton Jones,et al.  Secrets of the Glasgow Haskell Compiler inliner , 2002, Journal of Functional Programming.

[88]  Philip Wadler,et al.  Linear Types can Change the World! , 1990, Programming Concepts and Methods.

[89]  Fritz Henglein,et al.  Type inference with polymorphic recursion , 1993, TOPL.

[90]  Luca Cardelli,et al.  On understanding types, data abstraction, and polymorphism , 1985, CSUR.

[91]  John Launchbury,et al.  A natural semantics for lazy evaluation , 1993, POPL '93.

[92]  Torben Æ. Mogensen Types for 0, 1 or Many Uses , 1997, Implementation of Functional Languages.

[93]  Jens Palsberg,et al.  Constrained types and their expressiveness , 1996, TOPL.

[94]  Fritz Henglein,et al.  Polymorphic Binding-Time Analysis , 1994, ESOP.

[95]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[96]  John Launchbury,et al.  Implicit parameters: dynamic scoping with static types , 2000, POPL '00.

[97]  Andrew D. Gordon A Tutorial on Co-induction and Functional Programming , 1994, Functional Programming.

[98]  Jakob Rehof,et al.  Tractable Constraints in Finite Semilattices , 1999, Sci. Comput. Program..

[99]  Andrew Moran,et al.  Call-by-name, Call-by-need, and McCarthy's Amb , 1998 .

[100]  J. Michael Dunn,et al.  Relevance Logic and Entailment , 1986 .

[101]  Philip Wadler,et al.  A practical subtyping system for Erlang , 1997, ICFP '97.

[102]  R. Hindley The Principal Type-Scheme of an Object in Combinatory Logic , 1969 .

[103]  Luca Cardelli,et al.  Structural subtyping and the notion of power type , 1988, POPL '88.

[104]  Alan Mycroft,et al.  Polymorphic Type Schemes and Recursive Definitions , 1984, Symposium on Programming.

[105]  Simon L. Peyton Jones,et al.  Let-floating: moving bindings to give faster programs , 1996, ICFP '96.

[106]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1988, Theoretical Computer Science.

[107]  Simon L. Peyton Jones,et al.  Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine , 1992, Journal of Functional Programming.

[108]  Peter Sewell Global/Local Subtyping and Capability Inference for a Distributed pi-calculus , 1998, ICALP.

[109]  André L. M. Santos,et al.  Compilation by transformation in non-strict functional languages , 1995 .

[110]  Alexandre Frey Satisfying subtype inequalities in polynomial space , 2002, Theor. Comput. Sci..

[111]  Philip Wadler,et al.  A Syntax for Linear Logic , 1993, MFPS.

[112]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[113]  Tsung-Min Kuo,et al.  Strictness analysis: a new perspective based on type inference , 1989, FPCA.

[114]  Martín Abadi,et al.  Dynamic typing in polymorphic languages , 1995, Journal of Functional Programming.

[115]  John C. Mitchell,et al.  Algorithmic aspects of type inference with subtypes , 1992, POPL '92.

[116]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[117]  Mikhail A. Bulyonkov Polyvariant mixed computation for analyzer programs , 2004, Acta Informatica.

[118]  Paul Hudak,et al.  Single-threaded polymorphic lambda calculus , 1990, [1990] Proceedings. Fifth Annual IEEE Symposium on Logic in Computer Science.

[119]  Matthias Felleisen,et al.  Componential set-based analysis , 1997, TOPL.

[120]  Kwangkeun Yi,et al.  Proofs about a folklore let-polymorphic type inference algorithm , 1998, TOPL.

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

[122]  Scott F. Smith,et al.  Sound polymorphic type inference for objects , 1995, OOPSLA.

[123]  J. Y. Girard,et al.  Interpretation fonctionelle et elimination des coupures dans l'aritmetique d'ordre superieur , 1972 .

[124]  Simon L. Peyton Jones,et al.  Lazy functional state threads , 1994, PLDI '94.

[125]  Peter Sestoft,et al.  Deriving a lazy abstract machine , 1997, Journal of Functional Programming.

[126]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[127]  Philip Wadler Functional Programming: An Angry Half-Dozen , 1997, DBPL.

[128]  Stephan Merz,et al.  Type checking higher-order polymorphic multi-methods , 1997, POPL '97.

[129]  Johan Nordlander,et al.  Reactive Objects and Functional Programming , 1999 .

[130]  Liz Sonenberg,et al.  Fixed Point Theorems and Semantics: A Folk Tale , 1982, Inf. Process. Lett..

[131]  Jens Palsberg,et al.  Safety Analysis Versus Type Inference for Partial Types , 1992, Inf. Process. Lett..

[132]  Amr Sabry,et al.  The essence of compiling with continuations , 1993, PLDI '93.

[133]  Daniel Leivant,et al.  Polymorphic type inference , 1983, POPL '83.

[134]  Harry G. Mairson,et al.  Unification and ML-Type Reconstruction , 1991, Computational Logic - Essays in Honor of Alan Robinson.

[135]  Simon L. Peyton Jones,et al.  Asynchronous exceptions in Haskell , 2001, PLDI '01.

[136]  Benjamin Goldberg,et al.  Detecting sharing of partial applications in functional programs , 1987, FPCA.

[137]  Simon Peyton Jones,et al.  Playing by the rules: rewriting as a practical optimisation technique in GHC , 2001 .

[138]  Corrado Böhm,et al.  Automatic Synthesis of Typed Lambda-Programs on Term Algebras , 1985, Theor. Comput. Sci..

[139]  Luca Cardelli,et al.  An Extension of System F with Subtyping , 1991, TACS.

[140]  Josef Svenningsson,et al.  Constraint Abstractions , 2001, PADO.

[141]  B. Pierce Programming with intersection types and bounded polymorphism , 1992 .

[142]  Andrew John Gill,et al.  Cheap deforestation for non-strict functional languages , 1996 .

[143]  Martin Odersky,et al.  Type Inference with Constrained Types , 1999, Theory Pract. Object Syst..

[144]  Thomas P. Jensen,et al.  Inference of polymorphic and conditional strictness properties , 1998, POPL '98.

[145]  J. A. Robinson,et al.  A Machine-Oriented Logic Based on the Resolution Principle , 1965, JACM.

[146]  Fritz Henglein,et al.  Constraint Automata and the Complexity of Recursive Subtype Entailment , 1998, ICALP.

[147]  Fritz Henglein,et al.  Breaking Through the n3 Barrier: Faster Object Type Inference , 1999, Theory Pract. Object Syst..

[148]  Philip Wadler,et al.  Once upon a type , 1995, FPCA '95.

[149]  Carl A. Gunter Semantics of programming languages: structures and techniques , 1993, Choice Reviews Online.

[150]  Simon L. Peyton Jones,et al.  A modular fully‐lazy lambda lifter in Haskell , 1991, Softw. Pract. Exp..

[151]  Simon Peyton Jones,et al.  Simple Usage Polymorphism , 2000 .

[152]  Patrick Cousot,et al.  Inductive definitions, semantics and abstract interpretations , 1992, POPL '92.

[153]  E. Barendsen,et al.  Uniqueness Typing in Theory and PracticeErik , 1994 .

[154]  Esko Nuutila An Efficient Transitive Closure Algorithm for Cyclic Digraphs , 1994, Inf. Process. Lett..

[155]  Jean-Yves Girard,et al.  Linear logic: its syntax and semantics , 1995 .

[156]  Philip Wadler,et al.  A Taste of Linear Logic , 1993, MFCS.

[157]  Martin Odersky,et al.  The call-by-need lambda calculus , 1998, Journal of Functional Programming.

[158]  Prateek Mishra,et al.  Type Inference with Subtypes , 1990, Theor. Comput. Sci..

[159]  P. J. Landin The Mechanical Evaluation of Expressions , 1964, Comput. J..

[160]  Giorgio Ghelli,et al.  Coherence of Subsumption, Minimum Typing and Type-Checking in F<= , 1992, Math. Struct. Comput. Sci..

[161]  Erik Barendsen,et al.  Uniqueness Typing for Functional Languages with Graph Rewriting Semantics , 1996, Math. Struct. Comput. Sci..

[162]  Bruno Monsuez,et al.  Polymorphic Types and Widening Operators , 1993, WSA.

[163]  Simon Peyton Jones,et al.  Implementing Functional Languages: a tutorial , 2000 .

[164]  François Pottier,et al.  Simplifying Subtyping Constraints: A Theory , 2001, Inf. Comput..