Skip to content

Commit 3eb3590

Browse files
committed
Remove ty::bind_params_in_type
It does nothing that substitute_type_params can't do better.
1 parent 02505d8 commit 3eb3590

File tree

2 files changed

+20
-56
lines changed

2 files changed

+20
-56
lines changed

src/comp/middle/ty.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export node_id_to_ty_param_substs_opt_and_ty;
2828
export arg;
2929
export args_eq;
3030
export ast_constr_to_constr;
31-
export bind_params_in_type;
3231
export block_ty;
3332
export constr;
3433
export constr_general;
@@ -2632,23 +2631,6 @@ fn type_err_to_str(err: ty::type_err) -> str {
26322631
}
26332632
}
26342633

2635-
2636-
// Converts type parameters in a type to type variables and returns the
2637-
// resulting type along with a list of type variable IDs.
2638-
fn bind_params_in_type(cx: ctxt, next_ty_var: block() -> int, typ: t,
2639-
ty_param_count: uint) -> {ids: [int], ty: t} {
2640-
let param_var_ids = [], i = 0u;
2641-
while i < ty_param_count { param_var_ids += [next_ty_var()]; i += 1u; }
2642-
let param_var_ids = @param_var_ids;
2643-
fn binder(cx: ctxt, param_var_ids: @[int], index: uint,
2644-
_did: def_id) -> t {
2645-
ret mk_var(cx, param_var_ids[index]);
2646-
}
2647-
{ids: *param_var_ids,
2648-
ty: fold_ty(cx, fm_param(bind binder(cx, param_var_ids, _, _)), typ)}
2649-
}
2650-
2651-
26522634
// Replaces type parameters in the given type using the given list of
26532635
// substitions.
26542636
fn substitute_type_params(cx: ctxt, substs: [ty::t], typ: t) -> t {

src/comp/middle/typeck.rs

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,16 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
138138
}
139139
}
140140

141-
fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint)
142-
-> {ids: [int], ty: ty::t} {
143-
ty::bind_params_in_type(fcx.ccx.tcx, {|| next_ty_var_id(fcx)}, tp, count)
144-
}
145-
146141
// Instantiates the given path, which must refer to an item with the given
147142
// number of type parameters and type.
148143
fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
149144
tpt: ty_param_bounds_and_ty, sp: span)
150145
-> ty_param_substs_opt_and_ty {
151146
let ty_param_count = vec::len(*tpt.bounds);
152-
let bind_result = bind_params(fcx, tpt.ty, ty_param_count);
153-
let ty_param_vars = bind_result.ids;
154-
let ty_substs_opt;
155-
let ty_substs_len = vec::len::<@ast::ty>(pth.node.types);
147+
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, ty_param_count);
148+
let ty_substs_len = vec::len(pth.node.types);
156149
if ty_substs_len > 0u {
157-
let param_var_len = vec::len(ty_param_vars);
150+
let param_var_len = vec::len(vars);
158151
if param_var_len == 0u {
159152
fcx.ccx.tcx.sess.span_fatal
160153
(sp, "this item does not take type parameters");
@@ -165,32 +158,16 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
165158
fcx.ccx.tcx.sess.span_fatal
166159
(sp, "not enough type parameters provided for this item");
167160
}
168-
let ty_substs: [ty::t] = [];
169-
let i = 0u;
170-
while i < ty_substs_len {
171-
let ty_var = ty::mk_var(fcx.ccx.tcx, ty_param_vars[i]);
172-
let ty_subst = ast_ty_to_ty_crate(fcx.ccx, pth.node.types[i]);
173-
let res_ty = demand::simple(fcx, pth.span, ty_var, ty_subst);
174-
ty_substs += [res_ty];
175-
i += 1u;
161+
vec::iter2(pth.node.types, vars) {|sub, var|
162+
let ty_subst = ast_ty_to_ty_crate(fcx.ccx, sub);
163+
demand::simple(fcx, pth.span, var, ty_subst);
176164
}
177-
ty_substs_opt = some::<[ty::t]>(ty_substs);
178165
if ty_param_count == 0u {
179-
fcx.ccx.tcx.sess.span_fatal(sp,
180-
"this item does not take type \
181-
parameters");
182-
}
183-
} else {
184-
// We will acquire the type parameters through unification.
185-
let ty_substs: [ty::t] = [];
186-
let i = 0u;
187-
while i < ty_param_count {
188-
ty_substs += [ty::mk_var(fcx.ccx.tcx, ty_param_vars[i])];
189-
i += 1u;
166+
fcx.ccx.tcx.sess.span_fatal(
167+
sp, "this item does not take type parameters");
190168
}
191-
ty_substs_opt = some::<[ty::t]>(ty_substs);
192169
}
193-
ret {substs: ty_substs_opt, ty: tpt.ty};
170+
{substs: some(vars), ty: tpt.ty}
194171
}
195172

196173
// Type tests
@@ -1555,9 +1532,9 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15551532
alt vec::find(methods, {|m| m.ident == name}) {
15561533
some(m) {
15571534
let {n_tps, ty: self_ty} = impl_self_ty(tcx, did);
1558-
let {ids, ty: self_ty} = if n_tps > 0u {
1535+
let {vars, ty: self_ty} = if n_tps > 0u {
15591536
bind_params(fcx, self_ty, n_tps)
1560-
} else { {ids: [], ty: self_ty} };
1537+
} else { {vars: [], ty: self_ty} };
15611538
alt unify::unify(fcx, ty, self_ty) {
15621539
ures_ok(_) {
15631540
if option::is_some(result) {
@@ -1568,7 +1545,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15681545
result = some({
15691546
method_ty: ty_from_did(tcx, m.did),
15701547
n_tps: m.n_tps,
1571-
substs: vec::map(ids, {|id| ty::mk_var(tcx, id)}),
1548+
substs: vars,
15721549
origin: method_static(m.did)
15731550
});
15741551
}
@@ -2451,6 +2428,12 @@ fn next_ty_var(fcx: @fn_ctxt) -> ty::t {
24512428
ret ty::mk_var(fcx.ccx.tcx, next_ty_var_id(fcx));
24522429
}
24532430

2431+
fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint)
2432+
-> {vars: [ty::t], ty: ty::t} {
2433+
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, count);
2434+
{vars: vars, ty: ty::substitute_type_params(fcx.ccx.tcx, vars, tp)}
2435+
}
2436+
24542437
fn get_self_info(ccx: @crate_ctxt) -> option::t<self_info> {
24552438
ret vec::last(ccx.self_infos);
24562439
}
@@ -2951,10 +2934,9 @@ mod dict {
29512934
for im in *impls {
29522935
if im.iface_did == some(iface_id) {
29532936
let {n_tps, ty: self_ty} = impl_self_ty(tcx, im.did);
2954-
let {ids, ty: self_ty} = if n_tps > 0u {
2937+
let {vars, ty: self_ty} = if n_tps > 0u {
29552938
bind_params(fcx, self_ty, n_tps)
2956-
} else { {ids: [], ty: self_ty} };
2957-
let vars = vec::map(ids, {|id| ty::mk_var(tcx, id)});
2939+
} else { {vars: [], ty: self_ty} };
29582940
let im_bs = ty::lookup_item_type(tcx, im.did).bounds;
29592941
// FIXME[impl] don't do this in fcx (or make
29602942
// unify transactional by scrubbing bindings on fail)

0 commit comments

Comments
 (0)