Make casting helpers look more like in CoreCLR (#86029)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Thu, 11 May 2023 19:07:15 +0000 (04:07 +0900)
committerGitHub <noreply@github.com>
Thu, 11 May 2023 19:07:15 +0000 (12:07 -0700)
commitd4175a847a11c724e25407cc17929d35836e455e
treea454b2554b11c2074eb5b7125359a44b5aa35532
parentc6e435b135dab4254baee6e3d3d00672626a8838
Make casting helpers look more like in CoreCLR (#86029)

* Make casting helpers look more like in CoreCLR

Speeds up casting to interfaces by about 50%. Speeds up casting to classes by about 20%.

There are small differences compared to CoreCLR:
* NativeAOT runtime considers interfaces implementable by arrays to be variant. We don't need to special case casting arrays to non-variant (in IL sense) interfaces because those naturally take the variant paths.
* The base type field on arrays holds the array element type so we need to check for the array case before starting to chase the base hierarchy.

Otherwise the top level helpers now look mostly the same as the CoreCLR ones.

* Make it tailcallable

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
src/coreclr/nativeaot/Common/src/Internal/Runtime/MethodTable.cs
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/MethodTable.Runtime.cs
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/MethodInvoker.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs
src/coreclr/tools/Common/Internal/Runtime/MethodTable.Constants.cs
src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs
src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs