Skip to content

Commit a576aac

Browse files
committed
---
yaml --- r: 7099 b: refs/heads/master c: 8e89df6 h: refs/heads/master i: 7097: a2df9bc 7095: 3c14564 v: v3
1 parent 57e347d commit a576aac

File tree

10 files changed

+404
-304
lines changed

10 files changed

+404
-304
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: 7db640e63d36a1c812295e88a3d059ce5c70115d
2+
refs/heads/master: 8e89df69de47a4f944f5c3fc249a88c5934864b2

trunk/src/comp/back/abi.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const frame_glue_fns_field_drop: int = 1;
2626

2727
const frame_glue_fns_field_reloc: int = 2;
2828

29+
// n.b. must be same as cbox_elt_refcnt
2930
const box_rc_field_refcnt: int = 0;
30-
3131
const box_rc_field_body: int = 1;
3232

3333
const general_code_alignment: int = 16;
@@ -72,9 +72,13 @@ const obj_body_elt_inner_obj: int = 3;
7272
const fn_field_code: int = 0;
7373
const fn_field_box: int = 1;
7474

75-
const closure_elt_tydesc: int = 0;
76-
const closure_elt_ty_params: int = 1;
77-
const closure_elt_bindings: int = 2;
75+
// closure_box, see trans_closure.rs
76+
//
77+
// n.b. the refcnt must be compatible with a normal box
78+
const cbox_elt_refcnt: int = 0;
79+
const cbox_elt_tydesc: int = 1;
80+
const cbox_elt_ty_params: int = 2;
81+
const cbox_elt_bindings: int = 3;
7882

7983
const vec_elt_fill: int = 0;
8084

