3 ms·
I once faced a tricky bug involving fat pointers (containing virtual tables) in Rust. Two such pointers may be distinct, even if they reference to the same obje
by Panzerschrek 28d ago
I once faced a tricky bug involving fat pointers (containing virtual tables) in Rust. Two such pointers may be distinct, even if they reference to the same object, because (for some reason) the compiler may create two (or even more) copies of the virtual functions table and use them in different places.
- SkiFire13 27d ago> for some reason Just to expand on this: which vtables will be needed is not known before running codegen. At that point however multiple codegen units might generate the same vtable, and that might not get deduplicated by a later pass. Moreover with dynamic linking (especially on Windows) it's impossible to guarantee that such vtables will be unique.
- imtringued 27d agoRust has super traits but does not support subtyping. The way super traits work is that they merge all the vtables into one big vtable. However, you can still have a direct dyn trait reference to the sub traits. This means you need a separate vtable for all super traits and individual traits.