Skip to content

Commit d2dfb0e

Browse files
committed
Auto merge of #88811 - jackh726:issue-88446, r=nikomatsakis
Use a HashMap for UniverseInfo in mir borrowck Fixes #88446 r? `@nikomatsakis`
2 parents c7dbe7a + 47035e4 commit d2dfb0e

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
8080
}
8181

8282
fn create_next_universe(&mut self) -> ty::UniverseIndex {
83-
let info_universe =
84-
self.borrowck_context.constraints.universe_causes.push(self.universe_info.clone());
8583
let universe = self.infcx.create_next_universe();
86-
assert_eq!(info_universe, universe);
84+
self.borrowck_context
85+
.constraints
86+
.universe_causes
87+
.insert(universe, self.universe_info.clone());
8788
universe
8889
}
8990

src/test/ui/hrtb/issue-88446.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-pass
2+
3+
trait Yokeable<'a> {
4+
type Output: 'a;
5+
}
6+
impl<'a> Yokeable<'a> for () {
7+
type Output = ();
8+
}
9+
10+
trait DataMarker<'data> {
11+
type Yokeable: for<'a> Yokeable<'a>;
12+
}
13+
impl<'data> DataMarker<'data> for () {
14+
type Yokeable = ();
15+
}
16+
17+
struct DataPayload<'data, M>(&'data M);
18+
19+
impl DataPayload<'static, ()> {
20+
pub fn map_project_with_capture<M2, T>(
21+
_: for<'a> fn(
22+
capture: T,
23+
std::marker::PhantomData<&'a ()>,
24+
) -> <M2::Yokeable as Yokeable<'a>>::Output,
25+
) -> DataPayload<'static, M2>
26+
where
27+
M2: DataMarker<'static>,
28+
{
29+
todo!()
30+
}
31+
}
32+
33+
fn main() {
34+
let _: DataPayload<()> = DataPayload::<()>::map_project_with_capture::<_, &()>(|_, _| todo!());
35+
}

0 commit comments

Comments
 (0)