Skip to content

Commit 47cfeba

Browse files
committed
Add cases for iface values to rust_shape.h
They appear to log okay now, but I can't promise much beyond that. @pcwalton If you feel like taking a look, I'd be grateful. Interfaces are boxes containing a (tydesc, dict, value_of_any_type) tuple, where the leading tydesc describes the whole tuple. Issue #1437
1 parent 9fa7491 commit 47cfeba

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/rt/rust_shape.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const uint8_t SHAPE_OBJ = 19u;
5151
const uint8_t SHAPE_RES = 20u;
5252
const uint8_t SHAPE_VAR = 21u;
5353
const uint8_t SHAPE_UNIQ = 22u;
54+
const uint8_t SHAPE_IFACE = 24u;
5455

5556
#ifdef _LP64
5657
const uint8_t SHAPE_PTR = SHAPE_U64;
@@ -382,6 +383,7 @@ ctxt<T>::walk() {
382383
case SHAPE_RES: walk_res(); break;
383384
case SHAPE_VAR: walk_var(); break;
384385
case SHAPE_UNIQ: walk_uniq(); break;
386+
case SHAPE_IFACE: WALK_SIMPLE(walk_iface); break;
385387
default: abort();
386388
}
387389
}
@@ -566,6 +568,7 @@ class print : public ctxt<print> {
566568

567569
void walk_fn() { DPRINT("fn"); }
568570
void walk_obj() { DPRINT("obj"); }
571+
void walk_iface() { DPRINT("iface"); }
569572
void walk_closure();
570573

571574
template<typename T>
@@ -611,6 +614,7 @@ class size_of : public ctxt<size_of> {
611614
void walk_box() { sa.set(sizeof(void *), sizeof(void *)); }
612615
void walk_fn() { sa.set(sizeof(void *)*2, sizeof(void *)); }
613616
void walk_obj() { sa.set(sizeof(void *)*2, sizeof(void *)); }
617+
void walk_iface() { sa.set(sizeof(void *), sizeof(void *)); }
614618
void walk_closure();
615619

616620
void walk_vec(bool is_pod, uint16_t sp_size) {
@@ -819,6 +823,7 @@ class data : public ctxt< data<T,U> > {
819823
void walk_uniq_contents();
820824
void walk_fn_contents(ptr &dp);
821825
void walk_obj_contents(ptr &dp);
826+
void walk_iface_value(ptr &dp);
822827
void walk_variant(tag_info &tinfo, tag_variant_t variant);
823828

824829
static std::pair<uint8_t *,uint8_t *> get_vec_data_range(ptr dp);
@@ -863,6 +868,8 @@ class data : public ctxt< data<T,U> > {
863868
dp = next_dp;
864869
}
865870

871+
void walk_iface() { DATA_SIMPLE(void *, walk_iface()); }
872+
866873
void walk_res(const rust_fn *dtor, unsigned n_params,
867874
const type_param *params, const uint8_t *end_sp) {
868875
typename U::template data<uintptr_t>::t live = bump_dp<uintptr_t>(dp);
@@ -989,6 +996,20 @@ data<T,U>::walk_obj_contents(ptr &dp) {
989996
sub.walk();
990997
}
991998

999+
template<typename T,typename U>
1000+
void
1001+
data<T,U>::walk_iface_value(ptr &dp) {
1002+
uint8_t *box_ptr = bump_dp<uint8_t *>(dp);
1003+
if (!box_ptr) return;
1004+
uint8_t *body_ptr = box_ptr + sizeof(void*);
1005+
type_desc *valtydesc =
1006+
*reinterpret_cast<type_desc **>(body_ptr);
1007+
ptr value_dp(body_ptr + sizeof(void*) * 2);
1008+
T sub(*static_cast<T *>(this), valtydesc->shape + 2, NULL, NULL,
1009+
value_dp);
1010+
sub.align = true;
1011+
sub.walk();
1012+
}
9921013

9931014
// Polymorphic logging, for convenience
9941015

@@ -1073,6 +1094,13 @@ class log : public data<log,ptr> {
10731094
data<log,ptr>::walk_obj_contents(dp);
10741095
}
10751096

1097+
void walk_iface() {
1098+
out << prefix << "iface(";
1099+
prefix = "";
1100+
data<log,ptr>::walk_iface_value(dp);
1101+
out << prefix << ")";
1102+
}
1103+
10761104
void walk_subcontext(log &sub) { sub.walk(); }
10771105

10781106
void walk_box_contents(log &sub, ptr &ref_count_dp) {

0 commit comments

Comments
 (0)