TypeWriter: Neural Type Prediction with Search-based Validation

12/08/2019
by   Michael Pradel, et al.
0

Maintaining large code bases written in dynamically typed languages, such as JavaScript or Python, can be challenging: simple data compatibility errors proliferate, IDE support is lacking and APIs are harder to comprehend. Recent work attempts to address those issues through either static analysis or probabilistic type inference. 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 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 500 popular open-source projects. We show that TypeWriter's type predictor achieves a precision of 64 recall of 52 usage contexts are a helpful addition to neural type predictors. By combining predictions with search-based validation, TypeWriter can fully annotate between 42 correctness. A comparison with a static type inference tool shows that TypeWriter adds many more non-trivial types. Overall, TypeWriter provides developers with an effective way to help with the transition to fully type-annotated code.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
07/18/2023

Generative Type Inference for Python

Python is a popular dynamic programming language, evidenced by its ranki...
research
07/05/2018

Gradual Liquid Type Inference

Liquid typing provides a decidable refinement inference mechanism that i...
research
12/02/2019

DLTPy: Deep Learning Type Inference of Python Function Signatures using Natural Language Context

Due to the rise of machine learning, Python is an increasingly popular p...
research
02/15/2023

Path-sensitive Type Analysis with Backward Analysis for Quality Assurance of Dynamic Typed Language Code

Precise and fast static type analysis for dynamically typed language is ...
research
03/16/2023

TypeT5: Seq2seq Type Inference using Static Analysis

There has been growing interest in automatically predicting missing type...
research
05/09/2022

Static Analysis for AWS Best Practices in Python Code

Amazon Web Services (AWS) is a comprehensive and broadly adopted cloud p...
research
01/11/2023

Enhancing Comprehension and Navigation in Jupyter Notebooks with Static Analysis

Jupyter notebooks enable developers to interleave code snippets with ric...

Please sign up or login with your details

Forgot password? Click here to reset