Type Inference for Static Compilation of JavaScript (Extended Version)

Satish Chandra, Colin S. Gordon, Jean-Baptiste Jeannin, Cole Schlesinger, Manu Sridharan +2 more
8/25/2016
42 citations
cs.PL

Official code: Samsung/SJS (48 stars, Java, Apache-2.0, last commit 2023-04-07).

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.

Show full abstract

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.

View on arXivView PDF

Code Implementations(1)

Samsung/SJSOfficial100%
Apache-2.0

SJS is a static ahead of time compiler for a subset of JavaScript

487Java, JavaScriptOct 17, 20163 years agoApache-2.0

Similar Papers

Cite this paper

@article{chandra2016type,
  title  = {Type Inference for Static Compilation of JavaScript (Extended Version)},
  author = {Satish Chandra and Colin S. Gordon and Jean-Baptiste Jeannin and Cole Schlesinger and Manu Sridharan and Frank Tip and Youngil Choi},
  year   = {2016},
  eprint = {1608.07261},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1608.07261}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1608.07261.svg)](https://codeofpaper.com/paper/1608.07261)

Discussion