A little more guarding against wasted work in ty, typeck.
This commit is contained in:
parent
c4e13cd1fa
commit
cf23db6be5
2 changed files with 19 additions and 2 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue