Propagate Type.GetInterfaces through dataflow analysis#114149
Merged
MichalStrehovsky merged 5 commits intodotnet:mainfrom Apr 15, 2025
Merged
Propagate Type.GetInterfaces through dataflow analysis#114149MichalStrehovsky merged 5 commits intodotnet:mainfrom
Type.GetInterfaces through dataflow analysis#114149MichalStrehovsky merged 5 commits intodotnet:mainfrom
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`.
MichalStrehovsky
commented
Apr 2, 2025
eerhardt
reviewed
Apr 2, 2025
src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/Symbols.vb
Show resolved
Hide resolved
This was referenced Apr 2, 2025
This was referenced Apr 3, 2025
MichalStrehovsky
commented
Apr 9, 2025
| Return result | ||
| End Function | ||
|
|
||
| <UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", |
Member
Author
There was a problem hiding this comment.
This suppression was wrong, all that was needed was to annotate GetClassConstraint above.
| /// 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.")] |
Member
Author
There was a problem hiding this comment.
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.
This was referenced Apr 9, 2025
This was referenced Apr 14, 2025
Open
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes dotnet/linker#1731
We currently maintain two invariants:
.Interfacesannotations at minimum.All, the types returned by the API will also be.AllWe 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