Skip to content

Commit

Permalink
Move ReflectionCoreCallbacks into ReflectionAugments (#109912)
Browse files Browse the repository at this point in the history
Leftover work identified in #109857.
  • Loading branch information
MichalStrehovsky authored Nov 19, 2024
1 parent c0b52f6 commit 2ac0743
Show file tree
Hide file tree
Showing 21 changed files with 441 additions and 563 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.UInt64Collection</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Reflection.Augments.ReflectionAugments</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Reflection.Augments.ReflectionCoreCallbacks</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Reflection.Core.AssemblyBinder</Target>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public static void InitializeExecutionDomain(ExecutionEnvironment executionEnvir
{
Debug.Assert(s_executionEnvironment == null);
s_executionEnvironment = executionEnvironment;

ReflectionCoreCallbacks reflectionCallbacks = new ReflectionCoreCallbacksImplementation();
ReflectionAugments.Initialize(reflectionCallbacks);
}

internal static ExecutionEnvironment ExecutionEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected sealed override IEnumerable<CustomAttributeData> GetDeclaredCustomAttr

public sealed override MethodInfo GetParent(MethodInfo e)
{
return ReflectionAugments.ReflectionCoreCallbacks.GetImplicitlyOverriddenBaseClassMethod(e);
return ReflectionAugments.GetImplicitlyOverriddenBaseClassMethod(e);
}

public static readonly MethodCustomAttributeSearcher Default = new MethodCustomAttributeSearcher();
Expand All @@ -189,7 +189,7 @@ protected sealed override IEnumerable<CustomAttributeData> GetDeclaredCustomAttr

public sealed override PropertyInfo GetParent(PropertyInfo e)
{
return ReflectionAugments.ReflectionCoreCallbacks.GetImplicitlyOverriddenBaseClassProperty(e);
return ReflectionAugments.GetImplicitlyOverriddenBaseClassProperty(e);
}

public static readonly PropertyCustomAttributeSearcher Default = new PropertyCustomAttributeSearcher();
Expand All @@ -208,7 +208,7 @@ protected sealed override IEnumerable<CustomAttributeData> GetDeclaredCustomAttr

public sealed override EventInfo GetParent(EventInfo e)
{
return ReflectionAugments.ReflectionCoreCallbacks.GetImplicitlyOverriddenBaseClassEvent(e);
return ReflectionAugments.GetImplicitlyOverriddenBaseClassEvent(e);
}

public static readonly EventCustomAttributeSearcher Default = new EventCustomAttributeSearcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ internal static unsafe void FixupModuleCell(ModuleFixupCell* pCell)
dllImportSearchPath = pCell->DllImportSearchPathAndCookie & ~InteropDataConstants.HasDllImportSearchPath;
}

Assembly callingAssembly = ReflectionAugments.ReflectionCoreCallbacks.GetAssemblyForHandle(new RuntimeTypeHandle(pCell->CallingAssemblyType));
Assembly callingAssembly = ReflectionAugments.GetAssemblyForHandle(new RuntimeTypeHandle(pCell->CallingAssemblyType));

// First check if there's a NativeLibrary callback and call it to attempt the resolution
IntPtr hModule = NativeLibrary.LoadLibraryCallbackStub(moduleName, callingAssembly, hasDllImportSearchPath, dllImportSearchPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static Type ExtensibleGetType(string typeName, string callingAssemblyName
// This supports Assembly.GetExecutingAssembly() intrinsic expansion in the compiler
public static Assembly GetExecutingAssembly(RuntimeTypeHandle typeHandle)
{
return ReflectionAugments.ReflectionCoreCallbacks.GetAssemblyForHandle(typeHandle);
return ReflectionAugments.GetAssemblyForHandle(typeHandle);
}

// This supports MethodBase.GetCurrentMethod() intrinsic expansion in the compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@
<Compile Include="System\Reflection\Runtime\General\Assignability.cs" />
<Compile Include="System\Reflection\Runtime\General\Dispensers.NativeFormat.cs" />
<Compile Include="System\Reflection\Runtime\General\Helpers.NativeFormat.cs" />
<Compile Include="System\Reflection\Runtime\General\ReflectionCoreCallbacksImplementation.cs" />
<Compile Include="System\Reflection\Runtime\General\Dispensers.cs" />
<Compile Include="System\Reflection\Runtime\General\Helpers.cs" />
<Compile Include="System\Reflection\Runtime\General\IRuntimeMemberInfoWithNoMetadataDefinition.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ private struct StructWithNoConstructor { public StructWithNoConstructor() { } }
[DebuggerHidden]
[DebuggerStepThrough]
public static object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, bool nonPublic)
=> ReflectionAugments.ReflectionCoreCallbacks.ActivatorCreateInstance(type, nonPublic);
=> ReflectionAugments.ActivatorCreateInstance(type, nonPublic);

[DebuggerHidden]
[DebuggerStepThrough]
public static object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
=> ReflectionAugments.ReflectionCoreCallbacks.ActivatorCreateInstance(type, bindingAttr, binder, args, culture, activationAttributes);
=> ReflectionAugments.ActivatorCreateInstance(type, bindingAttr, binder, args, culture, activationAttributes);

[RequiresUnreferencedCode("Type and its constructor could be removed")]
public static ObjectHandle CreateInstance(string assemblyName, string typeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private IntPtr GetActualTargetFunctionPointer(object thisObject)
}
else
{
DynamicInvokeInfo dynamicInvokeInfo = ReflectionAugments.ReflectionCoreCallbacks.GetDelegateDynamicInvokeInfo(GetType());
DynamicInvokeInfo dynamicInvokeInfo = ReflectionAugments.GetDelegateDynamicInvokeInfo(GetType());

object? result = dynamicInvokeInfo.Invoke(_firstParameter, _functionPointer,
args, binderBundle: null, wrapInTargetInvocationException: true);
Expand All @@ -270,7 +270,7 @@ protected virtual MethodInfo GetMethodImpl()
return GetType().GetMethod("Invoke");
}

return ReflectionAugments.ReflectionCoreCallbacks.GetDelegateMethod(this);
return ReflectionAugments.GetDelegateMethod(this);
}

internal DiagnosticMethodInfo GetDiagnosticMethodInfo()
Expand All @@ -294,7 +294,7 @@ internal DiagnosticMethodInfo GetDiagnosticMethodInfo()
IntPtr ldftnResult = GetDelegateLdFtnResult(out RuntimeTypeHandle _, out bool isOpenResolver);
if (isOpenResolver)
{
MethodInfo mi = ReflectionAugments.ReflectionCoreCallbacks.GetDelegateMethod(this);
MethodInfo mi = ReflectionAugments.GetDelegateMethod(this);
Type? declaringType = mi.DeclaringType;
if (declaringType.IsConstructedGenericType)
declaringType = declaringType.GetGenericTypeDefinition();
Expand Down Expand Up @@ -354,17 +354,17 @@ public object? Target
}

// V2 api: Creates open or closed delegates to static or instance methods - relaxed signature checking allowed.
public static Delegate CreateDelegate(Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, firstArgument, method, throwOnBindFailure);
public static Delegate CreateDelegate(Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure) => ReflectionAugments.CreateDelegate(type, firstArgument, method, throwOnBindFailure);

// V1 api: Creates open delegates to static or instance methods - relaxed signature checking allowed.
public static Delegate CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, method, throwOnBindFailure);
public static Delegate CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure) => ReflectionAugments.CreateDelegate(type, method, throwOnBindFailure);

// V1 api: Creates closed delegates to instance methods only, relaxed signature checking disallowed.
[RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);
public static Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);

// V1 api: Creates open delegates to static methods only, relaxed signature checking disallowed.
public static Delegate CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.AllMethods)] Type target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);
public static Delegate CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.AllMethods)] Type target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);

internal IntPtr TryGetOpenStaticFunctionPointer() => (GetThunk(OpenStaticThunk) == _functionPointer) ? _extraFunctionPointerOrData : 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private bool TryInitializeMethodBase()

IntPtr methodStartAddress = _ipAddress - _nativeOffset;
Debug.Assert(RuntimeImports.RhFindMethodStartAddress(_ipAddress) == methodStartAddress);
_method = ReflectionAugments.ReflectionCoreCallbacks.GetMethodBaseFromStartAddressIfAvailable(methodStartAddress);
_method = ReflectionAugments.GetMethodBaseFromStartAddressIfAvailable(methodStartAddress);
if (_method == null)
{
_noMethodBaseAvailable = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal static EnumInfo<TStorage> GetEnumInfo<TStorage>(RuntimeType enumType, b
typeof(TStorage) == typeof(uint) ||
typeof(TStorage) == typeof(ulong));

return (EnumInfo<TStorage>)ReflectionAugments.ReflectionCoreCallbacks.GetEnumInfo(enumType,
return (EnumInfo<TStorage>)ReflectionAugments.GetEnumInfo(enumType,
static (underlyingType, names, valuesAsObject, isFlags) =>
{
// Only after we've sorted, create the underlying array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static Assembly GetCallingAssembly()
throw new PlatformNotSupportedException();
}

public static Assembly Load(AssemblyName assemblyRef) => ReflectionAugments.ReflectionCoreCallbacks.Load(assemblyRef, throwOnFileNotFound: true);
public static Assembly Load(AssemblyName assemblyRef) => ReflectionAugments.Load(assemblyRef, throwOnFileNotFound: true);

public static Assembly Load(string assemblyString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Reflection
{
public abstract partial class FieldInfo : MemberInfo
{
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle) => ReflectionAugments.ReflectionCoreCallbacks.GetFieldFromHandle(handle);
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType) => ReflectionAugments.ReflectionCoreCallbacks.GetFieldFromHandle(handle, declaringType);
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle) => ReflectionAugments.GetFieldFromHandle(handle);
public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType) => ReflectionAugments.GetFieldFromHandle(handle, declaringType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace System.Reflection
{
public abstract partial class MethodBase : MemberInfo
{
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) => ReflectionAugments.ReflectionCoreCallbacks.GetMethodFromHandle(handle);
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType) => ReflectionAugments.ReflectionCoreCallbacks.GetMethodFromHandle(handle, declaringType);
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) => ReflectionAugments.GetMethodFromHandle(handle);
public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType) => ReflectionAugments.GetMethodFromHandle(handle, declaringType);

[RequiresUnreferencedCode("Metadata for the method might be incomplete or removed")]
[System.Runtime.CompilerServices.Intrinsic]
Expand Down
Loading

0 comments on commit 2ac0743

Please sign in to comment.