Skip to content

Commit 24e4e60

Browse files
committed
Auto merge of #24615 - arielb1:rapid-reject, r=nikomatsakis
skolemize_late_bound_regions essentially copies the entire type (most of the times it shouldn't, but it does), and match_impl runs millions of times. Times compiling rustc, tested with $ make -j4 rustc-stage1 $ ( time RUSTFLAGS=-Z time-passes make -j4 rustc-stage2 ) # need LLVM time for calibration Before: real 21m44.960s user 29m38.812s sys 0m14.944s After: real 19m31.445s user 26m47.260s sys 0m14.952s Making this is a 10% performance improvement. LLVM passes took 867 seconds before, 862 seconds after.
2 parents 69e47c7 + 94a1b26 commit 24e4e60

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/librustc/middle/traits/select.rs

+20-27
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
532532
obligation.repr(self.tcx()));
533533

534534
self.infcx.probe(|snapshot| {
535-
let (skol_obligation_trait_ref, skol_map) =
536-
self.infcx().skolemize_late_bound_regions(&obligation.predicate, snapshot);
537-
match self.match_impl(impl_def_id, obligation, snapshot,
538-
&skol_map, skol_obligation_trait_ref.trait_ref.clone()) {
539-
Ok(substs) => {
535+
match self.match_impl(impl_def_id, obligation, snapshot) {
536+
Ok((substs, skol_map)) => {
540537
let vtable_impl = self.vtable_impl(impl_def_id,
541538
substs,
542539
obligation.cause.clone(),
@@ -1160,10 +1157,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11601157
let all_impls = self.all_impls(def_id);
11611158
for &impl_def_id in &all_impls {
11621159
self.infcx.probe(|snapshot| {
1163-
let (skol_obligation_trait_pred, skol_map) =
1164-
self.infcx().skolemize_late_bound_regions(&obligation.predicate, snapshot);
1165-
match self.match_impl(impl_def_id, obligation, snapshot,
1166-
&skol_map, skol_obligation_trait_pred.trait_ref.clone()) {
1160+
match self.match_impl(impl_def_id, obligation, snapshot) {
11671161
Ok(_) => {
11681162
candidates.vec.push(ImplCandidate(impl_def_id));
11691163
}
@@ -2115,11 +2109,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21152109
// First, create the substitutions by matching the impl again,
21162110
// this time not in a probe.
21172111
self.infcx.commit_if_ok(|snapshot| {
2118-
let (skol_obligation_trait_ref, skol_map) =
2119-
self.infcx().skolemize_late_bound_regions(&obligation.predicate, snapshot);
2120-
let substs =
2112+
let (substs, skol_map) =
21212113
self.rematch_impl(impl_def_id, obligation,
2122-
snapshot, &skol_map, skol_obligation_trait_ref.trait_ref);
2114+
snapshot);
21232115
debug!("confirm_impl_candidate substs={}", substs.repr(self.tcx()));
21242116
Ok(self.vtable_impl(impl_def_id, substs, obligation.cause.clone(),
21252117
obligation.recursion_depth + 1, skol_map, snapshot))
@@ -2306,14 +2298,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23062298
fn rematch_impl(&mut self,
23072299
impl_def_id: ast::DefId,
23082300
obligation: &TraitObligation<'tcx>,
2309-
snapshot: &infer::CombinedSnapshot,
2310-
skol_map: &infer::SkolemizationMap,
2311-
skol_obligation_trait_ref: Rc<ty::TraitRef<'tcx>>)
2312-
-> Normalized<'tcx, Substs<'tcx>>
2301+
snapshot: &infer::CombinedSnapshot)
2302+
-> (Normalized<'tcx, Substs<'tcx>>, infer::SkolemizationMap)
23132303
{
2314-
match self.match_impl(impl_def_id, obligation, snapshot,
2315-
skol_map, skol_obligation_trait_ref) {
2316-
Ok(substs) => substs,
2304+
match self.match_impl(impl_def_id, obligation, snapshot) {
2305+
Ok((substs, skol_map)) => (substs, skol_map),
23172306
Err(()) => {
23182307
self.tcx().sess.bug(
23192308
&format!("Impl {} was matchable against {} but now is not",
@@ -2326,10 +2315,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23262315
fn match_impl(&mut self,
23272316
impl_def_id: ast::DefId,
23282317
obligation: &TraitObligation<'tcx>,
2329-
snapshot: &infer::CombinedSnapshot,
2330-
skol_map: &infer::SkolemizationMap,
2331-
skol_obligation_trait_ref: Rc<ty::TraitRef<'tcx>>)
2332-
-> Result<Normalized<'tcx, Substs<'tcx>>, ()>
2318+
snapshot: &infer::CombinedSnapshot)
2319+
-> Result<(Normalized<'tcx, Substs<'tcx>>,
2320+
infer::SkolemizationMap), ()>
23332321
{
23342322
let impl_trait_ref = ty::impl_trait_ref(self.tcx(), impl_def_id).unwrap();
23352323

@@ -2340,6 +2328,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23402328
return Err(());
23412329
}
23422330

2331+
let (skol_obligation, skol_map) = self.infcx().skolemize_late_bound_regions(
2332+
&obligation.predicate,
2333+
snapshot);
2334+
let skol_obligation_trait_ref = skol_obligation.trait_ref;
2335+
23432336
let impl_substs = util::fresh_type_vars_for_impl(self.infcx,
23442337
obligation.cause.span,
23452338
impl_def_id);
@@ -2370,17 +2363,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23702363
return Err(());
23712364
}
23722365

2373-
if let Err(e) = self.infcx.leak_check(skol_map, snapshot) {
2366+
if let Err(e) = self.infcx.leak_check(&skol_map, snapshot) {
23742367
debug!("match_impl: failed leak check due to `{}`",
23752368
ty::type_err_to_str(self.tcx(), &e));
23762369
return Err(());
23772370
}
23782371

23792372
debug!("match_impl: success impl_substs={}", impl_substs.repr(self.tcx()));
2380-
Ok(Normalized {
2373+
Ok((Normalized {
23812374
value: impl_substs,
23822375
obligations: impl_trait_ref.obligations
2383-
})
2376+
}, skol_map))
23842377
}
23852378

23862379
fn fast_reject_trait_refs(&mut self,

0 commit comments

Comments
 (0)