-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
TrimmerRootDescriptor is not able to preserve generic instantiations #95058
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionAssuming we have the below lines in root.xml: <linker>
<assembly fullname="MyAssembly">
<type fullname="Foo`1[[System.Int32,System.Private.CoreLib]]" preserve="all" />
</assembly>
</linker> It will fail to resolve the type when compiling with NativeAOT because:
This is preventing us to move from /cc: @MichalStrehovsky Reproduction StepsCreate a console project var t = Console.ReadLine();
Console.WriteLine(typeof(Foo<>).MakeGenericType(Type.GetType(t!)!));
class Foo<T>
{
public override string ToString()
{
return typeof(T).ToString();
}
} and TrimmerRootDescriptor: <linker>
<assembly fullname="MyAssembly">
<type fullname="Foo`1[[System.Int32,System.Private.CoreLib]]" preserve="all" />
</assembly>
</linker> Run it and input Expected behaviorPrint Actual behavior
Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
This matches the behavior of IL linker. It's not legal in the descriptors file format to put instantiated generics as type name. The problem is more pronounced for generic methods. We'd need a file format change to do this. Cc @dotnet/illink-contrib |
Ideally you would not use the XML files at all, can you replace it with a |
Yeah that's the ideal case I want to see too. But in the real world you will have to workaround against some 3rd-party even 1st-party libraries using those XML files. |
Using the The experience with any of the XML formats is extremely poor (first one can never be sure whether the file is getting picked up at all, and then there's no way to troubleshoot it if things don't work). We don't optimize for them, they're last resort option and the user is already on pretty much unsupported paths (we cannot help authoring these XML files). |
Does this also work for delegate marshalling metadata and generic methods? I just tried Type.GetType("Foo`1[[System.Int32,System.Private.CoreLib]]")!.GetMethod("Test")!.MakeGenericMethod(typeof(int)) against class Foo<T>
{
public void Test<U>()
{
Console.WriteLine(typeof(U).ToString());
}
} but got
Apparently it's not working without #81204 |
I thought we're only discussing accepting generics in the |
I'm going to close this. I was looking at yet another customer-created RD.XML that had nonsensical things in it, like rooting all of CoreLib (that was then causing problems for the customer). Very few people understand how to use this. We don't want to build experiences around sidecar XML files that people cargo cult around. |
Description
Assuming we have the below lines in root.xml:
It will fail to resolve the type when compiling with NativeAOT because:
SplitFullName
it splits the full name into namespaceFoo`1[[System
and typeInt32,System.Private.CoreLib]]
:runtime/src/coreclr/tools/Common/Compiler/ProcessLinkerXmlBase.cs
Line 795 in 3b61ad9
Foo`1[[System.Int32,System.Private.CoreLib]]
was not in the name cache (there was onlyFoo`1
in the name cache, so any instantiations will fail to resolve):runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs
Line 324 in 3b61ad9
This is preventing us to move from
rd.xml
toTrimmerRootDescriptor
.TrimmerRootDescriptor
should handle generic instantiations as well./cc: @MichalStrehovsky
Reproduction Steps
Create a console project
MyAssembly
with code:and TrimmerRootDescriptor:
Run it and input
System.Int32
.Expected behavior
Print
Foo`1[System.Int32]
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: