Skip to content

Commit 13ca54d

Browse files
author
Ariel Ben-Yehuda
committed
add a fastpath to non-higher-ranked trait projection
this improves typeck performance by another 1%
1 parent 50fb018 commit 13ca54d

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/librustc/traits/project.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,29 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
162162
obligation);
163163

164164
let infcx = selcx.infcx();
165-
infcx.commit_if_ok(|snapshot| {
166-
let (skol_predicate, skol_map) =
167-
infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot);
168-
169-
let skol_obligation = obligation.with(skol_predicate);
170-
match project_and_unify_type(selcx, &skol_obligation) {
171-
Ok(result) => {
172-
let span = obligation.cause.span;
173-
match infcx.leak_check(false, span, &skol_map, snapshot) {
174-
Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, result)),
175-
Err(e) => Err(MismatchedProjectionTypes { err: e }),
165+
if let Some(skol_predicate) = infcx.tcx.no_late_bound_regions(&obligation.predicate) {
166+
// Fastpath: no escaping regions.
167+
project_and_unify_type(selcx, &obligation.with(skol_predicate))
168+
} else {
169+
infcx.commit_if_ok(|snapshot| {
170+
let (skol_predicate, skol_map) =
171+
infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot);
172+
173+
let skol_obligation = obligation.with(skol_predicate);
174+
match project_and_unify_type(selcx, &skol_obligation) {
175+
Ok(result) => {
176+
let span = obligation.cause.span;
177+
match infcx.leak_check(false, span, &skol_map, snapshot) {
178+
Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, result)),
179+
Err(e) => Err(MismatchedProjectionTypes { err: e }),
180+
}
181+
}
182+
Err(e) => {
183+
Err(e)
176184
}
177185
}
178-
Err(e) => {
179-
Err(e)
180-
}
181-
}
182-
})
186+
})
187+
}
183188
}
184189

185190
/// Evaluates constraints of the form:

0 commit comments

Comments
 (0)