Skip to content

Commit 55a59e0

Browse files
committed
feat: tests
1 parent 9122793 commit 55a59e0

File tree

11 files changed

+420
-342
lines changed

11 files changed

+420
-342
lines changed

libs/@local/hashql/mir/src/pass/analysis/dataflow/liveness/TEST_PLAN.md

Lines changed: 0 additions & 322 deletions
This file was deleted.

libs/@local/hashql/mir/src/pass/analysis/dataflow/liveness/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@
1010
//! - **Kills** (removes from live set): variables that are defined
1111
//! - **Gens** (adds to live set): variables that are used
1212
//!
13+
//! # Analysis Variants
14+
//!
15+
//! This module provides two liveness analyses:
16+
//!
17+
//! - [`LivenessAnalysis`]: Standard liveness following the gen/kill semantics above.
18+
//! - [`TraversalLivenessAnalysis`]: Traversal-aware liveness that suppresses uses of a traversal
19+
//! source when assigning to a known traversal destination.
20+
//!
21+
//! ## Traversal-Aware Liveness
22+
//!
23+
//! When performing traversal extraction, a source local (e.g., `entity`) may have multiple
24+
//! partial projections extracted into separate destination locals (e.g., `entity.uuid`,
25+
//! `entity.name`). Standard liveness would mark `entity` as live at every assignment to these
26+
//! destinations, even though only the projections are needed.
27+
//!
28+
//! [`TraversalLivenessAnalysis`] takes a [`Traversals`] reference and modifies the transfer
29+
//! function: when an assignment's left-hand side is a full definition of a registered traversal
30+
//! destination, uses of the traversal source on the right-hand side are *not* generated.
31+
//!
32+
//! ```text
33+
//! // Given: traversals.source() = _1, traversals.contains(_2) = true
34+
//! bb0:
35+
//! _2 = _1.uuid // Standard: gens _1. Traversal-aware: skips _1 (full def of _2)
36+
//! _3 = _1.name // If _3 not in traversals: gens _1 normally
37+
//! return _2
38+
//! ```
39+
//!
40+
//! This allows dead code elimination to remove the source local when all its uses are through
41+
//! extracted traversals.
42+
//!
1343
//! # Example
1444
//!
1545
//! ```text
@@ -46,6 +76,14 @@ use crate::{
4676
visit::Visitor,
4777
};
4878

79+
/// Traversal-aware liveness analysis.
80+
///
81+
/// Extends standard liveness with special handling for traversal extraction. When the left-hand
82+
/// side of an assignment is a full definition of a traversal destination, uses of the traversal
83+
/// source on the right-hand side are suppressed (not added to the live set).
84+
///
85+
/// This allows subsequent dead code elimination to remove the source local when its only uses
86+
/// are through extracted traversal projections.
4987
pub struct TraversalLivenessAnalysis<'ctx, 'heap> {
5088
pub traversals: &'ctx Traversals<'heap>,
5189
}

0 commit comments

Comments
 (0)