aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-04-25 05:39:18 +0000
committerGraydon Hoare <[email protected]>2011-04-25 05:39:18 +0000
commit485399a8d5de8a8bb759feacd9e4915055e51cb5 (patch)
treee0329754898c6a100117feae39282c658139aa5e /src
parentBind tag members as aliases rather than new locals. (diff)
downloadrust-485399a8d5de8a8bb759feacd9e4915055e51cb5.tar.xz
rust-485399a8d5de8a8bb759feacd9e4915055e51cb5.zip
Skip substitution and/or binding when there's no work to do.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/ty.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 3e3279ed..2b4a9a78 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -1391,6 +1391,34 @@ fn type_contains_vars(@type_store tystore, t typ) -> bool {
ret *flag;
}
+fn type_contains_params(@type_store tystore, t typ) -> bool {
+ fn checker(@type_store tystore, @mutable bool flag, t typ) {
+ alt (struct(tystore, typ)) {
+ case (ty_param(_)) { *flag = true; }
+ case (_) { /* fall through */ }
+ }
+ }
+
+ let @mutable bool flag = @mutable false;
+ auto f = bind checker(tystore, flag, _);
+ walk_ty(tystore, f, typ);
+ ret *flag;
+}
+
+fn type_contains_bound_params(@type_store tystore, t typ) -> bool {
+ fn checker(@type_store tystore, @mutable bool flag, t typ) {
+ alt (struct(tystore, typ)) {
+ case (ty_bound_param(_)) { *flag = true; }
+ case (_) { /* fall through */ }
+ }
+ }
+
+ let @mutable bool flag = @mutable false;
+ auto f = bind checker(tystore, flag, _);
+ walk_ty(tystore, f, typ);
+ ret *flag;
+}
+
// Type accessors for substructures of types
fn ty_fn_args(@type_store tystore, t fty) -> vec[arg] {
@@ -2495,6 +2523,9 @@ fn type_err_to_str(&ty.type_err err) -> str {
fn substitute_type_params(@type_store tystore,
vec[t] bindings,
t typ) -> t {
+ if (!type_contains_bound_params(tystore, typ)) {
+ ret typ;
+ }
fn replacer(@type_store tystore, vec[t] bindings, t typ) -> t {
alt (struct(tystore, typ)) {
case (ty_bound_param(?param_index)) {
@@ -2510,6 +2541,9 @@ fn substitute_type_params(@type_store tystore,
// Converts type parameters in a type to bound type parameters.
fn bind_params_in_type(@type_store tystore, t typ) -> t {
+ if (!type_contains_params(tystore, typ)) {
+ ret typ;
+ }
fn binder(@type_store tystore, t typ) -> t {
alt (struct(tystore, typ)) {
case (ty_bound_param(?index)) {