-
-
Notifications
You must be signed in to change notification settings - Fork 747
Remove extra field from Nullable when unnecessary #6253
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
Conversation
|
Thanks for your pull request and interest in making D better, @marler8997! 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. |
143c83f to
d2fc394
Compare
wilzbach
left a comment
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 think you do this without NoNullValue
std/typecons.d
Outdated
| { | ||
| private enum nullValue = NoNullValue._; | ||
| } | ||
| private enum hasNullValue = !is(typeof(nullValue) == NoNullValue); |
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 think you can entirely skip NoNullValue and simply use false or void.
std/typecons.d
Outdated
| } | ||
| else static if (is(T == class) || is(T == interface)) | ||
| { | ||
| private enum nullValue = cast(T)null; |
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.
space after cast
Same throughout
| { | ||
| return _isNull; | ||
| static if (hasNullValue) | ||
| return _value is nullValue; |
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.
This doesn't work in the enum case.
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 passes the unittests...
std/typecons.d
Outdated
| } | ||
|
|
||
| enum Foo2 : int {a = int.min} | ||
| assert(Nullable!Foo2.sizeof == Foo2.sizeof); |
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.
static assert
| class FooInterface { } | ||
| assert(Nullable!FooInterface.sizeof == FooInterface.sizeof); | ||
| } | ||
| @safe unittest |
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.
What's the purpose of this test?
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.
Because nullValue == false when the base type is bool, I think he wanted to ensure that the code won't accidently consider non-null false being null, or something like that. I think that's a good rationale.
|
This is an awful lot of extra special casing and ugly bloat for something that seems minimally useful to the end user. |
|
Well, for the cases covered here, the Nullable does now end up fitting into one register. |
|
This will also break code: Although the current behaviour is more an accident than anything else. |
Since D is a systems programming language, I would hardly consider cutting size of |
If somebody does that, he fairly much deserves what he's getting here. |
|
The entire concept of a Nullable class is very odd to begin with and probably should have been disallowed. In any case, this needs a changelog entry detailing the breakage. |
7273774 to
8ce241e
Compare
|
You've covered classes and interfaces, what about pointers? |
Some types like classes/interfaces and most enum types can be "nullified" by changing their value, rather than adding an extra field to hold this data. This change utilizes this "null" value when the the type has an applicable "null value".
| Nullable!(int*) npi; | ||
| assert(npi.isNull); | ||
|
|
||
| //Passes?! |
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.
lol :)
wilzbach
left a comment
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 think this is a useful change and the complication is worth it as fitting in one register will result in quite a speed-up for classes et.al.
|
@marler8997 Have a look at the failing diet-ng test. That seems to be a real error (I just restarted Jenkins to test it and it doesn't appear on other PRs). |
|
diet-ng is probably hitting the "Passes?!" case with an implicit |
|
I was initially going to require a deprecation, but I realized there's no easy way to have a deprecation for the new behavior without creating a different Any ideas on how to make the transition smoother? |
|
I'm at a loss. I'm not sure what we could deprecate or warn about. Both assigning a Maybe someone can come up with a brilliant idea to do this, I have been surprised before when it comes to what D can do. But if no one can come up with a solution, do we just leave |
|
The only other option I can think of is having a |
|
A |
|
|
|
We need a way to emphasize breaking changes in the changelog. For now, can you manually add |
|
In looking at the implementation a bit more I think a better way to implement this would be to make |
|
Honestly, I think that the assumption that it's not desirable and valid to have a For instance, I've sometimes found it annoying how |
|
Whoops. I accidentally submitted too soon. Anyway, while pointers and classes don't apply to |
|
@jmdavis Agreed. You've basically restated my point. However, it is confusing that the return value of |
I grant you that that could be confusing, and maybe |
|
Adding |
No, but changing Also, |
|
This spectre keeps coming up, but, all things considered, it's unlikely What we need is a new design that is properly thought-out, to be a replacement for |
|
@quickfur You may be right, but the only breakage that my change was proposing was to have |
Wow...deja vu... |
What is actually wrong with |
Let's stop repeating the same arguments and stop asking the same questions. Repetition is tiring when it comes to constructive conversation. |
|
Well, based on those points, I'm in complete disagreement that a replacement for |
Yes you've repeated this multiple times. You have made your opinion heard. I don't strongly agree or disagree with it, but repeating your opinion over and over doesn't help anyone. |
|
BTW, if we went forward with |
|
The point of contention here is really an ideological one, and centers on the question of whether you consider a reference type like a Poor naming aside, it seems reasonable in some situations to consider that In other situations, of course, such as when you want to make explicit in your API when a function can return null (e.g., write The current implementation makes me think that the original author likely did not consider instantiating it with a reference type (the code comments seem to point to the expectation that it would only be used with a value type -- and the lack of sig constraint does not help in this regard), so the above distinction likely was never considered, leading us to the unfortunate situation today where one could argue either way, with no clear answer as to what's the "right thing" to do. i.e., reasonable people will disagree, and no matter which way you choose, the other group of people will be unhappy. |
|
@quickfur I agree with your analysis. My proposal was to have |
|
Taking the above conversation in mind, here's how we can move forward on this PR.
|
|
@marler8997 Ping. |
|
I'm waiting for people to chime in on whether we should introduce the In other words, I don't think I want to move forward making |
|
Closing this PR and the matter of adding the Optional type. The only person to weigh in was @jmdavis who is against the addition. |
Some types like classes/interfaces and most enum types can be "nullified" by changing their value, rather than adding an extra field to hold this data. This change utilizes this "null" value for classes/interfaces and when it applies to enum types as well.