-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
@MichalPetryka unrelated to this PR, would you mind dropping me an email? both danmose and joperezr @ microsoft. |
@@ -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) |
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.
@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?
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.
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.
@MichalPetryka Could you grab some code samples to verify the results? |
This is producing exact same code before and after on simple tests: using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
m1();
m2();
m3<object>();
m3<KeyValuePair<object,object>>();
[MethodImpl(MethodImplOptions.NoInlining)]
void m1()
{
Activator.CreateInstance<DateTime>();
}
[MethodImpl(MethodImplOptions.NoInlining)]
void m2()
{
Activator.CreateInstance<object>();
}
[MethodImpl(MethodImplOptions.NoInlining)]
void m3<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T>()
{
Activator.CreateInstance<T>();
} Disassembly of relevant methods:
|
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.
Thanks! (And thank you Jan for checking the disassembly!).
Should improve codegen, removed redundant VM code.
cc @MichalStrehovsky