Abstract
In this paper we present the design and implementation of Flow, a fast and precise type checker for JavaScript that is used by thousands of developers on millions of lines of code at Facebook every day. Flow uses sophisticated type inference to understand common JavaScript idioms precisely. This helps it find non-trivial bugs in code and provide code intelligence to editors without requiring significant rewriting or annotations from the developer. We formalize an important fragment of Flow's analysis and prove its soundness. Furthermore, Flow uses aggressive parallelization and incrementalization to deliver near-instantaneous response times. This helps it avoid introducing any latency in the usual edit-refresh cycle of rapid JavaScript development. We describe the algorithms and systems infrastructure that we built to scale Flow's analysis.
- Alexander Aiken and Edward L. Wimmers. 1992. Solving systems of set constraints. Proceedings of the Seventh Annual IEEE Symposium on Logic in Computer Science (1992), 329–340. http://ieeexplore.ieee.org/lpdocs/epic03/wrapper.htm? arnumber=185545Google Scholar
- Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994. Soft Typing with Conditional Types. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’94). ACM, New York, NY, USA, 163–173. Google Scholar
Digital Library
- Davide Ancona and Andrea Corradi. 2016. Semantic subtyping for imperative object-oriented languages. Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications -OOPSLA 2016, 568–587. Google Scholar
Digital Library
- Christopher Anderson, Paola Giannini, and Sophia Drossopoulou. 2005. Towards Type Inference for Javascript. In Proceedings of the 19th European Conference on Object-Oriented Programming (ECOOP’05). Springer-Verlag, Berlin, Heidelberg, 428– 452. Google Scholar
Digital Library
- Esben Andreasen and Anders Møller. 2014. Determinacy in Static Analysis for jQuery. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications (OOPSLA ’14). ACM, New York, NY, USA, 17–31. Google Scholar
Digital Library
- Gavin Bierman, Martín Abadi, and Mads Torgersen. 2014. Understanding TypeScript. In ECOOP 2014 – Object-Oriented Programming: 28th European Conference, Uppsala, Sweden, July 28 – August 1, 2014. Proceedings, Richard Jones (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 257–281. Google Scholar
Digital Library
- Giuseppe Castagna and Victor Lanvin. 2017. Gradual Typing with Union and Intersection Types. In Proceedings of ICFP. Google Scholar
Digital Library
- Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyen. 2016. Set-theoretic Types for Polymorphic Variants. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). ACM, New York, NY, USA, 378–391. Google Scholar
Digital Library
- Satish Chandra, Colin S. Gordon, Jean-Baptiste Jeannin, Cole Schlesinger, Manu Sridharan, Frank Tip, and Youngil Choi. 2016. Type Inference for Static Compilation of JavaScript. In Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016). ACM, New York, NY, USA, 410–429. Google Scholar
Digital Library
- Avik Chaudhuri, Panagiotis Vekris, Sam Goldman, Marshall Roch, and Gabriel Levi. 2017. Fast and Precise Type Checking for JavaScript (Extended version). https://arxiv.org/abs/1708.08021 . (2017).Google Scholar
- Wontae Choi, Satish Chandra, George C. Necula, and Koushik Sen. 2015. SJS: A Type System for JavaScript with Fixed Object Layout. In SAS (Lecture Notes in Computer Science), Vol. 9291. Springer, 181–198. Google Scholar
Cross Ref
- Ravi Chugh, David Herman, and Ranjit Jhala. 2012. Dependent Types for JavaScript. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’12). ACM, New York, NY, USA, 587–606. Google Scholar
Digital Library
- Closure. 2009. Closure Compiler. https://developers.google.com/closure/compiler/ . (2009). Accessed: 2016-11-15.Google Scholar
- Yann Collet. 2011. LZ4-Extremely fast compression. (2011). https://github.com/lz4/lz4 .Google Scholar
- Dart. 2011. Dart Language Specification. https://www.dartlang.org/guides/language/spec . (2011). Accessed: 2016-11-15.Google Scholar
- Stephen Dolan and Alan Mycroft. 2017. Polymorphism, Subtyping, and Type Inference in MLsub. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages - POPL 2017. ACM Press, New York, New York, USA, 60–72.Google Scholar
Digital Library
- Jonathan Eifrig, Scott Smith, and Valery Trifonov. 1995. Sound Polymorphic Type Inference for Objects. SIGPLAN Not. 30, 10 (Oct. 1995), 169–184. Google Scholar
Digital Library
- Manuel Fähndrich and Alex Aiken. 1996. Making Set-Constraint Program Analyses Scale. Technical Report. Berkeley, CA, USA.Google Scholar
- Manuel Fähndrich, Jeffrey S. Foster, Zhendong Su, and Alexander Aiken. 1998. Partial Online Cycle Elimination in Inclusion Constraint Graphs. In Proceedings of the ACM SIGPLAN 1998 Conference on Programming Language Design and Implementation (PLDI ’98). ACM, New York, NY, USA, 85–96. Google Scholar
Digital Library
- Cormac Flanagan. 1997. Effective Static Debugging via Componential Set-Based Analysis. Ph.D. Dissertation. Rice University.Google Scholar
- Cormac Flanagan and Matthias Felleisen. 1999. Componential Set-based Analysis. ACM Trans. Program. Lang. Syst. 21, 2 (March 1999), 370–416. Google Scholar
Digital Library
- Alain Frisch, Giuseppe Castagna, and Véronique Benzaken. 2008. Semantic Subtyping: Dealing Set-theoretically with Function, Union, Intersection, and Negation Types. J. ACM 55, 4, Article 19 (Sept. 2008), 64 pages.Google Scholar
Digital Library
- Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. 2011. Typing Local Control and State Using Flow Analysis. In Proceedings of the 20th European Conference on Programming Languages and Systems: Part of the Joint European Conferences on Theory and Practice of Software (ESOP’11/ETAPS’11). Springer-Verlag, Berlin, Heidelberg, 256–275. Google Scholar
Cross Ref
- Hack. 2014. Hack Language Specification. https://github.com/hhvm/hack-langspec . (2014). Accessed: 2016-11-15.Google Scholar
- Thomas S. Heinze, Anders Møller, and Fabio Strocco. 2016. Type Safety Analysis for Dart. In Proceedings of the 12th Symposium on Dynamic Languages (DLS 2016). ACM, New York, NY, USA, 1–12. Google Scholar
Digital Library
- Simon Holm Jensen, Magnus Madsen, and Anders Møller. 2011. Modeling the HTML DOM and Browser API in Static Analysis of JavaScript Web Applications. In Proceedings of the 19th ACM SIGSOFT Symposium and the 13th European Conference on Foundations of Software Engineering (ESEC/FSE ’11). ACM, New York, NY, USA, 59–69. Google Scholar
Digital Library
- Simon Holm Jensen, Anders Møller, and Peter Thiemann. 2009. Type analysis for JavaScript. Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics) 5673 LNCS (2009), 238–255.Google Scholar
Digital Library
- Simon Holm Jensen, Anders Møller, and Peter Thiemann. 2010. Interprocedural Analysis with Lazy Propagation. In Proceedings of the 17th International Conference on Static Analysis (SAS’10). Springer-Verlag, Berlin, Heidelberg, 320–339. Google Scholar
Cross Ref
- Vineeth Kashyap, Kyle Dewey, Ethan A. Kuefner, John Wagner, Kevin Gibbons, John Sarracino, Ben Wiedermann, and Ben Hardekopf. 2014. JSAI: A Static Analysis Platform for JavaScript. In Proceedings of the 22Nd ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2014). ACM, New York, NY, USA, 121–132.Google Scholar
Digital Library
- Hongki Lee, Sooncheol Won, Joonho Jin, Junhee Cho, and Sukyoung Ryu. 2012. SAFE: Formal specification and implementation of a scalable analysis framework for ECMAScript. In International Workshop on Foundations of Object-Oriented Languages (FOOL), Vol. 10.Google Scholar
- Benjamin S. Lerner, Joe Gibbs Politz, Arjun Guha, and Shriram Krishnamurthi. 2013. TeJaS: Retrofitting Type Systems for JavaScript. Proceedings of the 9th symposium on Dynamic languages - DLS ’13, 1–16.Google Scholar
Digital Library
- Changhee Park and Sukyoung Ryu. 2015. Scalable and Precise Static Analysis of JavaScript Applications via LoopSensitivity. In 29th European Conference on Object-Oriented Programming (ECOOP 2015) (Leibniz International Proceedings in Informatics (LIPIcs)), John Tang Boyland (Ed.), Vol. 37. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany, 735–756.Google Scholar
- François Pottier. 1998. Type Inference in the Presence of Subtyping: from Theory to Practice. Research Report 3483. INRIA. http://hal.inria.fr/docs/00/07/32/05/PDF/RR-3483.pdfGoogle Scholar
- François Pottier. 2001. Simplifying Subtyping Constraints: a Theory. Information & Computation 170, 2 (Nov. 2001), 153–183.Google Scholar
- Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin Bierman, and Panagiotis Vekris. 2015. Safe & Efficient Gradual Typing for TypeScript. In Proceedings of the 42Nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). ACM, New York, NY, USA, 167–180.Google Scholar
Digital Library
- Patrick M. Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid Types. In Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’08). ACM, New York, NY, USA, 159–169. Google Scholar
Digital Library
- Frederick Smith, David Walker, and J. Gregory Morrisett. 2000. Alias Types. In Proceedings of the 9th European Symposium on Programming Languages and Systems (ESOP ’00). Springer-Verlag, London, UK, UK, 366–381. Google Scholar
Cross Ref
- Zhendong Su, Alexander Aiken, Joachim Niehren, Tim Priesnitz, and Ralf Treinen. 2002. The First-order Theory of Subtyping Constraints. In Proceedings of the 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’02). ACM, New York, NY, USA, 203–216. Google Scholar
Digital Library
- Zhendong Su, Manuel Fähndrich, and Alexander Aiken. 2000. Projection Merging: Reducing Redundancies in Inclusion Constraint Graphs. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’00). ACM, New York, NY, USA, 81–95. Google Scholar
Digital Library
- Peter Thiemann. 2005. Towards a Type System for Analyzing Javascript Programs. In Proceedings of the 14th European Conference on Programming Languages and Systems (ESOP’05). Springer-Verlag, Berlin, Heidelberg, 408–422. Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’08). ACM, New York, NY, USA, 395–406. Google Scholar
Digital Library
- Valery Trifonov and Scott Smith. 1996. Subtyping Constrained Types. SAS ’96: Proceedings of the 3rd International Symposium on Static Analysis (1996), 349–365.Google Scholar
- TypeScript. 2012. TypeScript Design Goals. https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals . (2012). Accessed: 2016-11-15.Google Scholar
- Dimitris Vardoulakis. 2012. CFA2: Pushdown Flow Analysis for Higher-Order Languages. Ph.D. Dissertation. Northeastern University.Google Scholar
- Panagiotis Vekris, Benjamin Cosman, and Ranjit Jhala. 2016. Refinement Types for TypeScript. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’16). ACM, New York, NY, USA, 310–325. Google Scholar
Digital Library
- A.K. Wright and M. Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput. 115, 1 (Nov. 1994), 38–94. Google Scholar
Digital Library
Index Terms
Fast and precise type checking for JavaScript
Recommendations
Type refinement for static analysis of JavaScript
DLS '13: Proceedings of the 9th symposium on Dynamic languagesStatic analysis of JavaScript has proven useful for a variety of purposes, including optimization, error checking, security auditing, program refactoring, and more. We propose a technique called type refinement that can improve the precision of such ...
Type Checking for JavaScript
JavaScript is a powerful imperative object based language made popular by its use in web pages. It supports flexible program development by allowing dynamic addition of members to objects. Code is dynamically typed: a runtime access to a non-existing ...






Comments