Skip to content

Commit 2ac0743

Browse files
Move ReflectionCoreCallbacks into ReflectionAugments (#109912)
Leftover work identified in #109857.
1 parent c0b52f6 commit 2ac0743

21 files changed

+441
-563
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,6 @@
653653
<DiagnosticId>CP0001</DiagnosticId>
654654
<Target>T:Internal.Metadata.NativeFormat.UInt64Collection</Target>
655655
</Suppression>
656-
<Suppression>
657-
<DiagnosticId>CP0001</DiagnosticId>
658-
<Target>T:Internal.Reflection.Augments.ReflectionAugments</Target>
659-
</Suppression>
660-
<Suppression>
661-
<DiagnosticId>CP0001</DiagnosticId>
662-
<Target>T:Internal.Reflection.Augments.ReflectionCoreCallbacks</Target>
663-
</Suppression>
664656
<Suppression>
665657
<DiagnosticId>CP0001</DiagnosticId>
666658
<Target>T:Internal.Reflection.Core.AssemblyBinder</Target>

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs

Lines changed: 411 additions & 56 deletions
Large diffs are not rendered by default.

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ReflectionCoreExecution.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public static void InitializeExecutionDomain(ExecutionEnvironment executionEnvir
2424
{
2525
Debug.Assert(s_executionEnvironment == null);
2626
s_executionEnvironment = executionEnvironment;
27-
28-
ReflectionCoreCallbacks reflectionCallbacks = new ReflectionCoreCallbacksImplementation();
29-
ReflectionAugments.Initialize(reflectionCallbacks);
3027
}
3128

3229
internal static ExecutionEnvironment ExecutionEnvironment

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected sealed override IEnumerable<CustomAttributeData> GetDeclaredCustomAttr
171171

172172
public sealed override MethodInfo GetParent(MethodInfo e)
173173
{
174-
return ReflectionAugments.ReflectionCoreCallbacks.GetImplicitlyOverriddenBaseClassMethod(e);
174+
return ReflectionAugments.GetImplicitlyOverriddenBaseClassMethod(e);
175175
}
176176

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

190190
public sealed override PropertyInfo GetParent(PropertyInfo e)
191191
{
192-
return ReflectionAugments.ReflectionCoreCallbacks.GetImplicitlyOverriddenBaseClassProperty(e);
192+
return ReflectionAugments.GetImplicitlyOverriddenBaseClassProperty(e);
193193
}
194194

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

209209
public sealed override EventInfo GetParent(EventInfo e)
210210
{
211-
return ReflectionAugments.ReflectionCoreCallbacks.GetImplicitlyOverriddenBaseClassEvent(e);
211+
return ReflectionAugments.GetImplicitlyOverriddenBaseClassEvent(e);
212212
}
213213

214214
public static readonly EventCustomAttributeSearcher Default = new EventCustomAttributeSearcher();

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ internal static unsafe void FixupModuleCell(ModuleFixupCell* pCell)
299299
dllImportSearchPath = pCell->DllImportSearchPathAndCookie & ~InteropDataConstants.HasDllImportSearchPath;
300300
}
301301

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

304304
// First check if there's a NativeLibrary callback and call it to attempt the resolution
305305
IntPtr hModule = NativeLibrary.LoadLibraryCallbackStub(moduleName, callingAssembly, hasDllImportSearchPath, dllImportSearchPath);

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static Type ExtensibleGetType(string typeName, string callingAssemblyName
3030
// This supports Assembly.GetExecutingAssembly() intrinsic expansion in the compiler
3131
public static Assembly GetExecutingAssembly(RuntimeTypeHandle typeHandle)
3232
{
33-
return ReflectionAugments.ReflectionCoreCallbacks.GetAssemblyForHandle(typeHandle);
33+
return ReflectionAugments.GetAssemblyForHandle(typeHandle);
3434
}
3535

3636
// This supports MethodBase.GetCurrentMethod() intrinsic expansion in the compiler

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@
425425
<Compile Include="System\Reflection\Runtime\General\Assignability.cs" />
426426
<Compile Include="System\Reflection\Runtime\General\Dispensers.NativeFormat.cs" />
427427
<Compile Include="System\Reflection\Runtime\General\Helpers.NativeFormat.cs" />
428-
<Compile Include="System\Reflection\Runtime\General\ReflectionCoreCallbacksImplementation.cs" />
429428
<Compile Include="System\Reflection\Runtime\General\Dispensers.cs" />
430429
<Compile Include="System\Reflection\Runtime\General\Helpers.cs" />
431430
<Compile Include="System\Reflection\Runtime\General\IRuntimeMemberInfoWithNoMetadataDefinition.cs" />

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Activator.NativeAot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ private struct StructWithNoConstructor { public StructWithNoConstructor() { } }
109109
[DebuggerHidden]
110110
[DebuggerStepThrough]
111111
public static object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, bool nonPublic)
112-
=> ReflectionAugments.ReflectionCoreCallbacks.ActivatorCreateInstance(type, nonPublic);
112+
=> ReflectionAugments.ActivatorCreateInstance(type, nonPublic);
113113

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

119119
[RequiresUnreferencedCode("Type and its constructor could be removed")]
120120
public static ObjectHandle CreateInstance(string assemblyName, string typeName)

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Delegate.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private IntPtr GetActualTargetFunctionPointer(object thisObject)
244244
}
245245
else
246246
{
247-
DynamicInvokeInfo dynamicInvokeInfo = ReflectionAugments.ReflectionCoreCallbacks.GetDelegateDynamicInvokeInfo(GetType());
247+
DynamicInvokeInfo dynamicInvokeInfo = ReflectionAugments.GetDelegateDynamicInvokeInfo(GetType());
248248

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

273-
return ReflectionAugments.ReflectionCoreCallbacks.GetDelegateMethod(this);
273+
return ReflectionAugments.GetDelegateMethod(this);
274274
}
275275

276276
internal DiagnosticMethodInfo GetDiagnosticMethodInfo()
@@ -294,7 +294,7 @@ internal DiagnosticMethodInfo GetDiagnosticMethodInfo()
294294
IntPtr ldftnResult = GetDelegateLdFtnResult(out RuntimeTypeHandle _, out bool isOpenResolver);
295295
if (isOpenResolver)
296296
{
297-
MethodInfo mi = ReflectionAugments.ReflectionCoreCallbacks.GetDelegateMethod(this);
297+
MethodInfo mi = ReflectionAugments.GetDelegateMethod(this);
298298
Type? declaringType = mi.DeclaringType;
299299
if (declaringType.IsConstructedGenericType)
300300
declaringType = declaringType.GetGenericTypeDefinition();
@@ -354,17 +354,17 @@ public object? Target
354354
}
355355

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

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

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

366366
// V1 api: Creates open delegates to static methods only, relaxed signature checking disallowed.
367-
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);
367+
public static Delegate CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.AllMethods)] Type target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);
368368

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

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackFrame.NativeAot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private bool TryInitializeMethodBase()
6969

7070
IntPtr methodStartAddress = _ipAddress - _nativeOffset;
7171
Debug.Assert(RuntimeImports.RhFindMethodStartAddress(_ipAddress) == methodStartAddress);
72-
_method = ReflectionAugments.ReflectionCoreCallbacks.GetMethodBaseFromStartAddressIfAvailable(methodStartAddress);
72+
_method = ReflectionAugments.GetMethodBaseFromStartAddressIfAvailable(methodStartAddress);
7373
if (_method == null)
7474
{
7575
_noMethodBaseAvailable = true;

0 commit comments

Comments
 (0)