Automated Program Repair (APR) improves software reliability by generating patches for a buggy program automatically. Recent APR techniques leverage deep learning (DL) to build models to learn to generate patches from existing patches and code corpora. While promising, DL-based APR techniques suffer from the abundant syntactically or semantically incorrect patches in the patch space. These patches often disobey the syntactic and semantic domain knowledge of source code and thus cannot be the correct patches to fix a bug. We propose a DL-based APR approach KNOD, which incorporates domain knowledge to guide patch generation in a direct and comprehensive way. KNOD has two major novelties, including (1) a novel three-stage tree decoder, which directly generates Abstract Syntax Trees of patched code according to the inherent tree structure, and (2) a novel domain-rule distillation, which leverages syntactic and semantic rules and teacher-student distributions to explicitly inject the domain knowledge into the decoding procedure during both the training and inference phases. We evaluate KNOD on three widely-used benchmarks. KNOD fixes 72 bugs on the Defects4J v1.2, 25 bugs on the QuixBugs, and 50 bugs on the additional Defects4J v2.0 benchmarks, outperforming all existing APR tools.
翻译:摘要:自动程序修复(APR)通过自动生成补丁来修复缺陷程序,从而提高软件可靠性。现有APR技术利用深度学习构建模型,从历史补丁和代码语料库中学习生成补丁。尽管前景可观,但基于深度学习的APR方法受限于补丁空间中大量语法或语义错误的补丁。这些补丁通常违反源代码的语法和语义领域知识,因此无法成为修复缺陷的正确补丁。本文提出一种基于深度学习的APR方法KNOD,以直接且全面的方式融入领域知识来指导补丁生成。KNOD具有两大创新点:(1)一种新颖的三阶段树解码器,根据代码的固有树结构直接生成修补后的抽象语法树;(2)一种新颖的领域规则蒸馏方法,利用语法规则、语义规则以及师生分布,在训练和推理阶段将领域知识显式注入解码过程。我们在三个广泛使用的基准测试上评估KNOD。在Defects4J v1.2上修复72个缺陷,在QuixBugs上修复25个缺陷,在额外添加的Defects4J v2.0基准测试上修复50个缺陷,其性能优于所有现有APR工具。