We had that idea recently, not sure it is what <@U...
# random
o
We had that idea recently, not sure it is what @amanda.hinchman-dominguez wants, but anyway here it is. We dubbed it Compile-Time Reflection (CTR). The idea is that if you write code like you’re using reflection (all pseudocode):
Copy code
for (property in MyClass::class.properties) { … }
The compiler knows statically which properties are there and can unroll the loop. Then, if you add
Copy code
for (property in MyClass::class.properties) {
   when (property.type) {
      Int::class -> callInt(property.name, property.get())
      … other types …
   }
}
While unrolling the loop compiler can eliminate all the cases and insert just specific calls for each property, inserting constant strings for property names, insert direct property access for
get
, etc. There are lots of caveats even in this naive idea. But still, that could be cool some day in the future 🙂