Repository navigation
Produce diagnostics for KnownValueTypes that have annotations in its members - #2418
Conversation
Add IL2110 and IL2111 to shared Diagnostic ids Add test in analyzer for now since intrinsics are still not handled Delete the use of context in the binder since the context is never used Produce diagnostics for KnownValueTypes that have annotations in its members
sbomer
left a comment
There was a problem hiding this comment.
Looking good! Would it be reasonable to turn on the test AnnotatedMembersAccessedViaReflection and use ProducedBy to skip the ones that rely on intrinsics? It would be good to get the extra coverage.
Remove simple test in DynamicallyAccessedMembersAnalyzerTests Add code to handle properties Add RequiresUnreferencedCode changes to be able to produce RUC from DAMAnalyzer
Only return one diagnostic per method Disable intrinsics GetMethod, GetProperty and GetField Fix tests
|
I will change this to draft, I realized that there is several tests having problems with interfaces and implementations. Need to spend more time on it. |
…was previously being built Changes tests to include Analyzer warnings Merge branch 'feature/damAnalyzer' of https://github.com/mono/linker into KnownTypeInDAMAnalyzer
| /* Skip Type and InterfaceImplementation marking since doesnt seem relevant for diagnostic generation | ||
| case ITypeSymbol nestedType: | ||
| MarkType (diagnosticContext, nestedType); | ||
| break; | ||
| case InterfaceImplementation interfaceImplementation: | ||
| MarkInterfaceImplementation (analysisContext, interfaceImplementation, dependencyKind); | ||
| break; | ||
| */ |
There was a problem hiding this comment.
What about Type level DAM/RUC?
I think it's OK for now.. but going forward... maybe.
There was a problem hiding this comment.
So I think is kind of handled, each member looks for RUC on the member and on the type based on the conditions (being static or constructor and the ContainingType has RUC), so at least type-level RUC seems fine to me. Maybe once more intrinsics and we enable more tests like ObjectGetType we can have enable the DAM on type level
| case IPropertySymbol property: | ||
| GetDiagnosticsForProperty (diagnosticContext, property); | ||
| break; | ||
| /* Skip Type and InterfaceImplementation marking since doesnt seem relevant for diagnostic generation |
There was a problem hiding this comment.
I think OK for now - I don't remember if this is important for interfaces when DAM on type is enabled.... but we'll get there eventually.
There was a problem hiding this comment.
I think
will cover this once we get there.Use FlowAnnotations helpers to cover the same usecases as in linker and rest of the dataflow
|
Added a bug for most of the properties inconsistencies #2575 |
…into KnownTypeInDAMAnalyzer Fix merge conflicts
| .WithArguments ("System.Type.GetMethod(String)", | ||
| "type", | ||
| "C.M(Type)", | ||
| "'DynamicallyAccessedMemberTypes.PublicMethods'")*/); |
There was a problem hiding this comment.
Not sure why lint decided on this format but is on purpose
| if (methodSymbol.GetDynamicallyAccessedMemberTypes () != DynamicallyAccessedMemberTypes.None) | ||
| diagnosticContext.AddDiagnostic (DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, methodSymbol.GetDisplayName ()); |
There was a problem hiding this comment.
Ideally this should be only done on instance method (non-static) and only when the declaring type derives from System.Type. The latter part is tracked by either #2409 or a line item in #2273.
So probably OK to leave it as is for now - as we will likely handle this as a separate part of the analyzer. It might produce noise if there's such a case in the code though, but not a big deal.
| [ExpectedWarning ("IL2111", nameof (VirtualPropertyWithAnnotationOnMembers) + ".get", ProducedBy = ProducedBy.Analyzer)] | ||
| [ExpectedWarning ("IL2111", nameof (VirtualPropertyWithAnnotationOnMembers) + ".get", ProducedBy = ProducedBy.Analyzer)] | ||
| [ExpectedWarning ("IL2111", nameof (VirtualPropertyWithAnnotationOnMembers) + ".set", ProducedBy = ProducedBy.Analyzer)] | ||
| [ExpectedWarning ("IL2111", nameof (VirtualPropertyWithAnnotationOnMembers) + ".set", ProducedBy = ProducedBy.Analyzer)] |
There was a problem hiding this comment.
The reason for the weird warnings from Linker is that the tests are matching substrings and linker doesn't produce the warnings in the same order as analyzer.
So for example the expected warning which is for PropertyWithAnnotationOnMembers.get will actually match the produced warning for VirtualPropertyWithAnnotationOnMembers.get. This leads to:
- The expected warning for the
Virtual...is not recognized and reported as missing - The produced warning for
Property...is not expected and reported as such -> leading to seemingly duplicate warnings.
There was a problem hiding this comment.
I pushed a change which fixes it for the property test - maybe we should do the same for the other tests in this file as well.
The fix is more of a workaround, I simply renamed the properties so that the substrings don't match.
As far as I can tell the correct warnings are generated. And the linker and analyzer behavior matches exactly now (nice).
That said there are still duplicate warnings, but that's a different matter.
Renamed the properties so that they don't match as substrings of one another.
vitek-karas
left a comment
There was a problem hiding this comment.
Looks good - just a few minor things
Add Struct Layout in the SharedProject
…members (dotnet/linker#2418) Add IL2110 and IL2111 to shared Diagnostic ids Delete the use of context in the binder since the context is never used Add ReflectionAccessAnalyzer which makes the work of ReflectionMethodBodyScanner without marking and only producing diagnostics Produce diagnostics for SystemTypeValue that have annotations in its members Enable the AnnotatedMembersAccessedViaReflection test Add RequiresUnreferencedCode changes to be able to produce RUC from DAMAnalyzer Disable intrinsics GetMethod, GetEvent, GetProperty, GetConstructor and GetField Add diagnosticContext as part of the ReflectionAction Add Struct Layout in ReflectionAction Co-authored-by: vitek-karas <[email protected]> Commit migrated from dotnet/linker@924ccec
Add KnownTypeValue as a subclass of ValueWithDynamicallyAccessedMembers
Add IL2110 and IL2111 to shared Diagnostic ids
Add test in analyzer for now since intrinsics are still not handled
Delete the use of context in the binder since the context is never used
Produce diagnostics for KnownValueTypes that have annotations in its members
Fixes #2410
Fixes #2339