Skip to content

Commit

Permalink
add a fastpath to non-higher-ranked trait projection
Browse files Browse the repository at this point in the history
this improves typeck performance by another 1%
  • Loading branch information
Ariel Ben-Yehuda committed Oct 4, 2016
1 parent 50fb018 commit 13ca54d
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 13ca54d

Please sign in to comment.