Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b207ca

Browse files
author
Ariel Ben-Yehuda
committedApr 22, 2017
bail out of selection when there are multiple surviving candidates
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.
1 parent dae49f1 commit 1b207ca

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎src/librustc/traits/select.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -943,17 +943,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
943943
debug!("Retaining candidate #{}/{}: {:?}",
944944
i, candidates.len(), candidates[i]);
945945
i += 1;
946+
947+
// If there are *STILL* multiple candidates, give up
948+
// and report ambiguity.
949+
if i > 1 {
950+
debug!("multiple matches, ambig");
951+
return Ok(None);
952+
}
946953
}
947954
}
948955
}
949956

950-
// If there are *STILL* multiple candidates, give up and
951-
// report ambiguity.
952-
if candidates.len() > 1 {
953-
debug!("multiple matches, ambig");
954-
return Ok(None);
955-
}
956-
957957
// If there are *NO* candidates, then there are no impls --
958958
// that we know of, anyway. Note that in the case where there
959959
// are unbound type variables within the obligation, it might

0 commit comments

Comments
 (0)
Please sign in to comment.