Skip to content

Commit 9a9d194

Browse files
committed
Auto merge of #163190 - jackh726:smallvec-in-constraint-graph, r=lqd
Use SmallVec in LocalizedConstraintGraph This seems to be good for some of the rustc-perf benches that remain regressed under polonius. r? lqd
2 parents 52d0fd8 + df8fb0f commit 9a9d194

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

‎compiler/rustc_borrowck/src/polonius/constraints.rs‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::rc::Rc;
22

3-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
3+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_index::IndexVec;
55
use rustc_middle::mir::{Body, Location};
66
use rustc_middle::ty::RegionVid;
77
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
8+
use smallvec::SmallVec;
89

910
use crate::BorrowSet;
1011
use 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

Comments
 (0)