]> git.lizzy.rs Git - rust.git/commitdiff
Add a fast path in ty::occurs_check_fails
authorTim Chevalier <chevalier@alum.wellesley.edu>
Thu, 4 Aug 2011 22:56:40 +0000 (15:56 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Thu, 4 Aug 2011 22:56:40 +0000 (15:56 -0700)
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. :-})

src/comp/middle/ty.rs

index ba4910c361610987879163e1c708c41cd284918b..00f2e6a1b86b2de32456ca8c622c1a856b2e15f8 100644 (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 @@ fn subst_vars(tcx: ty_ctxt, sp: &option::t[span], vb: @var_bindings,
               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,