The development of correct and efficient software can be hindered by compilation errors, which must be fixed to ensure the code's syntactic correctness and program language constraints. Neural network-based approaches have been used to tackle this problem, but they lack guarantees of output correctness and can require an unlimited number of modifications. Fixing compilation errors within a given number of modifications is a challenging task. We demonstrate that finding the minimum number of modifications to fix a compilation error is NP-hard. To address compilation error fixing problem, we propose OrdinalFix, a complete algorithm based on shortest-path CFL (context-free language) reachability with attribute checking that is guaranteed to output a program with the minimum number of modifications required. Specifically, OrdinalFix searches possible fixes from the smallest to the largest number of modifications. By incorporating merged attribute checking to enhance efficiency, the time complexity of OrdinalFix is acceptable for application. We evaluate OrdinalFix on two datasets and demonstrate its ability to fix compilation errors within reasonable time limit. Comparing with existing approaches, OrdinalFix achieves a success rate of 83.5%, surpassing all existing approaches (71.7%).
翻译:正确且高效软件的开发常因编译错误受阻,这些错误需被修复以确保代码的语法正确性和程序语言约束。基于神经网络的方法已被用于解决该问题,但此类方法缺乏输出正确性的保障,且可能需要无限次修改。在给定修改次数内修复编译错误是一项具有挑战性的任务。我们证明,找到修复编译错误所需的最小修改次数是NP难的。为解决编译错误修复问题,我们提出OrdinalFix——一种基于带属性检查的最短路径CFL(上下文无关语言)可达性的完备算法,该算法保证输出所需修改次数最少的程序。具体而言,OrdinalFix从最少修改次数到最多修改次数搜索可能的修复方案。通过引入合并属性检查以提升效率,OrdinalFix的时间复杂度在应用层面可被接受。我们在两个数据集上评估了OrdinalFix,并证明其能在合理时间限制内修复编译错误。与现有方法相比,OrdinalFix的成功率达到83.5%,超越了所有现有方法(71.7%)。