Skip to content
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

Issue 13074 - Old opCmp requirement for AA keys should be detected #3731

Merged
merged 1 commit into from Jul 11, 2014

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Jul 8, 2014

}
if (sd->xcmp && sd->xcmp != sd->xerrcmp)
{
error(loc, "%sAA key type %s is now required equality rather than comparison",
Copy link
Member

Choose a reason for hiding this comment

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

"%s AA key type %s now requires equality rather than comparison."

@schveiguy
Copy link
Member

I tested this pull, it fixes the problem from what I see. I will play around a bit with some other possibilities. I'll also look at phobos failures.

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 9, 2014

Phobos fix: dlang/phobos#2313

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 9, 2014

One more phobos fix: dlang/phobos#2314

TEST_OUTPUT:
---
fail_compilation/diag13074.d(29): Error: AA key type S is now required equality rather than comparison
fail_compilation/diag13074.d(29): Please define opEquals, or remove it to rely on default memberwise equality
Copy link
Member

Choose a reason for hiding this comment

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

Not sure whether it's critical to the test actually succeeding, but these messages should also be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, fixed. Thanks.

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 11, 2014

Ready to merge.

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 11, 2014

@yebblies Can you merge this? This is a blocker to prevent silent behavior change around AAs in 2.066.

@yebblies
Copy link
Member

I haven't really been following the related pulls - why is this better than generating an opEquals that internally calls the user opCmp?

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 11, 2014

@yebblies :

In git-head, AA implementation is changed to use TypeInfo.equals for key comparison (dlang/druntime#522).
Then, front-end is also fixed to follow the actual AA key requirement (#3711).

But, in 2.065 and earlier, AA had been used opCmp for the key comparison. So if things goes on without this, the existing code behavior will be silently changed with 2.066 (#3711 (comment)).

@yebblies
Copy link
Member

But can't an AA still function perfectly if a type defines opCmp and opHash, but not opEquals? Shouldn't we be able to make TypeInfo.equals call opCmp and preserve the old behavior? Or is there some reason opCmp can't be used to implement opEquals?

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 11, 2014

I don't say that automatic opEquals generation from opCmp is a bad idea. But it is an operator overloading enhancement, that is essentially orthogonal with AA implementation changing. It should have another discussion.

@yebblies
Copy link
Member

Ok, I'll pull this because it's currently a silent regression. Adding the opCmp -> opEquals rule would prevent the breakage completely.

@yebblies
Copy link
Member

Auto-merge toggled on

@9rnsr
Copy link
Contributor Author

9rnsr commented Jul 11, 2014

Thanks!

@schveiguy
Copy link
Member

Ok, I'll pull this because it's currently a silent regression. Adding the opCmp -> opEquals rule would prevent the breakage completely

I agree, and we can later remove the restriction for cases where we can generate the appropriate opEquals. The only thing to be concerned about in that case is if someone, for some reason, REALLY wanted to have the default opEquals vs. opCmp == 0, it would silently break that code. In reality, it's not illegal, just bad code. It's only illegal if we use it as an AA key.

yebblies added a commit that referenced this pull request Jul 11, 2014
Issue 13074 - Old opCmp requirement for AA keys should be detected
@yebblies yebblies merged commit 8bee69a into dlang:master Jul 11, 2014
9rnsr pushed a commit to 9rnsr/dmd that referenced this pull request Jul 11, 2014
Issue 13074 - Old opCmp requirement for AA keys should be detected
@9rnsr 9rnsr deleted the fix13074 branch July 11, 2014 14:53
@schveiguy
Copy link
Member

@9rnsr Just realized, classes also silently compile. Sorry for not noticing earlier! The case is a bit trickier, with runtime dispatch of the methods.

The bug report: https://issues.dlang.org/show_bug.cgi?id=13114

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