Reintroduce const violation bug to fix vibe.d build failure#2753
Reintroduce const violation bug to fix vibe.d build failure#2753CyberShadow merged 1 commit intodlang:masterfrom
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 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 + druntime#2753" |
6f38791 to
f052f08
Compare
|
This has fewer failures on BuildKite than master, so, I'm going to merge this. |
|
The vibe.d issue that this was intended to resolve is resolved by this PR. That other one is unrelated to anything I've done. |
|
Noting that the title of this PR is incorrect. It is not a bug to return
|
|
Thanks for pointing that out! So, this is actually a regression fix affecting value types. |
|
@n8sh Supplying a const ref to a function, and returning it with const stripped away is a bug, and it's a bad one. Andrei's example shows a This code is NOT a fix, it reintroduced the bug. |
If it returns by non-ref, then it should be perfectly fine to strip head const.
So, don't return |
Stripping head-const is not valid for struct's or classes. It was showed elsewhere numerous times: struct S { int* p; }
immutable S s;
S r = atomicLoad(s);
*r.p = 10; |
Yes, it is impossible to have tail-const in these cases. So, for structs or classes, it should return |
|
That's possible... but my general feeling is that so many 'cases' are bad. It makes meta way more complicated when it decides to do a special thing in one case and not some other... |
That really isn't anything new, it's a consequence of D's type system being generally very complicated. Have a look at the implementations of some templates in std.traits and std.typecons. This is why we encapsulate the complexity into a template which does a single thing and is documented to do this certain thing, then use it throughout. (Actually a bit surprised there isn't already something like that in Phobos, but maybe I missed it.)
I don't really see why this is an issue. It will result in a compilation error, and they will have to fix the code if they want it to support more kinds of types. The bottom line is, the code in vibe.d was correct, so we need to avoid breaking it and other such code, even if that means adding a little bit of complexity here. |
|
BTW, perhaps leveraging the implementation in the compiler will make this simpler. Does Edit: demo: https://run.dlang.io/is/34UqHd |
|
I can make a rule like that. It still feels pretty complex though. const(int) foo();
auto x = foo();
pragma(msg, typeof(x));
> const(int)This seems unnecessary... why doesn't auto strip away pointless qualifiers naturally? |
This should fix the vibe.d build failure.