-
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
Support unboxing a true nullable and opt-in to faster emitted IL invoke stubs #88952
Comments
Which part of the runtime needs to be modified to handle these boxed nullable objects ? The unbox.any implementation ? |
Yes the Unbox_Any implementation which is used in the current emit code. However, for consistency, Unbox should be supported as well IMO. |
Wouldn't this slow down the unbox implementation, since now it has to check for 2 cases instead of 1 ? |
Was this a change made to support the invoke functionality, or the clr always worked like that ? |
What should be the semantics of unbox.any in this case ? I.e. if the input object is a 'true' boxed nullable, and |
In v7 reflection added emit support that normalized all It is possible to change reflection to call these helper methods instead of unbox_any, at least for Mono, but that isn't ideal since the work to create the true nullable already occurred and that logic is shared across both clrs, and because as mentioned earlier the input is is "normalized" for either invoking the |
Looks like it's expected to throw so whatever we access with |
FWIW, see runtime/src/coreclr/vm/object.cpp Lines 1681 to 1682 in 9ffdb53
|
Sounds like we break the spec then? 😄 |
What should be the result of an |
That's another (or the same) case where we brake the spec, the spec says that So yeah, we do allocate it on stack |
I do not think it makes sense to try to replicate the current questionable poorly defined RyuJIT behavior in Mono JIT and interpreter. @steveharter Can we fix the reflection invoke to avoid dependency on this behavior? It should not result into any performance loss - create the local to store the |
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsFrom this PR, the ability to generate faster emit stubs from Mono was disabled since it caused issues in some cases when invoking methods that have a
Various tests fail in The issue is that the mono runtime is calling the Enabling this support and removing the 2
|
Closing - we'll go with a different emit approach. |
From this PR, the ability to generate faster emit stubs from Mono was disabled since it caused issues in some cases when invoking methods that have a
Nullable<T>
as an argument. This was disabled by these 2#if
statements (which should be removed with this issue):runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvokerCommon.cs
Line 110 in 7980421
runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvokerCommon.cs
Line 139 in 7980421
Various tests fail in
System.Reflection.Tests
such asInvoke(Type methodDeclaringType, string methodName, object obj, object[] parameters, object result)
where it is passingyield return new object[] { typeof(MethodInfoDefaultParameters), "NullableInt", new MethodInfoDefaultParameters(), new object[] { (int?)42 }, (int?)42 }
as the test data.The issue is that the mono runtime is calling the
Unbox()
andUnboxExact()
methods onNullable<T>
and appear to be passingint
, for example, instead ofNullable<int>
for theobject
parameter. The reflection invoke code creates temporary "true nullable" boxed objects (the default behavior of boxing is to createT
ornull
from aNullable<T>
) in order to invoke a method that has a nullable parameter, and runtime is not detecting them.Enabling this support and removing the 2
#if
statements should result in a 10%-20% perf gain invoke cases where these paths are hit.The text was updated successfully, but these errors were encountered: