Add helper method for reusing an existing interned region

This commit is contained in:
Matthew Jasper 2020-06-18 18:09:18 +01:00
parent e9b0ce8afa
commit aa117047f0
3 changed files with 9 additions and 8 deletions

View File

@ -326,13 +326,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
opportunistically resolved to {:?}",
vid, r
);
// micro-optimize -- avoid an interner look-up if the vid
// hasn't changed.
let r = if vid == resolved_vid {
r
} else {
self.tcx.mk_region(ty::ReVar(resolved_vid))
};
let r = self.tcx.reuse_or_mk_region(r, ty::ReVar(resolved_vid));
self.canonicalize_region_mode.canonicalize_free_region(self, r)
}

View File

@ -85,7 +85,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(rid);
if resolved == rid { r } else { self.tcx().mk_region(ty::ReVar(resolved)) }
self.tcx().reuse_or_mk_region(r, ty::ReVar(resolved))
}
_ => r,
}

View File

@ -2081,6 +2081,13 @@ pub fn signature_unclosure(
})
}
/// Same a `self.mk_region(kind)`, but avoids accessing the interners if
/// `*r == kind`.
#[inline]
pub fn reuse_or_mk_region(self, r: Region<'tcx>, kind: RegionKind) -> Region<'tcx> {
if *r == kind { r } else { self.mk_region(kind) }
}
#[allow(rustc::usage_of_ty_tykind)]
#[inline]
pub fn mk_ty(&self, st: TyKind<'tcx>) -> Ty<'tcx> {