arXiv:2604.26961cs.SEcs.AI2026-04ACL

用预训练+约束解码提升代码切片精度,减少幻觉。

Static Program Slicing Using Language Models With Dataflow-Aware Pretraining and Constrained Decoding

  • 将代码切片转为序列生成任务,用数据流图增强模型依赖理解。
  • 在Java和Python上比现有方法最高提升22%精确匹配率。
  • 适合需要高精度代码分析的开发者与自动化测试场景。

静态程序切片是软件工程中识别特定变量相关代码的基础技术。尽管基于语言模型的最新学习方法在自动化切片预测方面展现出潜力,但仍存在依赖建模不准和生成无约束的问题,导致模型无法准确捕捉数据流关系,并产生包含幻觉词元和语句的切片结果。为此,我们提出Sliceformer,一种基于小型语言模型(如CodeT5+)的新方法,将静态程序切片重构为序列到序列任务。Sliceformer引入两项关键创新:首先,为改进依赖建模,设计了数据流感知的预训练目标,利用数据流图(DFG)通过保持数据流的语句置换和数据流感知的跨度破坏来训练模型;其次,为消除幻觉,开发了一种同时施加词法与语法约束的约束解码机制。我们在Java和Python程序切片基准上评估了Sliceformer,结果显示其在多个指标上持续优于现有最先进基线,最高达到22%的ExactMatch提升。

原文摘要 · Abstract (English)

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.

代码分析语言模型切片约束解码

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。