Type Inference for Static Compilation of JavaScript

Chandra, Satish, Gordon, Colin S., Jeannin, Jean-Baptiste , Schlesinger, Cole, Sridharan, Manu, Tip, Frank, Choi, Young-Il

Proceedings of the 2016 ACM Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016), November 2016, doi: 10.1145/2983990.2984017

Abstract

We present a type system and inference algorithm for a rich subset of JavaScript equipped with objects, structural subtyping, prototype inheritance, and first-class methods. The type system supports abstract and recursive objects, and is expressive enough to accommodate several standard benchmarks with only minor workarounds. The invariants enforced by the types enable an ahead-of-time compiler to carry out optimizations typically beyond the reach of static compilers for dynamic languages. Unlike previous inference techniques for prototype inheritance, our algorithm uses a combination of lower and upper bound propagation to infer types and discover type errors in all code, including uninvoked functions. The inference is expressed in a simple constraint language, designed to leverage off-the-shelf fixed point solvers. We prove soundness for both the type system and inference algorithm. An experimental evaluation showed that the inference is powerful, handling the aforementioned benchmarks with no manual type annotation, and that the inferred types enable effective static compilation.

Bibtex

@inproceedings{oopsla16,
	author = {Chandra, Satish and Gordon, Colin S. and Jeannin, Jean-Baptiste
	          and Schlesinger, Cole and Sridharan, Manu and Tip, Frank and Choi,
	          Young-Il},
	title = {{Type Inference for Static Compilation of JavaScript}},
	booktitle = {{Proceedings of the 2016 ACM Conference on Object-Oriented
	             Programming, Systems, Languages, and Applications (OOPSLA 2016)}
	             },
	month = {November},
	year = {2016},
	doi = {10.1145/2983990.2984017},
	acm = {https://dl.acm.org/doi/10.1145/2983990.2984017},
	eprint = {1608.07261},
	address = {{Amsterdam, The Netherlands}},
	url = {http://dl.acm.org/citation.cfm?doid=2983990.2984017},
	abstract = { We present a type system and inference algorithm for a rich
	            subset of JavaScript equipped with objects, structural subtyping,
	            prototype inheritance, and first-class methods. The type system
	            supports abstract and recursive objects, and is expressive enough
	            to accommodate several standard benchmarks with only minor
	            workarounds. The invariants enforced by the types enable an
	            ahead-of-time compiler to carry out optimizations typically
	            beyond the reach of static compilers for dynamic languages.
	            Unlike previous inference techniques for prototype inheritance,
	            our algorithm uses a combination of lower and upper bound
	            propagation to infer types and discover type errors in all code,
	            including uninvoked functions. The inference is expressed in a
	            simple constraint language, designed to leverage off-the-shelf
	            fixed point solvers. We prove soundness for both the type system
	            and inference algorithm. An experimental evaluation showed that
	            the inference is powerful, handling the aforementioned benchmarks
	            with no manual type annotation, and that the inferred types
	            enable effective static compilation. },
	note = "Acceptance Rate 25.6\% (52/203).",
}