Skip to content
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 @@ -113,6 +113,10 @@ private static IntPtr RhResolveDynamicInterfaceCastableDispatchOnType(MethodTabl
return result;
}

[Intrinsic]
[AnalysisCharacteristic]
private static extern bool DynamicInterfaceCastablePresent();

private static unsafe IntPtr RhResolveDispatchWorker(object pObject, void* cell, ref DispatchCellInfo cellInfo)
{
// Type of object we're dispatching on.
Expand All @@ -125,7 +129,7 @@ private static unsafe IntPtr RhResolveDispatchWorker(object pObject, void* cell,
cellInfo.InterfaceSlot,
flags: default,
ppGenericContext: null);
if (pTargetCode == IntPtr.Zero && pInstanceType->IsIDynamicInterfaceCastable)
if (DynamicInterfaceCastablePresent() && pTargetCode == IntPtr.Zero && pInstanceType->IsIDynamicInterfaceCastable)
{
// Dispatch not resolved through normal dispatch map, try using the IDynamicInterfaceCastable
// This will either give us the appropriate result, or throw.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,5 @@ private static void ThrowArgumentOutOfRangeException()
// exception doesn't exist in MRT: throw PlatformNotSupportedException() instead
throw new PlatformNotSupportedException();
}

private static void ThrowFeatureBodyRemoved()
{
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<Compile Include="System\ValueType.cs" />
<Compile Include="System\Runtime\RuntimeExportAttribute.cs" />
<Compile Include="System\Runtime\RuntimeImportAttribute.cs" />
<Compile Include="System\Runtime\CompilerServices\AnalysisCharacteristicAttribute.cs" />
<Compile Include="System\Runtime\CompilerServices\ClassConstructorRunner.cs" />
<Compile Include="System\Runtime\CompilerServices\RuntimeHelpers.NativeAot.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\Runtime\InteropServices\IDynamicInterfaceCastable.cs">
<Link>Common\System\Runtime\InteropServices\IDynamicInterfaceCastable.cs</Link>
</Compile>
<Compile Include="..\..\System.Private.CoreLib\src\System\Runtime\CompilerServices\AnalysisCharacteristicAttribute.cs" />
<Compile Include="Internal\Runtime\MethodTable.Runtime.cs" />
<Compile Include="System\Runtime\CompilerServices\CastCache.cs" />
<Compile Include="System\Runtime\CompilerServices\ClassConstructorRunner.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
{
DependencyList dependencyList = base.ComputeNonRelocationBasedDependencies(factory);

if (_type.IsIDynamicInterfaceCastable)
{
dependencyList.Add(factory.AnalysisCharacteristic("DynamicInterfaceCastablePresent"), "Implements IDynamicInterfaceCastable");
}

// Ensure that we track the metadata type symbol if we are working with a constructed type symbol.
// The emitter will ensure we don't emit both, but this allows us assert that we only generate
// relocs to nodes we emit.
Expand Down
29 changes: 0 additions & 29 deletions src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ ILScanResults IILScanner.Scan()
_dependencyGraph.AddRoot(GetHelperEntrypoint(ReadyToRunHelper.CheckInstanceInterface), "Not tracked by scanner");
_dependencyGraph.AddRoot(GetHelperEntrypoint(ReadyToRunHelper.CheckInstanceClass), "Not tracked by scanner");
_dependencyGraph.AddRoot(GetHelperEntrypoint(ReadyToRunHelper.IsInstanceOfException), "Not tracked by scanner");
_dependencyGraph.AddRoot(_nodeFactory.MethodEntrypoint(_nodeFactory.TypeSystemContext.GetHelperEntryPoint("ThrowHelpers", "ThrowFeatureBodyRemoved")), "Substitution for methods removed based on scanning");

_dependencyGraph.ComputeMarkedNodes();

Expand Down Expand Up @@ -277,34 +276,6 @@ public ReadOnlyFieldPolicy GetReadOnlyFieldPolicy()
return new ScannedReadOnlyPolicy(MarkedNodes);
}

public BodyAndFieldSubstitutions GetBodyAndFieldSubstitutions()
{
Dictionary<MethodDesc, BodySubstitution> bodySubstitutions = [];

bool hasIDynamicInterfaceCastableType = false;

foreach (var type in ConstructedEETypes)
{
if (type.IsIDynamicInterfaceCastable)
{
hasIDynamicInterfaceCastableType = true;
break;
}
}

if (!hasIDynamicInterfaceCastableType)
{
// We can't easily trim out some of the IDynamicInterfaceCastable infrastructure because
// the callers do type checks based on flags on the MethodTable instead of an actual type cast.
// Trim out the logic that we can't do easily here.
TypeDesc iDynamicInterfaceCastableType = _factory.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.InteropServices", "IDynamicInterfaceCastable");
MethodDesc getDynamicInterfaceImplementationMethod = iDynamicInterfaceCastableType.GetKnownMethod("GetDynamicInterfaceImplementation", null);
bodySubstitutions.Add(getDynamicInterfaceImplementationMethod, BodySubstitution.ThrowingBody);
}

return new BodyAndFieldSubstitutions(bodySubstitutions, []);
}

public TypeMapManager GetTypeMapManager()
{
return new ScannedTypeMapManager(_factory);
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ void RunScanner()

interopStubManager = scanResults.GetInteropStubManager(interopStateManager, pinvokePolicy);

substitutions.AppendFrom(scanResults.GetBodyAndFieldSubstitutions());

substitutionProvider = new SubstitutionProvider(logger, featureSwitches, substitutions);

ilProvider = new SubstitutedILProvider(unsubstitutedILProvider, substitutionProvider, devirtualizationManager, metadataManager, scanResults.GetAnalysisCharacteristics());

// Use a more precise IL provider that uses whole program analysis for dead branch elimination
Expand Down
Loading