Abstract
We develop a type-theoretical method for optimizing type directed compilation of polymorphic languages, implement the method in SML#, which is a full-scale compiler of Standard ML extended with several advanced features that require type-passing operational semantics, and report its effectiveness through performance evaluation. For this purpose, we first define a predicative second-order lambda calculus with finitary polymorphism, where each type abstraction is explicitly constrained to a finite type universe, and establishes the type soundness with respect to a type-passing operational semantics. Different from a calculus with stratified type universes, type universes of the calculus are terms that represent a finite set of instance types. We then develop a universe reconstruction algorithm that takes a term of the standard second-order lambda calculus, checks if the term is typable with finitary polymorphism, and, if typable, constructs a term in the calculus of finitary polymorphism. Based on these results, we present a type-based optimization method for polymorphic functions. Since our formalism is based on the second-order lambda calculus, it can be used to optimize various polymorphic languages. We implement the optimization method for native (tag-free) data representation and record polymorphism, and evaluate its effectiveness through benchmarks. The evaluation shows that 83.79% of type passing abstractions are eliminated, and achieves the average of 15.28% speed-up of compiled code.
Supplemental Material
- F. Barbanera, M. Dezaniciancaglini, and U. Deliguoro. 1995. Intersection and Union Types: Syntax and Semantics. Information and Computation 119, 2 (1995), 202 – 230. Google Scholar
Digital Library
- Antonio Bucciarelli, Delia Kesner, and Daniel Ventura. 2017. Non-idempotent intersection types for the Lambda-Calculus. Logic Journal of the IGPL 25, 4 (2017), 431–464.Google Scholar
Cross Ref
- Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. 1981. Functional Characters of Solvable Terms. Math. Log. Q. 27, 2-6 (1981), 45–58.Google Scholar
Cross Ref
- Martin Elsman. 1998. Polymorphic equality — No tags required. In Types in Compilation, Xavier Leroy and Atsushi Ohori (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 136–155. Google Scholar
Digital Library
- Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. 1996. Type Classes in Haskell. ACM Trans. Program. Lang. Syst. 18, 2 (March 1996), 109–138. Google Scholar
Digital Library
- Robert Harper and Greg Morrisett. 1995. Compiling Polymorphism Using Intensional Type Analysis. In Proceedings of the 22Nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’95) . ACM, New York, NY, USA, 130–141. Google Scholar
Digital Library
- Mark P. Jones. 1994. A Theory of Qualified Types. Sci. Comput. Program. 22, 3 (1994), 231–256. Google Scholar
Digital Library
- Mark P. Jones. 1995. Dictionary-free overloading by partial evaluation. LISP and Symbolic Computation 8, 3 (01 Sep 1995), 229–248. Google Scholar
Digital Library
- Simon L. Peyton Jones and John Launchbury. 1991. Unboxed values as first class citizens in a non-strict functional language. In Functional Programming Languages and Computer Architecture, John Hughes (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 636–666. Google Scholar
Digital Library
- Daniel Leivant. 1989. Stratified Polymorphism (Extended Summary). In Proceedings of the Fourth Annual Symposium on Logic in Computer Science (LICS ’89), Pacific Grove, California, USA, June 5-8, 1989 . IEEE, 39–47. Google Scholar
Digital Library
- Daniel Leivant. 1991. Finitely stratified polymorphism. Information and Computation 93, 1 (1991), 93 – 113. Selections from 1989 IEEE Symposium on Logic in Computer Science. Google Scholar
Digital Library
- Xavier Leroy. 1992. Unboxed Objects and Polymorphic Typing. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’92) . ACM, New York, NY, USA, 177–188. Google Scholar
Digital Library
- Martin-Löf. 1975. An Intuitionistic Theory of Types: Predicative Part. In Logic Colloquium, H. E. Rose and J. C. Shepherdson (Eds.). Noth Holland, Amsterdam.Google Scholar
- Huu-Duc Nguyen and Atsushi Ohori. 2006. Compiling ML Polymorphism with Explicit Layout Bitmap. In Proceedings of the 8th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP ’06) . ACM, New York, NY, USA, 237–248. Google Scholar
Digital Library
- Atsushi Ohori. 1992. A Compilation Method for ML-style Polymorphic Record Calculi. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’92) . ACM, New York, NY, USA, 154–165. Google Scholar
Digital Library
- Atsushi Ohori. 1995. A Polymorphic Record Calculus and Its Compilation. ACM Trans. Program. Lang. Syst. 17, 6 (Nov. 1995), 844–895. Google Scholar
Digital Library
- Atsushi Ohori. 1999. Type-Directed Specialization of Polymorphism. Inf. Comput. 155, 1-2 (1999), 64–107. Google Scholar
Digital Library
- JENS PALSBERG and CHRISTINA PAVLOPOULOU. 2001. From Polyvariant flow information to intersection and union types. Journal of Functional Programming 11, 3 (2001), 263–317. Google Scholar
Digital Library
- John Peterson and Mark Jones. 1993. Implementing Type Classes. In Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation (PLDI ’93) . ACM, New York, NY, USA, 227–236. Google Scholar
Digital Library
- B. Russell. 1908. Mathematical logic based on a theory of types. Americal Journal of Mathematics 30 (1908), 222–262.Google Scholar
Cross Ref
- Zhong Shao. 1997. Flexible Representation Analysis. In Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming (ICFP ’97) . ACM, New York, NY, USA, 85–98. Google Scholar
Digital Library
- Olin Grigsby Shivers. 1991. Control-flow Analysis of Higher-order Languages of Taming Lambda. Ph.D. Dissertation. Carnegie Mellon University, Pittsburgh, PA, USA. UMI Order No. GAX91-26964.Google Scholar
- J.M. Siskind. 1999. Flow-Directed Lightweight Closure Conversion. Technical Report Technical Report 99-190R. NEC Research Institute, Inc.Google Scholar
- SML#-Project-Team. 2005 – 2018. SML# Project. http://www.riec.tohoku.ac.jp/smlsharp/Google Scholar
- D. Tarditi, G. Morrisett, P. Cheng, C. Stone, R. Harper, and P. Lee. 1996. TIL: A Type-directed Optimizing Compiler for ML. In Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation (PLDI ’96). ACM, New York, NY, USA, 181–192. Google Scholar
Digital Library
- Andrew Tolmach. 1994. Tag-free Garbage Collection Using Explicit Type Parameters. In Proceedings of the 1994 ACM Conference on LISP and Functional Programming (LFP ’94) . ACM, New York, NY, USA, 1–11. Google Scholar
Digital Library
- Andrew Tolmach and Dino P. Oliva. 1998. From ML to Ada: Strongly-typed language interoperability via source translation. Journal of Functional Programming 8, 4 (1998), 367–412. Google Scholar
Digital Library
- Stephen Weeks. 2006. Whole-program Compilation in MLton. In Proceedings of the 2006 Workshop on ML (ML ’06). ACM, New York, NY, USA, 1–1. Google Scholar
Digital Library
- J. B. WELLS, ALLYN DIMOCK, ROBERT MULLER, and FRANKLYN TURBAK. 2002. A calculus with polymorphic and polyvariant flow types. Journal of Functional Programming 12, 3 (2002), 183–227. Google Scholar
Digital Library
Index Terms
Finitary polymorphism for optimizing type-directed compilation
Recommendations
Type inference with rank 1 polymorphism for type-directed compilation of ML
This paper defines an extended polymorphic type system for an ML-style programming language, and develops a sound and complete type inference algorithm. Different frdm the conventional ML type discipline, the proposed type system allows full rank 1 ...
Type inference with rank 1 polymorphism for type-directed compilation of ML
ICFP '99: Proceedings of the fourth ACM SIGPLAN international conference on Functional programmingThis paper defines an extended polymorphic type system for an ML-style programming language, and develops a sound and complete type inference algorithm. Different frdm the conventional ML type discipline, the proposed type system allows full rank 1 ...
Programming Examples Needing Polymorphic Recursion
Inferring types for polymorphic recursive function definitions (abbreviated to polymorphic recursion) is a recurring topic on the mailing lists of popular typed programming languages. This is despite the fact that type inference for polymorphic ...






Comments