Skip to content
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

Trim/AOT analyzer missing some ILC warnings #101203

Closed
Sergio0694 opened this issue Apr 17, 2024 · 6 comments
Closed

Trim/AOT analyzer missing some ILC warnings #101203

Sergio0694 opened this issue Apr 17, 2024 · 6 comments
Assignees
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Milestone

Comments

@Sergio0694
Copy link
Contributor

Sergio0694 commented Apr 17, 2024

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]
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 17, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 17, 2024
@SingleAccretion SingleAccretion added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 17, 2024
Copy link
Contributor

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

@Sergio0694
Copy link
Contributor Author

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.

@agocke
Copy link
Member

agocke commented Apr 17, 2024

FYI @jtschuster

@Sergio0694
Copy link
Contributor Author

Sergio0694 commented Apr 24, 2024

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 🤔

@sbomer sbomer added this to the 9.0.0 milestone Apr 25, 2024
@sbomer sbomer removed the untriaged New issue has not been triaged by the area owner label Apr 25, 2024
@Sergio0694
Copy link
Contributor Author

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.

@sbomer
Copy link
Member

sbomer commented 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:

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.

@sbomer sbomer closed this as completed Apr 30, 2024
sbomer added a commit that referenced this issue May 1, 2024
And add a testcase to cover IL2068.

This just ensures that this particular testcase runs without
allowMissingWarnings for the analyzer, and adds one more testcase
to track the specific missing warning that was encountered in
#101203 (tracked in
#101734).
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this issue May 9, 2024
And add a testcase to cover IL2068.

This just ensures that this particular testcase runs without
allowMissingWarnings for the analyzer, and adds one more testcase
to track the specific missing warning that was encountered in
dotnet#101203 (tracked in
dotnet#101734).
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this issue May 30, 2024
And add a testcase to cover IL2068.

This just ensures that this particular testcase runs without
allowMissingWarnings for the analyzer, and adds one more testcase
to track the specific missing warning that was encountered in
dotnet#101203 (tracked in
dotnet#101734).
@github-actions github-actions bot locked and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Projects
Archived in project
Development

No branches or pull requests

4 participants