Add a fast path in ty::occurs_check_fails

Use type_contains_vars in occurs_check_fails to avoid doing
any work most of the time. This fixes a performance regression.
(No one else noticed yet that typechecking just got 4x slower, right?
Well, now it isn't anymore. :-})
This commit is contained in:
Tim Chevalier 2011-08-04 15:56:40 -07:00
parent 2baaeab784
commit 5f03ca48d8
1 changed files with 5 additions and 1 deletions

View File

@ -2015,6 +2015,10 @@ fn is_lval(expr: &@ast::expr) -> bool {
fn occurs_check_fails(tcx: &ctxt, sp: &option::t[span], vid: int, rt: &t)
-> bool {
if (!type_contains_vars(tcx, rt)) {
// Fast path
ret false;
}
// Occurs check!
if ivec::member(vid, vars_in_type(tcx, rt)) {
alt sp {
@ -2754,7 +2758,7 @@ mod unify {
none. { *unresolved = some(vid); ret ty::mk_var(tcx, vid); }
some(rt) {
if occurs_check_fails(tcx, sp, vid, rt) {
// Return the type unchanged, so we can error out downstream
// Return the type unchanged, so we can error out downstream
ret rt;
}
ret fold_ty(tcx,