Program Slicing Techniques
- Program slicing is a technique for extracting code segments relevant to chosen variables or computations, enabling efficient debugging and impact analysis.
- It utilizes data and control dependency models through static, dynamic, and hybrid approaches to identify code that influences specified computation points.
- Modern advances incorporate statistical, incremental, and learning-based methods to enhance precision, scalability, and applicability in diverse software engineering tasks.
Program slicing is a program analysis technique that extracts the subset of a program's statements relevant to a particular computation or property at a given program point, known as the slicing criterion. Slicing isolates the portions of code that may (statically or dynamically) affect, or be affected by, specified variables or values at certain points in the execution or specification of a program. The foundational aim is to support tasks such as debugging, program comprehension, impact analysis, reengineering, and the derivation of software artifacts (specifications, aspects) with precise attention to code relevance and dependency.
1. Formal Definitions and Fundamental Models
Slicing Criterion
A slicing criterion is, in the classical sense, a tuple ⟨ℓ, X⟩ where ℓ is a statement (program point) and X is a set of variables whose values or behavior at ℓ are of interest (Sasirekha et al., 2011, Kumar et al., 2014, Chang et al., 25 Jul 2025, El-Zawawy, 2014). The corresponding formal definition in static slicing is:
A similar formulation holds for dynamic slicing, with "can affect" replaced by "does affect in the concrete run." In specification slicing (as for VDM-SL), the criterion is ⟨o, e⟩ where o is an operation and e an expression node, and slicing extracts exactly those AST nodes that may influence the value of e during any execution of o (Oda et al., 2024).
Types of Slices
- Backward slice: All statements that may influence the criterion.
- Forward slice: All statements that may be influenced by the criterion.
- Static slice: Calculated with respect to all possible executions.
- Dynamic slice: Computed for a specific execution or trace.
- Conditional/quasi-static/abstract slices: Incorporate additional constraints, partial input, or track data abstractions.
Dependency Models
- Data dependency: Statement v data-depends on u if v uses a value last defined at u and no intermediate definition occurs (Sasirekha et al., 2011, Kumar et al., 2014, Shatnawi et al., 2018).
- Control dependency: u is control-dependent on p if execution of u depends on a predicate at p (Sasirekha et al., 2011, Kumar et al., 2014, Shatnawi et al., 2018).
- Program Dependence Graph (PDG): Nodes for statements, edges for data/control dependencies; slices are computed as reachability sets (Kumar et al., 2014, Dziemianczuk, 2014, Shatnawi et al., 2018).
2. Classical Slicing Algorithms and Variations
Static Slicing
Static slicing operates solely on source code, using PDG or SDG (System Dependence Graph for interprocedural analysis). Backward traversal from the slicing criterion along data and control dependence edges collects the slice (Sasirekha et al., 2011, Kumar et al., 2014, Shatnawi et al., 2018). Standard algorithms execute in O(N+E) time per slice, where N is the number of nodes and E the number of edges in the PDG (Kumar et al., 2014, Shatnawi et al., 2018).
Dynamic Slicing
Dynamic slicing records executions and constructs a dynamic dependence graph tracking actual control and data flows (including repeated statement instances from loops), then traverses it backward from the dynamic criterion (Pani et al., 2010, Sasirekha et al., 2011). This leads to highly precise, often markedly smaller, slices at the cost of trace instrumentation and often significant space/time overhead.
Refinements
- Data/Control slices: The data slice retains only computations that affect the criterion values; the control slice only those that affect reachability, yielding much smaller code fragments (Kumar et al., 2014).
- Conditional/quasi-static slices: Conditioning on input or execution predicates permits elimination of infeasible branches and finer slices (Sasirekha et al., 2011).
- Abstract/amorphous slices: Permits non-adjacent, possibly non-syntactic, transformations so long as the observable semantics are preserved, often reducing slices further (Mastroeni et al., 2016, Sasirekha et al., 2011).
Incremental/Symbolic Methods
- Incremental slicing for functional programs precomputes context-independent summaries, using automata or grammars, so future slicing queries can be answered in time proportional to only the demand specification (K. et al., 2017).
- Symbolic slicing (SymPas): Represents slices as parameterized summaries per procedure, enabling efficient context-sensitive, interprocedural slicing without PDG construction (Zhang, 2019).
3. Advances: Hybrid, Statistical, and Learning-Based Slicing
Hybrid Dynamic-Static and Statistical Slicing
Some contemporary approaches combine static analysis with lightweight dynamic or statistical components to balance cost with fidelity. For example, statistical program slicing combines hardware branch tracing (low-overhead control-flow capture), sampled heap memory tracing, and static must-alias analysis over code actually reached in a failure, yielding slices with 94% recall of full dynamic slices but only ~5% runtime overhead in production (Stoica et al., 2021).
Learning-Based Approaches (LLMs and Neural Models)
Recent work recasts slicing as a sequence-to-sequence or discriminative problem for LLMs. Notably, SliceT5 formulates static slicing as token-level sequence transduction, enhanced with copy mechanisms and constrained decoding (lexical and AST-structural constraints), achieving up to 27% higher ExactMatch accuracy than prior neural baselines, and preserving extractivity and dependency fidelity even on incomplete code (He et al., 22 Sep 2025). SliceMate orchestrates multiple LLM "agents" for synthesis, verification, and refinement, reaching F scores above 0.93 and outperforming both graph-based and neural competitors on large multi-file benchmarks (Chang et al., 25 Jul 2025).
However, experimentation with off-the-shelf LLMs (e.g., GPT-4o, Llama-2) reveals limited performance—~60% dependence-accuracy but very low exact match—due to failure to track data/control dependencies, context window limitations, and weaknesses on complex control flow or cross-file reasoning (Shahandashti et al., 2024). Prompt engineering, including chain-of-thought and iterative feedback, can provide modest improvements.
4. Specialized Slicing: Specifications, Legacy Code, Distributed Systems, Neural Architectures
Specification Slicing
The process extends to formal models (e.g., VDM-SL), where slicing aids debugging, maintenance, and refactoring by extracting exactly those parts of a specification that influence a chosen expression or property in an operation/postcondition (Oda et al., 2024). The agenda-driven, reverse AST traversal uses data- and control-dependency relations to build slices that enable pinpointing causes of postcondition failures, supporting modularization, and clarifying specification structure.
Aspect-Oriented and Functional Aspect Slicing
Program slicing, particularly backward static slicing, can extract "functional aspects" as cohesive units in legacy OO codebases, outperforming heuristic aspect miners by guaranteeing completeness and executable independence (Dagenais et al., 2021).
Slicing in Distributed/Region-Oriented Programs
In distributed programs, data slicing partitions code and heap across machines/regions, with the semantics and types preserved per region, using formal inference rules that guarantee soundness via an underlying type system (El-Zawawy, 2014).
Neural Network Slicing
Dynamic slicing adapts to deep neural networks by backpropagating neuron contributions (via activation deviations) from outputs of interest. The resulting "neuron slices" are then used for adversarial detection, model pruning, or selective protection, outperforming baseline path- or channel-based methods (Zhang et al., 2020).
5. Formal Guarantees, Complexity, and Limitations
Formal Properties
- All classical static slices conform to semantic equivalence at the slicing criterion: the values of interest at â„“ are identical in the slice and the original program for all executions (Sasirekha et al., 2011).
- Abstract slicing generalizes these guarantees to properties of values, not just precise values, via upper closure operators as abstractions (Mastroeni et al., 2016).
- In dynamic slicing, Korel–Laski's path-faithful slice and more relaxed variants have distinct complexity: verifying path-faithful dynamic slices is polynomial time, but the existence of minimal dynamic slices is NP-complete; minimal dynamic slices may not be unique (Danicic et al., 2017).
Computational Complexity and Scalability
- Classical static slicing (graph-based) scales as O(N+E) per slice or better (Kumar et al., 2014, Shatnawi et al., 2018).
- Interprocedural and context-sensitive analyses incur greater costs unless symbolic or incremental summary techniques are applied (Zhang, 2019, K. et al., 2017).
- Dynamic slicing instrumentation overhead remains high for full in-field trace capture; hybrid/statistical or sampling methods reduce this, at a cost of small over-approximation (Stoica et al., 2021).
- Learning-based and LLM-driven methods scale via context pruning, retrieval, or constraint-based decoding but remain sensitive to context-window size and fine-tuning.
Limitations
- Over-approximation in static slicing: includes statements not executed in some runs.
- Incomplete support for dynamic features: reflection, dynamic loading, multi-language artifacts, and concurrent/interleaved execution introduce additional complexity (Shatnawi et al., 2018, Chang et al., 25 Jul 2025).
- Environment and run-dependence: dynamic and observation-based slices can vary under different OS/compiler/runtime configurations, motivating techniques such as nVORBS (multi-environment validation) (Binkley et al., 2022).
- LLM-based slice extraction is not yet sufficiently robust for safety-critical or high-complexity codebases, especially with intricate data/control interdependencies or code requiring large context windows (Shahandashti et al., 2024, Chang et al., 25 Jul 2025).
6. Application Domains and Modern Extensions
Debugging, Comprehension, Verification
Slicing has direct applications in isolating bug-relevant code, semantic error analysis, and scalable model checking by reducing code to its relevant fragments (Kumar et al., 2014, Stoica et al., 2021). Control/data slice separation is instrumental in debugging wrong-value vs. wrong-path errors, and abstract slicing localizes influences with respect to properties (e.g., parity, cyclicity) rather than concrete values (Mastroeni et al., 2016).
Software Engineering Workflows
Slicing supports regression testing, change impact analysis, maintenance, refactoring, security auditing (e.g., by focusing on paths leading to vulnerabilities), and code summarization for specification inference and feature extraction (Shatnawi et al., 2018, Sasirekha et al., 2011, Chen et al., 12 Sep 2025).
Large-Scale and Incomplete Code
Graphless or ML-based slicing tools are rapidly advancing slice extraction accuracy and scalability to large multi-file projects, incomplete code snippets, and multi-language settings (Chang et al., 25 Jul 2025, He et al., 22 Sep 2025). Slicing is also being used as a pre-processing step prior to LLM-assisted specification or assertion generation in complex loop structures, vastly improving specification correctness and coverage (Chen et al., 12 Sep 2025).
References:
- (Sasirekha et al., 2011) Program slicing techniques and its applications
- (Kumar et al., 2014) Sliced Slices: Separating Data and Control Influences
- (Danicic et al., 2017) On the computational complexity of dynamic slicing problems for program schemas
- (Shatnawi et al., 2018) A Static Program Slicing Approach for Output Stream Objects in JEE Applications
- (Zhang, 2019) SymPas: Symbolic Program Slicing
- (Zhang et al., 2020) Dynamic Slicing for Deep Neural Networks
- (Dagenais et al., 2021) Slicing functional aspects out of legacy applications
- (Stoica et al., 2021) Statistical Program Slicing: a Hybrid Slicing Technique for Analyzing Deployed Software
- (Binkley et al., 2022) Assessing the Impact of Execution Environment on Observation-Based Slicing
- (Shahandashti et al., 2024) Program Slicing in the Era of LLMs
- (Oda et al., 2024) Specification Slicing for VDM-SL
- (Chang et al., 25 Jul 2025) SLICEMATE: Accurate and Scalable Static Program Slicing via LLM-Powered Agents
- (Chen et al., 12 Sep 2025) SLD-Spec: Enhancement LLM-assisted Specification Generation for Complex Loop Functions via Program Slicing and Logical Deletion
- (He et al., 22 Sep 2025) SLICET5: Static Program Slicing using LLMs with Copy Mechanism and Constrained Decoding
- (Mastroeni et al., 2016) Abstract Program Slicing: an Abstract Interpretation-based approach to Program Slicing
- (K. et al., 2017) An Incremental Slicing Method for Functional Programs
- (El-Zawawy, 2014) Distributed Data and Programs Slicing