diff --git a/src/rt/rust_cc.cpp b/src/rt/rust_cc.cpp index a96c3739ca3..d04ae2e09df 100644 --- a/src/rt/rust_cc.cpp +++ b/src/rt/rust_cc.cpp @@ -111,8 +111,7 @@ class irc : public shape::data { } void walk_iface() { - // an iface is always a ptr to a ref-counted obj. - shape::data::walk_box_contents(); + shape::data::walk_iface_contents(dp); } void walk_res(const shape::rust_fn *dtor, unsigned n_params, @@ -503,7 +502,7 @@ class sweep : public shape::data { } void walk_iface() { - shape::data::walk_box_contents(); + shape::data::walk_iface_contents(dp); } void walk_res(const shape::rust_fn *dtor, unsigned n_params, diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h index f9300cad443..b83d74f6bfe 100644 --- a/src/rt/rust_internal.h +++ b/src/rt/rust_internal.h @@ -260,23 +260,6 @@ struct rust_opaque_closure; // no arguments (and hence the final void*) is harmless typedef void (*CDECL spawn_fn)(void*, rust_opaque_closure*, void *); -// corresponds to the layout of an iface value -// -// Note: eventually, we should inline the contents of opaque_iface_contents -// into opaque_iface in the LLVM code. Otherwise, the alignment of -// opaque_iface_contents depends on the opaque data! - -struct opaque_iface_contents { - const type_desc *td; // describes opaque_iface_contents - const void *vtable; - // (opaque data goes here) -}; - -struct opaque_iface { - intptr_t ref_count; - opaque_iface_contents contents; -}; - // corresponds to the layout of a fn(), fn@(), fn~() etc struct fn_env_pair { spawn_fn f; diff --git a/src/rt/rust_shape.h b/src/rt/rust_shape.h index ca8cd2c88a5..0def948223f 100644 --- a/src/rt/rust_shape.h +++ b/src/rt/rust_shape.h @@ -363,7 +363,7 @@ public: template void ctxt::walk() { - switch (*sp++) { + switch (*sp++) { case SHAPE_U8: WALK_NUMBER(uint8_t); break; case SHAPE_U16: WALK_NUMBER(uint16_t); break; case SHAPE_U32: WALK_NUMBER(uint32_t); break; @@ -823,7 +823,7 @@ protected: void walk_uniq_contents(); void walk_fn_contents(ptr &dp); void walk_obj_contents(ptr &dp); - void walk_iface_value(ptr &dp); + void walk_iface_contents(ptr &dp); void walk_variant(tag_info &tinfo, tag_variant_t variant); static std::pair get_vec_data_range(ptr dp); @@ -870,7 +870,7 @@ public: void walk_iface() { ALIGN_TO(alignof()); - U next_dp = dp + sizeof(void *) * 2; + U next_dp = dp + sizeof(void *); static_cast(this)->walk_iface(); dp = next_dp; } @@ -1003,14 +1003,21 @@ data::walk_obj_contents(ptr &dp) { template void -data::walk_iface_value(ptr &dp) { - opaque_iface *box_ptr = bump_dp(dp); +data::walk_iface_contents(ptr &dp) { + uint8_t *box_ptr = bump_dp(dp); if (!box_ptr) return; - const type_desc *contents_td = box_ptr->contents.td; - ptr contents_dp((uintptr_t)&box_ptr->contents); - T sub(*static_cast(this), contents_td->shape, NULL, NULL, contents_dp); + U ref_count_dp(box_ptr); + uint8_t *body_ptr = box_ptr + sizeof(void*); + type_desc *valtydesc = + *reinterpret_cast(body_ptr); + ptr value_dp(body_ptr + sizeof(void*) * 2); + // FIXME The 5 is a hard-coded way to skip over a struct shape + // header and the first two (number-typed) fields. This is too + // fragile, but I didn't see a good way to properly encode it. + T sub(*static_cast(this), valtydesc->shape + 5, NULL, NULL, + value_dp); sub.align = true; - sub.walk(); + static_cast(this)->walk_box_contents(sub, ref_count_dp); } // Polymorphic logging, for convenience @@ -1099,7 +1106,7 @@ private: void walk_iface() { out << prefix << "iface("; prefix = ""; - data::walk_iface_value(dp); + data::walk_iface_contents(dp); out << prefix << ")"; }