Skip to content

Commit 70135a4

Browse files
committed
---
yaml --- r: 1209 b: refs/heads/master c: 3b0e207 h: refs/heads/master i: 1207: b145a46 v: v3
1 parent 9d43e03 commit 70135a4

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 2fb09eb58569f5a0e5544c6256173d4b6b8ffcf2
2+
refs/heads/master: 3b0e207109ba135e94264cef17bac989574ccb0b

trunk/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
418418
arith-0.rs \
419419
arith-1.rs \
420420
arith-2.rs \
421+
bind-interior.rs \
421422
bind-thunk.rs \
422423
bind-trivial.rs \
423424
bitwise.rs \

trunk/src/comp/middle/trans.rs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ fn T_closure_ptr(TypeRef lltarget_ty,
298298
}
299299

300300
fn T_opaque_closure_ptr() -> TypeRef {
301-
ret T_ptr(T_box(T_nil()));
301+
ret T_closure_ptr(T_struct(vec(T_ptr(T_nil()),
302+
T_ptr(T_nil()))),
303+
T_nil());
302304
}
303305

304306

@@ -849,6 +851,50 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @ty.t t) -> result {
849851
T_int(), C_int(0));
850852
}
851853

854+
case (ty.ty_fn(_,_)) {
855+
fn hit_zero(@block_ctxt cx, ValueRef v) -> result {
856+
857+
// Call through the closure's own fields-drop glue first.
858+
auto body =
859+
cx.build.GEP(v,
860+
vec(C_int(0),
861+
C_int(abi.box_rc_field_body)));
862+
863+
auto bindings =
864+
cx.build.GEP(body,
865+
vec(C_int(0),
866+
C_int(abi.closure_elt_bindings)));
867+
auto llrawptr = cx.build.BitCast(bindings, T_ptr(T_i8()));
868+
869+
auto tydescptr =
870+
cx.build.GEP(body,
871+
vec(C_int(0),
872+
C_int(abi.closure_elt_tydesc)));
873+
auto tydesc = cx.build.Load(tydescptr);
874+
auto llfnptr =
875+
cx.build.GEP(tydesc,
876+
vec(C_int(0),
877+
C_int(abi.tydesc_field_drop_glue_off)));
878+
auto llfn = cx.build.Load(llfnptr);
879+
cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, llrawptr));
880+
881+
// Then free the body.
882+
// FIXME: switch gc/non-gc on layer of the type.
883+
ret trans_non_gc_free(cx, v);
884+
}
885+
auto box_cell =
886+
cx.build.GEP(v,
887+
vec(C_int(0),
888+
C_int(abi.fn_field_box)));
889+
890+
auto boxptr = cx.build.Load(box_cell);
891+
892+
ret decr_refcnt_and_if_zero(cx, boxptr,
893+
bind hit_zero(_, boxptr),
894+
"free fn",
895+
T_int(), C_int(0));
896+
}
897+
852898
case (_) {
853899
if (ty.type_is_structural(t)) {
854900
ret iter_structural_ty(cx, v, t,
@@ -2145,13 +2191,11 @@ impure fn trans_bind(@block_ctxt cx, @ast.expr f,
21452191
auto pair_code = bcx.build.GEP(pair_v,
21462192
vec(C_int(0),
21472193
C_int(abi.fn_field_code)));
2194+
2195+
let @ty.t pair_ty = node_ann_type(cx.fcx.ccx, ann);
21482196
let ValueRef llthunk =
2149-
trans_bind_thunk(cx.fcx.ccx,
2150-
node_ann_type(cx.fcx.ccx, ann),
2151-
ty.expr_ty(f),
2152-
args,
2153-
llclosure_ty,
2154-
bound_tys);
2197+
trans_bind_thunk(cx.fcx.ccx, pair_ty, ty.expr_ty(f),
2198+
args, llclosure_ty, bound_tys);
21552199

21562200
bcx.build.Store(llthunk, pair_code);
21572201

@@ -2163,6 +2207,9 @@ impure fn trans_bind(@block_ctxt cx, @ast.expr f,
21632207
T_opaque_closure_ptr()),
21642208
pair_box);
21652209

2210+
find_scope_cx(cx).cleanups +=
2211+
clean(bind drop_slot(_, pair_v, pair_ty));
2212+
21662213
ret res(bcx, pair_v);
21672214
}
21682215
}

0 commit comments

Comments
 (0)