Static Program Slicing Using Language Models With Dataflow-Aware Pretraining and Constrained Decoding
Authors: Pengfei He, Shaowei Wang, Tse-Hsun Chen, Muhammad Asaduzzaman
Organizations: Department of Computer Science, University of Manitoba, Winnipeg, Canada · School of Engineering and Computer Science, Concordia University, Montreal, Canada · School of Computer Science, University of Windsor, Windsor, Canada
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.
Figures & tables
Figure 1: Motivating examples of incorrect program slices produced by LMs.
Figure 2: Illustration of dataflow-aware pre-training objectives. Left: given a snippet, we generate a statement permutation that preserves the dataflow of the original program. Right: we select a variable a with a dataflow chain [X]→a→[Y] , then mask its parent [X] (where it comes from) and child [Y] (where it flows to). The pre-training objective is to recover both [X] and [Y] .
Figure 3: TSED scores at statement boundaries for syntactically correct versus erroneous program slices based on the same input code snippet. The scores are derived from Example (3) in Figure 1 . When a syntactic error is introduced into the generated slice (Line 6), the TSED score deviates from its expected monotonic increasing pattern and instead decreases at the statement boundary.
Methods
Java
Python
Acc-D
ExactMatch
CodeBLEU
TSED
Acc-D
ExactMatch
CodeBLEU
TSED
LLM-based slicer (GPT-4/Zero-shot)
14.76
0.00
20.10
35.53
12.34
0.00
18.45
32.18
LLM-based slicer (GPT-4/RAG)
51.70
0.00
65.18
59.93
48.22
0.00
61.34
56.71
LLM-based slicer (GPT-4/COT)
56.84
0.00
68.41
59.68
53.17
0.00
65.23
57.42
LLM-based slicer (GPT-5/Zero-shot)
18.42
0.00
24.67
39.21
15.78
0.00
22.13
36.54
LLM-based slicer (GPT-5/RAG)
55.13
7.00
68.92
62.45
51.68
11.00
64.77
59.33
Table 1: Effectiveness comparison among different static learning-based program slicing methods.
Figure 4: The ablation analysis results highlight the contribution of each component. A larger performance drop indicates greater importance. We rank the component importance from left to right. Abbreviations: Perm. = statement permutation; Corr. = span corruption; Syn. = syntactic constraint; Lex. = lexical constraint.
Methods
Size
Runtime (per task)
NS-slicer (CodeBERT)
125M
0.105s
NS-slicer (GraphCodeBERT)
125M
0.135s
CodeT5+
770M
0.289s
Sliceformer
770M
0.296s
CodeLlama-7B (SFT)
7B
5.75s
Qwen3-8B (SFT)
8B
6.52s
Table 2: Inference latency comparison among different program slicing methods on Java dataset.
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Java
train
valid
test
Entries
30.8K
3.5K
8.7K
Avg. tokens
64
64
66
Avg. slocs
19
18
19
Python
train
valid
test
Appendix
Table 3: Statistics of the two language datasets
Figure 5: Workflow of constrained decoding
Model
Architecture
Pretraining
Super Fine-tuning
Constrained Decoding
ExactMatch
CodeT5
Encoder–Decoder
×
✓
×
82.80
CodeT5
Encoder–Decoder
✓
✓
✓
85.12
CodeLlama-7B
Decoder-Only
×
✓
×
75.27
CodeLlama-7B
Decoder-Only
×
✓
✓
78.40
Qwen3-8B
Decoder-Only
×
✓
×
80.55
Qwen3-8B
Decoder-Only
×
✓
✓
83.11
Appendix
Table 4: Comparison of transformer architectures and their compatibility with Sliceformer components (Java).
Figure 6: An erroneous example predicted by NS-slicer.
Pre-training on raw code teaches syntax but provides sparse signal for diverse real-world task formats. While synthetic data has proven transformative for language models, code remains largely unexplored beyond limited quality improvements. We present CodeAlchemy, a synthetic data generation framework that transforms publicly sourced code into semantically-rich training data through 5 strategies: CodeEnhance (quality-aware rewriting), CodeQA (template-based problems), CodeDev (developer tasks), CodeDialogue (multi-turn conversations), and CodeTrace (execution traces). We process 3 corpora across 15 languages to generate 500B+ tokens of synthetic data plus 350B reasoning tokens, orders of magnitude more than prior efforts. CodeTrace instruments and executes 1.3M+ files across 14 languages and 5K libraries, capturing control flow, state tracking, and library knowledge. We introduce DevEval (developer tasks) and TraceEval (execution prediction) benchmarks; frontier models like Claude Sonnet 4.5 achieve only 5.6% exact match on TraceEval, revealing critical gaps in semantic understanding. Our 3B models achieve 83.5% on HumanEval, 63.2% on MBPP, 8.09% win rate on DevEval, and 15.36 ROUGE-2 on TraceEval, outperforming frontier models 10x the size including 27B Gemma-3 and 32B Granite-4.0.
Supervised fine-tuning of code LLMs typically applies uniform cross-entropy loss to all response tokens, implicitly assuming that every token provides equally useful learning signals. Recent token-level selection methods challenge this assumption in natural-language SFT by supervising only high-value tokens. However, such pointwise selection can fragment the syntactic structures and program dependencies of code, leaving supervision scattered across incomplete code units. In experiments on 30K code instruction-response pairs, under the same 10% token budget, supervising complete coding blocks improves average performance by 11.7 points over prior approaches that supervise isolated tokens. Motivated by this observation, we propose CodeBlock, a structure-aware sparse supervision framework that uses complete, parser-aligned coding items as the basic units of supervision. CodeBlock constructs coding items from high-quality code instruction data, estimates their supervision utility using GCE, which is more robust to low-probability tokens, and further adjusts their supervision priority using data-flow reach and bridge signals. During training, the full response is retained as context, while loss is applied only to the selected supervision units. Experiments show that partial supervision over only about 6.9% of response tokens consistently outperforms full-token SFT across all five model settings, suggesting that effective code SFT depends not only on identifying high-value supervision, but also on allocating it at the appropriate structural granularity.
Zhijie Deng, Ling Li, Jinlong Pang +5
Hong Kong University of Science and Technology (Guangzhou) · UC Santa Cruz · Ant Group +1
Large Language Models achieve strong code generation for high resource languages like Python and Java but suffer sharp performance drops on Low-Resource Programming Languages~(LRPLs) such as Julia. Improving Small Language Models~(SLMs) for these languages faces a trilemma: Supervised Fine-Tuning~(SFT) is bottlenecked by data scarcity, inference-time scaling is too expensive for deployment, and Reinforcement Learning from scratch yields near zero advantages. We propose a three-phase pipeline that resolves this trilemma by decoupling syntax acquisition from algorithmic reasoning. First, we left-shift inference-time compute to an offline data synthesis engine that uses iterative compiler and test feedback to generate verified training examples. Second, we fine-tune an SLM on this synthetic, verified data to embed strong syntactic priors. Third, we apply Reinforcement Learning with Verifiable Reward~(RLVR) grounded by language-agnostic Input/Output tests, where the SFT prior constrains exploration away from syntax errors. Applied to Qwen3-8B, our pipeline improves pass@1 by up to +7.6 points on MultiPL-E and +14.2 points on the Agnostics LiveCodeBench for Julia compared to SOTA results. Furthermore, the pipeline only used 31 data and 61 cost over the previous state-of-the-art. We further demonstrate that the pipeline generalizes to Ballerina achieving 49.7% MultiPL-E Pass@1, a language with near-zero pretraining representation. Ablations confirm that both the SFT phase and execution-grounded rewards are necessary for stable training.