about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-04-25 18:05:09 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-04-25 18:08:13 -0700
commitcf23db6be52179f2acce1577ca1045fe2b5647cb (patch)
tree64437970a3dc27c3b626b752c7f044880519e471
parentc4e13cd1fa451327a756efc0c23bbbdbb9e7e1ae (diff)
downloadrust-cf23db6be52179f2acce1577ca1045fe2b5647cb.tar.gz
rust-cf23db6be52179f2acce1577ca1045fe2b5647cb.zip
A little more guarding against wasted work in ty, typeck.
-rw-r--r--src/comp/middle/ty.rs13
-rw-r--r--src/comp/middle/typeck.rs8
2 files changed, 19 insertions, 2 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index ca461bc427f..04bea450f7d 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -1629,6 +1629,10 @@ fn type_contains_vars(ctxt cx, t typ) -> bool {
     ret typ.has_vars;
 }
 
+fn type_contains_locals(ctxt cx, t typ) -> bool {
+    ret typ.has_locals;
+}
+
 fn type_contains_params(ctxt cx, t typ) -> bool {
     ret typ.has_params;
 }
@@ -2606,6 +2610,10 @@ mod Unify {
 
     // Performs type binding substitution.
     fn substitute(@ctxt cx, vec[t] set_types, t typ) -> t {
+        if (!type_contains_vars(cx.tcx, typ)) {
+            ret typ;
+        }
+
         fn substituter(@ctxt cx, vec[t] types, t typ) -> t {
             alt (struct(cx.tcx, typ)) {
                 case (ty_var(?id)) {
@@ -2755,8 +2763,9 @@ fn substitute_type_params(ctxt cx, vec[t] bindings, t typ) -> t {
 
 // Converts type parameters in a type to bound type parameters.
 fn bind_params_in_type(ctxt cx, t typ) -> t {
-    if (!type_contains_params(cx, typ)) { ret typ; }
-
+    if (!type_contains_params(cx, typ)) {
+        ret typ;
+    }
     fn binder(ctxt cx, t typ) -> t {
         alt (struct(cx, typ)) {
             case (ty_bound_param(?index)) {
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index fc13319df71..24aa8db0492 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -96,6 +96,10 @@ fn substitute_ty_params(&@crate_ctxt ccx,
         fail;
     }
 
+    if (!ty.type_contains_bound_params(ccx.tcx, typ)) {
+        ret typ;
+    }
+
     auto f = bind substituter(ccx, supplied, _);
     ret ty.fold_ty(ccx.tcx, f, typ);
 }
@@ -1532,6 +1536,10 @@ fn resolve_local_types_in_annotation(&option.t[@fn_ctxt] env, ast.ann ann)
             ret ann;
         }
         case (ast.ann_type(?typ, ?tps, ?ts_info)) {
+            auto tt = ann_to_type(ann);
+            if (!ty.type_contains_locals(fcx.ccx.tcx, tt)) {
+                ret ann;
+            }
             auto f = bind resolver(fcx, _);
             auto new_type = ty.fold_ty(fcx.ccx.tcx, f, ann_to_type(ann));
             ret ast.ann_type(new_type, tps, ts_info);