Repository navigation
Closed
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Milestone
Description
Description
We're in the process of fixing all trim/AOT warnings in CsWinRT, and as of our latest PR we're now down to 0 warnings when building. However, we still get 4 warnings from ILC at publish time. I figured I'd report them in case they're actual trim bugs. Annotations in code seem correct.
Reproduction Steps
Use this test project: MinimalWinRTComponentTest.zip.
The code for CsWinRT we're working on is here: https://github.com/microsoft/CsWinRT/tree/staging/AOT.
Expected behavior
No ILC warnings.
Actual behavior
ILC : Trim analysis warning IL2068: WinRT.Projections.FindCustomHelperTypeMapping(Type,Boolean): 'WinRT.Projections.FindCustomHelperTypeMapping(Type,Boolean)' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.PublicFields' requirements. The parameter '#ILLink.Shared.TypeSystemProxy.ParameterIndex' of method 'System.Collections.Generic.Dictionary`2<Type,Type>.TryGetValue(Type,Type&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\MinimalWinRTComponentTest\MinimalWinRTComponentTest\MinimalWinRTComponentTest.csproj]
ILC : Trim analysis warning IL2087: WinRT.ObjectReferenceWithContext`1.<GetCurrentContext>g__CreateForCurrentContext|19_0(IntPtr): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'WinRT.GuidGenerator.GetIID(Type)'. The generic parameter 'T' of 'WinRT.ObjectReferenceWithContext`1' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\MinimalWinRTComponentTest\MinimalWinRTComponentTest\MinimalWinRTComponentTest.csproj]
ILC : Trim analysis warning IL2055: WinRT.TypeNameSupport.<FindTypeByNameCore>g__ResolveGenericType|9_0(Type,Type[],String): Call to 'System.Type.MakeGenericType(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type. [D:\source\MinimalWinRTComponentTest\MinimalWinRTComponentTest\MinimalWinRTComponentTest.csproj]
ILC : Trim analysis warning IL2067: WinRT.GuidGenerator.GetSignature(Type): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'WinRT.GuidGenerator.GetSignature(Type)'. The parameter 'defaultInterface' of method 'WinRT.Projections.TryGetDefaultInterfaceTypeForRuntimeClassType(Type,Type&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [D:\source\MinimalWinRTComponentTest\MinimalWinRTComponentTest\MinimalWinRTComponentTest.csproj]
Metadata
Metadata
Assignees
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Apr 17, 2024
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.
Sergio0694 commentedon Apr 17, 2024
Some thoughts:
FindCustomHelperTypeMappingfeels like should definitely warn in the IDE (we need a suppression).CreateForCurrentContextis missing an annotation. Seems like the call being in a local function breaks the analyzer.ResolveGenericTypeis also missing a suppression, the analyzer seems to miss that.GetSignaturecalls are also missing the IL2067 warnings, we're only seeing IL2062 in the IDE.agocke commentedon Apr 17, 2024
FYI @jtschuster
Sergio0694 commentedon Apr 24, 2024
Found two more trim analyzer bugs in CsWinRT:
Here.
Here.
I'm a bit puzzled as to how the analyzer missed these ones 🤔
Sergio0694 commentedon Apr 29, 2024
Found a bit more in microsoft/CsWinRT#1592:
Here. Seems to only warn at publish time, but not in the IDE.
Same for these two.
sbomer commentedon Apr 30, 2024
I was able to see the described behavior by building CsWinRT locally. Most of these missing warnings have been fixed in .NET 9, and upgrading the project to target net9.0 reports these from the analyzer as well. The following are still missing in .NET 9:
This is a known issue - https://github.com/dotnet/linker/issues/2632 - and has existing linker tests.
This is a new issue - I've opened #101733 to track it.
Run MethodOutParameterDataFlow tests in analyzer (#101735)
Run MethodOutParameterDataFlow tests in analyzer (dotnet#101735)
Run MethodOutParameterDataFlow tests in analyzer (dotnet#101735)