-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
ILC fails to detect and trim some dependency cycles (interface -> attribute -> [DAM] -> type impl -> new()) #112029
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
The problem is that types referenced by Line 269 in 55e9ab5
And reflected types are marked as Maximally Constructable here: runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedTypeNode.cs Line 39 in 55e9ab5
We would need some way to represent "here's a System.Type that has reflectible but cannot be constructed". |
We'd normally cut this off much earlier than at the custom attribute analysis spot, but the uninstantiated generic type part makes it harder. Normally when there is a There is an optimization though for the case when the typeof is used in a type equality comparison like here. The compiler can represent types in two forms within the dependency graph: "constructed type" and "unconstructed type" (called just "type"). Constructed type is modeled as something that could be allocated on the GC heap, has a valid vtable, etc. The unconstructed form is mostly used for casting so we can get away with less stuff on it. For example, casting doesn't need reflection metadata so we don't generate it (that includes the custom attributes). The optimization for The problem is that uninstantiated generic types don't have a constructed form. So while the The fix will probably require distinguishing between You can check this yourself - if you make the |
Oh I see, that makes sense. I do remember a similar issue coming up a while back and that you had made some optimizations for this scenario, so I was wondering why this would be different. Thanks you for the explanation! We do have a fair amount of type checks with unconstructed generic types in CsWinRT, so optimizing this would be cool to see, assuming it's doable 😄 |
I'm wondering if this one can be addressed by using RyuJIT as the IL scanner. |
RyuJIT as scanner helps for optimizations that RyuJIT can sometimes do but we don't want to risk predicting them happening when building whole program view (we need guarantees that optimizations performed when building whole program view also happen during codegen - otherwise the whole program view is wrong). The type equality optimization can be done in the existing scanner and we do it. It is actually one of the things that will be more difficult to do in the RyuJIT codebase when RyuJIT is scanner. RyuJIT codebase expects that a type is always backed by a single symbol. For this optimizations, we potentially have two symbols for the same type (the constructed and unconstructed one). RyuJIT as it is right now cannot handle this. We actually need to do work to hide that from RyuJIT (dotnet/runtimelab#1754). |
Description
Found a possible miss by ILC when working on microsoft/CsWinRT#1907. This causes
IReferenceArray<T>
to be kept, which then produces a bunch of IL3050 warnings when I try to publish the Microsoft Store with a preview of CsWinRT from that PR. We can reworkIReferenceArray<T>
to be more AOT friendly, but this feels also feels like something that ILC should be able to handle.cc. @MichalStrehovsky @sbomer
Reproduction Steps
Expected behavior
IFoo<T>
types should be completely trimmed.M
to be optimized to justreturn false
, basically.KeepAttribute
should also be removed.There is no type that can possibly be instantiated, that implements
IFoo<T>
.Actual behavior
Both
IFoo<T>
types and[Keep]
are kept. Not sure ifM
is being optimized (don't see the codegen from here).Additional context
I tried changing the
Create
method to this:Thinking maybe if this just throws on AOT, ILC will see the type never being constructed and will trim. Nope, no changes.
Regression?
No.
Configuration
The text was updated successfully, but these errors were encountered: