New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix Issue 23558 - add __traits(getModuleClasses [, module name]) #14699
Conversation
Thanks for your pull request, @WalterBright! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14699" |
ab54347
to
70bdec4
Compare
I have to say, I'm not convinced by this approach for a couple of reasons. A filter approach that is more generic would be far better. Use cases: registration of web routes, ORM's, CLI handling. |
70bdec4
to
ecb0018
Compare
ecb0018
to
f149547
Compare
@rikkimax if you or anyone else want to write this function, please do so! |
Traits at least are something I can do, so yeah it can go on the back burner after the refactor in dub to output a list of modules. Just a shame that we are introducing an ultra-specific trait when we know a more generic one will come eventually ;) |
There's not much point in doing a spec PR until this is approved. |
|
But this trait won't work in the same way as the current runtime moduleinfo equivalent, will it?
The above is only for illustration, there are likely better/actual examples where traits produce different results depending on ordering (a traits inside a struct members list), but I don't have a compiler to test at the moment. |
f149547
to
f36895f
Compare
f36895f
to
53f51ff
Compare
It produces:
|
53f51ff
to
ebf73f8
Compare
This works as is, but will have to be changed when #14708 is merged. |
3bec540
to
36a56a3
Compare
25c638a
to
56979d1
Compare
@WalterBright could you maybe add a changelog entry + a spec PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs changelog entry.
56979d1
to
f5aa814
Compare
@RazvanN7 ready to go |
This has been done by several D programmers. It is an utterly trivial loop over the existing traits(allMembers). |
This gives you the actual types (which is more useful). I wrote it in 5 minutes. template AllClasses(alias mod) {
import std.meta : AliasSeq;
alias result = AliasSeq!();
static foreach(m; __traits(allMembers, mod))
static if(is(__traits(getMember, mod, m) == class))
result = AliasSeq!(result, __traits(getMember, mod, m));
alias AllClasses = result;
} |
Thank you, @schveiguy The idea is to replace the |
My point was just that the trait you created is not necessary, and in fact, not very helpful. It's hard to turn a string into a type, even when you know the module it comes from (unless you want to use What is needed is a complete solution of how to create a registration system. Ideally at compile-time, but if not, at least at runtime (keeping in mind that static constructors cannot be used as they add cycles to complex code). |
Let's revert this now before the useless baggage actually makes it into a release. |
…e]) (dlang#14699)" This reverts commit 450ba04.
Provide alternative to Object.factory(), see #14681