Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Finitary polymorphism for optimizing type-directed compilation

Published: 30 July 2018 Publication History
  • Get Citation Alerts
  • 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.

    Supplementary Material

    WEBM File (a81-ohori.webm)

    References

    [1]
    F. Barbanera, M. Dezaniciancaglini, and U. Deliguoro. 1995. Intersection and Union Types: Syntax and Semantics. Information and Computation 119, 2 (1995), 202 – 230.
    [2]
    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.
    [3]
    Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. 1981. Functional Characters of Solvable Terms. Math. Log. Q. 27, 2-6 (1981), 45–58.
    [4]
    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.
    [5]
    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.
    [6]
    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.
    [7]
    Mark P. Jones. 1994. A Theory of Qualified Types. Sci. Comput. Program. 22, 3 (1994), 231–256.
    [8]
    Mark P. Jones. 1995. Dictionary-free overloading by partial evaluation. LISP and Symbolic Computation 8, 3 (01 Sep 1995), 229–248.
    [9]
    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.
    [10]
    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.
    [11]
    Daniel Leivant. 1991. Finitely stratified polymorphism. Information and Computation 93, 1 (1991), 93 – 113. Selections from 1989 IEEE Symposium on Logic in Computer Science.
    [12]
    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.
    [13]
    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.
    [14]
    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.
    [15]
    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.
    [16]
    Atsushi Ohori. 1995. A Polymorphic Record Calculus and Its Compilation. ACM Trans. Program. Lang. Syst. 17, 6 (Nov. 1995), 844–895.
    [17]
    Atsushi Ohori. 1999. Type-Directed Specialization of Polymorphism. Inf. Comput. 155, 1-2 (1999), 64–107.
    [18]
    JENS PALSBERG and CHRISTINA PAVLOPOULOU. 2001. From Polyvariant flow information to intersection and union types. Journal of Functional Programming 11, 3 (2001), 263–317.
    [19]
    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.
    [20]
    B. Russell. 1908. Mathematical logic based on a theory of types. Americal Journal of Mathematics 30 (1908), 222–262.
    [21]
    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.
    [22]
    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.
    [23]
    J.M. Siskind. 1999. Flow-Directed Lightweight Closure Conversion. Technical Report Technical Report 99-190R. NEC Research Institute, Inc.
    [24]
    SML#-Project-Team. 2005 – 2018. SML# Project. http://www.riec.tohoku.ac.jp/smlsharp/
    [25]
    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.
    [26]
    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.
    [27]
    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.
    [28]
    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.
    [29]
    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.

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 2, Issue ICFP
    September 2018
    1133 pages
    EISSN:2475-1421
    DOI:10.1145/3243631
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution International 4.0 License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 30 July 2018
    Published in PACMPL Volume 2, Issue ICFP

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. Compiler Optimization
    2. Finitary Polymorphism
    3. SML#
    4. Second-Order Lambda Calculus
    5. Type-Directed Compilation

    Qualifiers

    • Research-article

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • 0
      Total Citations
    • 559
      Total Downloads
    • Downloads (Last 12 months)65
    • Downloads (Last 6 weeks)12

    Other Metrics

    Citations

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media