arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2204.02787cs.SE
收藏

DiffSearch:一个可扩展的、精确的代码更改搜索引擎

DiffSearch: A Scalable and Precise Search Engine for Code Changes

Luca Di Grazia, Paul Bredl, Michael Pradel

摘要:

成功的项目的源代码一直在不断发展,导致成千上万的代码更改存储在源代码存储库中。这些丰富的数据可能是有用的,例如,查找与计划的代码更改相似的更改或重复代码改进的示例。本文介绍了DiffSearch,一个搜索引擎,给定一个查询,描述了一个代码的变化,返回一组匹配的查询的变化。这一方法得益于三个关键贡献。首先,我们提出了一个查询语言,扩展了底层的编程语言与通配符和占位符,提供了一个直观的方式制定查询,很容易适应不同的程序设计语言。其次,为了确保可扩展性,该方法在一次性预处理步骤中索引代码更改,将其映射到特征空间中,然后在特征空间中为每个查询执行有效的搜索。第三,保证精度,即,任何返回的代码变化确实匹配给定的查询,我们提出了一个基于树的匹配算法,检查是否可以扩展到一个具体的代码变化的查询。我们提出了Java,JavaScript和Python的实现,并表明该方法在几秒钟内响应查询超过一百万个代码更改,具有80.7%的Java,89.6%的Python和90.4%的JavaScript的召回,使用户能够找到相关的代码更改更有效地比基于正则表达式的搜索,并且有助于收集真实世界错误修复的大规模数据集。

英文摘要:

The source code of successful projects is evolving all the time, resulting in hundreds of thousands of code changes stored in source code repositories. This wealth of data can be useful, e.g., to find changes similar to a planned code change or examples of recurring code improvements. This paper presents DiffSearch, a search engine that, given a query that describes a code change, returns a set of changes that match the query. The approach is enabled by three key contributions. First, we present a query language that extends the underlying programming language with wildcards and placeholders, providing an intuitive way of formulating queries that is easy to adapt to different programming languages. Second, to ensure scalability, the approach indexes code changes in a one-time preprocessing step, mapping them into a feature space, and then performs an efficient search in the feature space for each query. Third, to guarantee precision, i.e., that any returned code change indeed matches the given query, we present a tree-based matching algorithm that checks whether a query can be expanded to a concrete code change. We present implementations for Java, JavaScript, and Python, and show that the approach responds within seconds to queries across one million code changes, has a recall of 80.7% for Java, 89.6% for Python, and 90.4% for JavaScript, enables users to find relevant code changes more effectively than a regular expression-based search, and is helpful for gathering a large-scale dataset of real-world bug fixes.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