-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Use better order of evaluation in IsNull/IsNullLike #10769
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
KirkMunro
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.
LGTM
|
@PoshChan please retry macos |
|
@vexx32, successfully started retry of |
|
In case someone looking at this PR wants to know, the reason for comparing against null using |
Just to clarify, it's often considered a good practice in general but it doesn't actually make a difference when both sides are typed as object (SharpLab example). I like the change, just want to point that out because it can be confusing and I didn't hear that covered in the link. |
As maintainer I don't like such sporadic changes. If this is a best practice we should keep our code base clean and fix all code base in one step. This should be well-documented (youtube is not document) and approved by maintainers. I suggest to open new issue for this. |
|
I see what you mean. I can revert that part for now if we'd rather do these separately; this may be a wider-reaching change we need to account for across the entire codebase, and perhaps it's best to do that all at once. That said... I also don't see the harm in updating the code practices here and there as we make other changes anyway to gradually reduce the instances of the less advisable practice as well. Also, I know @KirkMunro was wanting that change to be in |
@iSazonov: This isn't sporadic. It's about updating a shared piece of code that is used by both the Do I think that using Yes. Do I think we should use Yes, because it's a best practice. Do I think this is a best practice to follow to the point where we should update our entire code base? No way. We haven't run into a problem with As for how well or not well documented you think that YouTube video is, well, Mads leads the C# design team, and what he said was pretty clear in that video. I can't find it in official docs though, because docs aren't always updated by the people who understand what should be said. The only Microsoft doc I found simply said you could use |
|
I am not against the best practices and new features that appeared just to help us. If I'll get understanding that this is great for PowerShell I'll first who ready to review all code base for this.
If it is important (do you insist on it?) here then why? Scripts have been malfunctioning for the past 15 (!) years and we should fix this? Such change of a public API is a breaking change in red area. It is unbelievable that such a change will be accepted. On the other incredible side, what if there is code or scripts that are based on virtual Equals? And again we will break them. As maintainer I'd want at first update our code style convention guideline and get MSFT docs so that we make reasonable requests to contributors at PR time review and not embarrass them and not waste time discussing this. |
Just to be completely clear here, when the LHS is typed as I have no strong personal opinions about whether PowerShell should or shouldn't prefer |
@SeeminglyScience Please share an example on Sharplab for my education. |
|
Here ya go. The first generates IL that specifically tests for a null reference, the second calls out to the custom equality operator. It's important to reiterate there is no virtual dispatch here. Because operators are static, it doesn't matter what the actual run-time type is, only the design time typing. |
This comment has been minimized.
This comment has been minimized.
There's no difference between |
|
Aye. And since we're talking about comparing against a parameter that is typed as Other usages within the PowerShell engine can be evaluated differently. But as with this one, anything that uses |
|
@SeeminglyScience Thanks, apologies for missing that in your earlier comments. Given that's the case, there is no reason not to merge this PR in as is, right, because it's just enhancing performance and making a very small style change. Either that or remove the style change and merge the perf change in, because it won't matter either way. |
|
Yup, I'm good with either. 🙂 |
|
I also removed my dependency on this from #10704 because it isn't a requirement for that to be reviewed and merged in. |
|
@SeeminglyScience Many thanks! With @SeeminglyScience's samples my understanding is that the issue can be only with custom classes with wrong Equals implementation. The samples also explicitly show that IL code is the same - no performance benefits. Then I found that PowerShell repo contains 5599 of All custom classes which could be passed to PowerShell and which have wrong design cannot be fixed in PowerShell engine with the feature. (We can’t even predict that there is a right design for these classes.) Then I make quick search in CoreFX. I hoped to find useful examples and was very wonder that I find a few ones although this feature was mentioned two years ago (!). At first look they used it to fix very thin bugs (in unsafe code - that I saw). After that, I'm not surprised that this feature is undocumented. So my current conclusion is that the PR doesn't add any value. |
|
@vexx32 Blue labels is for issues. Yellow is for PRs (they is used to generate changelog automatically) |
|
@iSazonov the |
|
@vexx32 I suggest to open new PR for null ordering. Our discussion about |
|
No problem, will do. 🙂 |
PR Summary
Initial implementation of IsNullLike used a slightly less optimal order of evaluation. The expected most common cases are (in order):
null,AutomationNull.Value,DBNull.Value,NullString.ValueThis also changes
IsNull()to useobj is nullinstead ofobj == null.PR Context
See #10422 and #10704 (this PR could be made a part of either of those, but is a smaller change and easier to get in first, so that we can focus on more important outstanding issues and review comments in the other PRs)
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.