Skip to content

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented May 27, 2013

This improvement has two purpose.

  • Refactoring
    Remove unnecessary workadounds that was for legacy compiler bugs.
  • Add relation between named-field tuple and unnamed-field one.
    Named-field tuple should be a subtype of unnamed-field tuple.

Required compiler fixes by this:
dlang/dmd#2084 (merged)
dlang/dmd#2085 (merged)

@@ -822,6 +803,21 @@ unittest
assert(t2[0] == 1 && t2[1] == 2);
}
}
@safe unittest
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting.. I didn't know we can add properties to unittests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It makes it possible to test that functions are pure or @safe or whatnot.

@ghost
Copy link

ghost commented May 27, 2013

Will #1248 be possible to implement after this pull? Perhaps we should try to pull that one before this one?

@9rnsr
Copy link
Contributor Author

9rnsr commented May 27, 2013

@AndrejMitrovic This improvement would not break #1248.

@@ -268,10 +268,8 @@ Tuple!(int, int) point2;
assert(!is(typeof(point1) == typeof(point2))); // passes
----
*/
struct Tuple(Specs...)
template Tuple(Specs...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change from struct to template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To hide some utility templates and functions by eponymous template trick.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have a question. When I originally proposed allowing additional members with the eponymous trick, I suggested that all other members should be private. It seems the feature works even with public members... why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently compiler always rewrite Tuple!(...).ident to Tuple!(...).Tuple.ident. The rewriting occurs before checking member access rights, so if eponymous member exists in the template instance, other instance members will be invisible from outside of the instance. Then there's no need adding private attribute to all other members.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, so I figured. Only access from within works. I'm just a bit bummed that now we have yet another way of hiding things :o).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, it's continuous behavior before the start of my contributing.

@9rnsr
Copy link
Contributor Author

9rnsr commented May 27, 2013

@andralex OK, I fixed all review points.

@andralex
Copy link
Member

merging now, still wondering about eponymous/private

andralex added a commit that referenced this pull request May 27, 2013
Improve std.typecons.Tuple implementation
@andralex andralex merged commit d9ebbdb into dlang:master May 27, 2013
@ghost
Copy link

ghost commented May 27, 2013

merging now, still wondering about eponymous/private

I'm wondering about this too. To recap, IIRC you want to allow these:

template S()
{
    struct S { }  // eponymous
    struct Priv { }  // private
    public struct Pub { }  // accessible
}

alias A = S!();  // A becomes struct S
alias B = S!().Priv;  // disallowed, 'Priv' is private
alias C = S!().Pub;  // C becomes 'Pub'

Is that it? Because I've actually had this come up in my own code several times, and I thought it was supposed to work.

@9rnsr
Copy link
Contributor Author

9rnsr commented May 27, 2013

@AndrejMitrovic B and C has not been worked until now. Allowing access Priv and Pub would cause name lookup ambiguity.

template S ()
{
    struct S { int Priv; int Pub; }   [a]
    struct Priv { }  // [b]
    public struct Pub { }  // [c]
}
alias A = S!();  // A becomes struct S
alias B = S!().Priv;  // is [a] or [b]? --> currently [a] is chosen
alias C = S!().Pub;  // [is [a] or [c]? --> currently [a] is chosen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants