resolve to universal regions when possible
This commit is contained in:
parent
13471d3b20
commit
f3dfa52fd1
@ -352,19 +352,17 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
}
|
||||
|
||||
ty::ReVar(vid) => {
|
||||
let resolved_vid = self
|
||||
let resolved = self
|
||||
.infcx
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.opportunistic_resolve_var(vid);
|
||||
.opportunistic_resolve_var(self.tcx, vid);
|
||||
debug!(
|
||||
"canonical: region var found with vid {:?}, \
|
||||
opportunistically resolved to {:?}",
|
||||
vid, resolved_vid
|
||||
"canonical: region var found with vid {vid:?}, \
|
||||
opportunistically resolved to {resolved:?}",
|
||||
);
|
||||
let r = self.tcx.mk_re_var(resolved_vid);
|
||||
self.canonicalize_mode.canonicalize_free_region(self, r)
|
||||
self.canonicalize_mode.canonicalize_free_region(self, resolved)
|
||||
}
|
||||
|
||||
ty::ReStatic
|
||||
|
@ -633,29 +633,15 @@ pub(super) fn glb_regions(
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the passed RegionVid to the root RegionVid in the unification table
|
||||
pub(super) fn opportunistic_resolve_var(&mut self, rid: ty::RegionVid) -> ty::RegionVid {
|
||||
self.unification_table().find(rid).vid
|
||||
}
|
||||
|
||||
/// If the Region is a `ReVar`, then resolves it either to the root value in
|
||||
/// the unification table, if it exists, or to the root `ReVar` in the table.
|
||||
/// If the Region is not a `ReVar`, just returns the Region itself.
|
||||
pub fn opportunistic_resolve_region(
|
||||
/// Resolves a region var to its value in the unification table, if it exists.
|
||||
/// Otherwise, it is resolved to the root `ReVar` in the table.
|
||||
pub fn opportunistic_resolve_var(
|
||||
&mut self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region: ty::Region<'tcx>,
|
||||
vid: ty::RegionVid,
|
||||
) -> ty::Region<'tcx> {
|
||||
match *region {
|
||||
ty::ReVar(rid) => {
|
||||
let unified_region = self.unification_table().probe_value(rid);
|
||||
unified_region.0.unwrap_or_else(|| {
|
||||
let root = self.unification_table().find(rid).vid;
|
||||
tcx.mk_re_var(root)
|
||||
})
|
||||
}
|
||||
_ => region,
|
||||
}
|
||||
let root_vid = self.unification_table().find(vid).vid;
|
||||
self.unification_table().probe_value(root_vid).0.unwrap_or_else(|| tcx.mk_re_var(root_vid))
|
||||
}
|
||||
|
||||
fn combine_map(&mut self, t: CombineMapType) -> &mut CombineMap<'tcx> {
|
||||
|
@ -85,15 +85,12 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
|
||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
match *r {
|
||||
ty::ReVar(rid) => {
|
||||
let resolved = self
|
||||
.infcx
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.opportunistic_resolve_var(rid);
|
||||
TypeFolder::interner(self).mk_re_var(resolved)
|
||||
}
|
||||
ty::ReVar(vid) => self
|
||||
.infcx
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.opportunistic_resolve_var(TypeFolder::interner(self), vid),
|
||||
_ => r,
|
||||
}
|
||||
}
|
||||
|
@ -871,12 +871,12 @@ fn fold_binder<T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
|
||||
fn fold_region(&mut self, r0: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
let r1 = match *r0 {
|
||||
ty::ReVar(_) => self
|
||||
ty::ReVar(vid) => self
|
||||
.infcx
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.opportunistic_resolve_region(self.infcx.tcx, r0),
|
||||
.opportunistic_resolve_var(self.infcx.tcx, vid),
|
||||
_ => r0,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user