@@ -29,7 +29,7 @@ pub(super) fn compute_loan_liveness<'tcx>(
2929 // edges when visualizing the constraint graph anyways.
3030 let kills = collect_kills ( body, tcx, borrow_set) ;
3131
32- let graph = index_constraints ( & localized_outlives_constraints) ;
32+ let graph = LocalizedConstraintGraph :: new ( & localized_outlives_constraints) ;
3333 let mut visited = FxHashSet :: default ( ) ;
3434 let mut stack = Vec :: new ( ) ;
3535
@@ -108,7 +108,7 @@ pub(super) fn compute_loan_liveness<'tcx>(
108108 let is_loan_killed =
109109 kills. get ( & current_location) . is_some_and ( |kills| kills. contains ( & loan_idx) ) ;
110110
111- for succ in outgoing_edges ( & graph , node) {
111+ for succ in graph . outgoing_edges ( node) {
112112 // If the loan is killed at this point, it is killed _on exit_. But only during
113113 // forward traversal.
114114 if is_loan_killed {
@@ -125,9 +125,12 @@ pub(super) fn compute_loan_liveness<'tcx>(
125125 live_loans
126126}
127127
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+ }
131134
132135/// A node in the graph to be traversed, one of the two vertices of a localized outlives constraint.
133136#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
@@ -136,24 +139,23 @@ struct LocalizedNode {
136139 point : PointIndex ,
137140}
138141
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+ }
147151
148- edges
149- }
152+ LocalizedConstraintGraph { edges }
153+ }
150154
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+ }
157159}
158160
159161/// Traverses the MIR and collects kills.
0 commit comments