-
-
Notifications
You must be signed in to change notification settings - Fork 705
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 19256: prevent JSONValue const conversion #6716
Fix issue 19256: prevent JSONValue const conversion #6716
Conversation
|
Thanks for your pull request and interest in making D better, @FeepingCreature! 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.
|
|
Test, please? You can use |
ff10901
to
5af12a1
Compare
|
Test added. |
6e11a63
to
421292b
Compare
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.
LGTM.
Generally, working around a bug in A by a patch in B is suspicious, but in this case I think it's justified as:
- 0 net lines of code added
- the compiler fix is likely to be non-trivial (it's a regression introduced by a large patch many years ago).
|
Regarding auto-tester failures, see dlang/druntime#2304 |
421292b
to
00efd40
Compare
|
druntime PR merged, retrying. |
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.
Something has to be done for the DUB projects that break.
|
I am not sure that things can be done. D allows you to write straight-up wrong code involving JSONValue right now. Presumably that's what they're doing. Occasionally fixing a bug implies breaking code that used to work, if it worked in a way that defied the language spec. |
|
Contacting people so that they change their code is what i had in mind. |
|
The problem could be in just 1 place in the code, with so many projects failing because said code is a dependency. |
|
Almost. After looking more carefully at the logs it's always vibe-d (but several places) excepted for the project dls. |
|
Perhaps leaving this to a compiler fix would be preferred after all, as then it could go through a deprecation phase. @WalterBright How likely are we to get a fix for https://issues.dlang.org/show_bug.cgi?id=12885 in DMD? |
|
Ping? "Not very likely"? |
I'd say we should fix that issue (https://issues.dlang.org/show_bug.cgi?id=12885#c3), though it will take some deprecation period. So this looks like a reasonable workaround in the meantime. |
|
Build failure of vibe.d (https://buildkite.com/dlang/phobos/builds/397#dccb2203-9142-4358-9840-e650356a4ccb/99-140). Errorvibe-core-1.4.3/vibe-core/source/vibe/core/args.d(68,27): Error: function `vibe.core.args.fromValue!bool.fromValue(JSONValue val)` is not callable using argument types `(const(JSONValue))` vibe-core-1.4.3/vibe-core/source/vibe/core/args.d(68,27): cannot pass argument `*pv` of type `const(JSONValue)` to parameter `JSONValue val` vibe-core-1.4.3/vibe-core/source/vibe/core/args.d(298,12): Error: template instance `vibe.core.args.readOption!bool` error instantiating vibe-core-1.4.3/vibe-core/source/vibe/core/core.d(692,70): Deprecation: `std.algorithm.setops.No` is not visible from module `core` vibe-core-1.4.3/vibe-core/source/vibe/core/args.d(68,27): Error: function `vibe.core.args.fromValue!string.fromValue(JSONValue val)` is not callable using argument types `(const(JSONValue))` vibe-core-1.4.3/vibe-core/source/vibe/core/args.d(68,27): cannot pass argument `*pv` of type `const(JSONValue)` to parameter `JSONValue val` vibe-core-1.4.3/vibe-core/source/vibe/core/core.d(1328,13): Error: template instance `vibe.core.args.readOption!string` error instantiating |
- "key" in JSONValue returns const(JSONValue)* - fromValue expected non-const JSONValue - implicit conversion of const(JSONValue) to JSONValue to be fixed with dlang/phobos#6716
|
Here is a trivial PR to vibe.d vibe-d/vibe-core#100, seems like a rare occurrence of sth. that breaks with this workaround, so it might still be reasonable to go ahead with this once a new vibe.d version is released. |
00efd40
to
1609b9e
Compare
|
Should work now with the fixed vibe-d and good to go for 2.085.0 from my side. Seemed to risky to put in 2.084.0 without beta. |
|
ping |
|
Ack, waiting on #7011 for green tests. |
|
Can you please rebase this so the circle error goes away? |
Reorder JSONValue's union members to make dmd realize that JSONValue contains const references and disallows reassigning const(JSONValue) to JSONValue, which would break constness. This works around https://issues.dlang.org/show_bug.cgi?id=12885 .
74f1760
to
12c73ff
Compare
|
Hmm vibe.d still fails. |
|
I think this PR should be closed. The only practical way forward is to deprecate and remove the behavior, and since the behavior is 100% compiler related (you can't hook an implicit cast away from const), it can't be done in a library. Note, I found that SumType suffers from the same problem. And it happens in |
|
oh wait I see, you mean get rid of that logic. Yeah, I guess. I'd rather see it codified as "well this sucks, but it's the best we can do." SumType can "fix" this by just reordering its union by edit: I think fixing 12885 is viable. For the record, I said in 2019 that I need this behavior, but this is no longer the case; librebindable uses a totally different approach (involving a lot more casting). |
It's not memory safe in
SumType will suffer exactly the same fate as And there is no way to deprecate it, unless we want to rename the type. The only path forward is to deprecate the current memory-unsafe behavior, and then fix it.
Rebindable in general is a horrendous hack, making up for a lack of tail-modifiers in the language. I'm not convinced it's sound type-wise. |
|
I mean, if the bug is fixed, JSONValue and SumType will break regardless, surely?
I believe that librebindable is typesafe, or rather, can be used to build typesafe abstractions if used correctly. Phobos Rebindable definitely wouldn't be typesafe, especially if it worked for structs, because it exposes its value by ref, leading to pointer leaks that allow observing immutable changes. My primary argument for librebindable being sound is that it does not do this. |
Yes, but the big difference is that the compiler can deprecate the behavior first, notifying anyone using it for a (probably long-ish) period of time. A library cannot hook the implicit cast. |
I honestly have not read much into it. The idea of deconstifying copied data is sound (i.e. deconstifying the head), but what I'm more worried about is if it's sound within the current model. That is, will amazingly obtuse optimizations suddenly happen because they are sound within the model, but not with the hacks performed here? |
Ah, now I get what you're saying. Yeah if there's hope of the bug being fixed, I agree that's better than this PR. |
|
Underlying issue has been fixed. You can reopen if it is still relevant. Closing this PR. |
|
Underlying issue has not been fixed? I just reproed 19256 on dmd master. |
|
https://issues.dlang.org/show_bug.cgi?id=12885 was allegedly fixed by dlang/dmd#16594 |
|
Oh! You are correct. It's gated behind |
|
Thanks for the investigation! |

Fix https://issues.dlang.org/show_bug.cgi?id=19256
Reorder JSONValue's union members to make dmd realize that JSONValue contains const references and disallows reassigning const(JSONValue) to JSONValue, which would break constness.
This works around https://issues.dlang.org/show_bug.cgi?id=12885 .
Sample code illustrating the problem: