|
10 | 10 | //! - **Kills** (removes from live set): variables that are defined |
11 | 11 | //! - **Gens** (adds to live set): variables that are used |
12 | 12 | //! |
| 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 | +//! |
13 | 43 | //! # Example |
14 | 44 | //! |
15 | 45 | //! ```text |
@@ -46,6 +76,14 @@ use crate::{ |
46 | 76 | visit::Visitor, |
47 | 77 | }; |
48 | 78 |
|
| 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. |
49 | 87 | pub struct TraversalLivenessAnalysis<'ctx, 'heap> { |
50 | 88 | pub traversals: &'ctx Traversals<'heap>, |
51 | 89 | } |
|
0 commit comments