Skip to content
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

Disable nullable comparison optimization for decimals #73536

Merged
merged 3 commits into from
May 18, 2024

Conversation

jjonescz
Copy link
Contributor

Fixes #73510, a regression introduced by #68069.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 17, 2024
@jjonescz jjonescz marked this pull request as ready for review May 17, 2024 11:34
@jjonescz jjonescz requested a review from a team as a code owner May 17, 2024 11:34
@AlekseyTs
Copy link
Contributor

Have we done similar change (the regression) for VB?

{
System.Console.Write(M(x) ? 1 : 0);
}
static bool M(decimal? x) => x == 0.0m;
Copy link
Member

@cston cston May 17, 2024

Choose a reason for hiding this comment

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

x == 0.0m;

Are we also testing cases where the constant is on the LHS such as 0.0m == x? #Closed

Copy link
Member

Choose a reason for hiding this comment

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

Consider testing x == 0.00m and 0.00m == x since the reported issue uses 0.00m.

Copy link
Member

Choose a reason for hiding this comment

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

Let's also test x != <constant> and <constant> != x.

C.Run(0.0m);
C.Run(1m);
C.Run(2m);
C.Run(null);
Copy link
Member

@cston cston May 17, 2024

Choose a reason for hiding this comment

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

C.Run

Consider also testing C.Run(default(decimal)); #Closed

or ConstantValueTypeDiscriminator.NUInt
or ConstantValueTypeDiscriminator.SByte
or ConstantValueTypeDiscriminator.Single
or ConstantValueTypeDiscriminator.String
Copy link
Member

@cston cston May 17, 2024

Choose a reason for hiding this comment

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

ConstantValueTypeDiscriminator.String

Consider removing String if this local function should only be called with value types. #Closed

return constantValue is
{
IsDefaultValue: false,
Discriminator: ConstantValueTypeDiscriminator.Boolean
Copy link
Member

Choose a reason for hiding this comment

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

Discriminator

It looks like we're testing the original optimization with boolean, int, double, and now decimal. We should also test the optimization for the other types below if we're not already doing so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Looks like integers smaller than 32 bits are not optimized because they use Int32's equality operator, so I will remove them from the list.

@jjonescz
Copy link
Contributor Author

Have we done similar change (the regression) for VB?

No, the optimization hasn't been implemented for VB.

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

No additional comments beyond Chuck's

{
System.Console.Write(M(x) ? 1 : 0);
}
static bool M(short? x) => x == 1;
Copy link
Member

Choose a reason for hiding this comment

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

1

Should this be (short)1?

Copy link
Contributor Author

@jjonescz jjonescz May 17, 2024

Choose a reason for hiding this comment

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

That results in longer IL, you can see that in SharpLab. Same for other less-than-32bit ints. Doesn't seem to have any effect on the optimization as it's currently (or was) implemented. The cast creates a more complicated bound tree

{
System.Console.Write(M(x) ? 1 : 0);
}
static bool M(ushort? x) => x == 1;
Copy link
Member

Choose a reason for hiding this comment

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

1

(ushort)1?

{
System.Console.Write(M(x) ? 1 : 0);
}
static bool M(sbyte? x) => x == 1;
Copy link
Member

Choose a reason for hiding this comment

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

1

(sbyte)1?

@jaredpar
Copy link
Member

Please cherry pick to release/dev17.10 after merge

@jjonescz jjonescz merged commit 40811c8 into dotnet:main May 18, 2024
24 checks passed
@jjonescz jjonescz deleted the 73510-DecimalNullableComparison branch May 18, 2024 11:45
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 18, 2024
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nullable decimal comparison bug in dotnet 8.0.5 (SDK 8.0.300)
6 participants