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 2012 Publication 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.

Supplementary Material

JPG File (popl_7b_2.jpg)
MP4 File (popl_7b_2.mp4)

References

[1]
O. Agesen, J. Palsberg, and M.I. Schwartzbach. Type Inference of SELF. ECOOP, 1993.
[2]
A. Aiken, E. L. Wimmers, and T. K. Lakshman. Soft Typing with Conditional Types. In POPL, pages 163--173, 1994.
[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.
[4]
D. Ancona, M. Ancona, A. Cuni, and N. Matsakis. RPython: Reconciling Dynamically and Statically Typed OO Languages. In DLS. ACM, 2007.
[5]
C. Anderson, P. Giannini, and S. Drossopoulou. Towards Type Inference for JavaScript. In ECOOP, 2005.
[6]
R. Cartwright and M. Fagan. Soft typing. In PLDI, pages 278--292, 1991.
[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.
[8]
C. Flanagan. Hybrid Type Checking. In POPL, pages 245--256. ACM, 2006.
[9]
M. Furr, J. D. An, J. S. Foster, and M. Hicks. Profile-Guided Static Typing for Dynamic Scripting Languages. In OOPSLA, 2009.
[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.
[11]
F. Henglein. Dynamic Typing: Syntax and Proof Theory. Science of Computer Programming, 22 (3): 197 -- 230, 1994.
[12]
D. Herman, A. Tomb, and C. Flanagan. Space-Efficient Gradual Typing. Trends in Functional Programming, 2007.
[13]
C. Moock. Essential ActionScript 3.0. O'Reilly, 2007.
[14]
J. Palsberg. Efficient Inference of Object Types. In LICS, pages 186--195. IEEE, 1994.
[15]
F. Pottier. A Framework for Type Inference with Subtyping. In ICFP, pages 228--238. ACM, 1998.
[16]
J. Siek and W. Taha. Gradual Typing for Objects. In ECOOP, pages 2--27. Springer-Verlag, 2007.
[17]
J. G. Siek and W. Taha. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop, 2006.
[18]
J. G. Siek and M. Vachharajani. Gradual Typing with Unification-Based Inference. In DLS, pages 1--12. ACM, 2008.
[19]
J. G. Siek and P. Wadler. Threesomes, With and Without blame. In POPL, pages 365--376. ACM, 2010.
[20]
SunSpider Benchmarks, 2010. http://www.webkit.org/perf/sunspider/sunspider.html.
[21]
P. Thiemann. Towards a Type System for Analyzing JavaScript Programs. In ESOP, 2005.
[22]
S. Tobin-Hochstadt and M. Felleisen. The Design and Implementation of Typed Scheme. In POPL, 2008.
[23]
V8 Benchmarks, 2011. http://code.google.com/apis/v8/benchmarks.html.
[24]
P. Wadler and R. B. Findler. Well-Typed Programs Can't Be Blamed. In ESOP, pages 1--16. Springer-Verlag, 2009.
[25]
A. K. Wright and R. Cartwright. A Practical Soft Type System for Scheme. ACM TOPLAS, 19 (1), 1997.
[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.

Cited By

View all
  • (2024)QuAC: Quick Attribute-Centric Type Inference for PythonProceedings of the ACM on Programming Languages10.1145/36897838:OOPSLA2(2040-2069)Online publication date: 8-Oct-2024
  • (2024)Type-Based Gradual Typing Performance OptimizationProceedings of the ACM on Programming Languages10.1145/36329318:POPL(2667-2699)Online publication date: 5-Jan-2024
  • (2024)Type-directed operational semantics for gradual typingJournal of Functional Programming10.1017/S095679682400007834Online publication date: 26-Sep-2024
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

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
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]

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 25 January 2012

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. actionscript
  2. gradual typing
  3. type inference

Qualifiers

  • Research-article

Conference

POPL '12
Sponsor:

Acceptance Rates

Overall Acceptance Rate 860 of 4,328 submissions, 20%

Upcoming Conference

POPL '26

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)7
  • Downloads (Last 6 weeks)1
Reflects downloads up to 08 Mar 2025

Other Metrics

Citations

Cited By

View all
  • (2024)QuAC: Quick Attribute-Centric Type Inference for PythonProceedings of the ACM on Programming Languages10.1145/36897838:OOPSLA2(2040-2069)Online publication date: 8-Oct-2024
  • (2024)Type-Based Gradual Typing Performance OptimizationProceedings of the ACM on Programming Languages10.1145/36329318:POPL(2667-2699)Online publication date: 5-Jan-2024
  • (2024)Type-directed operational semantics for gradual typingJournal of Functional Programming10.1017/S095679682400007834Online publication date: 26-Sep-2024
  • (2024)Static Blame for gradual typingJournal of Functional Programming10.1017/S095679682400002934Online publication date: 25-Mar-2024
  • (2024)Gradual Typing Performance, Micro Configurations and Macro PerspectivesTheoretical Aspects of Software Engineering10.1007/978-3-031-64626-3_15(261-278)Online publication date: 29-Jul-2024
  • (2023)How Profilers Can Help Navigate Type MigrationProceedings of the ACM on Programming Languages10.1145/36228177:OOPSLA2(544-573)Online publication date: 16-Oct-2023
  • (2023)How to Evaluate Blame for Gradual Types, Part 2Proceedings of the ACM on Programming Languages10.1145/36078367:ICFP(159-186)Online publication date: 31-Aug-2023
  • (2023)Typed–Untyped Interactions: A Comparative AnalysisACM Transactions on Programming Languages and Systems10.1145/357983345:1(1-54)Online publication date: 5-Mar-2023
  • (2022)Gradual System FJournal of the ACM10.1145/355598669:5(1-78)Online publication date: 28-Oct-2022
  • (2022)C to checked C by 3cProceedings of the ACM on Programming Languages10.1145/35273226:OOPSLA1(1-29)Online publication date: 29-Apr-2022
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media