-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
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
#if !MONO // Temporary until Mono can unbox a true Nullable<T> runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvokerCommon.cs
Line 139 in 7980421
#if !MONO // Temporary until Mono can unbox a true Nullable<T>
Various tests fail in System.Reflection.Tests such as Invoke(Type methodDeclaringType, string methodName, object obj, object[] parameters, object result) where it is passing yield 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() and UnboxExact() methods on Nullable<T> and appear to be passing int, for example, instead of Nullable<int> for the object parameter. The reflection invoke code creates temporary "true nullable" boxed objects (the default behavior of boxing is to create T or null from a Nullable<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.