mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-11 07:21:51 +00:00
Eliminate "target" field in closures.
This commit is contained in:
parent
b977b5c508
commit
55a65a51aa
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user