@@ -33,23 +33,6 @@ use std::option::None;
33
33
use syntax:: ast;
34
34
use syntax:: codemap;
35
35
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
-
53
36
// Boxed vector types are in some sense currently a "shorthand" for a box
54
37
// containing an unboxed vector. This expands a boxed vector type into such an
55
38
// 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 {
59
42
let unboxed_vec_ty = ty:: mk_mut_unboxed_vec ( tcx, unit_ty) ;
60
43
match ty:: get ( t) . sty {
61
44
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 )
63
46
}
64
47
ty:: ty_estr( ty:: vstore_box) | ty:: ty_evec( _, ty:: vstore_box) => {
65
48
ty:: mk_imm_box ( tcx, unboxed_vec_ty)
@@ -80,8 +63,12 @@ pub fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
80
63
Load ( bcx, GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_alloc] ) )
81
64
}
82
65
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
+ }
85
72
}
86
73
87
74
pub fn get_dataptr ( bcx : block , vptr : ValueRef ) -> ValueRef {
@@ -104,25 +91,24 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
104
91
let vecbodyty = ty:: mk_mut_unboxed_vec ( bcx. tcx ( ) , unit_ty) ;
105
92
let vecsize = Add ( bcx, alloc, llsize_of ( ccx, ccx. opaque_vec_type ) ) ;
106
93
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) ;
118
99
} 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) ;
120
106
}
121
107
}
122
108
123
109
pub fn alloc_uniq_raw ( bcx : block , unit_ty : ty:: t ,
124
110
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) )
126
112
}
127
113
128
114
pub fn alloc_vec ( bcx : block ,
@@ -146,12 +132,12 @@ pub fn alloc_vec(bcx: block,
146
132
pub fn duplicate_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ) -> Result {
147
133
let _icx = push_ctxt ( "tvec::duplicate_uniq" ) ;
148
134
149
- let fill = get_fill ( bcx, get_bodyptr ( bcx, vptr) ) ;
135
+ let fill = get_fill ( bcx, get_bodyptr ( bcx, vptr, vec_ty ) ) ;
150
136
let unit_ty = ty:: sequence_element_type ( bcx. tcx ( ) , vec_ty) ;
151
137
let Result { bcx, val : newptr} = alloc_uniq_raw ( bcx, unit_ty, fill, fill) ;
152
138
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 ) ) ;
155
141
base:: call_memcpy ( bcx, new_data_ptr, data_ptr, fill, 1 ) ;
156
142
157
143
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
323
309
324
310
// Handle ~"".
325
311
match heap {
326
- heap_exchange_vector => {
312
+ heap_exchange => {
327
313
match content_expr. node {
328
314
ast:: expr_lit( @codemap:: spanned {
329
315
node : ast:: lit_str( s) , _
@@ -346,7 +332,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
346
332
_ => { }
347
333
}
348
334
}
349
- heap_exchange | heap_exchange_closure => fail ! ( "vectors use vector_exchange_alloc " ) ,
335
+ heap_exchange_closure => fail ! ( "vectors use exchange_alloc " ) ,
350
336
heap_managed | heap_managed_unique => { }
351
337
}
352
338
@@ -356,7 +342,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
356
342
let Result { bcx, val} = alloc_vec ( bcx, vt. unit_ty , count, heap) ;
357
343
358
344
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 ) ) ;
360
346
361
347
debug ! ( "alloc_vec() returned val=%s, dataptr=%s" ,
362
348
bcx. val_to_str( val) , bcx. val_to_str( dataptr) ) ;
@@ -562,7 +548,7 @@ pub fn get_base_and_len(bcx: block,
562
548
( base, len)
563
549
}
564
550
ty:: vstore_uniq | ty:: vstore_box => {
565
- let body = get_bodyptr ( bcx, llval) ;
551
+ let body = get_bodyptr ( bcx, llval, vec_ty ) ;
566
552
( get_dataptr ( bcx, body) , get_fill ( bcx, body) )
567
553
}
568
554
}
@@ -604,7 +590,7 @@ pub fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
604
590
pub fn iter_vec_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ,
605
591
fill : ValueRef , f : iter_vec_block ) -> block {
606
592
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 ) ) ;
608
594
iter_vec_raw ( bcx, data_ptr, vec_ty, fill, f)
609
595
}
610
596
0 commit comments