From 5f402b827726607b04887c7c7b8d8b95cce8f487 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Steinbrink?= Date: Thu, 10 Jan 2019 19:28:42 +0100 Subject: [PATCH] Add a fast path for identical regions in lub_concrete_regions In functions with lots of region constraint, if the fixed point iteration converges only slowly, a lot of the var/var constraints will have equal regions most of the time. Yet, we still perform the LUB calculation and try to intern the result. Especially the latter incurs quite some overhead. This reduces the take taken by the item bodies checking pass for the unicode_normalization crate by about 75%. --- src/librustc/infer/lexical_region_resolve/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 2a93217b9b4..39ce8cc621b 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -274,6 +274,13 @@ fn expand_node( fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> { let tcx = self.tcx(); + + // Equal scopes can show up quite often, if the fixed point + // iteration converges slowly, skip them + if a == b { + return a; + } + match (a, b) { (&ty::ReClosureBound(..), _) | (_, &ty::ReClosureBound(..)) -- 2.44.0