Skip to content

Commit a34f7c8

Browse files
committed
Switch the heap build and load environment functions to use GEP_tup_like.
1 parent 56f0fbe commit a34f7c8

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/comp/middle/trans.rs

+29-25
Original file line numberDiff line numberDiff line change
@@ -3671,8 +3671,8 @@ fn build_environment_heap(bcx: @block_ctxt, lltydescs: ValueRef[],
36713671
// ourselves) into a vector. The whole things ends up looking
36723672
// like:
36733673

3674-
// closure_tys = [tydesc_ty, outgoing_fty, [bound_ty1, bound_ty2,
3675-
// ...], [tydesc_ty, tydesc_ty, ...]]
3674+
// closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty,
3675+
// tydesc_ty, ...]]
36763676
let closure_tys: ty::t[] =
36773677
~[tydesc_ty, bindings_ty, ty::mk_imm_tup(bcx_tcx(bcx), captured_tys)];
36783678

@@ -3697,22 +3697,27 @@ fn build_environment_heap(bcx: @block_ctxt, lltydescs: ValueRef[],
36973697
// Copy expr values into boxed bindings.
36983698
let i = 0u;
36993699
let bindings =
3700-
bcx.build.GEP(closure, ~[C_int(0), C_int(abi::closure_elt_bindings)]);
3700+
GEP_tup_like(bcx, closure_ty, closure,
3701+
~[0, abi::closure_elt_bindings]);
3702+
bcx = bindings.bcx;
37013703
for lv: lval_result in bound_vals {
3702-
let bound = bcx.build.GEP(bindings, ~[C_int(0), C_int(i as int)]);
3703-
bcx = move_val_if_temp(bcx, INIT, bound, lv, bound_tys.(i)).bcx;
3704+
let bound = GEP_tup_like(bcx, bindings_ty, bindings.val,
3705+
~[0, i as int]);
3706+
bcx = move_val_if_temp(bound.bcx, INIT,
3707+
bound.val, lv, bound_tys.(i)).bcx;
37043708
i += 1u;
37053709
}
37063710

37073711
// If necessary, copy tydescs describing type parameters into the
37083712
// appropriate slot in the closure.
37093713
let ty_params_slot =
3710-
bcx.build.GEP(closure,
3711-
~[C_int(0), C_int(abi::closure_elt_ty_params)]);
3714+
GEP_tup_like(bcx, closure_ty, closure,
3715+
~[0, abi::closure_elt_ty_params]);
3716+
bcx = ty_params_slot.bcx;
37123717
i = 0u;
37133718
for td: ValueRef in lltydescs {
37143719
let ty_param_slot =
3715-
bcx.build.GEP(ty_params_slot, ~[C_int(0), C_int(i as int)]);
3720+
bcx.build.GEP(ty_params_slot.val, ~[C_int(0), C_int(i as int)]);
37163721
bcx.build.Store(td, ty_param_slot);
37173722
i += 1u;
37183723
}
@@ -3802,34 +3807,33 @@ fn load_environment_heap(enclosing_cx: &@block_ctxt, fcx: &@fn_ctxt,
38023807
envty: &ty::t, upvars: &@ast::node_id[]) {
38033808
let bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
38043809

3805-
let llenvptr =
3806-
bcx.build.GEP(fcx.llenv, ~[C_int(0), C_int(abi::box_rc_field_body)]);
3807-
let llenvptrty = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, envty));;
3808-
llenvptr = bcx.build.PointerCast(llenvptr, llenvptrty);
3810+
let ty = ty::mk_imm_box(bcx_tcx(bcx), envty);
3811+
let llty = type_of(bcx_ccx(bcx), bcx.sp, ty);
3812+
let llclosure = bcx.build.PointerCast(fcx.llenv, llty);
3813+
3814+
let path = ~[0, abi::box_rc_field_body];
38093815

38103816
// Populate the upvars from the environment.
3811-
let llbindingsptr =
3812-
bcx.build.GEP(llenvptr,
3813-
~[C_int(0), C_int(abi::closure_elt_bindings)]);
3817+
let bindings_path = path + ~[abi::closure_elt_bindings];
38143818
let i = 0u;
38153819
for upvar_id: ast::node_id in *upvars {
38163820
let llupvarptr =
3817-
bcx.build.GEP(llbindingsptr, ~[C_int(0), C_int(i as int)]);
3821+
GEP_tup_like(bcx, ty, llclosure, bindings_path + ~[i as int]);
3822+
bcx = llupvarptr.bcx;
38183823
let def_id = ast::def_id_of_def(bcx_tcx(bcx).def_map.get(upvar_id));
3819-
fcx.llupvars.insert(def_id.node, llupvarptr);
3824+
fcx.llupvars.insert(def_id.node, llupvarptr.val);
38203825
i += 1u;
38213826
}
38223827

38233828
// Populate the type parameters from the environment.
3824-
let lltydescsptr =
3825-
bcx.build.GEP(llenvptr,
3826-
~[C_int(0), C_int(abi::closure_elt_ty_params)]);
38273829
let tydesc_count = std::ivec::len(enclosing_cx.fcx.lltydescs);
3830+
let tydesc_path = path + ~[abi::closure_elt_ty_params];
38283831
i = 0u;
38293832
while i < tydesc_count {
38303833
let lltydescptr =
3831-
bcx.build.GEP(lltydescsptr, ~[C_int(0), C_int(i as int)]);
3832-
fcx.lltydescs += ~[bcx.build.Load(lltydescptr)];
3834+
GEP_tup_like(bcx, ty, llclosure, tydesc_path + ~[i as int]);
3835+
bcx = lltydescptr.bcx;
3836+
fcx.lltydescs += ~[bcx.build.Load(lltydescptr.val)];
38333837
i += 1u;
38343838
}
38353839
}
@@ -4442,7 +4446,7 @@ fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result {
44424446

44434447
fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
44444448
outgoing_fty: &ty::t, args: &(option::t[@ast::expr])[],
4445-
closure_ty: &ty::t, bound_tys: &ty::t[],
4449+
env_ty: &ty::t, bound_tys: &ty::t[],
44464450
ty_param_count: uint) -> {val: ValueRef, ty: TypeRef} {
44474451

44484452
// Here we're not necessarily constructing a thunk in the sense of
@@ -4491,8 +4495,8 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
44914495

44924496
// The llenv pointer needs to be the correct size. That size is
44934497
// 'closure_ty', which was determined by trans_bind.
4494-
let llclosure_ptr_ty =
4495-
type_of(cx.ccx, sp, ty::mk_imm_box(cx.ccx.tcx, closure_ty));
4498+
let closure_ty = ty::mk_imm_box(cx.ccx.tcx, env_ty);
4499+
let llclosure_ptr_ty = type_of(cx.ccx, sp, closure_ty);
44964500
let llclosure =
44974501
copy_args_bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty);
44984502

0 commit comments

Comments
 (0)