Skip to content

Commit 794e228

Browse files
committed
Auto merge of #57697 - dotdash:fast_lex_reg_resol_item_bodies, r=nagisa
Use a faster early exit during region expansion Turns out that the equality check for regions is rather expensive, and the current early exit check works in such a way, that the comparison is even done twice. As we only really care about the case of equal scopes, we can perform a faster, more specialized check and move it up one level, so we can eventually skip the additional full comparison as well.
2 parents 4db2394 + f0d3df3 commit 794e228

File tree

1 file changed

+8
-6
lines changed
  • src/librustc/infer/lexical_region_resolve

1 file changed

+8
-6
lines changed

Diff for: src/librustc/infer/lexical_region_resolve/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
241241

242242
match *b_data {
243243
VarValue::Value(cur_region) => {
244+
// Identical scopes can show up quite often, if the fixed point
245+
// iteration converges slowly, skip them
246+
if let (ReScope(a_scope), ReScope(cur_scope)) = (a_region, cur_region) {
247+
if a_scope == cur_scope {
248+
return false;
249+
}
250+
}
251+
244252
let mut lub = self.lub_concrete_regions(a_region, cur_region);
245253
if lub == cur_region {
246254
return false;
@@ -280,12 +288,6 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
280288
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
281289
let tcx = self.tcx();
282290

283-
// Equal scopes can show up quite often, if the fixed point
284-
// iteration converges slowly, skip them
285-
if a == b {
286-
return a;
287-
}
288-
289291
match (a, b) {
290292
(&ty::ReClosureBound(..), _)
291293
| (_, &ty::ReClosureBound(..))

0 commit comments

Comments
 (0)