Skip to content

Don't include new() constraint for generic params with struct constraint when warn=5 - #2

Closed
jtschuster wants to merge 1 commit into
sbomer:warningQuirksfrom
jtschuster:NoNewConstraintForStructs
Closed

jtschuster wants to merge 1 commit into
sbomer:warningQuirksfrom
jtschuster:NoNewConstraintForStructs

Conversation

@jtschuster

Copy link
Copy Markdown

In dotnet 6.0 we did not consider the struct constraint to imply the new() constraint, and this led to a few extra warnings in the dotnet 7 linker.

I'm not sure where the best place to put this change is, but here isolates the differences. Let me know if I should target dotnet/linker main or something else.

@jtschuster
jtschuster requested a review from sbomer as a code owner August 18, 2022 23:40
@jtschuster

Copy link
Copy Markdown
Author

cc @tlakollo

@jtschuster

jtschuster commented Aug 18, 2022 •

Copy link
Copy Markdown
Author

Here are the excess warnings the 7.0 linker produces on a hello world with the runtime as all copy assemblies (warnings that the 7.0 linker produces that the 6.0 sdk doesn't produce, Warnings removed by this change crossed out)

I'm not sure why this change stops producing the MakeGenericMethod and MakeGenericType warnings, and it still needs testing to make sure it will warn when we want it to.

Warnings
ILLink warning IL2063: System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptor.TypeDescriptorCache.GetAssociatedMetadataType(Type): Value returned from method 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptor.TypeDescriptorCache.GetAssociatedMetadataType(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]
ILLink warning IL2060: System.Data.DataRowExtensions.UnboxT.Create(): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]
ILLink warning IL2063: System.RuntimeType.GetInterface(String, Boolean): Value returned from method 'System.RuntimeType.GetInterface(String, Boolean)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]
ILLink warning IL2065: System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(Type): Value passed to implicit 'this' parameter of method 'System.Type.GetFields(BindingFlags)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]
ILLink warning IL2070: System.Text.Json.Serialization.Converters.EnumConverterFactory.GetEnumConverterType(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Type.MakeGenericType(Type[])'. The parameter 'enumType' of method 'System.Text.Json.Serialization.Converters.EnumConverterFactory.GetEnumConverterType(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. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]
ILLink warning IL2055: System.Text.Json.Serialization.Converters.FSharpTypeConverterFactory.CreateConverter(Type, JsonSerializerOptions): 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. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]
ILLink warning IL2070: System.Text.Json.Serialization.Converters.NullableConverterFactory.GetNullableConverterType(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Type.MakeGenericType(Type[])'. The parameter 'valueTypeToConvert' of method 'System.Text.Json.Serialization.Converters.NullableConverterFactory.GetNullableConverterType(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. [C:\Users\jschuster\source\repro\linkWarn\linkWarn.csproj]

@sbomer sbomer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This branch is fine for now - I am still not sure if we want to take any of these changes into main because they are hard to reason about, but this is good to get an idea for what kinds of quirks would be necessary. We should discuss options when @vitek-karas is available.

@jtschuster jtschuster closed this Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants