Skip to content

Commit a993621

Browse files
committed
Log and compare unique boxes
Issue #409
1 parent 42fd2a9 commit a993621

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/rt/rust_shape.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ class cmp : public data<cmp,ptr_pair> {
279279
result = sub.result;
280280
}
281281

282+
inline void walk_uniq_contents(cmp &sub) {
283+
sub.align = true;
284+
sub.walk();
285+
result = sub.result;
286+
}
287+
282288
inline void cmp_two_pointers() {
283289
ALIGN_TO(alignof<void *>() * 2);
284290
data_pair<uint8_t *> fst = bump_dp<uint8_t *>(dp);
@@ -341,6 +347,10 @@ class cmp : public data<cmp,ptr_pair> {
341347
data<cmp,ptr_pair>::walk_box_contents();
342348
}
343349

350+
void walk_uniq() {
351+
data<cmp,ptr_pair>::walk_uniq_contents();
352+
}
353+
344354
void walk_fn() { return cmp_two_pointers(); }
345355
void walk_obj() { return cmp_two_pointers(); }
346356

src/rt/rust_shape.h

+38
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const uint8_t SHAPE_FN = 18u;
4646
const uint8_t SHAPE_OBJ = 19u;
4747
const uint8_t SHAPE_RES = 20u;
4848
const uint8_t SHAPE_VAR = 21u;
49+
const uint8_t SHAPE_UNIQ = 22u;
4950

5051
#ifdef _LP64
5152
const uint8_t SHAPE_PTR = SHAPE_U64;
@@ -244,6 +245,7 @@ class ctxt {
244245
void walk_vec();
245246
void walk_tag();
246247
void walk_box();
248+
void walk_uniq();
247249
void walk_struct();
248250
void walk_res();
249251
void walk_var();
@@ -346,6 +348,7 @@ ctxt<T>::walk() {
346348
case SHAPE_OBJ: WALK_SIMPLE(walk_obj); break;
347349
case SHAPE_RES: walk_res(); break;
348350
case SHAPE_VAR: walk_var(); break;
351+
case SHAPE_UNIQ: walk_uniq(); break;
349352
default: abort();
350353
}
351354
}
@@ -441,6 +444,17 @@ ctxt<T>::walk_box() {
441444
sp = end_sp;
442445
}
443446

447+
template<typename T>
448+
void
449+
ctxt<T>::walk_uniq() {
450+
uint16_t sp_size = get_u16_bump(sp);
451+
const uint8_t *end_sp = sp + sp_size;
452+
453+
static_cast<T *>(this)->walk_uniq();
454+
455+
sp = end_sp;
456+
}
457+
444458
template<typename T>
445459
void
446460
ctxt<T>::walk_struct() {
@@ -760,6 +774,7 @@ class data : public ctxt< data<T,U> > {
760774
U end_dp;
761775

762776
void walk_box_contents();
777+
void walk_uniq_contents();
763778
void walk_fn_contents(ptr &dp);
764779
void walk_obj_contents(ptr &dp);
765780
void walk_variant(tag_info &tinfo, uint32_t variant);
@@ -790,6 +805,8 @@ class data : public ctxt< data<T,U> > {
790805

791806
void walk_box() { DATA_SIMPLE(void *, walk_box()); }
792807

808+
void walk_uniq() { DATA_SIMPLE(void *, walk_uniq()); }
809+
793810
void walk_fn() {
794811
ALIGN_TO(alignof<void *>());
795812
U next_dp = dp + sizeof(void *) * 2;
@@ -834,6 +851,15 @@ data<T,U>::walk_box_contents() {
834851
static_cast<T *>(this)->walk_box_contents(sub, ref_count_dp);
835852
}
836853

854+
template<typename T,typename U>
855+
void
856+
data<T,U>::walk_uniq_contents() {
857+
typename U::template data<uint8_t *>::t box_ptr = bump_dp<uint8_t *>(dp);
858+
U data_ptr(box_ptr);
859+
T sub(*static_cast<T *>(this), data_ptr);
860+
static_cast<T *>(this)->walk_uniq_contents(sub);
861+
}
862+
837863
template<typename T,typename U>
838864
void
839865
data<T,U>::walk_variant(tag_info &tinfo, uint32_t variant_id) {
@@ -993,6 +1019,12 @@ class log : public data<log,ptr> {
9931019
data<log,ptr>::walk_box_contents();
9941020
}
9951021

1022+
void walk_uniq() {
1023+
out << prefix << "~";
1024+
prefix = "";
1025+
data<log,ptr>::walk_uniq_contents();
1026+
}
1027+
9961028
void walk_fn() {
9971029
out << prefix << "fn";
9981030
prefix = "";
@@ -1017,6 +1049,12 @@ class log : public data<log,ptr> {
10171049
}
10181050
}
10191051

1052+
void walk_uniq_contents(log &sub) {
1053+
out << prefix;
1054+
sub.align = true;
1055+
sub.walk();
1056+
}
1057+
10201058
void walk_struct(const uint8_t *end_sp);
10211059
void walk_vec(bool is_pod, const std::pair<ptr,ptr> &data);
10221060
void walk_variant(tag_info &tinfo, uint32_t variant_id,

src/test/run-pass/unique-cmp.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let i = ~100;
3+
assert i == ~100;
4+
assert i < ~101;
5+
assert i <= ~100;
6+
assert i > ~99;
7+
assert i >= ~99;
8+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let i = ~100;
3+
log_err i;
4+
}

0 commit comments

Comments
 (0)