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

Martin Nowak via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 12 20:06:22 PDT 2016


On Wednesday, 7 September 2016 at 19:29:05 UTC, Ali Çehreli wrote:
> On 09/03/2016 09:37 AM, Martin Nowak wrote:
> > On Wednesday, 31 August 2016 at 21:12:54 UTC, Ali Çehreli
> wrote:
>
> >> 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.
> >
> > Exaggeration won't help us to find good solutions. Remember
> that private
> > fields never were accessible, so only some edge cases will be
> affected.
> > The need for mixin templates will remain rare.
>
> I don't see how the user of a template library can decide 
> whether to mixin or not without knowing the current 
> implementation if of the library.
>
> For that reason, I must mixin. For example, the following 
> program is broken because I don't know whether writeln uses 
> allMembers or not:
>
>     // BROKEN CODE:
>     MyStruct s;
>     writeln(s);
>
> Do you see the problem? I can't leave that code that way. I 
> have to figure out mixin writeln's instantiation. As you see, 
> mixins will not be rare. Every template use must be mixed in.

Well, I can only repeat what I stated several times before, 
private members were never accessible by name (via getMember or 
.name). So either writeln uses .tupleof (unnamed) or ignores 
private members.

This is the pre 2.071 state.

method    | visible | accessible
--------------------------------
.name     |    y    |    n
getMember |    y    |    n
.tupleof  |    y    |    y

This was the 2.071.1 state (for which the allMembers fix was a 
valid solution).

method    | visible | accessible
--------------------------------
.name     |    n    |    n
getMember |    n    |    n
.tupleof  |    y    |    y

This is what we're now doing in 2.071.2 (see 
https://github.com/dlang/dmd/pull/6111),

method    | visible | accessible
--------------------------------
.name     |    n    |    n
getMember |    y    |    n
.tupleof  |    y    |    y

and what we plan to do with 2.072 or 2.073.

method    | visible | accessible
--------------------------------
.name     |    n    |    n
getMember |    y    |    y
.tupleof  |    y    |    y

In fact access checks will get removed soon.


More information about the Digitalmars-d mailing list