Skip to content

Commit 2e0d075

Browse files
committed
Fix bug in bind thunks failing top drop unbound args; add test and adjust rustc to use bind again.
1 parent 62c224f commit 2e0d075

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
462462
deep.rs \
463463
deref.rs \
464464
destructor-ordering.rs \
465+
drop-bind-thunk-args.rs \
465466
drop-on-empty-block-exit.rs \
466467
export-non-interference.rs \
467468
exterior.rs \

src/boot/me/trans.ml

+16
Original file line numberDiff line numberDiff line change
@@ -1640,12 +1640,28 @@ let trans_visitor
16401640
get_element_ptr closure_target_cell Abi.fn_field_code
16411641
in
16421642

1643+
let self_args_cell =
1644+
get_element_ptr all_self_args_cell Abi.calltup_elt_args
1645+
in
1646+
1647+
let self_ty_params_cell =
1648+
get_element_ptr all_self_args_cell Abi.calltup_elt_ty_params
1649+
in
1650+
16431651
merge_bound_args
16441652
self_args_rty callee_args_rty
16451653
arg_slots arg_bound_flags;
16461654
iflog (fun _ -> annotate "call through to closure target fn");
16471655

16481656
call_code (code_of_cell closure_target_code_cell);
1657+
1658+
(* Drop the args we were passed. *)
1659+
Array.iteri
1660+
(fun i slot ->
1661+
let cell = get_element_ptr self_args_cell i in
1662+
drop_slot self_ty_params_cell cell slot)
1663+
unbound_slots;
1664+
16491665
trans_glue_frame_exit fix spill g
16501666

16511667

src/comp/middle/trans.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ state type fn_ctxt = rec(ValueRef llfn,
5151
type terminator = fn(@fn_ctxt cx, builder build);
5252

5353
tag cleanup {
54-
clean(fn(@block_ctxt cx, ValueRef v), ValueRef);
54+
clean(fn(@block_ctxt cx));
5555
}
5656

5757
state type block_ctxt = rec(BasicBlockRef llbb,
@@ -303,8 +303,7 @@ fn trans_lit(@block_ctxt cx, &ast.lit lit) -> ValueRef {
303303
vec(p2i(C_str(cx.fcx.tcx, s)),
304304
C_int(len)));
305305
v = cx.build.IntToPtr(v, T_ptr(T_str()));
306-
auto f = drop_str;
307-
cx.cleanups += vec(clean(f, v));
306+
cx.cleanups += vec(clean(bind drop_str(_, v)));
308307
ret v;
309308
}
310309
}
@@ -496,8 +495,8 @@ fn trans_block(@fn_ctxt cx, &ast.block b, terminator term) {
496495

497496
for (cleanup c in bcx.cleanups) {
498497
alt (c) {
499-
case (clean(?cfn, ?v)) {
500-
cfn(bcx, v);
498+
case (clean(?cfn)) {
499+
cfn(bcx);
501500
}
502501
}
503502
}

src/rt/rust_builtin.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ debug_fn(rust_task *task, type_desc *t, rust_fn *fn)
338338
debug_tydesc_helper(task, t);
339339
task->log(rust_log::STDLIB, " thunk at 0x%" PRIxPTR, fn->thunk);
340340
task->log(rust_log::STDLIB, " closure at 0x%" PRIxPTR, fn->closure);
341+
if (fn->closure) {
342+
task->log(rust_log::STDLIB, " refcount %" PRIdPTR,
343+
fn->closure->ref_count);
344+
}
341345
}
342346

343347
extern "C" CDECL void *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn f(@int x) { }
2+
3+
fn main() {
4+
auto x = @10;
5+
auto ff = bind f(_);
6+
ff(x);
7+
ff(x);
8+
}

0 commit comments

Comments
 (0)