Skip to content

Treat some nint/nuint conversions as standard conversions#61034

Merged
jcouv merged 5 commits intodotnet:mainfrom
jcouv:nint-standard
May 7, 2022
Merged

Treat some nint/nuint conversions as standard conversions#61034
jcouv merged 5 commits intodotnet:mainfrom
jcouv:nint-standard

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Apr 29, 2022

@jcouv jcouv self-assigned this Apr 29, 2022
@ghost ghost added the Area-Compilers label Apr 29, 2022

// Notice that there is no implicit numeric conversion from a type to itself. That's an
// identity conversion.
private static readonly bool[,] s_implicitNumericConversions =
Copy link
Member Author

Choose a reason for hiding this comment

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

To assist with review of the removed tables, here's the portion table from ConversionEasyOut relevant to numeric types:
image

@jcouv jcouv force-pushed the nint-standard branch 2 times, most recently from d391fe9 to 55ed6ee Compare April 29, 2022 06:14
@jcouv jcouv marked this pull request as ready for review April 29, 2022 14:56
@jcouv jcouv requested a review from a team as a code owner April 29, 2022 14:56
@jcouv jcouv requested a review from cston April 29, 2022 14:56
@jcouv jcouv added this to the 17.3 milestone Apr 30, 2022
@AlekseyTs
Copy link
Contributor

@jcouv

Treat some nint/nuint conversions as standard conversions

I do not see https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/native-integers.md#conversions mention the word "standard" anywhere. What am I missing.
Also, it would be good to clarify what some conversions are supposed to be treated as standard.

@AlekseyTs
Copy link
Contributor

It is not clear to me whether this is a bug fix or a feature work. If this is a bug fix, what is the corresponding tracking issue?

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

@jcouv
Copy link
Member Author

jcouv commented May 6, 2022

@AlekseyTs This is a bug fix (thus done in main branch). The expected behavior falls out from original spec (linked in OP):

10.4.2 Standard implicit conversions
The following implicit conversions are classified as standard implicit conversions:
...

  • Implicit numeric conversions

...

10.4.3 Standard explicit conversions
The standard explicit conversions are all standard implicit conversions plus the subset of the explicit conversions for which an opposite standard implicit conversion exists.

}

#nullable enable
private static bool HasImplicitNumericConversion(TypeSymbol source, TypeSymbol destination)
Copy link
Contributor

@cston cston May 6, 2022

Choose a reason for hiding this comment

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

HasImplicitNumericConversion

Consider extracting a GetNumericConversion() method that can be shared between the two methods since it looks like the only difference between the two is the last line. #Resolved

using System;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
Copy link
Contributor

@cston cston May 6, 2022

Choose a reason for hiding this comment

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

System.Runtime.CompilerServices

Is this used? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. This using wasn't used, but also wasn't grayed out in IDE.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 3)

@jcouv jcouv merged commit 4e31f20 into dotnet:main May 7, 2022
@jcouv jcouv deleted the nint-standard branch May 7, 2022 16:56
@ghost ghost modified the milestones: 17.3, Next May 7, 2022
@Cosifne Cosifne modified the milestones: Next, 17.3 P2 May 31, 2022
@jcouv jcouv mentioned this pull request Oct 14, 2022
49 tasks
@jcouv jcouv mentioned this pull request Oct 14, 2022
49 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants