Internal references as a separate type

  1. The stored reference would be a usize; the offset could be much shorter. This could be significant if the offset was u8 or u16 and the usize was u128.

  2. A physical move of the object in memory or a clone would just memcpy the offset, whereas extra code would need to be emitted immediately after the memcpy to relocate the reference before the relocated object was available for use.

  3. The reference could be used as is, whereas relocation code would need to be emitted each time the offset needed to be converted (de-relativized?) to a reference, and the inverse offset-computation code would need to be emitted each time an object self-reference needed to be converted to and stored as an offset.

2 Likes