在野外挖掘成语
Mining Idioms in the Wild
摘要:
现有的代码存储库包含大量的代码模式实例,这些代码模式是完成特定编程任务的惯用方法。有时,所使用的程序设计语言支持特定的运算符或API,这些运算符或API可以更简洁地表达相同的惯用命令式代码。然而,这些代码模式仍然存在于存储库中,因为开发人员可能不知道新的API,或者还没有找到它们。对惯用代码的检测也可以指出对新API的需求。我们分享我们在Facebook的Hack repo中挖掘惯用模式的经验。我们发现,现有的技术要么不能识别有意义的模式,从语法树或需要测试套件为基础的动态分析,将语义属性挖掘有用的模式。本文提出的方法\emph{Jezero}的关键见解是,可以从\emph{canonicalized}树中学习来自大型代码库的语义习语。我们提出了一个可扩展的,轻量级的静态分析为基础的方法来构建这样一个树,非常适合使用非参数贝叶斯方法挖掘语义成语。我们在Hack代码上使用Jezero的实验显示了向AST添加规范化的XML信息的明显优势:\emph{Jezero}比没有XML增强的基线更有效,能够有效地从未注释的遗留代码中找到重构机会。
英文摘要:
Existing code repositories contain numerous instances of code patterns that are idiomatic ways of accomplishing a particular programming task. Sometimes, the programming language in use supports specific operators or APIs that can express the same idiomatic imperative code much more succinctly. However, those code patterns linger in repositories because the developers may be unaware of the new APIs or have not gotten around to them. Detection of idiomatic code can also point to the need for new APIs. We share our experiences in mine idiomatic patterns from the Hack repo at Facebook. We found that existing techniques either cannot identify meaningful patterns from syntax trees or require test-suite-based dynamic analysis to incorporate semantic properties to mine useful patterns. The key insight of the approach proposed in this paper -- \emph{Jezero} -- is that semantic idioms from a large codebase can be learned from \emph{canonicalized} dataflow trees. We propose a scalable, lightweight static analysis-based approach to construct such a tree that is well suited to mine semantic idioms using nonparametric Bayesian methods. Our experiments with Jezero on Hack code shows a clear advantage of adding canonicalized dataflow information to ASTs: \emph{Jezero} was significantly more effective than a baseline that did not have the dataflow augmentation in being able to effectively find refactoring opportunities from unannotated legacy code.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。