Skip to content

'ConvertOrWidenPrimitivesEnumsAndPointersIfPossible' in NativeAOT is unnecessarily rooting 'BigInteger' (and a bunch more stuff) due to 'Convert.*' calls #101821

Closed
@Sergio0694

Description

@Sergio0694

While working on reducing the size for WinRT component using NativeAOT, we found some numeric stuff being kept:

image

Quoting @MichalStrehovsky on Discord:

"Looks like the Convert.ToSingle call in ConvertOrWidenPrimitivesEnumsAndPointersIfPossible is an overkill, we don't need code to parse floats since conversion from string to single would have been disallowed"

This is the entire set that needs to be supported:

ReadOnlySpan<ushort> primitiveAttributes = [
0x0000, // Unknown
0x0000, // Void
0x0004, // Boolean (W = BOOL)
0xCf88, // Char (W = U2, CHAR, I4, U4, I8, U8, R4, R8)
0xC550, // SByte (W = I1, I2, I4, I8, R4, R8)
0xCFE8, // Byte (W = CHAR, U1, I2, U2, I4, U4, I8, U8, R4, R8)
0xC540, // Int16 (W = I2, I4, I8, R4, R8)
0xCF88, // UInt16 (W = U2, CHAR, I4, U4, I8, U8, R4, R8)
0xC500, // Int32 (W = I4, I8, R4, R8)
0xCE00, // UInt32 (W = U4, I8, R4, R8)
0xC400, // Int64 (W = I8, R4, R8)
0xC800, // UInt64 (W = U8, R4, R8)
0x0000, // IntPtr
0x0000, // UIntPtr
0xC000, // Single (W = R4, R8)
0x8000, // Double (W = R8)
];
. Calling into convert just calls IConvertible methods so instead of the subset, one gets conversions from everything that was allocated in the app and supports IConvertible (that's why you get string -> double conversions). I don't know if there's a better mechanism in the BCL. One could just inline conversions for the whole matrix since there is an upper bound but that may not pass Jan's code review. If you can find a more narrow codepath in the BCL that handles the subset, that would be a good fix"

Opening this issue for tracking. @jkotas do you happen to know whether there's already some helper we can reuse here, or do you have any suggestions on how we could remove that dependency on Convert.* calls? Would hardcoding all possible combinations be acceptable, or something else? 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions