Skip to content

Commit e67b5b2

Browse files
committed
Introduce a SHAPE_UNBOXED_VEC shape in order to seperate out vector logic.
1 parent ebdf0c2 commit e67b5b2

File tree

6 files changed

+102
-7
lines changed

6 files changed

+102
-7
lines changed

src/rt/rust_box_annihilator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class annihilator : public shape::data<annihilator,shape::ptr> {
4545
task->kernel->free(vec);
4646
}
4747

48+
void walk_unboxed_vec2(bool is_pod) {
49+
walk_vec2(is_pod, get_unboxed_vec_data_range(dp));
50+
}
51+
4852
void walk_fixedvec2(uint16_t n_elts, size_t elt_sz, bool is_pod) {
4953
walk_vec2(is_pod, get_fixedvec_data_range(n_elts, elt_sz, dp));
5054
}

src/rt/rust_cc.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class irc : public shape::data<irc,shape::ptr> {
9191
walk_vec2(is_pod, get_vec_data_range(dp));
9292
}
9393

94+
void walk_unboxed_vec2(bool is_pod) {
95+
walk_vec2(is_pod, get_unboxed_vec_data_range(dp));
96+
}
97+
9498
void walk_slice2(bool is_pod, bool is_str) {
9599
walk_vec2(is_pod, get_slice_data_range(is_str, dp));
96100
}
@@ -341,6 +345,10 @@ class mark : public shape::data<mark,shape::ptr> {
341345
walk_vec2(is_pod, get_vec_data_range(dp));
342346
}
343347

348+
void walk_unboxed_vec2(bool is_pod) {
349+
walk_vec2(is_pod, get_unboxed_vec_data_range(dp));
350+
}
351+
344352
void walk_slice2(bool is_pod, bool is_str) {
345353
walk_vec2(is_pod, get_slice_data_range(is_str, dp));
346354
}

src/rt/rust_shape.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ class cmp : public data<cmp,ptr_pair> {
263263
walk_vec2(is_pod, get_vec_data_range(dp));
264264
}
265265

266+
void walk_unboxed_vec2(bool is_pod) {
267+
walk_vec2(is_pod, get_unboxed_vec_data_range(dp));
268+
}
269+
270+
266271
void walk_slice2(bool is_pod, bool is_str) {
267272
// Slices compare just like vecs.
268273
walk_vec2(is_pod, get_slice_data_range(is_str, dp));

src/rt/rust_shape.h

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const uint8_t SHAPE_SEND_TYDESC = 29u;
5858
const uint8_t SHAPE_RPTR = 31u;
5959
const uint8_t SHAPE_FIXEDVEC = 32u;
6060
const uint8_t SHAPE_SLICE = 33u;
61+
const uint8_t SHAPE_UNBOXED_VEC = 34u;
6162

6263
#ifdef _LP64
6364
const uint8_t SHAPE_PTR = SHAPE_U64;
@@ -263,9 +264,9 @@ class ctxt {
263264

264265
private:
265266
void walk_vec0();
267+
void walk_unboxed_vec0();
266268
void walk_tag0();
267269
void walk_box0();
268-
void walk_box_old0();
269270
void walk_uniq0();
270271
void walk_struct0();
271272
void walk_res0();
@@ -318,6 +319,7 @@ ctxt<T>::walk() {
318319
case SHAPE_RPTR: walk_rptr0(); break;
319320
case SHAPE_FIXEDVEC: walk_fixedvec0(); break;
320321
case SHAPE_SLICE: walk_slice0(); break;
322+
case SHAPE_UNBOXED_VEC: walk_unboxed_vec0(); break;
321323
default: abort();
322324
}
323325
}
@@ -375,6 +377,19 @@ ctxt<T>::walk_vec0() {
375377
sp = end_sp;
376378
}
377379

380+
template<typename T>
381+
void
382+
ctxt<T>::walk_unboxed_vec0() {
383+
bool is_pod = *sp++;
384+
385+
uint16_t sp_size = get_u16_bump(sp);
386+
const uint8_t *end_sp = sp + sp_size;
387+
388+
static_cast<T *>(this)->walk_unboxed_vec1(is_pod);
389+
390+
sp = end_sp;
391+
}
392+
378393
template<typename T>
379394
void
380395
ctxt<T>::walk_tag0() {
@@ -516,6 +531,9 @@ class print : public ctxt<print> {
516531
void walk_vec1(bool is_pod) {
517532
DPRINT("vec<"); walk(); DPRINT(">");
518533
}
534+
void walk_unboxed_vec1(bool is_pod) {
535+
DPRINT("unboxed_vec<"); walk(); DPRINT(">");
536+
}
519537
void walk_uniq1() {
520538
DPRINT("~<"); walk(); DPRINT(">");
521539
}
@@ -603,6 +621,11 @@ class size_of : public ctxt<size_of> {
603621
sa.set(sizeof(void *), sizeof(void *));
604622
}
605623

624+
void walk_unboxed_vec1(bool is_pod) {
625+
assert(false &&
626+
"trying to compute size of dynamically sized unboxed vector");
627+
}
628+
606629
void walk_res1(const rust_fn *dtor, const uint8_t *end_sp) {
607630
abort(); // TODO
608631
}
@@ -849,6 +872,12 @@ class data : public ctxt< data<T,U> > {
849872
static std::pair<uint8_t *,uint8_t *> get_vec_data_range(ptr dp);
850873
static std::pair<ptr_pair,ptr_pair> get_vec_data_range(ptr_pair &dp);
851874

875+
static std::pair<uint8_t *,uint8_t *> get_unboxed_vec_data_range(ptr dp);
876+
static std::pair<ptr_pair,ptr_pair>
877+
get_unboxed_vec_data_range(ptr_pair &dp);
878+
static ptr get_unboxed_vec_end(ptr dp);
879+
static ptr_pair get_unboxed_vec_end(ptr_pair &dp);
880+
852881
static std::pair<uint8_t *,uint8_t *> get_slice_data_range(bool is_str,
853882
ptr dp);
854883
static std::pair<ptr_pair,ptr_pair> get_slice_data_range(bool is_str,
@@ -880,6 +909,13 @@ class data : public ctxt< data<T,U> > {
880909
DATA_SIMPLE(void *, walk_vec2(is_pod));
881910
}
882911

912+
void walk_unboxed_vec1(bool is_pod) {
913+
// align?
914+
U next_dp = get_unboxed_vec_end(dp);
915+
static_cast<T *>(this)->walk_unboxed_vec2(is_pod);
916+
dp = next_dp;
917+
}
918+
883919
void walk_slice1(bool is_pod, bool is_str) {
884920
DATA_SIMPLE(void *, walk_slice2(is_pod, is_str));
885921
}
@@ -955,7 +991,7 @@ data<T,U>::walk_uniq_contents1() {
955991
if (body_td) {
956992
U body_dp(dp.box_body());
957993
arena arena;
958-
T sub(*static_cast<T *>(this), body_td->shape,
994+
T sub(*static_cast<T *>(this), /*body_td->shape,*/ this->sp,
959995
body_td->shape_tables, body_dp);
960996
sub.align = true;
961997
static_cast<T *>(this)->walk_uniq_contents2(sub);
@@ -1000,6 +1036,38 @@ data<T,U>::get_vec_data_range(ptr_pair &dp) {
10001036
return std::make_pair(start, end);
10011037
}
10021038

1039+
template<typename T,typename U>
1040+
std::pair<uint8_t *,uint8_t *>
1041+
data<T,U>::get_unboxed_vec_data_range(ptr dp) {
1042+
rust_vec* ptr = (rust_vec*)dp;
1043+
uint8_t* data = &ptr->data[0];
1044+
return std::make_pair(data, data + ptr->fill);
1045+
}
1046+
1047+
template<typename T,typename U>
1048+
std::pair<ptr_pair,ptr_pair>
1049+
data<T,U>::get_unboxed_vec_data_range(ptr_pair &dp) {
1050+
std::pair<uint8_t *,uint8_t *> fst =
1051+
get_unboxed_vec_data_range(shape::ptr(dp.fst));
1052+
std::pair<uint8_t *,uint8_t *> snd =
1053+
get_unboxed_vec_data_range(shape::ptr(dp.snd));
1054+
ptr_pair start(fst.first, snd.first);
1055+
ptr_pair end(fst.second, snd.second);
1056+
return std::make_pair(start, end);
1057+
}
1058+
1059+
template<typename T,typename U>
1060+
ptr data<T,U>::get_unboxed_vec_end(ptr dp) {
1061+
rust_vec* ptr = (rust_vec*)dp;
1062+
return dp + sizeof(rust_vec) + ptr->fill;
1063+
}
1064+
1065+
template<typename T,typename U>
1066+
ptr_pair data<T,U>::get_unboxed_vec_end(ptr_pair &dp) {
1067+
return ptr_pair(get_unboxed_vec_end(ptr(dp.fst)),
1068+
get_unboxed_vec_end(ptr(dp.snd)));
1069+
}
1070+
10031071
template<typename T,typename U>
10041072
std::pair<uint8_t *,uint8_t *>
10051073
data<T,U>::get_slice_data_range(bool is_str, ptr dp) {
@@ -1135,6 +1203,10 @@ class log : public data<log,ptr> {
11351203
walk_vec2(is_pod, get_vec_data_range(dp));
11361204
}
11371205

1206+
void walk_unboxed_vec2(bool is_pod) {
1207+
walk_vec2(is_pod, get_unboxed_vec_data_range(dp));
1208+
}
1209+
11381210
void walk_slice2(bool is_pod, bool is_str) {
11391211
walk_vec2(is_pod, get_slice_data_range(is_str, dp));
11401212
out << "/&";

src/rustc/middle/trans/shape.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const shape_send_tydesc: u8 = 29u8;
9393
const shape_rptr: u8 = 31u8;
9494
const shape_fixedvec: u8 = 32u8;
9595
const shape_slice: u8 = 33u8;
96+
const shape_unboxed_vec: u8 = 34u8;
9697

9798
fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
9899
ValueRef {
@@ -225,6 +226,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
225226
ty::ty_float(ast::ty_f64) { [shape_f64] }
226227
ty::ty_estr(ty::vstore_uniq) |
227228
ty::ty_str {
229+
// FIXME: we want to emit this as a unique pointer to an unboxed vec,
230+
// but it doesn't work at the moment, since trans doesn't put
231+
// tydescs in string boxes...
228232
let mut s = [shape_vec];
229233
add_bool(s, true); // type is POD
230234
let unit_ty = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
@@ -267,9 +271,11 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
267271
}
268272
ty::ty_evec(mt, ty::vstore_uniq) |
269273
ty::ty_vec(mt) {
270-
let mut s = [shape_vec];
271-
add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty));
272-
add_substr(s, shape_of(ccx, mt.ty));
274+
let mut s_inner = [shape_unboxed_vec];
275+
add_bool(s_inner, ty::type_is_pod(ccx.tcx, mt.ty));
276+
add_substr(s_inner, shape_of(ccx, mt.ty));
277+
let mut s = [shape_uniq];
278+
add_substr(s, s_inner);
273279
s
274280
}
275281

src/test/run-pass/log-str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
2-
assert "[1, 2, 3]" == sys::log_str([1, 2, 3]);
3-
assert #fmt["%?/%5?", [1, 2, 3], "hi"] == "[1, 2, 3]/ \"hi\"";
2+
assert "~[1, 2, 3]" == sys::log_str([1, 2, 3]);
3+
assert #fmt["%?/%5?", [1, 2, 3], "hi"] == "~[1, 2, 3]/ \"hi\"";
44
}

0 commit comments

Comments
 (0)