Static program slicing is a fundamental software engineering technique for isolating code relevant to specific variables. While recent learning-based approaches using language models (LMs) show promise in automating slice prediction, they suffer from inaccurate dependency modeling and unconstrained generation, where LMs fail to capture precise data flow relations and produce slices containing hallucinated tokens and statements. To address these challenges, we propose Sliceformer, a novel approach that reformulates static program slicing as a sequence-to-sequence task using small language models such as CodeT5+. Sliceformer introduces two key innovations that directly target the identified limitations. First, to improve dependency modeling, we design dataflow-aware pretraining objectives that leverage data flow graphs (DFG) to teach models data dependencies through dataflow-preserving statement permutation and dataflow-aware span corruption. Second, to eliminate hallucination, we develop a constrained decoding mechanism that enforces both lexical and syntactic constraints. We evaluate Sliceformer on Java and Python program slicing benchmarks, demonstrating consistent improvements over state-of-the-art baselines with up to 22% gain in ExactMatch.
翻译:静态程序切片是一种用于隔离与特定变量相关代码的基础软件工程技术。尽管近期基于语言模型的学习方法在自动化切片预测方面展现出潜力,但它们存在依赖关系建模不准确和生成不受约束的问题——语言模型无法精确捕获数据流关系,且生成的切片包含幻觉标记和语句。为应对这些挑战,我们提出Sliceformer——一种创新方法,该方法将静态程序切片重新定义为基于CodeT5+等小型语言模型的序列到序列任务。Sliceformer引入了两项直接针对上述局限性的关键创新。首先,为改进依赖关系建模,我们设计了数据流感知预训练目标,通过利用数据流图进行数据流保持的语句置换和数据流感知的跨度掩码,教导模型学习数据依赖关系。其次,为消除幻觉现象,我们开发了强制词汇和句法约束的约束解码机制。我们在Java和Python程序切片基准上评估Sliceformer,结果表明其相较于现有最优基线方法取得持续改进,ExactMatch指标提升高达22%。