Skip to content
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

Remove RuntimeHelpers.IsReference from NativeAOT #105118

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static partial class Activator
try
{
// Call the default constructor on the allocated instance.
if (RuntimeHelpers.IsReference<T>())
if (!typeof(T).IsValueType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichalStrehovsky Can we assume that typeof(T).IsValueType is always recognized as an intrinsic by the toolchain and that typeof(T) won't introduce any undesirable additional reflection dependencies?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is in activator implementation, I'm not too worried about possibility of more reflection dependencies - we're already allocating the type and it better be seen as reflected on and allocated.

But if the PR description has a claim of "Should improve codegen", I would want to see that claim backed up by disassembly of before/after code for a value type and for a ref type to ensure there's no surprise regression.

{
// Grab a pointer to the optimized allocator for the type and call it.
IntPtr allocator = AllocatorOf<T>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ public static unsafe bool TryEnsureSufficientExecutionStack()
return (t_sufficientStackLimit = limit);
}

[Intrinsic]
internal static unsafe bool IsReference<T>()
{
return !MethodTable.Of<T>()->IsValueType;
}

[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsBitwiseEquatable<T>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public static MethodIL EmitIL(MethodDesc method)
return null;

bool result;
if (methodName == "IsReference")
{
result = elementType.IsGCPointer;
}
else if (methodName == "IsBitwiseEquatable")
if (methodName == "IsBitwiseEquatable")
{
// Ideally we could detect automatically whether a type is trivially equatable
// (i.e., its operator == could be implemented via memcmp). But for now we'll
Expand Down
Loading