-
Notifications
You must be signed in to change notification settings - Fork 5k
Only root infrastructure and dependencies for IDynamicInterfaceCastable when IDIC is implemented #116660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Remove weak symbol handling
…DIC is used at all.
else if (NodeFactory.DevirtualizationManager.CanHaveDynamicInterfaceImplementations()) | ||
{ | ||
return NodeFactory.MaximallyConstructableType(type); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we get a "metadata" type representation, we could limit this to "metadata" types.
Additionally, depending on the failure mode for "always will fail" types, we could go even further:
If a given interface type has no [DynamicInterfaceCastableImplementation]
implementations, then we could return a NecessaryTypeSymbolIfPossible
because there's no way the user's implementation can successfully return an implementation type. This will take further investigation though, so I didn't want to do it in this PR.
...lr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/IDynamicInterfaceCastableSupport.cs
Outdated
Show resolved
Hide resolved
...aries/System.Private.CoreLib/src/System/Runtime/InteropServices/IDynamicInterfaceCastable.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs
Outdated
Show resolved
Hide resolved
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs
Outdated
Show resolved
Hide resolved
I've adjusted the With the current changes, we have 1.7kB from |
I've added a commit to explicitly substitute away the entry-point to the logic that I couldn't get trimmed away so we can get most of the size savings now. |
{ | ||
Dictionary<MethodDesc, BodySubstitution> bodySubstitutions = []; | ||
|
||
TypeDesc iDynamicInterfaceCastableType = _factory.TypeSystemContext.SystemModule.GetType("System.Runtime.InteropServices", "IDynamicInterfaceCastable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetType has throwIfNotFound arg. You can use it to enable this path only when the type is present in CoreLib, and avoid omit IDynamicInterfaceCastable from Test.CoreLib. I assume that the type exists in Test.Corelib just to make this check happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDynamicInterfaceCastable
exists in Test.CoreLib because TypeCast and CachedInterfaceDispatch call into the interface directly now instead of going through a "support" static class.
…es based on scanning results
Implement a mechanism to conditionally root
[RuntimeExport]
methods based on the type corresponding to their feature being used. Use this mechanism to only rootIDynamicInterfaceCastable
logic when someone implementsIDynamicInterfaceCastable
and provide "default" implementations that should never be called in the bootstrapper when IDIC is unused.Additionally, enhance the
ScannedDevirtualizationManager
to make two observations that we can optimize around:IDynamicInterfaceCastable
has any implementors[DynamicInterfaceCastableImplementation]
type is rooted butIDynamicInterfaceCastable
is not, the interfaces implemented by the attributed type still can have a known set of implementors.Finally, adjust the "what type handle to use for casting" logic to only root a
MaximallyConstructableType
symbol when the target type is notIDynamicInterfaceCastable
and whenIDynamicInterfaceCastable
is implemented in the compilation (based onDevirtualizationManager
).