-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add trimmer annotations to System.Data.Common #52046
Conversation
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. In reply to: 829128156 |
Tagging subscribers to this area: @roji, @ajcvickers Issue Details
|
What is the process for finding what needs annotation for trimming? |
For assemblies in the netcoreapp shared framework, we have a build step that runs the trimming tool in "analysis mode", and spits out all the warnings. We've baselined the warnings in For libraries outside of the shared framework, we are still working through the user experience. See https://github.com/dotnet/docs/blob/main/docs/core/deploying/prepare-libraries-for-trimming.md for more info. For whole applications, you publish your app with |
Setting the ColumnName is unsafe? In reply to: 829648326 In reply to: 829648326 Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:125 in 4872c21. [](commit_id = 4872c21, deletion_comment = False) |
Is there any way we can annotate the In reply to: 829648848 In reply to: 829648848 Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:103 in 4872c21. [](commit_id = 4872c21, deletion_comment = False) |
How come Adding and Removing from a collection is unsafe? This message doesn't really tell me what is the issue. Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:177 in 4872c21. [](commit_id = 4872c21, deletion_comment = False) |
src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.xml
Outdated
Show resolved
Hide resolved
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer Issue Details
|
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.
@krwq - overall, I think this is a good start. However, I think we may be marking too many constructors as RequiresUnreferencedCode
- ex. DataColumn and DataSet. I wonder if there is something that can be done so we don't have to mark the constructors as unsafe, but instead marking the methods that are unsafe.
I think I marked one of the events it executed as RUC at first and then reverted it but this was left as RUC. Reverting
Adding - I've tried to remove RUC there couple of times but seems like it needs to read the default value for the record which is unsafe as in some cases it might be reading some data through reflection.
For DataColumn I believe only some constructors are unsafe and DataSet is mainly suffering because of inheritance... perhaps one solution could be to mark GetObjectData as RUC and suppress the warning about not matching inherited -- but then that might actually allow to bypass the message in case where you would get error but that still might be better than making more common case suffer |
I think DynamicallyAccessedMemberTypes.PublicProperties should fix this specific constructor but not the other as the other one is unsafe because of expression |
@eerhardt I've removed RUCs from two DataSet ctors but after I did investigation and some backtracing on them it didn't really help much with removing any other public RUCs, I only was able to remove it from couple of internal/private members. |
What about adding an existing DataColumn to a collection is unsafe? Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:177 in 33b3e45. [](commit_id = 33b3e45, deletion_comment = False) |
Is this necessary to be marked as RUC? In reply to: 834485445 Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:180 in 33b3e45. [](commit_id = 33b3e45, deletion_comment = False) |
What about removing columns from the collection is unsafe? Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:192 in 33b3e45. [](commit_id = 33b3e45, deletion_comment = False) |
@eerhardt there is a merge conflict between this PR and #52629 - all string changes @safern has made were already in this PR but there is a diff between |
src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactories.cs
Outdated
Show resolved
Hide resolved
These should have different messages on them. In reply to: 849186450 In reply to: 849186450 Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:2543 in e63d347. [](commit_id = e63d347, deletion_comment = False) |
It might be good to do all this formatting separately.... It's causing a lot of noise in this PR Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:2613 in e63d347. [](commit_id = e63d347, deletion_comment = True) |
Should have a different message In reply to: 849187167 Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:3681 in e63d347. [](commit_id = e63d347, deletion_comment = False) |
src/libraries/System.Data.Common/src/System/Data/LinqDataView.cs
Outdated
Show resolved
Hide resolved
How come setting a field is unsafe, but the Field methods above getting it back aren't? I would have expected that T above to be annotated in order for the values to be preserved. Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:421 in e63d347. [](commit_id = e63d347, deletion_comment = False) |
Can't you annotate the T to have it be safe? Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:423 in e63d347. [](commit_id = e63d347, deletion_comment = False) |
Having the same message in all of the RUC attributes could be confusing. It is great to try to reuse when possible and when it makes sense, but these messeges will be public-facing so we should try to keep them be understandable from the API called perspective Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:592 in e63d347. [](commit_id = e63d347, deletion_comment = False) |
not sure how user friendly this message is Refers to: src/libraries/System.Data.Common/ref/System.Data.Common.cs:1120 in e63d347. [](commit_id = e63d347, deletion_comment = False) |
@@ -273,6 +278,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte | |||
protected virtual void InitializeDerivedDataSet() { } | |||
|
|||
// Serialize all the tables. | |||
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)] |
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.
Correct me if I'm wrong but this is only unsafe if the serializationformat is not xml right since in that case it would use BF. If so, would it make sense to add it to the message so it can be suppressed upstack when we know that the format is xml?
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.
No, XML can contain filter expressions which are unsafe
@@ -367,6 +374,7 @@ internal void DeserializeDataSet(SerializationInfo info, StreamingContext contex | |||
} | |||
|
|||
// Deserialize schema. | |||
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)] |
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.
Same comment here, seems like the only unsafe path is BinaryFormatter.Deserialize right?
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.
as above (XML itself can contain filter expressions which are unsafe)
src/libraries/System.Data.Common/src/System/Data/Common/DataStorage.cs
Outdated
Show resolved
Hide resolved
@@ -188,7 +193,7 @@ private static DbProviderFactory GetFactoryInstance(Type providerFactoryClass) | |||
return (DbProviderFactory)factory; | |||
} | |||
|
|||
|
|||
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)] |
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.
Same here, we should probably adjust message to just say here that the reason why this is unsafe is because we are calling Type.GetType(string) #Closed
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ITypedList.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactories.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Data.Common/src/System/Data/Common/DBSchemaRow.cs
Outdated
Show resolved
Hide resolved
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.
This is getting really close @krwq. Thanks for the good work here.
Just a few more comments. Once those are addressed I think this will be ready to merge.
src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactories.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Data.Common/src/System/Data/Filter/BinaryNode.cs
Outdated
Show resolved
Hide resolved
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.
This looks good. Let's get this merged. Thanks for the work.
No description provided.