Repository navigation
Validation of annotations across virtual method hierarchies - #1315
Conversation
e43ef5b to
e95455c
Compare
| if (results.Count == 0) | ||
| return DynamicallyAccessedMemberTypes.None.ToString (); | ||
|
|
||
| return string.Join (" | ", results.Select (r => r.ToString ())); |
There was a problem hiding this comment.
Do we actually want such output? It can produce almost unreadable text
There was a problem hiding this comment.
It should recreate the text used in the attribute in source code pretty well. By far the most common case is annotations with one or two flags from the enum, so that should be fine.
I must admit I don't understand the scenario when this would produce a mess. The only potential is "I want to include everything", but for that we have the All value which is handled explicitly.
There was a problem hiding this comment.
We used this to dump to user two sets of enums and let him compare. This is very hard as most of the options are very similar. I don't know if the common path will use 2, 3 or more values but I think it'd be better to re-word the error message to allow us to report only single enum value instead.
(ignoring the aspect that this is C#-ish in IL-based tool)
There was a problem hiding this comment.
I'd like to address this in a separate PR as it's mostly unrelated to this one (the validation introduced in this PR doesn't actually use this method, I just moved it out of the already large ReflectionMethodBodyScanner).
I added note about this to #1157 which should address the warning message where this is used from.
| if (!method.IsVirtual) | ||
| return; | ||
|
|
||
| if (context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (method) || |
There was a problem hiding this comment.
| if (context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (method) || | |
| if (FlowAnnotations.RequiresDataFlowAnalysis (method) || HasLinkerAttribute<RequiresUnreferencedCodeAttribute> (method)) |
| protected override void Process () | ||
| { | ||
| Context.VirtualMethodAnnotationValidator.Validate (); | ||
| foreach (var method in Context.Annotations.VirtualMethodsWithAnnotationsToValidate) { |
There was a problem hiding this comment.
You could store Context.Annotations in local variable to have fewer prefixes here
For the linker to work correctly all correctness annotations must be exactly the same on all methods in a single virtual method override hierarchy. Currently this applies to DynamicallyAccessedMemberAttribute and RequiresUnreferencedCodeAttribute. The validation is postponed after the MarkStep since it requires full knowledge of virtual method hierarchies (and interface method hierarchies). With TypeMapStep these are available during MarkStep as well, but we're trying to move away from that requirement, so the validation is done after MarkStep, this only adds a very small amount of memory (the list of methods to validate is currently cca 200 for the entire corelibe). Refactorings to help with this change: * Change how we store generic parameter annotations - it now copies the method parameter annotation storage - array indexed by the index of the generic parameter on the type/method. This makes it easy to map the annotation to a generic parameter on any method in the virtual hierarchy (as they all share the same index). * FlowAnnotations are now stored directly on the Annotations class (since the new step needs them after MarkStep) * Move some helpers into DataFlowUtilities - mostly around getting description of members for error message purposes * Synchronize behavior of LogContains and LogDoesNotContain test attributes - both now support "contains" and "regex" versions * Correctly detect persense of LogContains and LogDoesNotContain attributes on all members of a test, so that test logging is turned on when they're used * Added a TestSystemTypeBase class - which is a class derived from System.Type and implements all abstract members. This is used to then write test classes which need to derive from System.Type (to test the "this" parameter annotations).
Remove left-over debugging write Update comments
dfffc96 to
b47ed47
Compare
…inker#1315) For the linker to work correctly all correctness annotations must be exactly the same on all methods in a single virtual method override hierarchy. Currently this applies to DynamicallyAccessedMemberAttribute and RequiresUnreferencedCodeAttribute. The validation is postponed after the MarkStep since it requires full knowledge of virtual method hierarchies (and interface method hierarchies). With TypeMapStep these are available during MarkStep as well, but we're trying to move away from that requirement, so the validation is done after MarkStep, this only adds a very small amount of memory (the list of methods to validate is currently cca 200 for the entire corelibe). Refactorings to help with this change: * Change how we store generic parameter annotations - it now copies the method parameter annotation storage - array indexed by the index of the generic parameter on the type/method. This makes it easy to map the annotation to a generic parameter on any method in the virtual hierarchy (as they all share the same index). * FlowAnnotations are now stored directly on the Annotations class (since the new step needs them after MarkStep) * Move some helpers into DataFlowUtilities - mostly around getting description of members for error message purposes * Synchronize behavior of LogContains and LogDoesNotContain test attributes - both now support "contains" and "regex" versions * Correctly detect persense of LogContains and LogDoesNotContain attributes on all members of a test, so that test logging is turned on when they're used * Added a TestSystemTypeBase class - which is a class derived from System.Type and implements all abstract members. This is used to then write test classes which need to derive from System.Type (to test the "this" parameter annotations). Commit migrated from dotnet/linker@cf697fc
For the linker to work correctly all correctness annotations must be exactly the same on all methods in a single virtual method override hierarchy.
Currently this applies to DynamicallyAccessedMemberAttribute and RequiresUnreferencedCodeAttribute.
The validation is postponed after the MarkStep since it requires full knowledge of virtual method hierarchies (and interface method hierarchies). With TypeMapStep these are available during MarkStep as well, but we're trying to move away from that requirement, so the validation is done after MarkStep, this only adds a very small amount of memory (the list of methods to validate is currently cca 200 for the entire corelibe).
Refactorings to help with this change:
This implements #1028 and #1271 - the very strict version. We can dial it back for the case of implementation->interface if we think that's important, but that's relatively tricky (for example it's possibly OK to not annotate implementation's in parameters even if interface has it, but it's not OK to omit annotation on the return value in this case - so we would have to correctly track in/out annotations for the purposes of validation).