Correct lowering of conversions between decimal and nint/nuint#40271
Correct lowering of conversions between decimal and nint/nuint#40271cston merged 2 commits intodotnet:features/NativeIntfrom
Conversation
|
@gafter, @dotnet/roslyn-compiler, please review, thanks. |
| base(other) | ||
| { | ||
| _underlying = other; | ||
| IsNativeInt = true; |
There was a problem hiding this comment.
true [](start = 30, length = 4)
Please add this as an explicit parameter for clarity. #Closed
| IL_0000: ldarg.0 | ||
| IL_0001: call ""long decimal.op_Explicit(decimal)"" | ||
| IL_0006: conv.i | ||
| IL_0007: newobj ""nint?..ctor(nint)"" |
There was a problem hiding this comment.
nint [](start = 25, length = 4)
Can we change the way this is displayed? nint doesn't exist at the IL level. #Closed
There was a problem hiding this comment.
When generating IL, we generate a set of tokens for the untranslated symbols referenced in IL (see CommonPEModuleBuilder.GetFakeSymbolTokenForIL). Those fake tokens are then translated later when emitting (see MetadataWriter.ResolveEntityHandleFromPseudoToken which eventually calls PEModuleBuilder.Translate) so that references to dynamic are converted to object and references to nint are converted to System.IntPtr, etc.
The IL visualizer in the test code (see ILBuilderVisualizer.ILBuilderToString) is handed the untranslated symbols and those are the symbols displayed. (Note that the IL visualizer reports references to dynamic rather than object as well.)
To fix the IL visualizer, we'd probably need to change CommonPEModuleBuilder.GetReferenceFromToken to call Translate on the symbol before returning it. That would change the display of dynamic and nint and perhaps other symbols however.
Logged #40340.
In reply to: 357284988 [](ancestors = 357284988)
Include missing conversions to/from 64-bit values when lowering conversions between
decimalandnint/nuint.Conversions within expression lambdas will be handled later.
Relates to #38821 (test plan for native ints)