r/kiwilang•
OpenFileW

vtables in kiwi

i hate how langs like C++ make vtables implicit and present for any virtual methods (at least in O0, as far as i know) - so for Kiwi i decided to make it explicit as much as i can. a &dyn T reference carries a vptr along with a ptr to the object. T can be a class containing dyn funs, or a trait. if T has virtual methods but is not used as a dyn reference, all method calls will be concrete for that type specifically, not invoked via the virtual table. you can also cast &dyn T to &T or *T to call concrete methods directly, but this can be unsafe if you cast to the wrong type, so you need to use pun<Dst, Src>(x: Src) -> Dst, which is essentially the same as Rust's std::mem::transmute or a C cast over ptr. but anyways meow
TLDR; &dyn T carries a vtable ptr for T if it is a class with dyn fun methods or if it is a trait. use that if you want virtual dispatch.

Posted Jul 9, 2026, 7:46 PM UTC

11
Loading comments…