-
-
Notifications
You must be signed in to change notification settings - Fork 421
Renovate core.atomic, improve and simplify the constraints on functions #2745
Conversation
Thanks for your pull request and interest in making D better, @TurkeyMan! 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 + druntime#2745" |
f267ade
to
5295e4e
Compare
5295e4e
to
230dceb
Compare
That buildkite error is problematic... it's in master now. https://github.com/vibe-d/vibe.d/blob/master/crypto/vibe/crypto/cryptorand.d#L170 I don't know how that ever worked; but it looks like I've broken it. |
See, the old I think this is acceptable breakage, because this fixes a heinous const violation bug. |
Yes -> #2739 (comment)
You just broke ten of the top 50 dub packages. It would have been okay if Vibe.d was fixed before. |
230dceb
to
4255664
Compare
I can hack the bug back in there... but it's a terrible bug, no matter how you slice it. |
Also, I didn't break it, I don't have merge rights! |
Surely is a terrible code, but breaking the ability to compile older Vibe.d with newer release is terrible for the ecosystem. |
I'll give them a day or 2 to respond, or I'll commit the bug back in there. |
This PR fixes 5 issues, why does dlang-bot only mention one? |
What do you suggest? I don't think tremendously bad bugs in druntime are acceptable... :/ |
Dlang-bot only looks at commit messages. |
All 5 are in the commit message. |
The CI should never be red though :/ |
I can hack the bug back in there... although I reckon they'll fix it in vibe.d by tomorrow. Does one of you wanna push a patch to vibe.d now? Replace |
Why doesn't dlang-bot see the issues that are fixed? They won't appear in the changelog unless they're referenced here... |
4255664
to
7ad46d3
Compare
Oh well, I guess the changelog is just missing some great info! Why would dlang-bot only look at the commit messages? He should look at the PR description... I always forget to add text to the commit message, and then I need to cause a full rebuild of the CI to amend the message... that's terribly wasteful. |
Because only the commit messages are available when you look at the git log between two releases.
No, I doubt it will get fixed within the two months. Vibe.d isn't really maintained + you need to release the change in Vibe.d and then upgrade all libraries/apps that use it + release them. |
Looks like it only looks at the first "fixes" string. However, there's this: https://github.com/dlang/dlang-bot#referencing-multiple-issues |
7ad46d3
to
8d789fa
Compare
So, should I put the bug back? Should we give it a short while and put it back later? |
Unfortunately, I think you have to :/
Yes, but you also need to release a new version which only happens every 2-3 months and afterwards update all the other projects that depend on Vibe.d. |
According to #2745 (comment) the "tremendous" part was quite exaggerated. As mentioned in the Vibe.d PR, the bug you fixed didn't have any impact on the user. But fixing it means that:
Don't get me wrong, this needs to be fixed eventually, but fixing it only makes life worse for users of druntime at the moment, not better. So having everything fixed beforehand and giving it at least a release to propagate is, I think, not too much to ask for. |
Well, it's just applicable to I'm not good with a function that silently casts const away from a struct.
I buy your arguments, which is why I reintroduced it to this PR. Fix is also in isolation here: #2753 |
7114eb2
to
fcc5dbe
Compare
I separated the whitespace change and casWeak into separate patches. |
fcc5dbe
to
48749a7
Compare
And split it some more for good measure. |
The old behavior was not a bug because it only could occur for types without indirections. It is legal to convert |
There is a bug. To clear up the confusion (to which I contributed earlier), here is an example: import core.atomic;
struct S { int* p; }
void main()
{
immutable int* p = new immutable int(42);
auto s = immutable S(p);
auto x = atomicLoad(s);
pragma(msg, typeof(x.p)); /* shared(int)* - uh oh */
*x.p = 13; /* mutating an immutable int */
} The problem is that |
Is there something wrong with this? |
@@ -539,9 +666,9 @@ private | |||
} | |||
|
|||
// TODO: it'd be nice if we had @trusted scopes; we could remove this... |
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.
Could be replaced with a @trusted
lambda (something like (() @trusted => casWeak(&val, &get, set))()
)? Not sure if that's better here though.
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.
Yeah, possibly the lamest pattern D ever manifested. I don't want to put another another another function call around an asm opcode. There's already 3-4 more than enough.
{ | ||
static if ( __traits(isFloating, T) ) | ||
// resolve implicit conversions | ||
T arg = newval; |
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.
Hmm, doesn't this end up @trust
ing potentially arbitrary user code?
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's an interesting point.
It's invalid for any type that interacts with atomic to have non-trivial copy anyway (because copy semantics are bypassed by the atomics)... so I can assert that in the constraint and then we can have confidence this is safe.
I actually thought about that while doing this (not for this exact reason), but it's stuck on https://issues.dlang.org/show_bug.cgi?id=19902, which is a really bad regression, and it's been sitting there for months!
I figured I'd add that restriction whenever this is solved.
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 put the assert.
I'm not sure if the same assert should be everywhere though; atomicStore
is definitely a copying assignment, whereas exchange and cas are both actually swap operations, which are move operations, so they don't actually interact with copy semantics.
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.
@TurkeyMan: This line causes a regression for:
struct S
{
int x;
alias x this;
}
shared S s;
s = 0x1234_5678;
atomicStore(s, 0); // => Error: cannot implicitly convert expression `newval` of type `int` to `S`
assert(s.x == 0);
Note that the removed __traits( compiles, { val = newval; } )
constraint doesn't play a role due to alias this
magic, i.e., assignment is fine, but construction via implicit conversion fails. An explicit cast would work.
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.
interesting.
so you're saying the semantic difference is that i changed a copy to a construction?
is this real code? does this occur somewhere?
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.
It's only an additional LDC test (https://github.com/ldc-developers/druntime/blob/77066d7d399b0da1e94699da37436066589898ef/src/core/atomic.d#L1073-L1081), so I hope code like this isn't in the wild.
I'm not sure how to handle it best, i.e., whether such code should be disallowed or whether an explicit cast in atomicStore
is justified (or even T arg = void; arg = newval;
?).
Most functions are slightly more efficient. Concentrate more specific work into less surface area. Fixes issues 20107, 18643, 15007, 8831
Fixes issue 20105
Fixes issue 20106
7d0c478
to
be56fff
Compare
be56fff
to
a336e4d
Compare
2 weeks feels like a long time to twiddle my thumbs... I could be programming, but I'm playing video games instead ;) |
Add missing features to the API.
Most functions are slightly more efficient.
Concentrate more specific work into less surface area.
Fixes Issue 20107 - core.atomic : Memory order is missing keys
Fixes Issue 20106 - core.atomic : atomicFence doesn't accept MemoryOrder
Fixes Issue 20105 - core.atomic 'cas' function is incomplete
Fixes Issue 18643 - Compiling error when combining CAS and numeric literal.
Fixes Issue 15007 - core.atomic match C++11
Fixes Issue 8831 - core.atomic: add compare-and-swap function with other result type