Uh oh!
There was an error while loading. Please reload this page.
Propagate Type.GetInterfaces through dataflow analysis - #114149
Merged
Conversation
Fixesdotnet/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`.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eerhardt
reviewed
Apr 2, 2025
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Apr 2, 2025
This was referenced Apr 3, 2025
| Return result | ||
| End Function | ||
| <UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", |
MemberAuthor
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.")] |
MemberAuthor
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.
MichalStrehovsky
marked this pull request as ready for review
April 9, 2025 13:05
This was referenced Apr 9, 2025
This was referenced Apr 14, 2025
Open
sbomer
approved these changes
Apr 14, 2025
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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.
Fixesdotnet/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