paperbot · PL 论文追踪

全部论文 待读 收藏

P1 NL2Type: Inferring JavaScript Function Types from Natural Language Information

NL2Type:从自然语言信息推断 JavaScript 函数类型
ICSE 2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE)2019匹配度 5/10 · 论文属于利用机器学习改进类型推断/静态分析的 AI→PL 方向,与‘用 LLM/Agent 改进静态分析’有目标上的部分重叠;但其方法是较早期的 LSTM,任务聚焦 JavaScript 函数类型预测,未涉及 LLM/Agent、浮点程序分析或贝叶斯程序分析,因此与研究画像仅有中等关联。引用 136 inbox
Rabee Sohail Malik, Jibesh Patra, Michael Pradel
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:利用注释、函数名与参数名等自然语言信息,以 LSTM 预测 JavaScript 函数类型签名,并可用于检查类型注解一致性。

JavaScript 动态类型语言缺少静态类型安全,导致 IDE 支持不佳、API 难理解与意外运行时行为;Flow、TypeScript 等渐进类型系统依赖开发者手动标注。本文提出 NL2Type,基于学习预测 JavaScript 函数类型签名,核心思想是利用注释、函数名、参数名等常被类型推断算法忽略的自然语言信息。方法将类型预测形式化为分类问题,训练 LSTM 循环神经模型,在带标注代码库上学习后为未标注代码预测函数类型。在 162,673 个真实项目 JavaScript 文件上,top-1 建议精确率 84.1%、召回率 78.9%,top-5 精确率 95.5%、召回率 89.6%,优于 JSNice 与 DeepTyper。NL2Type 还可充当已有类型注解的一致性检查器,在人工分析 50 条警告后发现 39 个值得关注的不一致,多因类型注解错误。

问题
JavaScript 缺少静态类型,而 Flow、TypeScript 等渐进类型系统需开发者手动标注类型,加重负担且容易出错。
方法
将类型预测建模为分类问题,训练基于 LSTM 的循环神经模型,从代码中的注释、函数名和参数名等自然语言信息学习,预测未标注函数的类型签名。
评估
在来自真实项目的 162,673 个 JavaScript 文件语料上评估,报告 top-1 与 top-5 的精确率和召回率,并与 JSNice、DeepTyper 对比;同时将模型用于类型注解一致性检查并人工分析警告。
原文摘要(Abstract)

JavaScript is dynamically typed and hence lacks the type safety of statically typed languages, leading to suboptimal IDE support, difficult to understand APIs, and unexpected runtime behavior. Several gradual type systems have been proposed, e.g., Flow and TypeScript, but they rely on developers to annotate code with types. This paper presents NL2Type, a learning-based approach for predicting likely type signatures of JavaScript functions. The key idea is to exploit natural language information in source code, such as comments, function names, and parameter names, a rich source of knowledge that is typically ignored by type inference algorithms. We formulate the problem of predicting types as a classification problem and train a recurrent, LSTM-based neural model that, after learning from an annotated code base, predicts function types for unannotated code. We evaluate the approach with a corpus of 162,673 JavaScript files from real-world projects. NL2Type predicts types with a precision of 84.1% and a recall of 78.9% when considering only the top-most suggestion, and with a precision of 95.5% and a recall of 89.6% when considering the top-5 suggestions. The approach outperforms both JSNice, a state-of-the-art approach that analyzes implementations of functions instead of natural language information, and DeepTyper, a recent type prediction approach that is also based on deep learning. Beyond predicting types, NL2Type serves as a consistency checker for existing type annotations. We show that it discovers 39 inconsistencies that deserve developer attention (from a manual analysis of 50 warnings), most of which are due to incorrect type annotations.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{MalikPP19,
  title = {NL2Type: Inferring JavaScript Function Types from Natural Language Information},
  author = {Rabee Sohail Malik and Jibesh Patra and Michael Pradel},
  booktitle = {ICSE},
  year = {2019},
  doi = {10.1109/icse.2019.00045}
}