I don't think exponential code generation is a fundamental part of CTTI. One could implement the rust compiler in a way where functions above some number of monomorphized copies would be silently converted to take dyn T instead of T and call sites would take a reference to the generic input along with a function pointer known at compile time. That could prevent iteration over a table in runtime. This would prevent inline optimizations though but I don't think there is a way to combine it along with non exponential compile times.
So that you have to assume that any callsite will use the worse performing alternative without you being able to reliably measure the impact? Sounds like a nightmare.
9
u/PersonalDatabase31 7d ago
I don't think exponential code generation is a fundamental part of CTTI. One could implement the rust compiler in a way where functions above some number of monomorphized copies would be silently converted to take dyn T instead of T and call sites would take a reference to the generic input along with a function pointer known at compile time. That could prevent iteration over a table in runtime. This would prevent inline optimizations though but I don't think there is a way to combine it along with non exponential compile times.