mozilla/rust — Issue #1493: make boxes self-describing
Author: nikomatsakis
Created: 2012-01-11 16:33:48+00:00
State: open

Today we have a map that maps from each box allocation to a type descriptor describing its payload. This requires hashtable lookups on malloc/free and seems inefficient. However, to do cycle collection or any form of GC, boxes DO need to be self-describing. Therefore, I propose we layout a box like this:

struct box {
tydesc *desc;
int refcnt;

}

This has a few advantages:

- no more map lookups on alloc, free
- the desc and refcnt are always at known offsets, regardless of the alignment of payload
- we can unify the paths for opaque types like closures, objects, and ifaces. They should also begin with a type descriptor.

I think it would be best if the type descriptor describes the *entire* box (including the desc and refcnt fields). The reason is that this avoids the need to consider the alignment of payload when finding the offset of the data described by the type descriptor.