11use std:: rc:: Rc ;
22
3- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
3+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
44use rustc_index:: IndexVec ;
55use rustc_middle:: mir:: { Body , Location } ;
66use rustc_middle:: ty:: RegionVid ;
77use rustc_mir_dataflow:: points:: { DenseLocationMap , PointIndex } ;
8+ use smallvec:: SmallVec ;
89
910use crate :: BorrowSet ;
1011use crate :: constraints:: OutlivesConstraint ;
@@ -44,12 +45,12 @@ pub(super) struct LocalizedConstraintGraph {
4445
4546 /// The actual, physical, edges we have recorded for a given node. We localize them on-demand
4647 /// when traversing from the node to the successor region.
47- edges : FxHashMap < LocalizedNode , FxIndexSet < RegionVid > > ,
48+ edges : FxHashMap < LocalizedNode , SmallVec < [ RegionVid ; 4 ] > > ,
4849
4950 /// The logical edges representing the outlives constraints that hold at all points in the CFG,
5051 /// which we don't localize to avoid creating a lot of unnecessary edges in the graph. Some CFGs
5152 /// can be big, and we don't need to create such a physical edge for every point in the CFG.
52- logical_edges : IndexVec < RegionVid , FxIndexSet < RegionVid > > ,
53+ logical_edges : IndexVec < RegionVid , SmallVec < [ RegionVid ; 4 ] > > ,
5354}
5455
5556/// The visitor interface when traversing a `LocalizedConstraintGraph`.
@@ -69,23 +70,28 @@ impl LocalizedConstraintGraph {
6970 location_map : Rc < DenseLocationMap > ,
7071 outlives_constraints : impl Iterator < Item = OutlivesConstraint < ' tcx > > ,
7172 ) -> Self {
72- let mut edges: FxHashMap < _ , FxIndexSet < _ > > = FxHashMap :: default ( ) ;
73- let mut logical_edges: IndexVec < _ , FxIndexSet < _ > > = IndexVec :: new ( ) ;
73+ let mut edges: FxHashMap < _ , SmallVec < [ RegionVid ; 4 ] > > = FxHashMap :: default ( ) ;
74+ let mut logical_edges: IndexVec < _ , SmallVec < [ RegionVid ; 4 ] > > = IndexVec :: new ( ) ;
7475
7576 for outlives_constraint in outlives_constraints {
7677 match outlives_constraint. locations {
7778 Locations :: All ( _) => {
78- logical_edges
79- . ensure_contains_elem ( outlives_constraint. sup , FxIndexSet :: default)
80- . insert ( outlives_constraint. sub ) ;
79+ let succs =
80+ logical_edges. ensure_contains_elem ( outlives_constraint. sup , SmallVec :: new) ;
81+ if !succs. contains ( & outlives_constraint. sub ) {
82+ succs. push ( outlives_constraint. sub ) ;
83+ }
8184 }
8285
8386 Locations :: Single ( location) => {
8487 let node = LocalizedNode {
8588 region : outlives_constraint. sup ,
8689 point : location_map. point_from_location ( location) ,
8790 } ;
88- edges. entry ( node) . or_default ( ) . insert ( outlives_constraint. sub ) ;
91+ let succs = edges. entry ( node) . or_default ( ) ;
92+ if !succs. contains ( & outlives_constraint. sub ) {
93+ succs. push ( outlives_constraint. sub ) ;
94+ }
8995 }
9096 }
9197 }
0 commit comments