diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs index be875ba1731c52..541f62969ab526 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs @@ -27,18 +27,6 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle) throw new PlatformNotSupportedException(); } - private static unsafe ref byte GetSpanDataFrom( - RuntimeFieldHandle fldHandle, - RuntimeTypeHandle targetTypeHandle, - out int count) - { - // We only support this intrinsic when it occurs within a well-defined IL sequence. - // If a call to this method occurs within the recognized sequence, codegen must expand the IL sequence completely. - // For any other purpose, the API is currently unsupported. - // https://github.com/dotnet/corert/issues/364 - throw new PlatformNotSupportedException(); - } - [RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")] public static void RunClassConstructor(RuntimeTypeHandle type) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs index 6543046573bf3f..83e401940e4da1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs @@ -151,7 +151,15 @@ internal static bool CanPrimitiveWiden(CorElementType srcET, CorElementType dstE /// This method is intended for compiler use rather than use directly in code. T must be one of byte, sbyte, bool, char, short, ushort, int, uint, long, ulong, float, or double. [Intrinsic] public static ReadOnlySpan CreateSpan(RuntimeFieldHandle fldHandle) +#if NATIVEAOT + // We only support this intrinsic when it occurs within a well-defined IL sequence. + // If a call to this method occurs within the recognized sequence, codegen must expand the IL sequence completely. + // For any other purpose, the API is currently unsupported. + // We shortcut this here instead of in `GetSpanDataFrom` to avoid `typeof(T)` below marking T target of reflection. + => throw new PlatformNotSupportedException(); +#else => new ReadOnlySpan(ref Unsafe.As(ref GetSpanDataFrom(fldHandle, typeof(T).TypeHandle, out int length)), length); +#endif // The following intrinsics return true if input is a compile-time constant