Affiliation:
1. Epic Systems Corporation, Verona, WI, USA
2. Advanced Technology Labs, Adobe Systems, San Jose, CA, USA
3. University of Maryland, College Park, College Park, MD, USA
Abstract
There have been several efforts to bring static type inference to object-oriented dynamic languages such as Ruby, Python, and Perl. In our experience, however, such type inference systems are extremely difficult to develop, because dynamic languages are typically complex, poorly specified, and include features, such as eval and reflection, that are hard to analyze.
In this paper, we introduce
constraint-based dynamic type inference
, a technique that infers static types based on dynamic program executions. In our approach, we wrap each run-time value to associate it with a type variable, and the wrapper generates constraints on this type variable when the wrapped value is used. This technique avoids many of the often overly conservative approximations of static tools, as constraints are generated based on how values are used during actual program runs. Using wrappers is also easy to implement, since we need only write a constraint resolution algorithm and a transformation to introduce the wrappers. The best part is that we can eat our cake, too: our algorithm will infer sound types as long as it observes every path through each method body---note that the number of such paths may be dramatically smaller than the number of paths through the program as a whole.
We have developed Rubydust, an implementation of our algorithm for Ruby. Rubydust takes advantage of Ruby's dynamic features to implement wrappers as a language library. We applied Rubydust to a number of small programs and found it to be both easy to use and useful: Rubydust discovered 1 real type error, and all other inferred types were correct and readable.
Publisher
Association for Computing Machinery (ACM)
Subject
Computer Graphics and Computer-Aided Design,Software
Cited by
13 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. DyPyBench: A Benchmark of Executable Python Software;Proceedings of the ACM on Software Engineering;2024-07-12
2. Generating Python Type Annotations from Type Inference: How Far Are We?;ACM Transactions on Software Engineering and Methodology;2024-06-03
3. LExecutor: Learning-Guided Execution;Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering;2023-11-30
4. DLInfer: Deep Learning with Static Slicing for Python Type Inference;2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE);2023-05
5. Learning to Predict User-Defined Types;IEEE Transactions on Software Engineering;2023-04-01