From 13ca54dd4a7f6e89a52f7189a95d0b55e2390692 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Tue, 4 Oct 2016 14:45:43 +0300 Subject: [PATCH] add a fastpath to non-higher-ranked trait projection this improves typeck performance by another 1% --- src/librustc/traits/project.rs | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index ddabc53a89a81..04c38696aa058 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -162,24 +162,29 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>( obligation); let infcx = selcx.infcx(); - infcx.commit_if_ok(|snapshot| { - let (skol_predicate, skol_map) = - infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot); - - let skol_obligation = obligation.with(skol_predicate); - match project_and_unify_type(selcx, &skol_obligation) { - Ok(result) => { - let span = obligation.cause.span; - match infcx.leak_check(false, span, &skol_map, snapshot) { - Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, result)), - Err(e) => Err(MismatchedProjectionTypes { err: e }), + if let Some(skol_predicate) = infcx.tcx.no_late_bound_regions(&obligation.predicate) { + // Fastpath: no escaping regions. + project_and_unify_type(selcx, &obligation.with(skol_predicate)) + } else { + infcx.commit_if_ok(|snapshot| { + let (skol_predicate, skol_map) = + infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot); + + let skol_obligation = obligation.with(skol_predicate); + match project_and_unify_type(selcx, &skol_obligation) { + Ok(result) => { + let span = obligation.cause.span; + match infcx.leak_check(false, span, &skol_map, snapshot) { + Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, result)), + Err(e) => Err(MismatchedProjectionTypes { err: e }), + } + } + Err(e) => { + Err(e) } } - Err(e) => { - Err(e) - } - } - }) + }) + } } /// Evaluates constraints of the form: