-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Fix Issue 17864 - POD struct not equivalent to primitive type in comparison #8358
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! 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 references
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#8358" |
| @@ -3056,8 +3056,6 @@ Lagain: | |||
| { | |||
| if (t1.mod != t2.mod) | |||
| { | |||
| if (!t1.isImmutable() && !t2.isImmutable() && t1.isShared() != t2.isShared()) | |||
| goto Lincompatible; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is immutable-mutable ok, immutable-shared ok, but shared-mutable not ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commenting the if doesn't seem to influence any code in the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try to implement a custom, non synchronized opEquals ?
|
OK, so writing to shared isn't "special" in the compiler. You can do this just fine: shared int a;
a = 5;The only thing that the compiler complains about is read/modify/write operations. And this restriction is pretty crude as well: shared int a;
a++; // error, use atomicInc
a = a + 1; // no complaintsSo really the benefit of shared is simply to give you a type-system mechanism to ensure you can do the right thing. It really doesn't enforce the right thing. IMO, I think shared should be pretty near useless, you should have to cast it away to be able to use it. And that's not what the original restriction does anyway -- if it's not OK to compare mutable to shared, why is it OK to compare shared to shared? I mean, BOTH are subject to races! I'd say the restriction is misguided at best, and this PR makes sense in the world where shared is "usable". But ultimately, I think shared should simply be locked down completely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll approve this, knowing that shared is a mess and will continue to be a mess after this PR is merged :)
|
So we're overdue a major DIP defining |
I have to admit that I am terribly confused about
shared. So this code:would print : "Error: incompatible types for ((a) is (b)): 'shared(A)' and 'A'", but the comparison succeeds if a's type qualifier is changed to
immutable(and a = b is commented, obviously). Now, I am actually surprised thata=bcompiles (from what I knew about shared, you were supposed to synchronize accesses to shared variables, although a is not global so it's not subject to concurrency issues). If a=b works there's no reason for a==b to fail compilation. The current fix is a noobish attempt from someone who doesn't really understand how shared works, so if there are anysharedexperts out there, please destroy!