@@ -33,23 +33,6 @@ use std::option::None;
3333use syntax:: ast;
3434use syntax:: codemap;
3535
36- pub fn make_uniq_free_glue ( bcx : block , vptrptr : ValueRef , box_ty : ty:: t )
37- -> block {
38- let box_datum = immediate_rvalue ( Load ( bcx, vptrptr) , box_ty) ;
39-
40- let not_null = IsNotNull ( bcx, box_datum. val ) ;
41- do with_cond( bcx, not_null) |bcx| {
42- let body_datum = box_datum. box_body ( bcx) ;
43- let bcx = glue:: drop_ty ( bcx, body_datum. to_ref_llval ( bcx) ,
44- body_datum. ty ) ;
45- if ty:: type_contents ( bcx. tcx ( ) , box_ty) . contains_managed ( ) {
46- glue:: trans_free ( bcx, box_datum. val )
47- } else {
48- glue:: trans_exchange_free ( bcx, box_datum. val )
49- }
50- }
51- }
52-
5336// Boxed vector types are in some sense currently a "shorthand" for a box
5437// containing an unboxed vector. This expands a boxed vector type into such an
5538// expanded type. It doesn't respect mutability, but that doesn't matter at
@@ -59,7 +42,7 @@ pub fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
5942 let unboxed_vec_ty = ty:: mk_mut_unboxed_vec ( tcx, unit_ty) ;
6043 match ty:: get ( t) . sty {
6144 ty:: ty_estr( ty:: vstore_uniq) | ty:: ty_evec( _, ty:: vstore_uniq) => {
62- fail ! ( "cannot treat vectors/strings as exchange allocations yet" ) ;
45+ ty :: mk_imm_uniq ( tcx , unboxed_vec_ty )
6346 }
6447 ty:: ty_estr( ty:: vstore_box) | ty:: ty_evec( _, ty:: vstore_box) => {
6548 ty:: mk_imm_box ( tcx, unboxed_vec_ty)
@@ -80,8 +63,12 @@ pub fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
8063 Load ( bcx, GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_alloc] ) )
8164}
8265
83- pub fn get_bodyptr ( bcx : block , vptr : ValueRef ) -> ValueRef {
84- GEPi ( bcx, vptr, [ 0 u, abi:: box_field_body] )
66+ pub fn get_bodyptr ( bcx : block , vptr : ValueRef , t : ty:: t ) -> ValueRef {
67+ if ty:: type_contents ( bcx. tcx ( ) , t) . contains_managed ( ) {
68+ GEPi ( bcx, vptr, [ 0 u, abi:: box_field_body] )
69+ } else {
70+ vptr
71+ }
8572}
8673
8774pub fn get_dataptr ( bcx : block , vptr : ValueRef ) -> ValueRef {
@@ -104,25 +91,24 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
10491 let vecbodyty = ty:: mk_mut_unboxed_vec ( bcx. tcx ( ) , unit_ty) ;
10592 let vecsize = Add ( bcx, alloc, llsize_of ( ccx, ccx. opaque_vec_type ) ) ;
10693
107- let base:: MallocResult { bcx, box : bx, body} =
108- base:: malloc_general_dyn ( bcx, vecbodyty, heap, vecsize) ;
109- Store ( bcx, fill, GEPi ( bcx, body, [ 0 u, abi:: vec_elt_fill] ) ) ;
110- Store ( bcx, alloc, GEPi ( bcx, body, [ 0 u, abi:: vec_elt_alloc] ) ) ;
111- base:: maybe_set_managed_unique_rc ( bcx, bx, heap) ;
112- return rslt ( bcx, bx) ;
113- }
114-
115- pub fn heap_for_unique_vector ( bcx : block , t : ty:: t ) -> heap {
116- if ty:: type_contents ( bcx. tcx ( ) , t) . contains_managed ( ) {
117- heap_managed_unique
94+ if heap == heap_exchange {
95+ let Result { bcx : bcx, val : val } = malloc_raw_dyn ( bcx, vecbodyty, heap_exchange, vecsize) ;
96+ Store ( bcx, fill, GEPi ( bcx, val, [ 0 u, abi:: vec_elt_fill] ) ) ;
97+ Store ( bcx, alloc, GEPi ( bcx, val, [ 0 u, abi:: vec_elt_alloc] ) ) ;
98+ return rslt ( bcx, val) ;
11899 } else {
119- heap_exchange_vector
100+ let base:: MallocResult { bcx, box : bx, body} =
101+ base:: malloc_general_dyn ( bcx, vecbodyty, heap, vecsize) ;
102+ Store ( bcx, fill, GEPi ( bcx, body, [ 0 u, abi:: vec_elt_fill] ) ) ;
103+ Store ( bcx, alloc, GEPi ( bcx, body, [ 0 u, abi:: vec_elt_alloc] ) ) ;
104+ base:: maybe_set_managed_unique_rc ( bcx, bx, heap) ;
105+ return rslt ( bcx, bx) ;
120106 }
121107}
122108
123109pub fn alloc_uniq_raw ( bcx : block , unit_ty : ty:: t ,
124110 fill : ValueRef , alloc : ValueRef ) -> Result {
125- alloc_raw ( bcx, unit_ty, fill, alloc, heap_for_unique_vector ( bcx, unit_ty) )
111+ alloc_raw ( bcx, unit_ty, fill, alloc, base :: heap_for_unique ( bcx, unit_ty) )
126112}
127113
128114pub fn alloc_vec ( bcx : block ,
@@ -146,12 +132,12 @@ pub fn alloc_vec(bcx: block,
146132pub fn duplicate_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ) -> Result {
147133 let _icx = push_ctxt ( "tvec::duplicate_uniq" ) ;
148134
149- let fill = get_fill ( bcx, get_bodyptr ( bcx, vptr) ) ;
135+ let fill = get_fill ( bcx, get_bodyptr ( bcx, vptr, vec_ty ) ) ;
150136 let unit_ty = ty:: sequence_element_type ( bcx. tcx ( ) , vec_ty) ;
151137 let Result { bcx, val : newptr} = alloc_uniq_raw ( bcx, unit_ty, fill, fill) ;
152138
153- let data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, vptr) ) ;
154- let new_data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, newptr) ) ;
139+ let data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, vptr, vec_ty ) ) ;
140+ let new_data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, newptr, vec_ty ) ) ;
155141 base:: call_memcpy ( bcx, new_data_ptr, data_ptr, fill, 1 ) ;
156142
157143 let bcx = if ty:: type_needs_drop ( bcx. tcx ( ) , unit_ty) {
@@ -323,7 +309,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
323309
324310 // Handle ~"".
325311 match heap {
326- heap_exchange_vector => {
312+ heap_exchange => {
327313 match content_expr. node {
328314 ast:: expr_lit( @codemap:: spanned {
329315 node : ast:: lit_str( s) , _
@@ -346,7 +332,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
346332 _ => { }
347333 }
348334 }
349- heap_exchange | heap_exchange_closure => fail ! ( "vectors use vector_exchange_alloc " ) ,
335+ heap_exchange_closure => fail ! ( "vectors use exchange_alloc " ) ,
350336 heap_managed | heap_managed_unique => { }
351337 }
352338
@@ -356,7 +342,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
356342 let Result { bcx, val} = alloc_vec ( bcx, vt. unit_ty , count, heap) ;
357343
358344 add_clean_free ( bcx, val, heap) ;
359- let dataptr = get_dataptr ( bcx, get_bodyptr ( bcx, val) ) ;
345+ let dataptr = get_dataptr ( bcx, get_bodyptr ( bcx, val, vt . vec_ty ) ) ;
360346
361347 debug ! ( "alloc_vec() returned val=%s, dataptr=%s" ,
362348 bcx. val_to_str( val) , bcx. val_to_str( dataptr) ) ;
@@ -562,7 +548,7 @@ pub fn get_base_and_len(bcx: block,
562548 ( base, len)
563549 }
564550 ty:: vstore_uniq | ty:: vstore_box => {
565- let body = get_bodyptr ( bcx, llval) ;
551+ let body = get_bodyptr ( bcx, llval, vec_ty ) ;
566552 ( get_dataptr ( bcx, body) , get_fill ( bcx, body) )
567553 }
568554 }
@@ -604,7 +590,7 @@ pub fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
604590pub fn iter_vec_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ,
605591 fill : ValueRef , f : iter_vec_block ) -> block {
606592 let _icx = push_ctxt ( "tvec::iter_vec_uniq" ) ;
607- let data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, vptr) ) ;
593+ let data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, vptr, vec_ty ) ) ;
608594 iter_vec_raw ( bcx, data_ptr, vec_ty, fill, f)
609595}
610596
0 commit comments