std.reflection prototype
rcorre via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 13 05:57:26 PDT 2015
For me, having a solid reflection library like this is one of
the most important improvements D can make right now.
After releasing jsonizer (a json serializer) I started talking to
the authors of PainlessJson (another json serializer that was
released around the same time) about how there was a substantial
amount of overlap between our implementations, a large portion of
which was related to reflection rather than actually handling
json. While I won't speak for painlessjson, I can say that the
techniques I used in jsonizer got pretty hacky -- there's a whole
lot of __traits and one monstrous mixin template.
For the most part, this looks really nice. Thanks for putting it
together, bitwise!
That being said, there are a few limitiations I see to this
implementation:
How can you get the user-defined attributes of a given ScopeRefl?
It would be awesome to say:
foreach(field ; reflect!Foo.fields) {
static if (field.hasAttribute(...)) { ... }
}
I guess the difficulty here is that a user-defined attribute in
D can be pretty much anything from a primitive type to a struct
instance to some arbitrary symbol.
How can you get the static type of a reflected field? For example:
alias T = reflect!Foo.fields[0].field_type
doSomethingWithType!T
This is available in FieldRefImpl, but disappears on FieldRefl so
it can be stuck into an array with a bunch of other FieldRefl,
and I'm not sure if there is a way of getting that information
back (other than resorting back to __traits on the user-end,
which kind of defeats the purpose).
If I understand correctly, more work needs to be done in druntime
to better support reflection, but I've read this thread about 3
times and I'm still having a hard time figuring out whats going
on :)
If these changes were made to druntime, would they obviate the
need for a reflection library, or simply make it easier to
implement a reflection library? Is more help needed? If so, where
should I start looking? I'm not familiar with druntime at all,
but wouldn't mind trying to make sense of it.
More information about the Digitalmars-d
mailing list