Weekly-meetings/2014-09-09 (FnMut sugar; assoc types; inheritance; AST smart pointers; drop reform)


#1

#2

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?


#3

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 = TypeId in vtable, expensive = going through a virtual method to retrieve a TypeId (or worse)

#4

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.


#5

Since then, someone has shown me these benchmarks of dynamic_cast in C++ and my Many contraption should be faster than most of those cases: it’s just a virtual call with a tiny switch over the TypeId of the trait inside, no pointer chasing.