Skip to content

Simplify conditional operator #112074

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

Merged
merged 3 commits into from
Apr 28, 2025
Merged

Conversation

xtqqczze
Copy link
Contributor

@xtqqczze xtqqczze commented Feb 2, 2025

Simplify conditional operator in src/coreclr/System.Private.CoreLib/System.Private.CoreLib.sln

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 2, 2025
@xtqqczze
Copy link
Contributor Author

xtqqczze commented Feb 2, 2025

@MihuBot

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 2, 2025
@hez2010
Copy link
Contributor

hez2010 commented Feb 2, 2025

They were originally written like that to mitigate some CQ issue. I believe they have been fixed in RyuJIT now but I'm not sure about mono.

@xtqqczze
Copy link
Contributor Author

xtqqczze commented Feb 2, 2025

They were originally written like that to mitigate some CQ issue. I believe they have been fixed in RyuJIT now but I'm not sure about mono.

It seems base and diff are compiled to identical IL (sharplab)

@@ -314,12 +314,12 @@ internal static object DefaultToType(IConvertible value, Type targetType, IForma
// Conversions to Boolean
public static bool ToBoolean([NotNullWhen(true)] object? value)
{
return value == null ? false : ((IConvertible)value).ToBoolean(null);
return value != null && ((IConvertible)value).ToBoolean(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be value is IConvertible convertible && convertible.ToBoolean(null), yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a change in behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly a change in code generation, arguably for the worse: https://csharp.godbolt.org/z/nrM7df3YP

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes you say it's "worse"?

The code is nearly identical, just without the early exit for null.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

@am11 am11 removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 9, 2025
@tannergooding tannergooding merged commit 8233e6b into dotnet:main Apr 28, 2025
138 of 141 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants