Usability of "allMembers and derivedMembers traits now only return visible symbols"

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 31 14:12:54 PDT 2016


On 08/30/2016 03:24 PM, Ali Çehreli wrote:
 > v2.071.2-b3 is bringing a change for this bug:
 >
 >   https://issues.dlang.org/show_bug.cgi?id=15907
 >
 > I don't agree with the current solution:
 >
 >   http://dlang.org/changelog/2.071.2.html#traits-members-visibility
 >
 > Modules should be able to use library templates without needing to mix
 > them in first.
 >
 > Do you think the solution in the change log usable? I don't think so
 > because silently skipping my private members is an unexpected behavior
 > that will cause bugs.

Here is a regression caused by the above change:

interface I {
     void foo();

package:

     void foo(int);
}

string how(alias Base, alias func)() {
     return "";
}

import std.typecons;
class C : AutoImplement!(I, how) {
}

void main() {
     auto c = new C();
     c.foo();
     c.foo(42);    // COMPILATION ERROR:
// deneme.o: In function `_Dmain':
// deneme.d:(.text._Dmain+0x39): undefined reference to 
`_D6deneme1I3fooMFiZv'
// collect2: error: ld returned 1 exit status
}

WAT?

It's not reasonable for the user to somehow suspect that AutoImplement 
may be using a D feature (__traits(allMembers) in this case) which 
happens to not see foo(int). (Note that AutoImplement may see foo(int) 
today but not tomorrow, if it's moved out of this package.)

The recommended solution of mixing in every template instance is not a 
viable solution because that would effectively remove IFTI from D. What 
a huge loss that would be. We can't afford that.

So, to be safe, every D code out there that happens to pass a struct to 
a piece of library function would have to

1) Know that that library function happens to be a template and

2) mixin the particular instantiation of that template.

That would be the only sane thing to do. Further, what happens if a 
function changes its implementation and becomes a template that happens 
to call __traits(allMembers)? How can the library notify its users to 
tell them to mixin an explicit instantiation?

Ali



More information about the Digitalmars-d mailing list