@@ -29,7 +29,7 @@ pub(super) fn compute_loan_liveness<'tcx>(
29
29
// edges when visualizing the constraint graph anyways.
30
30
let kills = collect_kills ( body, tcx, borrow_set) ;
31
31
32
- let graph = index_constraints ( & localized_outlives_constraints) ;
32
+ let graph = LocalizedConstraintGraph :: new ( & localized_outlives_constraints) ;
33
33
let mut visited = FxHashSet :: default ( ) ;
34
34
let mut stack = Vec :: new ( ) ;
35
35
@@ -108,7 +108,7 @@ pub(super) fn compute_loan_liveness<'tcx>(
108
108
let is_loan_killed =
109
109
kills. get ( & current_location) . is_some_and ( |kills| kills. contains ( & loan_idx) ) ;
110
110
111
- for succ in outgoing_edges ( & graph , node) {
111
+ for succ in graph . outgoing_edges ( node) {
112
112
// If the loan is killed at this point, it is killed _on exit_. But only during
113
113
// forward traversal.
114
114
if is_loan_killed {
@@ -125,9 +125,12 @@ pub(super) fn compute_loan_liveness<'tcx>(
125
125
live_loans
126
126
}
127
127
128
- /// The localized constraint graph is currently the per-node map of its physical edges. In the
129
- /// future, we'll add logical edges to model constraints that hold at all points in the CFG.
130
- type LocalizedConstraintGraph = FxHashMap < LocalizedNode , FxIndexSet < LocalizedNode > > ;
128
+ /// The localized constraint graph indexes the physical edges to compute a given node's successors
129
+ /// during traversal.
130
+ struct LocalizedConstraintGraph {
131
+ /// The actual, physical, edges we have recorded for a given node.
132
+ edges : FxHashMap < LocalizedNode , FxIndexSet < LocalizedNode > > ,
133
+ }
131
134
132
135
/// A node in the graph to be traversed, one of the two vertices of a localized outlives constraint.
133
136
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
@@ -136,24 +139,23 @@ struct LocalizedNode {
136
139
point : PointIndex ,
137
140
}
138
141
139
- /// Traverses the constraints and returns the indexable graph of edges per node.
140
- fn index_constraints ( constraints : & LocalizedOutlivesConstraintSet ) -> LocalizedConstraintGraph {
141
- let mut edges = LocalizedConstraintGraph :: default ( ) ;
142
- for constraint in & constraints. outlives {
143
- let source = LocalizedNode { region : constraint. source , point : constraint. from } ;
144
- let target = LocalizedNode { region : constraint. target , point : constraint. to } ;
145
- edges. entry ( source) . or_default ( ) . insert ( target) ;
146
- }
142
+ impl LocalizedConstraintGraph {
143
+ /// Traverses the constraints and returns the indexed graph of edges per node.
144
+ fn new ( constraints : & LocalizedOutlivesConstraintSet ) -> Self {
145
+ let mut edges: FxHashMap < _ , FxIndexSet < _ > > = FxHashMap :: default ( ) ;
146
+ for constraint in & constraints. outlives {
147
+ let source = LocalizedNode { region : constraint. source , point : constraint. from } ;
148
+ let target = LocalizedNode { region : constraint. target , point : constraint. to } ;
149
+ edges. entry ( source) . or_default ( ) . insert ( target) ;
150
+ }
147
151
148
- edges
149
- }
152
+ LocalizedConstraintGraph { edges }
153
+ }
150
154
151
- /// Returns the outgoing edges of a given node, not its transitive closure.
152
- fn outgoing_edges (
153
- graph : & LocalizedConstraintGraph ,
154
- node : LocalizedNode ,
155
- ) -> impl Iterator < Item = LocalizedNode > + use < ' _ > {
156
- graph. get ( & node) . into_iter ( ) . flat_map ( |edges| edges. iter ( ) . copied ( ) )
155
+ /// Returns the outgoing edges of a given node, not its transitive closure.
156
+ fn outgoing_edges ( & self , node : LocalizedNode ) -> impl Iterator < Item = LocalizedNode > + use < ' _ > {
157
+ self . edges . get ( & node) . into_iter ( ) . flat_map ( |targets| targets. iter ( ) . copied ( ) )
158
+ }
157
159
}
158
160
159
161
/// Traverses the MIR and collects kills.
0 commit comments