]> git.lizzy.rs Git - rust.git/commitdiff
Make build_environment and trans_bind_thunk GEP bound arguments the same
authorBrian Anderson <banderson@mozilla.com>
Wed, 12 Oct 2011 19:03:30 +0000 (12:03 -0700)
committerBrian Anderson <banderson@mozilla.com>
Wed, 12 Oct 2011 19:11:07 +0000 (12:11 -0700)
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
src/test/run-pass/bind-generic.rs [new file with mode: 0644]

index 0e3e95e5f9f8f2e252993a60a56887e2ea299970..9d80a97eb86c718c0ba5b8c71c324c30035ec6d0 100644 (file)
@@ -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 (file)
index 0000000..888c502
--- /dev/null
@@ -0,0 +1,16 @@
+fn wrapper3<T>(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<T>(i: T, j: int) {
+    let wrapped = bind wrapper3(i, j);
+    wrapped();
+}
+
+fn main() {
+    spawn3(127u8, 123456789);
+}
\ No newline at end of file