-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement RuntimeHelpers.SizeOf #100618
Implement RuntimeHelpers.SizeOf #100618
Conversation
Note regarding the
|
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...veaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs
Outdated
Show resolved
Hide resolved
src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <[email protected]>
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Show resolved
Hide resolved
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
…/Runtime/CompilerServices/RuntimeHelpersTests.cs Co-authored-by: Jan Kotas <[email protected]>
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Show resolved
Hide resolved
...veaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <[email protected]>
/// <returns>The size of instances of the type.</returns> | ||
/// <exception cref="ArgumentException">The passed-in type is not a valid type to get the size of.</exception> | ||
/// <remarks> | ||
/// This API has the same behavior as if you were to use the IL sizeof instruction with the passed in type as the operand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This API has the same behavior as if you were to use the IL sizeof instruction with the passed in type as the operand. | |
/// This API returns the same value as the IL sizeof instruction with the passed in type as the operand. |
Nit: It does not have the same behavior for error cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe even link to https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.sizeof that has more details.
# Conflicts: # src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs # src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs # src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs # src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs # src/mono/mono/metadata/icall.c
|
||
Type typeObj = Type.GetTypeFromHandle(type)!; | ||
if (typeObj.ContainsGenericParameters || typeObj.IsGenericParameter || typeObj == typeof(void)) | ||
throw new ArgumentException(SR.Arg_TypeNotSupported); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a limitation of mono runtime (which doesn't exist in coreclr)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is the same limitation in CoreCLR and NativeAOT (though the implementations are slightly different due to how the different type systems are implemented).
/ba-g Slow mac timeout |
Co-authored-by: Jan Kotas <[email protected]>
Fixes #97344
Implement the SizeOf API with the same behavior as the
sizeof
IL instruction.