@@ -58,14 +58,24 @@ pub fn trans_exchange_free<'a>(cx: &'a Block<'a>, v: ValueRef)
58
58
Some ( expr:: Ignore ) ) . bcx
59
59
}
60
60
61
- pub fn take_ty < ' a > ( cx : & ' a Block < ' a > , v : ValueRef , t : ty:: t )
61
+ pub fn take_ty < ' a > ( bcx : & ' a Block < ' a > , v : ValueRef , t : ty:: t )
62
62
-> & ' a Block < ' a > {
63
63
// NB: v is an *alias* of type t here, not a direct value.
64
64
let _icx = push_ctxt ( "take_ty" ) ;
65
- if ty:: type_needs_drop ( cx. tcx ( ) , t) {
66
- return call_tydesc_glue ( cx, v, t, abi:: tydesc_field_take_glue) ;
65
+ match ty:: get ( t) . sty {
66
+ ty:: ty_box( _) |
67
+ ty:: ty_vec( _, ty:: vstore_box) | ty:: ty_str( ty:: vstore_box) => {
68
+ incr_refcnt_of_boxed ( bcx, v)
69
+ }
70
+ ty:: ty_trait( _, _, ty:: BoxTraitStore , _, _) => {
71
+ incr_refcnt_of_boxed ( bcx, GEPi ( bcx, v, [ 0 u, abi:: trt_field_box] ) )
72
+ }
73
+ _ if ty:: type_is_structural ( t)
74
+ && ty:: type_needs_drop ( bcx. tcx ( ) , t) => {
75
+ iter_structural_ty ( bcx, v, t, take_ty)
76
+ }
77
+ _ => bcx
67
78
}
68
- return cx;
69
79
}
70
80
71
81
pub fn drop_ty < ' a > ( cx : & ' a Block < ' a > , v : ValueRef , t : ty:: t )
@@ -88,30 +98,15 @@ pub fn drop_ty_immediate<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t)
88
98
89
99
pub fn lazily_emit_all_tydesc_glue ( ccx : @CrateContext ,
90
100
static_ti : @tydesc_info ) {
91
- lazily_emit_tydesc_glue ( ccx, abi:: tydesc_field_take_glue, static_ti) ;
92
101
lazily_emit_tydesc_glue ( ccx, abi:: tydesc_field_drop_glue, static_ti) ;
93
102
lazily_emit_tydesc_glue ( ccx, abi:: tydesc_field_visit_glue, static_ti) ;
94
103
}
95
104
96
105
fn simplified_glue_type ( tcx : ty:: ctxt , field : uint , t : ty:: t ) -> ty:: t {
97
- if ( field == abi:: tydesc_field_take_glue || field == abi:: tydesc_field_drop_glue)
98
- && !ty:: type_needs_drop ( tcx, t) {
99
- return ty:: mk_nil ( ) ;
100
- }
101
-
102
- if field == abi:: tydesc_field_take_glue {
103
- match ty:: get ( t) . sty {
104
- ty:: ty_str( ty:: vstore_uniq) | ty:: ty_vec( _, ty:: vstore_uniq) |
105
- ty:: ty_unboxed_vec( ..) | ty:: ty_uniq( ..) => return ty:: mk_nil ( ) ,
106
- _ => { }
107
- }
108
- }
109
-
110
- if field == abi:: tydesc_field_take_glue && ty:: type_is_boxed ( t) {
111
- return ty:: mk_box ( tcx, ty:: mk_nil ( ) ) ;
112
- }
113
-
114
106
if field == abi:: tydesc_field_drop_glue {
107
+ if !ty:: type_needs_drop ( tcx, t) {
108
+ return ty:: mk_nil ( ) ;
109
+ }
115
110
match ty:: get ( t) . sty {
116
111
ty:: ty_box( typ)
117
112
if !ty:: type_needs_drop ( tcx, typ) =>
@@ -145,9 +140,7 @@ fn lazily_emit_tydesc_glue(ccx: @CrateContext, field: uint, ti: @tydesc_info) {
145
140
let simpl_ti = get_tydesc ( ccx, simpl) ;
146
141
lazily_emit_tydesc_glue ( ccx, field, simpl_ti) ;
147
142
148
- if field == abi:: tydesc_field_take_glue {
149
- ti. take_glue . set ( simpl_ti. take_glue . get ( ) ) ;
150
- } else if field == abi:: tydesc_field_drop_glue {
143
+ if field == abi:: tydesc_field_drop_glue {
151
144
ti. drop_glue . set ( simpl_ti. drop_glue . get ( ) ) ;
152
145
} else if field == abi:: tydesc_field_visit_glue {
153
146
ti. visit_glue . set ( simpl_ti. visit_glue . get ( ) ) ;
@@ -158,20 +151,7 @@ fn lazily_emit_tydesc_glue(ccx: @CrateContext, field: uint, ti: @tydesc_info) {
158
151
159
152
let llfnty = Type :: glue_fn ( type_of ( ccx, ti. ty ) . ptr_to ( ) ) ;
160
153
161
- if field == abi:: tydesc_field_take_glue {
162
- match ti. take_glue . get ( ) {
163
- Some ( _) => ( ) ,
164
- None => {
165
- debug ! ( "+++ lazily_emit_tydesc_glue TAKE {}" ,
166
- ppaux:: ty_to_str( ccx. tcx, ti. ty) ) ;
167
- let glue_fn = declare_generic_glue ( ccx, ti. ty , llfnty, "take" ) ;
168
- ti. take_glue . set ( Some ( glue_fn) ) ;
169
- make_generic_glue ( ccx, ti. ty , glue_fn, make_take_glue, "take" ) ;
170
- debug ! ( "--- lazily_emit_tydesc_glue TAKE {}" ,
171
- ppaux:: ty_to_str( ccx. tcx, ti. ty) ) ;
172
- }
173
- }
174
- } else if field == abi:: tydesc_field_drop_glue {
154
+ if field == abi:: tydesc_field_drop_glue {
175
155
match ti. drop_glue . get ( ) {
176
156
Some ( _) => ( ) ,
177
157
None => {
@@ -213,9 +193,7 @@ pub fn call_tydesc_glue_full(bcx: &Block, v: ValueRef, tydesc: ValueRef,
213
193
None => None ,
214
194
Some ( sti) => {
215
195
lazily_emit_tydesc_glue ( ccx, field, sti) ;
216
- if field == abi:: tydesc_field_take_glue {
217
- sti. take_glue . get ( )
218
- } else if field == abi:: tydesc_field_drop_glue {
196
+ if field == abi:: tydesc_field_drop_glue {
219
197
sti. drop_glue . get ( )
220
198
} else if field == abi:: tydesc_field_visit_glue {
221
199
sti. visit_glue . get ( )
@@ -472,53 +450,16 @@ fn decr_refcnt_maybe_free<'a>(bcx: &'a Block<'a>, box_ptr_ptr: ValueRef,
472
450
next_bcx
473
451
}
474
452
475
- fn make_take_glue < ' a > ( bcx : & ' a Block < ' a > , v : ValueRef , t : ty:: t ) -> & ' a Block < ' a > {
476
- let _icx = push_ctxt ( "make_take_glue" ) ;
477
- // NB: v is a *pointer* to type t here, not a direct value.
478
- match ty:: get ( t) . sty {
479
- ty:: ty_box( _) |
480
- ty:: ty_vec( _, ty:: vstore_box) | ty:: ty_str( ty:: vstore_box) => {
481
- incr_refcnt_of_boxed ( bcx, Load ( bcx, v) ) ; bcx
482
- }
483
- ty:: ty_vec( _, ty:: vstore_slice( _) )
484
- | ty:: ty_str( ty:: vstore_slice( _) ) => {
485
- bcx
486
- }
487
- ty:: ty_closure( _) => bcx,
488
- ty:: ty_trait( _, _, ty:: BoxTraitStore , _, _) => {
489
- let llbox = Load ( bcx, GEPi ( bcx, v, [ 0 u, abi:: trt_field_box] ) ) ;
490
- incr_refcnt_of_boxed ( bcx, llbox) ;
491
- bcx
492
- }
493
- ty:: ty_trait( _, _, ty:: UniqTraitStore , _, _) => {
494
- let lluniquevalue = GEPi ( bcx, v, [ 0 , abi:: trt_field_box] ) ;
495
- let llvtable = Load ( bcx, GEPi ( bcx, v, [ 0 , abi:: trt_field_vtable] ) ) ;
496
-
497
- // Cast the vtable to a pointer to a pointer to a tydesc.
498
- let llvtable = PointerCast ( bcx, llvtable,
499
- bcx. ccx ( ) . tydesc_type . ptr_to ( ) . ptr_to ( ) ) ;
500
- let lltydesc = Load ( bcx, llvtable) ;
501
- call_tydesc_glue_full ( bcx,
502
- lluniquevalue,
503
- lltydesc,
504
- abi:: tydesc_field_take_glue,
505
- None ) ;
506
- bcx
507
- }
508
- _ if ty:: type_is_structural ( t) => {
509
- iter_structural_ty ( bcx, v, t, take_ty)
510
- }
511
- _ => bcx
512
- }
513
- }
514
-
515
- fn incr_refcnt_of_boxed ( cx : & Block , box_ptr : ValueRef ) {
453
+ fn incr_refcnt_of_boxed < ' a > ( bcx : & ' a Block < ' a > ,
454
+ box_ptr_ptr : ValueRef ) -> & ' a Block < ' a > {
516
455
let _icx = push_ctxt ( "incr_refcnt_of_boxed" ) ;
517
- let ccx = cx. ccx ( ) ;
518
- let rc_ptr = GEPi ( cx, box_ptr, [ 0 u, abi:: box_field_refcnt] ) ;
519
- let rc = Load ( cx, rc_ptr) ;
520
- let rc = Add ( cx, rc, C_int ( ccx, 1 ) ) ;
521
- Store ( cx, rc, rc_ptr) ;
456
+ let ccx = bcx. ccx ( ) ;
457
+ let box_ptr = Load ( bcx, box_ptr_ptr) ;
458
+ let rc_ptr = GEPi ( bcx, box_ptr, [ 0 u, abi:: box_field_refcnt] ) ;
459
+ let rc = Load ( bcx, rc_ptr) ;
460
+ let rc = Add ( bcx, rc, C_int ( ccx, 1 ) ) ;
461
+ Store ( bcx, rc, rc_ptr) ;
462
+ bcx
522
463
}
523
464
524
465
@@ -554,7 +495,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
554
495
size : llsize,
555
496
align : llalign,
556
497
name : ty_name,
557
- take_glue : Cell :: new ( None ) ,
558
498
drop_glue : Cell :: new ( None ) ,
559
499
visit_glue : Cell :: new ( None ) ,
560
500
} ;
@@ -616,21 +556,6 @@ pub fn emit_tydescs(ccx: &CrateContext) {
616
556
// before being put into the tydesc because we only have a singleton
617
557
// tydesc type. Then we'll recast each function to its real type when
618
558
// calling it.
619
- let take_glue =
620
- match ti. take_glue . get ( ) {
621
- None => {
622
- ccx. stats . n_null_glues . set ( ccx. stats . n_null_glues . get ( ) +
623
- 1 ) ;
624
- C_null ( glue_fn_ty)
625
- }
626
- Some ( v) => {
627
- unsafe {
628
- ccx. stats . n_real_glues . set ( ccx. stats . n_real_glues . get ( ) +
629
- 1 ) ;
630
- llvm:: LLVMConstPointerCast ( v, glue_fn_ty. to_ref ( ) )
631
- }
632
- }
633
- } ;
634
559
let drop_glue =
635
560
match ti. drop_glue . get ( ) {
636
561
None => {
@@ -665,7 +590,6 @@ pub fn emit_tydescs(ccx: &CrateContext) {
665
590
let tydesc = C_named_struct ( ccx. tydesc_type ,
666
591
[ ti. size , // size
667
592
ti. align , // align
668
- take_glue, // take_glue
669
593
drop_glue, // drop_glue
670
594
visit_glue, // visit_glue
671
595
ti. name ] ) ; // name
0 commit comments