Skip to content

Commit 4cf369e

Browse files
[release/10.0] Avoid marking types as reflected on in CreateSpan (#118908)
* Avoid marking types as reflected on in CreateSpan This seems to be at least one of the reasons why Hello World on Linux still needs support for boxed enums. `CreateSpan` is used with an enum type in Unix System.Console, which brings a boxed enum into whole program view and we can't undo the damage this causes to the whole program view during compilation anymore (even though we no longer need the `typeof` then because RyuJIT always expands `CreateSpan`). * Update src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs --------- Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
1 parent 6c6dac8 commit 4cf369e

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
2727
throw new PlatformNotSupportedException();
2828
}
2929

30-
private static unsafe ref byte GetSpanDataFrom(
31-
RuntimeFieldHandle fldHandle,
32-
RuntimeTypeHandle targetTypeHandle,
33-
out int count)
34-
{
35-
// We only support this intrinsic when it occurs within a well-defined IL sequence.
36-
// If a call to this method occurs within the recognized sequence, codegen must expand the IL sequence completely.
37-
// For any other purpose, the API is currently unsupported.
38-
// https://github.com/dotnet/corert/issues/364
39-
throw new PlatformNotSupportedException();
40-
}
41-
4230
[RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")]
4331
public static void RunClassConstructor(RuntimeTypeHandle type)
4432
{

src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,15 @@ internal static bool CanPrimitiveWiden(CorElementType srcET, CorElementType dstE
151151
/// <remarks>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.</remarks>
152152
[Intrinsic]
153153
public static ReadOnlySpan<T> CreateSpan<T>(RuntimeFieldHandle fldHandle)
154+
#if NATIVEAOT
155+
// We only support this intrinsic when it occurs within a well-defined IL sequence.
156+
// If a call to this method occurs within the recognized sequence, codegen must expand the IL sequence completely.
157+
// For any other purpose, the API is currently unsupported.
158+
// We shortcut this here instead of in `GetSpanDataFrom` to avoid `typeof(T)` below marking T target of reflection.
159+
=> throw new PlatformNotSupportedException();
160+
#else
154161
=> new ReadOnlySpan<T>(ref Unsafe.As<byte, T>(ref GetSpanDataFrom(fldHandle, typeof(T).TypeHandle, out int length)), length);
162+
#endif
155163

156164

157165
// The following intrinsics return true if input is a compile-time constant

0 commit comments

Comments
 (0)