Hacker News new | ask | show | jobs
by StilesCrisis 13 days ago
Why did they eliminate reflection? That doesn't need huge runtime support or garbage collection.
2 comments

Reflection to do what? Getting/setting fields, calling methods, etc. uses `object` which means boxing, which means allocating. Going AOT also means there is no JIT to compile methods (including generic instances) that were not statically referenced.
I mean, yes, but also, no - you can generate and cache (or return manual ownership to the caller) IL/whatever runtime code that doesn't box for any reflection thing that you need on the fly, assuming the type information is available. Like you make it an explicit API to do the code gen, no JIT required.

Just because the code isn't baked into the binary doesn't mean that it theoretically can't be done at runtime. At least, AFAICT.

It seems like you are contradicting yourself here. Just generate code that doesn't box on the fly, but without a JIT compiler? Boxing isn't even the biggest issue here - you could probably avoid that with a strongly typed reflection API, but I don't know if that makes it less useful.

IMO the big issue is AOT compilers only compile code that is referenced statically. Without a JIT you would have no choice but to error if you try to call something that wasn't compiled in. Compiling everything is not an option because generics.

JIT != capability to dynamically generate and run code at runtime, was my only point. A JIT can and does do that, but it is not the only way of doing that. And if there's a homegrown project like this, they can do whatever they want. Such as explicitly provide an API to do reflection like things instead of requiring JIT to implicitly handle it on the fly.

An approach that doesn't need runtime would be to allow reflection for types provided at compile time (say, with a config file). There are many ways to approach reflection, from none to some to full. This appears to have chosen none. It could have chosen some, or potentially even full.

Makes more sense doing what .NET is currently doing for NativeAOT right now: use source generators to extract what you need at build time.
Ehh, it kinda does, at least from a binary size standpoint. Both for how reflection is handled and the compile metadata that needs to be included in the runtime (may be wrong on the second part but I'm 70% sure that's a cost)