skip to main content
10.1145/2103656.2103714acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
research-article

The ins and outs of gradual type inference

Published:25 January 2012Publication History

ABSTRACT

Gradual typing lets programmers evolve their dynamically typed programs by gradually adding explicit type annotations, which confer benefits like improved performance and fewer run-time failures.

However, we argue that such evolution often requires a giant leap, and that type inference can offer a crucial missing step. If omitted type annotations are interpreted as unknown types, rather than the dynamic type, then static types can often be inferred, thereby removing unnecessary assumptions of the dynamic type. The remaining assumptions of the dynamic type may then be removed by either reasoning outside the static type system, or restructuring the code.

We present a type inference algorithm that can improve the performance of existing gradually typed programs without introducing any new run-time failures. To account for dynamic typing, types that flow in to an unknown type are treated in a fundamentally different manner than types that flow out. Furthermore, in the interests of backward-compatibility, an escape analysis is conducted to decide which types are safe to infer. We have implemented our algorithm for ActionScript, and evaluated it on the SunSpider and V8 benchmark suites. We demonstrate that our algorithm can improve the performance of unannotated programs as well as recover most of the type annotations in annotated programs.

Skip Supplemental Material Section

Supplemental Material

popl_7b_2.mp4

mp4

241.4 MB

References

  1. O. Agesen, J. Palsberg, and M.I. Schwartzbach. Type Inference of SELF. ECOOP, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. Aiken, E. L. Wimmers, and T. K. Lakshman. Soft Typing with Conditional Types. In POPL, pages 163--173, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. J. D. An, A. Chaudhuri, J. S. Foster, and M. Hicks. Dynamic Inference of Static Types for Ruby. In POPL, pages 459--472. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. D. Ancona, M. Ancona, A. Cuni, and N. Matsakis. RPython: Reconciling Dynamically and Statically Typed OO Languages. In DLS. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. C. Anderson, P. Giannini, and S. Drossopoulou. Towards Type Inference for JavaScript. In ECOOP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R. Cartwright and M. Fagan. Soft typing. In PLDI, pages 278--292, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. M. Chang, B. Mathiske, E. Smith, A. Chaudhuri, A. Gal, M. Bebenita, C. Wimmer, and M. Franz. The Impact of Optional Type Information on JIT Compilation of Dynamically Typed Languages. In DLS. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. C. Flanagan. Hybrid Type Checking. In POPL, pages 245--256. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. M. Furr, J. D. An, J. S. Foster, and M. Hicks. Profile-Guided Static Typing for Dynamic Scripting Languages. In OOPSLA, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. A. Gal, B. Eich, M. Shaver, D. Anderson, D. Mandelin, M. R. Haghighat, B. Kaplan, G. Hoare, B. Zbarsky, J. Orendorff, J. Ruderman, E. W. Smith, R. Reitmaier, M. Bebenita, M. Chang, and M. Franz. Trace-based just-in-time type specialization for dynamic languages. In PLDI, pages 465--478. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. F. Henglein. Dynamic Typing: Syntax and Proof Theory. Science of Computer Programming, 22 (3): 197 -- 230, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. D. Herman, A. Tomb, and C. Flanagan. Space-Efficient Gradual Typing. Trends in Functional Programming, 2007.Google ScholarGoogle Scholar
  13. C. Moock. Essential ActionScript 3.0. O'Reilly, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. J. Palsberg. Efficient Inference of Object Types. In LICS, pages 186--195. IEEE, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  15. F. Pottier. A Framework for Type Inference with Subtyping. In ICFP, pages 228--238. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. J. Siek and W. Taha. Gradual Typing for Objects. In ECOOP, pages 2--27. Springer-Verlag, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. G. Siek and W. Taha. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop, 2006.Google ScholarGoogle Scholar
  18. J. G. Siek and M. Vachharajani. Gradual Typing with Unification-Based Inference. In DLS, pages 1--12. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. J. G. Siek and P. Wadler. Threesomes, With and Without blame. In POPL, pages 365--376. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. SunSpider Benchmarks, 2010. http://www.webkit.org/perf/sunspider/sunspider.html.Google ScholarGoogle Scholar
  21. P. Thiemann. Towards a Type System for Analyzing JavaScript Programs. In ESOP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Tobin-Hochstadt and M. Felleisen. The Design and Implementation of Typed Scheme. In POPL, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. V8 Benchmarks, 2011. http://code.google.com/apis/v8/benchmarks.html.Google ScholarGoogle Scholar
  24. P. Wadler and R. B. Findler. Well-Typed Programs Can't Be Blamed. In ESOP, pages 1--16. Springer-Verlag, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. A. K. Wright and R. Cartwright. A Practical Soft Type System for Scheme. ACM TOPLAS, 19 (1), 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. T. Wrigstad, F. Z. Nardelli, S. Lebresne, J. Östlund, and J. Vitek. Integrating Typed and Untyped Code in a Scripting Language. In POPL, pages 377--388. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. The ins and outs of gradual type inference

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in
          • Published in

            cover image ACM Conferences
            POPL '12: Proceedings of the 39th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
            January 2012
            602 pages
            ISBN:9781450310833
            DOI:10.1145/2103656
            • cover image ACM SIGPLAN Notices
              ACM SIGPLAN Notices  Volume 47, Issue 1
              POPL '12
              January 2012
              569 pages
              ISSN:0362-1340
              EISSN:1558-1160
              DOI:10.1145/2103621
              Issue’s Table of Contents

            Copyright © 2012 ACM

            Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 25 January 2012

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article

            Acceptance Rates

            Overall Acceptance Rate824of4,130submissions,20%

            Upcoming Conference

            POPL '25

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader