From 55a65a51aafe3097ff13055578d265adcc47c42b Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Wed, 27 Jul 2011 15:14:59 -0700 Subject: [PATCH] Eliminate "target" field in closures. --- src/comp/back/abi.rs | 6 ++---- src/comp/middle/trans.rs | 11 +++++------ src/comp/middle/trans_common.rs | 13 +++++-------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs index fc6385da4a0..4fbf46c4243 100644 --- a/src/comp/back/abi.rs +++ b/src/comp/back/abi.rs @@ -97,11 +97,9 @@ const fn_field_box: int = 1; const closure_elt_tydesc: int = 0; -const closure_elt_target: int = 1; +const closure_elt_bindings: int = 1; -const closure_elt_bindings: int = 2; - -const closure_elt_ty_params: int = 3; +const closure_elt_ty_params: int = 2; const ivec_default_length: uint = 4u; diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 8c104b56402..1475887ae4d 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -3721,14 +3721,14 @@ fn build_environment(cx: &@block_ctxt, upvars: &freevar_set) -> } // Create an environment and populate it with the bindings. - let tydesc_count = std::ivec::len[ValueRef](cx.fcx.lltydescs); + let tydesc_count = std::ivec::len(cx.fcx.lltydescs); let llenvptrty = - T_closure_ptr(*bcx_ccx(cx), T_ptr(T_nil()), val_ty(llbindingsptr), - tydesc_count); + T_closure_ptr(*bcx_ccx(cx), val_ty(llbindingsptr), tydesc_count); let llenvptr = alloca(cx, llvm::LLVMGetElementType(llenvptrty)); let llbindingsptrptr = cx.build.GEP(llenvptr, - ~[C_int(0), C_int(abi::box_rc_field_body), C_int(2)]); + ~[C_int(0), C_int(abi::box_rc_field_body), + C_int(abi::closure_elt_bindings)]); cx.build.Store(llbindingsptr, llbindingsptrptr); // Copy in our type descriptors, in case the iterator body needs to refer @@ -4610,8 +4610,7 @@ fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result, // closure_tys = [tydesc_ty, outgoing_fty, [bound_ty1, bound_ty2, // ...], [tydesc_ty, tydesc_ty, ...]] let closure_tys: ty::t[] = - ~[tydesc_ty, outgoing_fty, bindings_ty, - ty::mk_imm_tup(bcx_tcx(cx), captured_tys)]; + ~[tydesc_ty, bindings_ty, ty::mk_imm_tup(bcx_tcx(cx), captured_tys)]; // Finally, synthesize a type for that whole vector. let closure_ty: ty::t = ty::mk_imm_tup(bcx_tcx(cx), closure_tys); diff --git a/src/comp/middle/trans_common.rs b/src/comp/middle/trans_common.rs index 7f6392397d4..443d4e1de4c 100644 --- a/src/comp/middle/trans_common.rs +++ b/src/comp/middle/trans_common.rs @@ -674,13 +674,12 @@ fn T_typaram(tn: &type_names) -> TypeRef { fn T_typaram_ptr(tn: &type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); } -fn T_closure_ptr(cx: &crate_ctxt, lltarget_ty: TypeRef, - llbindings_ty: TypeRef, n_ty_params: uint) -> TypeRef { +fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, + n_ty_params: uint) -> TypeRef { // NB: keep this in sync with code in trans_bind; we're making // an LLVM typeref structure that has the same "shape" as the ty::t // it constructs. - - ret T_ptr(T_box(T_struct(~[T_ptr(cx.tydesc_type), lltarget_ty, + ret T_ptr(T_box(T_struct(~[T_ptr(cx.tydesc_type), llbindings_ty, T_captured_tydescs(cx, n_ty_params)]))); } @@ -688,9 +687,7 @@ fn T_closure_ptr(cx: &crate_ctxt, lltarget_ty: TypeRef, fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef { let s = "*closure"; if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); } - let t = - T_closure_ptr(cx, T_struct(~[T_ptr(T_nil()), T_ptr(T_nil())]), - T_nil(), 0u); + let t = T_closure_ptr(cx, T_nil(), 0u); cx.tn.associate(s, t); ret t; } @@ -836,4 +833,4 @@ fn C_named_struct(T: TypeRef, elts: &ValueRef[]) -> ValueRef { fn C_array(ty: TypeRef, elts: &ValueRef[]) -> ValueRef { ret llvm::LLVMConstArray(ty, std::ivec::to_ptr(elts), std::ivec::len(elts)); -} \ No newline at end of file +}