Taming Type Annotations in Gradual Typing

被引:6
作者
Campora, John Peter [1 ]
Chen, Sheng [1 ]
机构
[1] Univ Louisiana Lafayette, CACS, Lafayette, LA 70504 USA
来源
PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL | 2020年 / 4卷 / 04期
基金
美国国家科学基金会;
关键词
gradual typing; case errors; variational Types; INFERENCE;
D O I
10.1145/3428259
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Gradual typing provides a methodology to integrate static and dynamic typing, harmonizing their often conflicting advantages in a single language. When a user wants to enjoy the advantages of static typing, most gradual languages require that they add type annotations. Many nontrivial tasks must be undertaken while adding type annotations, including understanding program behaviors and invariants. Unfortunately, if this is done incorrectly then the added type annotations can be wrong leading to inconsistencies between the program and the type annotations. Gradual typing implementations detect such inconsistencies at runtime, raise cast errors, and generate messages. However, solely relying on such error messages for understanding and fixing inconsistencies and their resulting cast errors is often insufficient for multiple reasons. One reason is that while such messages cover inconsistencies in one execution path, fixing them often requires reconciling information from multiple paths. Another is that users may add many wrong type annotations that they later find difficult to identify and fix, when considering all added annotations. Recent studies provide evidence that type annotations added during program migration are often wrong and that many programmers prefer compile-time warnings about wrong annotations. Motivated by these results, we develop exploratory typing to help with the static detection, understanding, and fixing of inconsistencies. The key idea of exploratory typing is that it systematically removes dynamic types and explores alternative types for static type annotations that can remedy inconsistencies. To demonstrate the feasibility of exploratory typing, we have implemented it in PYHOUND, which targets programs written in Reticulated Python, a gradual variant of Python. We have evaluated PYHOUND on a set of Python programs, and the evaluation results demonstrate that our idea can effectively detect inconsistencies in 98% of the tested programs and fix 93% of inconsistencies, significantly outperforming pytype, a widely used Python tool for enforcing type annotations.
引用
收藏
页数:30
相关论文
共 57 条
  • [31] Hybrid Type Checking
    Knowles, Kenneth
    Flanagan, Cormac
    [J]. ACM TRANSACTIONS ON PROGRAMMING LANGUAGES AND SYSTEMS, 2010, 32 (02):
  • [32] Type test scripts for TypeScript testing
    Méller A.
    Kristensen E.K.
    [J]. Proceedings of the ACM on Programming Languages, 2017, 1 (OOPSLA)
  • [33] Inference and Evolution of TypeScript Declaration Files
    Kristensen, Erik Krogh
    Moller, Anders
    [J]. FUNDAMENTAL APPROACHES TO SOFTWARE ENGINEERING, FASE 2017, 2017, 10202 : 99 - 115
  • [34] Gradual Refinement Types
    Lehmann, Nico
    Tanter, Eric
    [J]. ACM SIGPLAN NOTICES, 2017, 52 (01) : 775 - 788
  • [35] Soft Contract Verification
    Nguyen, Phuc C.
    Tobin-Hochstadt, Sam
    Van Horn, David
    [J]. ICFP'14: PROCEEDINGS OF THE 2014 ACM SIGPLAN INTERNATIONAL CONFERENCE ON FUNCTIONAL PROGRAMMING, 2014, : 139 - 152
  • [36] Ningning Xie, 2018, Programming Languages and Systems. 27th European Symposium on Programming, ESOP 2018, held as part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2018. Proceedings: LNCS 10801, P3, DOI 10.1007/978-3-319-89884-1_1
  • [37] Gradual type-and-effect systems
    Schwerter, Felipe Banados
    Garcia, Ronald
    Tanter, Eric
    [J]. JOURNAL OF FUNCTIONAL PROGRAMMING, 2016, 26 : 1 - 66
  • [38] Sergey I, 2012, LECT NOTES COMPUT SC, V7211, P579, DOI 10.1007/978-3-642-28869-2_29
  • [39] Siek J.G., 2015, 1 SUMM ADV PROGR LAN
  • [40] Siek J.G., 2008, Proceedings of the 2008 symposium on Dynamic languages, P7, DOI DOI 10.1145/1408681.1408688