fixup for enhancement 7804 - allow __traits(getMember) as basic type#8945
Conversation
|
Thanks for your pull request and interest in making D better, @bbasile! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#8945" |
Geod24
left a comment
There was a problem hiding this comment.
Special-casing getMember has all the smells of bad design. The following just needs to work:
class Foo
{
void func() {}
}
alias Truc = __traits(getOverloads, Foo, __traits(allMembers, Foo)[0])[0];- Having the special casing as a parse error is a bad idea. Consider:
class Foo
{
void func() {}
}
version (none)
alias Truc = __traits(getOverloads, Foo, __traits(allMembers, Foo)[0])[0];This errors out. I really don't think it should.
|
Thanks so much for resurrecting this PR! |
|
Without special handling, the overload set obtained from |
|
From the example above it would seem that you (well the users code) needs to index the |
|
|
|
The PR is ready for a second review i think. getOverloads is also supported so the feature is decently usable now. |
|
(fixed) module bench;
import std.meta : AliasSeq;
class Foo(int number){}
enum Bar(int number) = 8;
class Class(int number){}
template Stuff(int number)
{
@Foo!number @Bar!number @(number) class ClassN : Class!number {}
version(new_way) alias Attribs = __traits(getAttributes, ClassN);
else alias Attribs = AliasSeq!(__traits(getAttributes, ClassN));
}
enum int count = 10_000;
static foreach (immutable(int) i; 0 .. count)
mixin Stuff!i;
void main(){}gives $ time ./dmd bench.d
real 0m12,850s
user 0m12,186s
sys 0m0,637s
$ time ./dmd bench.d -version=new_way
real 0m25,344s
user 0m24,578s
sys 0m0,679s |
|
Seems like a good candidate for https://github.com/CyberShadow/dmdprof although I'm not particularly convinced thats a typical usage pattern, but a 2x slowdown isn't exactly negligible either. |
UplinkCoder
left a comment
There was a problem hiding this comment.
A change of this scale will need a DIP, I think.
|
@UplinkCoder, it was more or less preapproved by @WalterBright here. Although i won't get mad if it has to be done, now that the implementation is finished. |
|
@bbasile is there anything more to be done? |
|
Maybe i'll feel the need to push more tests but otherwise, unless changes required by future reviewers, it's good. |
Addresses the problems detected in #8938 after it's been merged by error.