Skip to content

Trim/AOT analyzer missing some ILC warnings #101203

Closed

Description

@Sergio0694

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]

Activity

  1. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Apr 17, 2024
  2. added
    area-Tools-ILLink.NET linker development as well as trimming analyzers
    and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Apr 17, 2024
  3. dotnet-policy-service commented on Apr 17, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
    See info in area-owners.md if you want to be subscribed.

  4. Sergio0694 commented on Apr 17, 2024

    @Sergio0694
    ContributorAuthor

    Some thoughts:

    • FindCustomHelperTypeMapping feels like should definitely warn in the IDE (we need a suppression).
    • CreateForCurrentContext is missing an annotation. Seems like the call being in a local function breaks the analyzer.
    • ResolveGenericType is also missing a suppression, the analyzer seems to miss that.
    • GetSignature calls are also missing the IL2067 warnings, we're only seeing IL2062 in the IDE.
  5. agocke commented on Apr 17, 2024

    @agocke
    Member
  6. Sergio0694 commented on Apr 24, 2024

    @Sergio0694
    ContributorAuthor

    Found two more trim analyzer bugs in CsWinRT:

    "ILC : Trim analysis warning IL2075: ABI.Microsoft.UI.Xaml.Data.ManagedCustomPropertyProviderVftbl.Do_Abi_GetCustomProperty_0(IntPtr,IntPtr,IntPtr*): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags)'. The return value of method 'System.Object.GetType()' 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."

    Here.

    "ILC : Trim analysis warning IL2075: ABI.Microsoft.UI.Xaml.Data.ManagedCustomPropertyProviderVftbl.Do_Abi_GetIndexedProperty_1(IntPtr,IntPtr,Type,IntPtr*): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags,Binder,Type,Type[],ParameterModifier[])'. The return value of method 'System.Object.GetType()' 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."

    Here.

    I'm a bit puzzled as to how the analyzer missed these ones 🤔

  7. added this to the 9.0.0 milestone on Apr 25, 2024
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Apr 25, 2024
  9. Sergio0694 commented on Apr 29, 2024

    @Sergio0694
    ContributorAuthor

    Found a bit more in microsoft/CsWinRT#1592:

    D:\a_work\1\s\src\WinRT.Runtime\Projections.cs(259,25): Trim analysis error IL2055: WinRT.Projections.FindCustomHelperTypeMapping(Type, Boolean): 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:\a_work\1\s\src\Tests\FunctionalTests\ClassActivation\ClassActivation.csproj::TargetFramework=net6.0]

    Here. Seems to only warn at publish time, but not in the IDE.

    D:\a_work\1\s\src\WinRT.Runtime\TypeExtensions.cs(115,17): Trim analysis error IL2057: WinRT.TypeExtensions.g__FindHelperTypeFallback|1_2(Type): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type. [D:\a_work\1\s\src\Tests\FunctionalTests\ClassActivation\ClassActivation.csproj::TargetFramework=net6.0]

    D:\a_work\1\s\src\WinRT.Runtime\TypeExtensions.cs(91,21): Trim analysis error IL2055: WinRT.TypeExtensions.g__GetHelperTypeFromAttribute|1_1(WindowsRuntimeHelperTypeAttribute, Type): 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:\a_work\1\s\src\Tests\FunctionalTests\ClassActivation\ClassActivation.csproj::TargetFramework=net6.0]

    Same for these two.

  10. sbomer commented on Apr 30, 2024

    @sbomer
    Member

    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:

    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 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]

    This is a known issue - https://github.com/dotnet/linker/issues/2632 - and has existing linker tests.

    D:\a_work\1\s\src\WinRT.Runtime\Projections.cs(259,25): Trim analysis error IL2055: WinRT.Projections.FindCustomHelperTypeMapping(Type, Boolean): 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:\a_work\1\s\src\Tests\FunctionalTests\ClassActivation\ClassActivation.csproj::TargetFramework=net6.0]

    This is a new issue - I've opened #101733 to track it.

  11. locked and limited conversation to collaborators on May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions