Skip to content

Use reflection metadata to represent methods/fields in native layout #113413

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

Merged
merged 8 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -717,18 +717,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CompilerServices.OpenMethodResolver</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CompilerServices.RuntimeFieldHandleInfo</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CompilerServices.RuntimeMethodHandleInfo</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CompilerServices.RuntimeSignature</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.TypeManagerHandle</Target>
Expand All @@ -753,6 +741,14 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.MDArray</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.FieldHandleInfo</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.MethodHandleInfo</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Reflection.BinderBundle</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ public abstract class TypeLoaderCallbacks
public abstract bool TryGetConstructedGenericTypeForComponents(RuntimeTypeHandle genericTypeDefinitionHandle, RuntimeTypeHandle[] genericTypeArgumentHandles, out RuntimeTypeHandle runtimeTypeHandle);
public abstract IntPtr GetThreadStaticGCDescForDynamicType(TypeManagerHandle handle, int index);
public abstract IntPtr GenericLookupFromContextAndSignature(IntPtr context, IntPtr signature, out IntPtr auxResult);
public abstract bool GetRuntimeMethodHandleComponents(RuntimeMethodHandle runtimeMethodHandle, out RuntimeTypeHandle declaringTypeHandle, out MethodNameAndSignature nameAndSignature, out RuntimeTypeHandle[] genericMethodArgs);
public abstract RuntimeMethodHandle GetRuntimeMethodHandleForComponents(RuntimeTypeHandle declaringTypeHandle, string methodName, RuntimeSignature methodSignature, RuntimeTypeHandle[] genericMethodArgs);
public abstract bool CompareMethodSignatures(RuntimeSignature signature1, RuntimeSignature signature2);
public abstract RuntimeMethodHandle GetRuntimeMethodHandleForComponents(RuntimeTypeHandle declaringTypeHandle, MethodHandle handle, RuntimeTypeHandle[] genericMethodArgs);
public abstract IntPtr TryGetDefaultConstructorForType(RuntimeTypeHandle runtimeTypeHandle);
public abstract IntPtr ResolveGenericVirtualMethodTarget(RuntimeTypeHandle targetTypeHandle, RuntimeMethodHandle declMethod);
public abstract bool GetRuntimeFieldHandleComponents(RuntimeFieldHandle runtimeFieldHandle, out RuntimeTypeHandle declaringTypeHandle, out string fieldName);
public abstract RuntimeFieldHandle GetRuntimeFieldHandleForComponents(RuntimeTypeHandle declaringTypeHandle, string fieldName);
public abstract RuntimeFieldHandle GetRuntimeFieldHandleForComponents(RuntimeTypeHandle declaringTypeHandle, FieldHandle handle);
public abstract bool TryGetPointerTypeForTargetType(RuntimeTypeHandle pointeeTypeHandle, out RuntimeTypeHandle pointerTypeHandle);
public abstract bool TryGetArrayTypeForElementType(RuntimeTypeHandle elementTypeHandle, bool isMdArray, int rank, out RuntimeTypeHandle arrayTypeHandle);
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;

using Internal.Metadata.NativeFormat;

namespace Internal.Runtime.CompilerServices
{
[CLSCompliant(false)]
public class MethodNameAndSignature
{
public MetadataReader Reader { get; }
public MethodHandle Handle { get; }

public MethodNameAndSignature(MetadataReader reader, MethodHandle handle)
{
Reader = reader;
Handle = handle;
}

public string GetName()
{
Method method = Reader.GetMethod(Handle);
return Reader.GetString(method.Name);
}

public override bool Equals(object? compare)
{
if (compare == null)
return false;

MethodNameAndSignature? other = compare as MethodNameAndSignature;
if (other == null)
return false;

// Comparing handles is enough if there's only one metadata blob
// (Same assumption in GetHashCode below!)
Debug.Assert(Reader == other.Reader);

Method thisMethod = Reader.GetMethod(Handle);
Method otherMethod = other.Reader.GetMethod(other.Handle);

return thisMethod.Signature.Equals(otherMethod.Signature)
&& thisMethod.Name.Equals(otherMethod.Name);
}

public override int GetHashCode()
{
Method method = Reader.GetMethod(Handle);

// Assumes we only have one metadata blob
return method.Signature.GetHashCode() ^ method.Name.GetHashCode();
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@
<Compile Include="Internal\Runtime\CompilerHelpers\MathHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerServices\FunctionPointerOps.cs" />
<Compile Include="Internal\Runtime\CompilerServices\GenericMethodDescriptor.cs" />
<Compile Include="Internal\Runtime\CompilerServices\RuntimeFieldHandleInfo.cs" />
<Compile Include="Internal\Runtime\CompilerServices\RuntimeMethodHandleInfo.cs" />
<Compile Include="Internal\Runtime\CompilerServices\RuntimeSignature.cs" />
<Compile Include="Internal\Runtime\CompilerServices\MethodNameAndSignature.cs" />
<Compile Include="Internal\Runtime\CompilerServices\OpenMethodResolver.cs" />
<Compile Include="Internal\Runtime\TypeLoaderExceptionHelper.cs" />
<Compile Include="Internal\DeveloperExperience\DeveloperExperience.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public sealed override RuntimeFieldHandle FieldHandle
{
return RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleForComponents(
DeclaringType.TypeHandle,
Name);
_fieldHandle);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,9 @@ public RuntimeMethodHandle GetRuntimeMethodHandle(Type[] genericArgs)
genericArgHandles = null;
}

TypeManagerHandle typeManager = RuntimeAugments.TypeLoaderCallbacks.GetModuleForMetadataReader(Reader);

return RuntimeAugments.TypeLoaderCallbacks.GetRuntimeMethodHandleForComponents(
DeclaringType.TypeHandle,
Name,
RuntimeSignature.CreateFromMethodHandle(typeManager, MethodHandle.AsInt()),
_methodHandle,
genericArgHandles);
}

Expand Down
Loading
Loading