TypeWriter: Neural Type Prediction with Search-Based Validation

Michael Pradel, Georgios Gousios, Jason Liu, Satish Chandra

Research output: Chapter in Book/Conference proceedings/Edited volumeConference contributionScientificpeer-review

1 Citation (Scopus)
3 Downloads (Pure)

Abstract

Maintaining large code bases written in dynamically typed languages, such as JavaScript or Python, can be challenging due to the absence of type annotations: simple data compatibility errors proliferate, IDE support is limited, and APIs are hard to comprehend. Recent work attempts to address those issues through either static type inference or probabilistic type prediction. Unfortunately, static type inference for dynamic languages is inherently limited, while probabilistic approaches suffer from imprecision. This paper presents TypeWriter, the first combination of probabilistic type prediction with search-based refinement of predicted types. TypeWriter’s predictor learns to infer the return and argument types for functions from partially annotated code bases by combining the natural language properties of code with programming language-level information. To validate predicted types, TypeWriter invokes a gradual type checker with different combinations of the predicted types, while navigating the space of possible type combinations in a feedback-directed manner. We implement the TypeWriter approach for Python and evaluate it on two code corpora: a multi-million line code base at Facebook and a collection of 1,137 popular open-source projects. We show that TypeWriter’s type predictor achieves an F1 score of 0.64 (0.79) in the top-1 (top-5) predictions for return types, and 0.57 (0.80) for argument types, which clearly outperforms prior type prediction models. By combining predictions with search-based validation, TypeWriter can fully annotate between 14% to 44% of the files in a randomly selected corpus, while ensuring type correctness. A comparison with a static type inference tool shows that TypeWriter adds many more non-trivial types. TypeWriter currently suggests types to developers at Facebook and several thousands of types have already been accepted with minimal changes.
Original languageEnglish
Title of host publicationProceedings of the 28th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering
EditorsPrem Devanbu, Myra Cohen, Thomas Zimmermann
Place of PublicationNew York, NY, USA
PublisherAssociation for Computing Machinery (ACM)
Pages209–220
Number of pages12
ISBN (Electronic)9781450370431
ISBN (Print)9781450370431
DOIs
Publication statusPublished - 2020
EventESEC/FSE 2020: ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering - Sacramento, United States
Duration: 8 Nov 202013 Nov 2020

Publication series

NameESEC/FSE 2020
PublisherAssociation for Computing Machinery

Conference

ConferenceESEC/FSE 2020: ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering
Abbreviated titleESEC/FSE 2020
CountryUnited States
CitySacramento
Period8/11/2013/11/20

Keywords

  • Machine learning models of code
  • Type annotations

Fingerprint Dive into the research topics of 'TypeWriter: Neural Type Prediction with Search-Based Validation'. Together they form a unique fingerprint.

Cite this