SeTemAPR: Incorporating Semantic Knowledge in Template-based Neural Program Repair

Yanbo Zhang, Yawen Wang · 2024

Automated program repair has been widely studied in recent years. Template-based and NMT-based program repair methods have achieved promising outcomes. However, template-based methods only consider syntax structure and lack semantic information. NMT-based methods lack type information for variables or functions with the same name in different code snippets. At the same time, studies have also shown that NMT-based methods have the problem of over-reliance on faulty statements. Subsequent studies have integrated templates and NMT by generating templates and key information instead of directly producing repair codes. However, the generated templates do not consider the code semantics, leading to a significant number of failed fixes that lack semantic coherence with the faulty statement. In this paper, we propose SeTemAPR, a template-based neural program repair method that fuses semantic information. Specifically, SeTemAPR proposes semantic embedding to provide type information to variables and functions. Then, SeTemAPR proposes a rule-based semantic filter with an extra loss to learn the semantic differences between input code snippets and selected fix templates. At the same time, we set external placeholders to solve the OOV (out-of-vocabulary) problem and ensure the efficiency of generation. Finally, we train an additional model by masking the faulty statements. We combine the model with an ordinary trained model using a joint inference mechanism to solve the problem of over-reliance on faulty statements. We evaluate SeTemAPR on the widely used benchmark Defects4j. EExperimental results show that SeTemAPR can effectively learn semantic and type information, and repair 6 more faults than the state of the art methods. Meanwhile, we conduct extensive experiments on SeTemAPR to verify its effectiveness.

Read the paper · More papers on PaperTik