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
Suppress the "read-modify-write" error if type is a struct or a class #10281
Conversation
Thanks for your pull request and interest in making D better, @ErnyTech! 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. 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#10281" |
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.
No test
@@ -1353,7 +1353,7 @@ extern (C++) abstract class Expression : ASTNode | |||
extern (D) final bool checkReadModifyWrite(TOK rmwOp, Expression ex = null) | |||
{ | |||
//printf("Expression::checkReadModifyWrite() %s %s", toChars(), ex ? ex.toChars() : ""); | |||
if (!type || !type.isShared()) | |||
if (!type || !type.isShared() || type.isTypeStruct() || type.isTypeClass()) |
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.
That doesn't look right. It's blindly allowing struct
/ class
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.
If the class/struct does not implement the operator the compiler will give the error "is not a scalar"
Line 5574 in d9826c8
if (exp.e1.checkScalar() || |
So I don't think further checks are necessary
Added compilable test |
|
{ | ||
S s; | ||
s++; | ||
shared(C) c = new C(); |
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 does this need to be shared if C
is a shared class
?
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.
Using shared in the class declaration does not seem to make the class type "implicitly" shared unlike what it does in a struct
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 realized that the formatting has problems (badly converted tabs), I have to solve it
If a struct or class with shared type implements the opUnary or opOpAssign operator then it is possible to perform "read-modify-write" operations because the operator's implementation is supposed to perform atomic operations. Signed-off-by: Ernesto Castellotti <erny.castell@gmail.com>
Fixed |
If a struct or class with shared type implements the opUnary or opOpAssign
operator then it is possible to perform "read-modify-write" operations
because the operator's implementation is supposed to perform atomic operations.
The purpose of this modification is to allow the creation of wrappers
(with structs or classes) to run atomic operations silently, for example: