Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ 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 bool GetRuntimeMethodHandleComponents(RuntimeMethodHandle runtimeMethodHandle, out RuntimeTypeHandle declaringTypeHandle, out MethodHandle handle, out RuntimeTypeHandle[] genericMethodArgs);
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 bool GetRuntimeFieldHandleComponents(RuntimeFieldHandle runtimeFieldHandle, out RuntimeTypeHandle declaringTypeHandle, out FieldHandle handle);
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
using System.Reflection;
using System.Runtime.InteropServices;

using Internal.Metadata.NativeFormat;
using Internal.Runtime.Augments;

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

public MethodNameAndSignature(string name, RuntimeSignature signature)
public MethodNameAndSignature(MetadataReader reader, MethodHandle handle)
{
Name = name;
Signature = signature;
Reader = reader;
Handle = handle;
}

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

public override bool Equals(object? compare)
Expand All @@ -30,24 +38,17 @@ public override bool Equals(object? compare)
if (other == null)
return false;

if (Name != other.Name)
if (GetName() != other.GetName())
Copy link

Copilot AI Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated calls to GetName() in the equality check may incur unnecessary performance overhead if this method is computationally expensive. Consider caching the result of GetName() in a local variable for comparison.

Copilot uses AI. Check for mistakes.
return false;

return Signature.Equals(other.Signature);
// Comparing handles is enough if there's only one metadata blob
Debug.Assert(Reader == other.Reader);
return Reader.GetMethod(Handle).Signature.Equals(other.Reader.GetMethod(other.Handle).Signature);
}

public override int GetHashCode()
{
int hash = Name.GetHashCode();

return hash;
return Handle.GetHashCode();
}
}

[StructLayout(LayoutKind.Sequential)]
[CLSCompliant(false)]
public unsafe struct RuntimeMethodHandleInfo
{
public IntPtr NativeLayoutInfoSignature;
}
}

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\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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

using Internal.Metadata.NativeFormat;
using Internal.Runtime.Augments;

namespace System
Expand Down Expand Up @@ -37,26 +38,26 @@ public bool Equals(RuntimeFieldHandle handle)
if (_value == IntPtr.Zero || handle._value == IntPtr.Zero)
return false;

string fieldName1, fieldName2;
FieldHandle fieldHandle1, fieldHandle2;
RuntimeTypeHandle declaringType1, declaringType2;

RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleComponents(this, out declaringType1, out fieldName1);
RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleComponents(handle, out declaringType2, out fieldName2);
RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleComponents(this, out declaringType1, out fieldHandle1);
RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleComponents(handle, out declaringType2, out fieldHandle2);

return declaringType1.Equals(declaringType2) && fieldName1 == fieldName2;
return declaringType1.Equals(declaringType2) && fieldHandle1.Equals(fieldHandle2);
}

public override int GetHashCode()
{
if (_value == IntPtr.Zero)
return 0;

string fieldName;
FieldHandle fieldHandle;
RuntimeTypeHandle declaringType;
RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleComponents(this, out declaringType, out fieldName);
RuntimeAugments.TypeLoaderCallbacks.GetRuntimeFieldHandleComponents(this, out declaringType, out fieldHandle);

int hashcode = declaringType.GetHashCode();
return (hashcode + int.RotateLeft(hashcode, 13)) ^ fieldName.GetHashCode();
return (hashcode + int.RotateLeft(hashcode, 13)) ^ fieldHandle.GetHashCode();
}

public static RuntimeFieldHandle FromIntPtr(IntPtr value) => new RuntimeFieldHandle(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

using Internal.Metadata.NativeFormat;
using Internal.Reflection.Augments;
using Internal.Runtime.Augments;
using Internal.Runtime.CompilerServices;
Expand Down Expand Up @@ -40,7 +41,7 @@ public bool Equals(RuntimeMethodHandle handle)
return false;

RuntimeTypeHandle declaringType1, declaringType2;
MethodNameAndSignature nameAndSignature1, nameAndSignature2;
MethodHandle nameAndSignature1, nameAndSignature2;
RuntimeTypeHandle[] genericArgs1, genericArgs2;

RuntimeAugments.TypeLoaderCallbacks.GetRuntimeMethodHandleComponents(this, out declaringType1, out nameAndSignature1, out genericArgs1);
Expand Down Expand Up @@ -72,12 +73,12 @@ public override int GetHashCode()
return 0;

RuntimeTypeHandle declaringType;
MethodNameAndSignature nameAndSignature;
MethodHandle nameAndSignature;
RuntimeTypeHandle[] genericArgs;
RuntimeAugments.TypeLoaderCallbacks.GetRuntimeMethodHandleComponents(this, out declaringType, out nameAndSignature, out genericArgs);

int hashcode = declaringType.GetHashCode();
hashcode = (hashcode + int.RotateLeft(hashcode, 13)) ^ nameAndSignature.Name.GetHashCode();
hashcode = (hashcode + int.RotateLeft(hashcode, 13)) ^ nameAndSignature.GetHashCode();
if (genericArgs != null)
{
for (int i = 0; i < genericArgs.Length; i++)
Expand Down
Loading
Loading