Skip to main content
QUICK REVIEW

[论文解读] Data-Driven Program Completion

Yanxin Lu, Swarat Chaudhuri|arXiv (Cornell University)|May 25, 2017
Software Engineering Research参考文献 20被引用 11
一句话总结

本文提出程序拼接(program splicing),一种数据驱动的代码合成方法,通过结合程序员提供的草稿(包含不完整代码、注释和测试用例)与包含350万条真实世界Java片段的数据库,实现代码补全的自动化。该方法利用基于相关性的代码片段检索与代码片段的组合枚举,高效完成程序生成,在自动化基准测试和用户研究中均展现出显著的生产力提升。

ABSTRACT

We introduce program splicing, a programming methodology that aims to automate the commonly used workflow of copying, pasting, and modifying code available online. Here, the programmer starts by writing a "draft" that mixes unfinished code, natural language comments, and correctness requirements in the form of test cases or API call sequence constraints. A program synthesizer that interacts with a large, searchable database of program snippets is used to automatically complete the draft into a program that meets the requirements. The synthesis process happens in two stages. First, the synthesizer identifies a small number of programs in the database that are relevant to the synthesis task. Next it uses an enumerative search to systematically fill the draft with expressions and statements from these relevant programs. The resulting program is returned to the programmer, who can modify it and possibly invoke additional rounds of synthesis. We present an implementation of program splicing for the Java programming language. The implementation uses a corpus of over 3.5 million procedures from an open-source software repository. Our evaluation uses the system in a suite of everyday programming tasks, and includes a comparison with a state-of-the-art competing approach as well as a user study. The results point to the broad scope and scalability of program splicing and indicate that the approach can significantly boost programmer productivity.

研究动机与目标

  • 为解决广泛存在但易出错的从在线源代码复制粘贴行为,提供一种有原则的自动化替代方案。
  • 通过支持上下文感知的程序合成,减轻外部代码集成过程中手动修改与调试的负担。
  • 通过利用开源代码库中的真实世界代码作为知识库,提升程序合成的可扩展性与正确性。
  • 支持程序员仅通过自然语言注释和测试用例作为规格说明,完成部分程序的补全,最大限度减少手动工作量。
  • 评估数据驱动合成在真实编程任务中的有效性,并与当前最先进的方法进行比较。

提出的方法

  • 系统接收程序员提供的草稿,其中包含不完整代码、自然语言注释以及正确性约束(如测试用例或API调用序列)。
  • 利用来自开源代码库的350万条Java方法数据库,基于草稿内容检索语义相关的代码片段。
  • 对相关片段进行分析,提取出代码片段(codelets)——即可能填补草稿中代码空缺的可重用表达式与语句。
  • 采用枚举搜索算法,结合启发式方法系统性地组合这些代码片段与草稿,以剪枝搜索空间。
  • 合成过程为迭代式:生成的程序可进一步修改并重新提交,以进行多轮补全。
  • 该方法避免使用统计模型,转而基于真实人类编写的代码进行组合搜索,从而降低生成无意义或语法错误输出的风险。

实验结果

研究问题

  • RQ1基于开源代码库中真实代码片段的数据驱动合成方法,能否有效自动化部分编写程序的补全?
  • RQ2在常见编程任务中,程序拼接与现有先进合成工具(如μScalpel)相比,在性能与可用性方面表现如何?
  • RQ3在真实编程场景中,程序拼接在多大程度上能减少程序员工作量并提升生产力?
  • RQ4使用真实程序中的代码片段作为引导,在多大程度上能有效促进合成过程生成正确且可读的解决方案?
  • RQ5该系统能否在极少规格说明下,处理包括算法修改、GUI开发和组件原型设计在内的多样化编程任务?

主要发现

  • 系统仅使用注释和测试用例作为输入,成功完成了包括算法修改、GUI开发和HTTP服务器原型设计在内的一系列日常编程任务。
  • 与最先进的合成工具μScalpel相比,程序拼接在多样化任务中展现出更广的应用范围和更高的成功率。
  • 用户研究表明,使用程序拼接的开发人员完成任务的速度显著更快,且出错更少,优于传统复制粘贴工作流。
  • 该方法实现了高可扩展性,在包含350万条Java方法的语料库上处理合成任务时延迟极低。
  • 使用生产环境中真实代码生成的代码片段,显著提升了生成程序的可读性与正确性,降低了语义或语法错误的发生概率。
  • 迭代式合成机制支持结果的持续优化,使开发人员能够以最小的返工量逐步改进和适应生成的代码。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。