Skip to content

Commit 47035e4

Browse files
committed
Use FxHashMap
1 parent 0a3c6bb commit 47035e4

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct RegionInferenceContext<'tcx> {
8585
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
8686

8787
/// Map universe indexes to information on why we created it.
88-
universe_causes: IndexVec<ty::UniverseIndex, UniverseInfo<'tcx>>,
88+
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
8989

9090
/// Contains the minimum universe of any variable within the same
9191
/// SCC. We will ensure that no SCC contains values that are not
@@ -256,7 +256,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
256256
Location,
257257
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
258258
>,
259-
universe_causes: IndexVec<ty::UniverseIndex, UniverseInfo<'tcx>>,
259+
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
260260
type_tests: Vec<TypeTest<'tcx>>,
261261
liveness_constraints: LivenessValues<RegionVid>,
262262
elements: &Rc<RegionValueElements>,
@@ -2149,7 +2149,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21492149
}
21502150

21512151
crate fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
2152-
self.universe_causes[universe].clone()
2152+
self.universe_causes[&universe].clone()
21532153
}
21542154
}
21552155

compiler/rustc_borrowck/src/type_check/canonical.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5050
None => UniverseInfo::other(),
5151
};
5252
for u in old_universe..universe {
53-
let info_universe =
54-
self.borrowck_context.constraints.universe_causes.push(universe_info.clone());
55-
assert_eq!(u.as_u32() + 1, info_universe.as_u32());
53+
self.borrowck_context
54+
.constraints
55+
.universe_causes
56+
.insert(u + 1, universe_info.clone());
5657
}
5758
}
5859

@@ -70,9 +71,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
7071
let (instantiated, _) =
7172
self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
7273

73-
for _ in 0..canonical.max_universe.as_u32() {
74+
for u in 0..canonical.max_universe.as_u32() {
7475
let info = UniverseInfo::other();
75-
self.borrowck_context.constraints.universe_causes.push(info);
76+
self.borrowck_context
77+
.constraints
78+
.universe_causes
79+
.insert(ty::UniverseIndex::from_u32(u), info);
7680
}
7781

7882
instantiated

compiler/rustc_borrowck/src/type_check/input_output.rs

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
194194
b
195195
}
196196
};
197+
// Note: if we have to introduce new placeholders during normalization above, then we won't have
198+
// added those universes to the universe info, which we would want in `relate_tys`.
197199
if let Err(terr) =
198200
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
199201
{

compiler/rustc_borrowck/src/type_check/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ pub(crate) fn type_check<'mir, 'tcx>(
136136
upvars: &[Upvar<'tcx>],
137137
) -> MirTypeckResults<'tcx> {
138138
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
139+
let mut universe_causes = FxHashMap::default();
140+
universe_causes.insert(ty::UniverseIndex::from_u32(0), UniverseInfo::other());
139141
let mut constraints = MirTypeckRegionConstraints {
140142
placeholder_indices: PlaceholderIndices::default(),
141143
placeholder_index_to_region: IndexVec::default(),
@@ -144,7 +146,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
144146
member_constraints: MemberConstraintSet::default(),
145147
closure_bounds_mapping: Default::default(),
146148
type_tests: Vec::default(),
147-
universe_causes: IndexVec::from_elem_n(UniverseInfo::other(), 1),
149+
universe_causes,
148150
};
149151

150152
let CreateResult {
@@ -159,9 +161,9 @@ pub(crate) fn type_check<'mir, 'tcx>(
159161
&mut constraints,
160162
);
161163

162-
for _ in ty::UniverseIndex::ROOT..infcx.universe() {
164+
for u in ty::UniverseIndex::ROOT..infcx.universe() {
163165
let info = UniverseInfo::other();
164-
constraints.universe_causes.push(info);
166+
constraints.universe_causes.insert(u, info);
165167
}
166168

167169
let mut borrowck_context = BorrowCheckContext {
@@ -924,7 +926,7 @@ crate struct MirTypeckRegionConstraints<'tcx> {
924926
crate closure_bounds_mapping:
925927
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
926928

927-
crate universe_causes: IndexVec<ty::UniverseIndex, UniverseInfo<'tcx>>,
929+
crate universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
928930

929931
crate type_tests: Vec<TypeTest<'tcx>>,
930932
}

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,10 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
8181

8282
fn create_next_universe(&mut self) -> ty::UniverseIndex {
8383
let universe = self.infcx.create_next_universe();
84-
// FIXME: If we relate tys after normalizing with late-bound regions, there will
85-
// be extra universes. A proper solution would be to somehow track those universes
86-
// during projection, but here we just treat those as "other"
8784
self.borrowck_context
8885
.constraints
8986
.universe_causes
90-
.ensure_contains_elem(universe, || UniverseInfo::other());
91-
self.borrowck_context.constraints.universe_causes[universe] = self.universe_info.clone();
87+
.insert(universe, self.universe_info.clone());
9288
universe
9389
}
9490

0 commit comments

Comments
 (0)