trunk/src/comp/metadata/tydecode.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,14 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
277277
'E' { let def = parse_def(st, conv); ret ty::mk_native(st.tcx, def); }
278278
'Y' { ret ty::mk_type(st.tcx); }
279279
'y' { ret ty::mk_send_type(st.tcx); }
280-
'C' { ret ty::mk_opaque_closure(st.tcx); }
280+
'C' {
281+
let ck = alt next(st) as char {
282+
'&' { ty::closure_block }
283+
'@' { ty::closure_shared }
284+
'~' { ty::closure_send }
285+
};
286+
ret ty::mk_opaque_closure_ptr(st.tcx, ck);
287+
}
281288
'#' {
282289
let pos = parse_hex(st);
283290
assert (next(st) as char == ':');

trunk/src/comp/metadata/tyencode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
189189
}
190190
ty::ty_type. { w.write_char('Y'); }
191191
ty::ty_send_type. { w.write_char('y'); }
192-
ty::ty_opaque_closure. { w.write_char('C'); }
192+
ty::ty_opaque_closure_ptr(ty::closure_block.) { w.write_str("C&"); }
193+
ty::ty_opaque_closure_ptr(ty::closure_shared.) { w.write_str("C@"); }
194+
ty::ty_opaque_closure_ptr(ty::closure_send.) { w.write_str("C~"); }
193195
ty::ty_constr(ty, cs) {
194196
w.write_str("A[");
195197
enc_ty(w, cx, ty);

trunk/src/comp/middle/shape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const shape_obj: u8 = 19u8;
5151
const shape_res: u8 = 20u8;
5252
const shape_var: u8 = 21u8;
5353
const shape_uniq: u8 = 22u8;
54-
const shape_opaque_closure: u8 = 23u8; // the closure itself.
54+
const shape_opaque_closure_ptr: u8 = 23u8; // the closure itself.
5555

5656
// FIXME: This is a bad API in trans_common.
5757
fn C_u8(n: u8) -> ValueRef { ret trans_common::C_u8(n as uint); }
@@ -419,8 +419,8 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
419419
ty::ty_fn(_) {
420420
s += [shape_fn];
421421
}
422-
ty::ty_opaque_closure. {
423-
s += [shape_opaque_closure];
422+
ty::ty_opaque_closure_ptr(_) {
423+
s += [shape_opaque_closure_ptr];
424424
}
425425
}
426426

trunk/src/comp/middle/trans.rs

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn type_of_fn(cx: @crate_ctxt, sp: span, is_method: bool, inputs: [ty::arg],
9393
if is_method {
9494
atys += [T_ptr(cx.rust_object_type)];
9595
} else {
96-
atys += [T_opaque_boxed_closure_ptr(cx)];
96+
atys += [T_opaque_cbox_ptr(cx)];
9797
}
9898

9999
// Args >2: ty params, if not acquired via capture...
@@ -202,8 +202,8 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
202202
}
203203
T_struct(tys)
204204
}
205-
ty::ty_opaque_closure. {
206-
T_opaque_closure(cx)
205+
ty::ty_opaque_closure_ptr(_) {
206+
T_opaque_cbox_ptr(cx)
207207
}
208208
ty::ty_constr(subt,_) {
209209
// FIXME: could be a constraint on ty_fn
@@ -415,25 +415,13 @@ fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
415415
}
416416

417417
fn size_of(bcx: @block_ctxt, t: ty::t) -> result {
418-
assert !ty::type_has_opaque_size(bcx_tcx(bcx), t);
419418
let {bcx, sz, align: _} = metrics(bcx, t, none);
420419
rslt(bcx, sz)
421420
}
422421

423422
fn align_of(bcx: @block_ctxt, t: ty::t) -> result {
424-
assert !ty::type_has_opaque_size(bcx_tcx(bcx), t);
425-
alt ty::struct(ccx.tcx, t) {
426-
ty::ty_opaque_closure. {
427-
// Hack: the alignment of an opaque closure is always defined as the
428-
// alignment of a pointer. This is not, however, strictly correct,
429-
// depending on your point of view.
430-
llalign_of(bcx, T_ptr(T_i8()));
431-
}
432-
_ {
433-
let {bcx, sz: _, align} = metrics(bcx, t, none);
434-
rslt(bcx, align)
435-
}
436-
}
423+
let {bcx, sz: _, align} = metrics(bcx, t, none);
424+
rslt(bcx, align)
437425
}
438426

439427
// Computes the size/alignment of the type `t`. `opt_v`, if provided, should
@@ -443,8 +431,6 @@ fn align_of(bcx: @block_ctxt, t: ty::t) -> result {
443431
// instance is required.
444432
fn metrics(bcx: @block_ctxt, t: ty::t, opt_v: option<ValueRef>)
445433
-> metrics_result {
446-
assert (option::is_some(opt_v) ||
447-
!ty::type_has_opaque_size(bcx_tcx(bcx), t));
448434
let ccx = bcx_ccx(bcx);
449435
if check type_has_static_size(ccx, t) {
450436
let sp = bcx.sp;
@@ -651,29 +637,6 @@ fn dynamic_metrics(bcx: @block_ctxt,
651637
let total_align = C_int(bcx_ccx(bcx), 1); // FIXME: stub
652638
ret {bcx: bcx, sz: total_size, align: total_align};
653639
}
654-
ty::ty_opaque_closure. {
655-
// Unlike most other types, the type of an opaque closure does not
656-
// fully specify its size. This is because the opaque closure type
657-
// only says that this is a closure over some data, but doesn't say
658-
// how much data there is (hence the word opaque). This is an
659-
// unavoidable consequence of the way that closures encapsulate the
660-
// closed over data. Therefore the only way to know the
661-
// size/alignment of a particular opaque closure instance is to load
662-
// the type descriptor from the instance and consult its
663-
// size/alignment fields. Note that it is meaningless to say "what is
664-
// the size of the type opaque closure?" One can only ask "what is the
665-
// size of this particular opaque closure?"
666-
let v = alt opt_v {
667-
none. { fail "Require value to compute metrics of opaque closures"; }
668-
some(v) { v }
669-
};
670-
let v = PointerCast(bcx, v, T_ptr(T_opaque_closure(bcx_ccx(bcx))));
671-
let tdptrptr = GEPi(bcx, v, [0, abi::closure_elt_tydesc]);
672-
let tdptr = Load(bcx, tdptrptr);
673-
let sz = Load(bcx, GEPi(bcx, tdptr, [0, abi::tydesc_field_size]));
674-
let align = Load(bcx, GEPi(bcx, tdptr, [0, abi::tydesc_field_align]));
675-
ret { bcx: bcx, sz: sz, align: align };
676-
}
677640
}
678641
}
679642

@@ -1354,9 +1317,8 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) {
13541317
ty::ty_native_fn(_, _) | ty::ty_fn(_) {
13551318
trans_closure::make_fn_glue(bcx, v, t, take_ty)
13561319
}
1357-
ty::ty_opaque_closure. {
1358-
trans_closure::call_opaque_closure_glue(
1359-
bcx, v, abi::tydesc_field_take_glue)
1320+
ty::ty_opaque_closure_ptr(ck) {
1321+
trans_closure::make_opaque_cbox_take_glue(bcx, ck, v)
13601322
}
13611323
_ when ty::type_is_structural(bcx_tcx(bcx), t) {
13621324
iter_structural_ty(bcx, v, t, take_ty)
@@ -1429,9 +1391,8 @@ fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) {
14291391
ty::ty_native_fn(_, _) | ty::ty_fn(_) {
14301392
trans_closure::make_fn_glue(bcx, v, t, free_ty)
14311393
}
1432-
ty::ty_opaque_closure. {
1433-
trans_closure::call_opaque_closure_glue(
1434-
bcx, v, abi::tydesc_field_free_glue)
1394+
ty::ty_opaque_closure_ptr(ck) {
1395+
trans_closure::make_opaque_cbox_free_glue(bcx, ck, v)
14351396
}
14361397
_ { bcx }
14371398
};
@@ -1458,9 +1419,8 @@ fn make_drop_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
14581419
ty::ty_native_fn(_, _) | ty::ty_fn(_) {
14591420
trans_closure::make_fn_glue(bcx, v0, t, drop_ty)
14601421
}
1461-
ty::ty_opaque_closure. {
1462-
trans_closure::call_opaque_closure_glue(
1463-
bcx, v0, abi::tydesc_field_drop_glue)
1422+
ty::ty_opaque_closure_ptr(ck) {
1423+
trans_closure::make_opaque_cbox_drop_glue(bcx, ck, v0)
14641424
}
14651425
_ {
14661426
if ty::type_needs_drop(ccx.tcx, t) &&
@@ -2617,7 +2577,7 @@ type lval_maybe_callee = {bcx: @block_ctxt,
26172577
generic: option::t<generic_info>};
26182578

26192579
fn null_env_ptr(bcx: @block_ctxt) -> ValueRef {
2620-
C_null(T_opaque_boxed_closure_ptr(bcx_ccx(bcx)))
2580+
C_null(T_opaque_cbox_ptr(bcx_ccx(bcx)))
26212581
}
26222582

26232583
fn lval_from_local_var(bcx: @block_ctxt, r: local_var_result) -> lval_result {
@@ -3274,7 +3234,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
32743234
let llenv, dict_param = none;
32753235
alt f_res.env {
32763236
null_env. {
3277-
llenv = llvm::LLVMGetUndef(T_opaque_boxed_closure_ptr(bcx_ccx(cx)));
3237+
llenv = llvm::LLVMGetUndef(T_opaque_cbox_ptr(bcx_ccx(cx)));
32783238
}
32793239
obj_env(e) { llenv = e; }
32803240
dict_env(dict, e) { llenv = e; dict_param = some(dict); }
@@ -5257,7 +5217,7 @@ fn fill_fn_pair(bcx: @block_ctxt, pair: ValueRef, llfn: ValueRef,
52575217
Store(bcx, llfn, code_cell);
52585218
let env_cell = GEPi(bcx, pair, [0, abi::fn_field_box]);
52595219
let llenvblobptr =
5260-
PointerCast(bcx, llenvptr, T_opaque_boxed_closure_ptr(ccx));
5220+
PointerCast(bcx, llenvptr, T_opaque_cbox_ptr(ccx));
52615221
Store(bcx, llenvblobptr, env_cell);
52625222
}
52635223

0 commit comments

Comments
 (0)