一句话:V2 用反馈导向搜索检测 Python 代码片段因依赖破坏性变更而产生的配置漂移,并给出修复补丁。
代码片段被广泛使用却难以复用,原因之一是它们往往缺少配套的环境配置,而且大多缺乏维护,使得片段与当前可能的依赖配置之间产生漂移,逐渐过时。已有工作指出,验证并检测过时代码片段是代码复用最重要的考量,但要判定一个片段是“仍然正确、只是过时”并不简单:最好情况下破坏性变更有所记录,最坏情况下则需穷举搜索历史依赖版本。本文提出 V2,通过检测离散的配置漂移实例来判断片段是否过时,即片段使用的 API 后来经历了破坏性变更。每个漂移实例由一个验证阶段遇到的失败以及一个配置补丁(依赖版本变更)来刻画,该补丁可修复底层故障。V2 采用反馈导向搜索探索片段可能的配置空间,从而减少需要验证的潜在环境配置数量。在来自先前研究的公开 Python 片段语料上运行,V2 共识别出 248 个配置漂移实例。
Code snippets are prevalent, but are hard to reuse because they often lack an accompanying environment configuration. Most are not actively maintained, allowing for drift between the most recent possible configuration and the code snippet as the snippet becomes out-of-date over time. Recent work has identified the problem of validating and detecting out-of-date code snippets as the most important consideration for code reuse. However, determining if a snippet is correct, but simply out-of-date, is a non-trivial task. In the best case, breaking changes are well documented, allowing developers to manually determine when a code snippet contains an out-of-date API usage. In the worst case, determining if and when a breaking change was made requires an exhaustive search through previous dependency versions. We present V2, a strategy for determining if a code snippet is out-of-date by detecting discrete instances of configuration drift, where the snippet uses an API which has since undergone a breaking change. Each instance of configuration drift is classified by a failure encountered during validation and a configuration patch, consisting of dependency version changes, which fixes the underlying fault. V2 uses feedback-directed search to explore the possible configuration space for a code snippet, reducing the number of potential environment configurations that need to be validated. When run on a corpus of public Python snippets from prior research, V2 identifies 248 instances of configuration drift.