-
Notifications
You must be signed in to change notification settings - Fork 5k
Propagate Type.GetInterfaces
through dataflow analysis
#114149
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
Conversation
Fixes dotnet/linker#1731 We currently maintain two invariants: 1. The types returned by the API will have `.Interfaces` annotations at minimum 2. If the parent type was annotated `.All`, the types returned by the API will also be `.All` We do this in the logic that keeps things, but we don't do this in terms of dataflow analysis warnings (the types retrieved from the array are not annotated as such, as far as the analysis is concerned). Because of the lacking annotation, we have warning suppressions in multiple places within the framework. This fixes it. Opening as a draft because I'm having trouble making `foreach` of arrays work with the Roslyn analyzer. Roslyn models it as `IEnumerable` instead of array indexing (which is how foreach is actually expanded for arrays). I hope we can somehow force Roslyn to surface this as array indexing. In the worst case we'll need to live with the wart that `foreach` doesn't work, only `for`.
src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/Symbols.vb
Show resolved
Hide resolved
@@ -950,9 +950,6 @@ Namespace Microsoft.VisualBasic.CompilerServices | |||
Return result | |||
End Function | |||
|
|||
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", |
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 suppression was wrong, all that was needed was to annotate GetClassConstraint
above.
@@ -45,7 +45,7 @@ internal ReflectedTypeData(Type type, bool isRegisteredType) | |||
/// Retrieves custom attributes. | |||
/// </summary> | |||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062:UnrecognizedReflectionPattern", | |||
Justification = "_type is annotated as preserve All members, so any Types returned from GetInterfaces should be preserved as well once https://github.com/mono/linker/issues/1731 is fixed.")] |
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.
The justification was incorrect, the warning is on lines working with elements of Type[]
returned by TrimSafeReflectionHelper.GetInterfaces
, not Type.GetInterfaces
. That will not work without warnings.
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, thank you!
Fixes dotnet/linker#1731
We currently maintain two invariants:
.Interfaces
annotations at minimum.All
, the types returned by the API will also be.All
We do this in the logic that keeps things, but we don't do this in terms of dataflow analysis warnings (the types retrieved from the array are not annotated as such, as far as the analysis is concerned). Because of the lacking annotation, we have warning suppressions in multiple places within the framework.
This fixes it.
Cc @dotnet/illink