-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Resolve ILLink warnings in Microsoft.VisualBasic.Core #51725
Conversation
Tagging subscribers to this area: @cston Issue Detailscc: @eerhardt @vitek-karas @agocke Addressing all Linker warnings on Microsoft.VisualBasic.Core assembly. Changes are ready for review, but the RequiresUnreferencedCode messages are not final yet, I need to do another pass thorugh all of them to make sure we actually communicate what is actionable, so don't really pay much attention to those as they will be all changed in a commit that I'll add here. I'm just sending the PR now as the logic of it is ready and I want to start getting feedback. Contributes to #45623
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
@cston FYI |
src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs
Outdated
Show resolved
Hide resolved
...icrosoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/ConversionResolution.vb
Show resolved
Hide resolved
src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs
Outdated
Show resolved
Hide resolved
@@ -1,28 +1,4 @@ | |||
Compat issues with assembly Microsoft.VisualBasic: | |||
|
|||
# Loaded via reflection so needs to be public in the implementation but we don't want to expose them publicly in the ref assembly: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes intentional? What is the reasoning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of, yeah. Not really related to this PR in particular but when adding the annotations on the src I started getting new APICompat warnings on since they didn't match the ref (as I hadn't updated that yet at that point) so I regenerated this file a few times until finally I regenerated it one last time after adding the changes back to the ref assembly again. Long story short, these baselines had gone way out of date since we don't regenerate them regularly, so this is just the result of regenerating them today. Of course I could remove this change from the PR and regenerate them outside of this effort if preferred.
TypesMustExist : Type 'Microsoft.VisualBasic.CompilerServices.SiteDelegate6' does not exist in the reference but it does exist in the implementation. | ||
TypesMustExist : Type 'Microsoft.VisualBasic.CompilerServices.SiteDelegate7' does not exist in the reference but it does exist in the implementation. | ||
|
||
# C# doesn't permit setting the parameter name of the setter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this comment still add value? If so, it should be kept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure why this was here but the whole purpose of these files is for them to be auto generated, and we were supposed to regenerate them every now and then (which clearly we haven't done in a while) so I wouldn't personally revert this change as comment will be removed next regeneration anyway.
src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Interaction.vb
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb
Outdated
Show resolved
Hide resolved
...ibraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Helpers/UnsafeNativeMethods.vb
Outdated
Show resolved
Hide resolved
@@ -155,8 +166,9 @@ Namespace Microsoft.VisualBasic.FileIO | |||
Return FileSystem.NormalizePath(Directory) | |||
End Function | |||
|
|||
<RequiresUnreferencedCode("Cannot statically analyze the passed in type.")> | |||
Private Shared Function GetWindowsFormsDirectory(typeName As String, propertyName As String) As String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change this to have a DynamicallyAccessedMembers attribute on the typeName As String
? And then pass the fully-qualified type in above. That way, when the assembly is present, the linker will see the full type name, and know to preserve properties on the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I tried that, but then wasn't really sure if it would work since I was still getting the warning due to of course System.Windows.Forms not being present so I left it as RUC for now. I'll change it to be just annotated and suppress the warning for the missing assembly instead.
...aries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6RandomFile.vb
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6File.vb
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/Symbols.vb
Outdated
Show resolved
Hide resolved
.../Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/OverloadResolution.vb
Outdated
Show resolved
Hide resolved
...libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
Outdated
Show resolved
Hide resolved
...libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
Outdated
Show resolved
Hide resolved
ByVal method As MethodBase, | ||
ByVal Parameters As ParameterInfo(), | ||
ByVal args As Object(), | ||
ByVal objType As Type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really required as the actual type that is being reflected on is objIReflect
when we pass it down to InvokeMemberOnIReflect
so just annotating that seems to be enough.
...libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
Outdated
Show resolved
Hide resolved
...libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
Outdated
Show resolved
Hide resolved
@@ -932,6 +940,9 @@ Namespace Microsoft.VisualBasic.CompilerServices | |||
Return result | |||
End Function | |||
|
|||
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", | |||
Justification:="_type is annotated with .All, so it's BaseType will be annotated as well and it is safe to call GetMember on the BaseType. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this message. Where is BaseType
used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies as it is not straight forward to figure this out. The variable classConstraint is created by calling GetClassConstraint(_type)
, which if you see it's implementation, all it's doing is:
Lines 522 to 531 in ac82799
Friend Shared Function GetClassConstraint(ByVal genericParameter As Type) As Type | |
'Returns the class constraint for the type parameter, Nothing if it has | |
'no class constraint. | |
Debug.Assert(IsGenericParameter(genericParameter), "expected type parameter") | |
'Type parameters with no class constraint have System.Object as their base type. | |
Dim classConstraint As Type = genericParameter.BaseType | |
If IsRootObjectType(classConstraint) Then Return Nothing | |
Return classConstraint | |
End Function |
which basically means it is calling BaseType on _type
and then the linker is warning because we are then calling GetMember into that and we haven't annotated the basetype, but because of the fact that _type
itself is annotated with DAM.All
then it's basetype and members should be preserved too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @joperezr!
Hello @joperezr! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
cc: @eerhardt @vitek-karas @agocke
Addressing all Linker warnings on Microsoft.VisualBasic.Core assembly.
Contributes to #45623