Skip to content

Commit 74076ee

Browse files
Only root infrastructure and dependencies for IDynamicInterfaceCastable when IDIC is implemented (#116660)
Co-authored-by: Austin Wise <[email protected]>
1 parent a3929e2 commit 74076ee

File tree

19 files changed

+179
-77
lines changed

19 files changed

+179
-77
lines changed

src/coreclr/nativeaot/Bootstrap/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ MANAGED_RUNTIME_EXPORT(AppendExceptionStackFrame)
125125
MANAGED_RUNTIME_EXPORT(GetSystemArrayEEType)
126126
MANAGED_RUNTIME_EXPORT(OnFirstChanceException)
127127
MANAGED_RUNTIME_EXPORT(OnUnhandledException)
128-
MANAGED_RUNTIME_EXPORT(IDynamicCastableIsInterfaceImplemented)
129-
MANAGED_RUNTIME_EXPORT(IDynamicCastableGetInterfaceImplementation)
130128
#ifdef FEATURE_OBJCMARSHAL
131129
MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalTryGetTaggedMemory)
132130
MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalGetIsTrackedReferenceCallback)
@@ -145,8 +143,6 @@ static const pfn c_classlibFunctions[] = {
145143
&MANAGED_RUNTIME_EXPORT_NAME(GetSystemArrayEEType),
146144
&MANAGED_RUNTIME_EXPORT_NAME(OnFirstChanceException),
147145
&MANAGED_RUNTIME_EXPORT_NAME(OnUnhandledException),
148-
&MANAGED_RUNTIME_EXPORT_NAME(IDynamicCastableIsInterfaceImplemented),
149-
&MANAGED_RUNTIME_EXPORT_NAME(IDynamicCastableGetInterfaceImplementation),
150146
#ifdef FEATURE_OBJCMARSHAL
151147
&MANAGED_RUNTIME_EXPORT_NAME(ObjectiveCMarshalTryGetTaggedMemory),
152148
&MANAGED_RUNTIME_EXPORT_NAME(ObjectiveCMarshalGetIsTrackedReferenceCallback),

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime;
66
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
78

89
using Internal.Runtime;
910

@@ -138,9 +139,7 @@ private static unsafe IntPtr RhResolveDispatchWorker(object pObject, void* cell,
138139
{
139140
// Dispatch not resolved through normal dispatch map, try using the IDynamicInterfaceCastable
140141
// This will either give us the appropriate result, or throw.
141-
var pfnGetInterfaceImplementation = (delegate*<object, MethodTable*, ushort, IntPtr>)
142-
pInstanceType->GetClasslibFunction(ClassLibFunctionId.IDynamicCastableGetInterfaceImplementation);
143-
pTargetCode = pfnGetInterfaceImplementation(pObject, cellInfo.InterfaceType, cellInfo.InterfaceSlot);
142+
pTargetCode = IDynamicInterfaceCastable.GetDynamicInterfaceImplementation((IDynamicInterfaceCastable)pObject, cellInfo.InterfaceType, cellInfo.InterfaceSlot);
144143
Diagnostics.Debug.Assert(pTargetCode != IntPtr.Zero);
145144
}
146145
return pTargetCode;

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ internal enum ClassLibFunctionId
4444
GetSystemArrayEEType = 5,
4545
OnFirstChance = 6,
4646
OnUnhandledException = 7,
47-
IDynamicCastableIsInterfaceImplemented = 8,
48-
IDynamicCastableGetInterfaceImplementation = 9,
49-
ObjectiveCMarshalTryGetTaggedMemory = 10,
50-
ObjectiveCMarshalGetIsTrackedReferenceCallback = 11,
51-
ObjectiveCMarshalGetOnEnteredFinalizerQueueCallback = 12,
52-
ObjectiveCMarshalGetUnhandledExceptionPropagationHandler = 13,
47+
ObjectiveCMarshalTryGetTaggedMemory = 8,
48+
ObjectiveCMarshalGetIsTrackedReferenceCallback = 9,
49+
ObjectiveCMarshalGetOnEnteredFinalizerQueueCallback = 10,
50+
ObjectiveCMarshalGetUnhandledExceptionPropagationHandler = 11,
5351
}
5452

5553
internal static class InternalCalls

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,7 @@ private static unsafe object CheckCastClassSpecial(MethodTable* pTargetType, obj
469469

470470
private static unsafe bool IsInstanceOfInterfaceViaIDynamicInterfaceCastable(MethodTable* pTargetType, object obj, bool throwing)
471471
{
472-
var pfnIsInterfaceImplemented = (delegate*<object, MethodTable*, bool, bool>)
473-
pTargetType->GetClasslibFunction(ClassLibFunctionId.IDynamicCastableIsInterfaceImplemented);
474-
return pfnIsInterfaceImplemented(obj, pTargetType, throwing);
472+
return ((IDynamicInterfaceCastable)obj).IsInterfaceImplemented(new RuntimeTypeHandle(pTargetType), throwing);
475473
}
476474

477475
internal static unsafe bool IsDerived(MethodTable* pDerivedType, MethodTable* pBaseType)

src/coreclr/nativeaot/Runtime.Base/src/System/ThrowHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@ private static void ThrowArgumentOutOfRangeException()
5757
// exception doesn't exist in MRT: throw PlatformNotSupportedException() instead
5858
throw new PlatformNotSupportedException();
5959
}
60+
61+
private static void ThrowFeatureBodyRemoved()
62+
{
63+
throw new NotSupportedException();
64+
}
6065
}
6166
}

src/coreclr/nativeaot/Runtime/ICodeManager.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ enum class ClasslibFunctionId
105105
GetSystemArrayEEType = 5,
106106
OnFirstChanceException = 6,
107107
OnUnhandledException = 7,
108-
IDynamicCastableIsInterfaceImplemented = 8,
109-
IDynamicCastableGetInterfaceImplementation = 9,
110-
ObjectiveCMarshalTryGetTaggedMemory = 10,
111-
ObjectiveCMarshalGetIsTrackedReferenceCallback = 11,
112-
ObjectiveCMarshalGetOnEnteredFinalizerQueueCallback = 12,
113-
ObjectiveCMarshalGetUnhandledExceptionPropagationHandler = 13,
108+
ObjectiveCMarshalTryGetTaggedMemory = 8,
109+
ObjectiveCMarshalGetIsTrackedReferenceCallback = 9,
110+
ObjectiveCMarshalGetOnEnteredFinalizerQueueCallback = 10,
111+
ObjectiveCMarshalGetUnhandledExceptionPropagationHandler = 11,
114112
};
115113

116114
enum class AssociatedDataFlags : unsigned char

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
<Compile Include="Internal\IntrinsicSupport\ComparerHelpers.cs" />
114114
<Compile Include="Internal\IntrinsicSupport\EqualityComparerHelpers.cs" />
115115
<Compile Include="Internal\Reflection\Augments\ReflectionAugments.cs" />
116-
<Compile Include="Internal\Runtime\IDynamicInterfaceCastableSupport.cs" />
117116
<Compile Include="Internal\Runtime\MethodTable.Runtime.cs" />
118117
<Compile Include="Internal\Runtime\CompilerHelpers\ThrowHelpers.cs" />
119118
<Compile Include="Internal\Runtime\CompilerServices\FunctionPointerOps.cs" />
@@ -200,6 +199,7 @@
200199
<Compile Include="System\Runtime\InteropServices\ComEventsHelper.NativeAot.cs" Condition="'$(FeatureCominterop)' == 'true'" />
201200
<Compile Include="System\Runtime\InteropServices\ComWrappers.NativeAot.cs" Condition="'$(FeatureComWrappers)' == 'true'" />
202201
<Compile Include="System\Runtime\InteropServices\GCHandle.NativeAot.cs" />
202+
<Compile Include="System\Runtime\InteropServices\IDynamicInterfaceCastable.cs" />
203203
<Compile Include="System\Runtime\InteropServices\NativeFunctionPointerWrapper.cs" />
204204
<Compile Include="System\Runtime\InteropServices\NativeLibrary.NativeAot.cs" />
205205
<Compile Include="System\Runtime\InteropServices\PInvokeMarshal.cs" />
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,22 @@
33

44
using System;
55
using System.Runtime;
6+
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
7-
using System.Threading;
88

9+
using Internal.Runtime;
910
using Internal.Runtime.Augments;
1011
using Internal.TypeSystem;
1112

1213
using Debug = System.Diagnostics.Debug;
1314

14-
namespace Internal.Runtime
15+
namespace System.Runtime.InteropServices
1516
{
16-
internal static unsafe class IDynamicCastableSupport
17+
public unsafe partial interface IDynamicInterfaceCastable
1718
{
18-
[RuntimeExport("IDynamicCastableIsInterfaceImplemented")]
19-
internal static bool IDynamicCastableIsInterfaceImplemented(IDynamicInterfaceCastable instance, MethodTable* interfaceType, bool throwIfNotImplemented)
20-
{
21-
return instance.IsInterfaceImplemented(new RuntimeTypeHandle(interfaceType), throwIfNotImplemented);
22-
}
23-
2419
private static readonly object s_thunkPoolHeap = RuntimeAugments.CreateThunksHeap(RuntimeImports.GetInteropCommonStubAddress());
2520

26-
[RuntimeExport("IDynamicCastableGetInterfaceImplementation")]
27-
internal static IntPtr IDynamicCastableGetInterfaceImplementation(IDynamicInterfaceCastable instance, MethodTable* interfaceType, ushort slot)
21+
internal static nint GetDynamicInterfaceImplementation(IDynamicInterfaceCastable instance, MethodTable* interfaceType, ushort slot)
2822
{
2923
RuntimeTypeHandle handle = instance.GetInterfaceImplementation(new RuntimeTypeHandle(interfaceType));
3024
MethodTable* implType = handle.ToMethodTable();
@@ -38,10 +32,10 @@ internal static IntPtr IDynamicCastableGetInterfaceImplementation(IDynamicInterf
3832
}
3933

4034
MethodTable* genericContext = null;
41-
IntPtr result = RuntimeImports.RhResolveDynamicInterfaceCastableDispatchOnType(implType, interfaceType, slot, &genericContext);
42-
if (result == IntPtr.Zero)
35+
nint result = RuntimeImports.RhResolveDynamicInterfaceCastableDispatchOnType(implType, interfaceType, slot, &genericContext);
36+
if (result == nint.Zero)
4337
{
44-
IDynamicCastableGetInterfaceImplementationFailure(instance, interfaceType, implType);
38+
GetInterfaceImplementationFailure(instance, interfaceType, implType);
4539
}
4640

4741
if (genericContext != null)
@@ -73,7 +67,7 @@ private static void ThrowInvalidOperationException(MethodTable* resolvedImplType
7367
throw new InvalidOperationException(SR.Format(SR.IDynamicInterfaceCastable_NotInterface, Type.GetTypeFromMethodTable(resolvedImplType)));
7468
}
7569

76-
private static void IDynamicCastableGetInterfaceImplementationFailure(object instance, MethodTable* interfaceType, MethodTable* resolvedImplType)
70+
private static void GetInterfaceImplementationFailure(object instance, MethodTable* interfaceType, MethodTable* resolvedImplType)
7771
{
7872
if (resolvedImplType->DispatchMap == null)
7973
throw new InvalidOperationException(SR.Format(SR.IDynamicInterfaceCastable_MissingImplementationAttribute, Type.GetTypeFromMethodTable(resolvedImplType), nameof(DynamicInterfaceCastableImplementationAttribute)));

src/coreclr/nativeaot/Test.CoreLib/src/Internal/Runtime/IDynamicInterfaceCastableSupport.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Runtime.CompilerServices
5+
{
6+
public static partial class RuntimeFeature
7+
{
8+
/// <summary>
9+
/// Name of the Portable PDB feature.
10+
/// </summary>
11+
public const string PortablePdb = nameof(PortablePdb);
12+
13+
/// <summary>
14+
/// Indicates that this version of runtime supports default interface method implementations.
15+
/// </summary>
16+
public const string DefaultImplementationsOfInterfaces = nameof(DefaultImplementationsOfInterfaces);
17+
18+
/// <summary>
19+
/// Indicates that this version of runtime supports the Unmanaged calling convention value.
20+
/// </summary>
21+
public const string UnmanagedSignatureCallingConvention = nameof(UnmanagedSignatureCallingConvention);
22+
23+
/// <summary>
24+
/// Indicates that this version of runtime supports covariant returns in overrides of methods declared in classes.
25+
/// </summary>
26+
public const string CovariantReturnsOfClasses = nameof(CovariantReturnsOfClasses);
27+
28+
/// <summary>
29+
/// Represents a runtime feature where types can define ref fields.
30+
/// </summary>
31+
public const string ByRefFields = nameof(ByRefFields);
32+
33+
/// <summary>
34+
/// Represents a runtime feature where byref-like types can be used in Generic parameters.
35+
/// </summary>
36+
public const string ByRefLikeGenerics = nameof(ByRefLikeGenerics);
37+
38+
/// <summary>
39+
/// Indicates that this version of runtime supports virtual static members of interfaces.
40+
/// </summary>
41+
public const string VirtualStaticsInInterfaces = nameof(VirtualStaticsInInterfaces);
42+
43+
/// <summary>
44+
/// Indicates that this version of runtime supports <see cref="System.IntPtr" /> and <see cref="System.UIntPtr" /> as numeric types.
45+
/// </summary>
46+
public const string NumericIntPtr = nameof(NumericIntPtr);
47+
}
48+
}

0 commit comments

Comments
 (0)