diff options
| author | Graydon Hoare <[email protected]> | 2011-04-25 18:05:09 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-25 18:08:13 -0700 |
| commit | cf23db6be52179f2acce1577ca1045fe2b5647cb (patch) | |
| tree | 64437970a3dc27c3b626b752c7f044880519e471 | |
| parent | rustc: Use the abbreviated type names to avoid LLVM bitcode size explosion (diff) | |
| download | rust-cf23db6be52179f2acce1577ca1045fe2b5647cb.tar.xz rust-cf23db6be52179f2acce1577ca1045fe2b5647cb.zip | |
A little more guarding against wasted work in ty, typeck.
| -rw-r--r-- | src/comp/middle/ty.rs | 13 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 8 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index ca461bc4..04bea450 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 fc13319d..24aa8db0 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); |