nrc: I think there is agreement on the problem. constraints: cheap field access from internal methods; cheap dynamic dispatch of methods; cheap downcasting; thin pointers; sharing of fields and methods between definitions; safe, i.e., doesn’t require a bunch of transmutes or other unsafe code to be usable.
Can we have some examples of what would and wouldn’t qualify as “cheap” in each case?
I think I can try to answer, but these are not “official” in any way:
- field access: cheap = constant offset (fixed prefix layout), less cheap = offset in vtable, expensive = virtual method
- dynamic dispatch of methods: “cheap” = current virtual methods, expensive = going through an indirection for each link in the inheritance chain, i.e. a non-flattened tree-like structure
- downcasting (I’m assuming
Any): cheap =
TypeIdin vtable, expensive = going through a virtual method to retrieve a
I think @eddyb is right on all those counts. To give a guiding principle, we should not be slower than C++ on any of these.