From 99f876e3a8da7423252c6b4bad901c5c6f881f1e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 12 Oct 2011 12:03:30 -0700 Subject: [PATCH] Make build_environment and trans_bind_thunk GEP bound arguments the same These functions both use GEP_tup_like to get at the arguments bound to the environment, but they were starting from a different 'level' of the environment-box structure. Frighteningly, this was leading to them having different opinions of how the bound arguments were aligned in some cases. --- src/comp/middle/trans.rs | 11 ++++++----- src/test/run-pass/bind-generic.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/test/run-pass/bind-generic.rs diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 0e3e95e5f9f..9d80a97eb86 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2705,13 +2705,14 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef], // Copy expr values into boxed bindings. // Silly check check type_is_tup_like(bcx, closure_ty); - let bindings = GEP_tup_like(bcx, closure_ty, closure, - [0, abi::closure_elt_bindings]); - bcx = bindings.bcx; + let closure_box = box; + let closure_box_ty = ty::mk_imm_box(bcx_tcx(bcx), closure_ty); let i = 0u; for bv in bound_values { - let bound = - GEP_tup_like_1(bcx, bindings_ty, bindings.val, [0, i as int]); + let bound = GEP_tup_like_1(bcx, closure_box_ty, closure_box, + [0, abi::box_rc_field_body, + abi::closure_elt_bindings, + i as int]); bcx = bound.bcx; alt bv { env_expr(e) { diff --git a/src/test/run-pass/bind-generic.rs b/src/test/run-pass/bind-generic.rs new file mode 100644 index 00000000000..888c5021b3f --- /dev/null +++ b/src/test/run-pass/bind-generic.rs @@ -0,0 +1,16 @@ +fn wrapper3(i: T, j: int) { + log i; + log j; + // This is a regression test that the spawn3 thunk to wrapper3 + // correctly finds the value of j + assert j == 123456789; +} + +fn spawn3(i: T, j: int) { + let wrapped = bind wrapper3(i, j); + wrapped(); +} + +fn main() { + spawn3(127u8, 123456789); +} \ No newline at end of file