Skip to content

Commit 5f03ca4

Browse files
committed
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. :-})
1 parent 2baaeab commit 5f03ca4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/comp/middle/ty.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,10 @@ fn is_lval(expr: &@ast::expr) -> bool {
20152015

20162016
fn occurs_check_fails(tcx: &ctxt, sp: &option::t[span], vid: int, rt: &t)
20172017
-> bool {
2018+
if (!type_contains_vars(tcx, rt)) {
2019+
// Fast path
2020+
ret false;
2021+
}
20182022
// Occurs check!
20192023
if ivec::member(vid, vars_in_type(tcx, rt)) {
20202024
alt sp {
@@ -2754,7 +2758,7 @@ mod unify {
27542758
none. { *unresolved = some(vid); ret ty::mk_var(tcx, vid); }
27552759
some(rt) {
27562760
if occurs_check_fails(tcx, sp, vid, rt) {
2757-
// Return the type unchanged, so we can error out downstream
2761+
// Return the type unchanged, so we can error out downstream
27582762
ret rt;
27592763
}
27602764
ret fold_ty(tcx,

0 commit comments

Comments
 (0)