diff options
author | Ariel Ben-Yehuda <arielb1@mail.tau.ac.il> | 2017-04-22 15:05:18 +0300 |
---|---|---|
committer | Ariel Ben-Yehuda <arielb1@mail.tau.ac.il> | 2017-04-22 15:14:32 +0300 |
commit | 1b207ca3b3e45e6dfb33933748d5136d147a4064 (patch) | |
tree | a491c7b21fc06e6b2750b00894f6412251482097 | |
parent | dae49f178f53c1aefb14201091eb671363e949b9 (diff) | |
download | rustc-spring-cleaning.tar.gz |
bail out of selection when there are multiple surviving candidatesrustc-spring-cleaning
In some cases (e.g. <[int-var] as Add<[int-var]>>), selection can turn up
a large number of candidates. Bailing out early avoids O(n^2) performance.
This improves item-type checking time by quite a bit, resulting in ~2% of total
time-to-typeck.
-rw-r--r-- | src/librustc/traits/select.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 70ddcff5181..6442487ead9 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -943,17 +943,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { debug!("Retaining candidate #{}/{}: {:?}", i, candidates.len(), candidates[i]); i += 1; + + // If there are *STILL* multiple candidates, give up + // and report ambiguity. + if i > 1 { + debug!("multiple matches, ambig"); + return Ok(None); + } } } } - // If there are *STILL* multiple candidates, give up and - // report ambiguity. - if candidates.len() > 1 { - debug!("multiple matches, ambig"); - return Ok(None); - } - // If there are *NO* candidates, then there are no impls -- // that we know of, anyway. Note that in the case where there // are unbound type variables within the obligation, it might |