Repository navigation
[feature/dataflow] Implement FlowAnnotations helper class - #1024
Conversation
IFlowAnnotationSource lets us abstract away the source of the annotations. We expect to have an attribute-based one and JSON-based one (the JSON based one mostly for internal purposes right now - it probably won't be public).
|
|
||
| namespace Mono.Linker.Dataflow | ||
| { | ||
| // TODO: enforce virtual methods have consistent annotations |
There was a problem hiding this comment.
File a tracking issue for this - just in case :-)
| } | ||
|
|
||
| found = field; | ||
| } |
There was a problem hiding this comment.
Should we fail if the field can't be resolved or it's not static as expected? Because if the getter/setter has two field accesses, one which passes this check and one which doesn't we will still treat it as "yeah, we completely understand this one" - which is not true. I would rather this to be very careful and only return non-null when it's absolutely sure it got it right.
There was a problem hiding this comment.
If we want to be absolutely sure, we need to run the flow analysis on this.
E.g.
[DynamicallyAccessedMembers(Constructors)]
Type BaseType => _isValueType ? typeof(ValueType) : typeof(Object);This would currently incorrectly propagate the annotation to the _isValueType field. We could check that the type of the field matches the type of the property but even that one is not certain.
That's why I left the TODO: could restrict this to compiler-generated fields as well so that it only works for auto properties, but maybe that's too restrictive. - maybe we should do that...
There was a problem hiding this comment.
Hmm - yeah - I'm starting to like that more - it is restrictive, but on the other hand it's correct - which wins it for me.
…ker#1024) * `IFlowAnnotationSource` lets us abstract away the source of the annotations. We expect to have an attribute-based one and JSON-based one (the JSON based one mostly for internal purposes right now - it probably won't be public). * The `FlowAnnotations` class deals with caching and propagating the attributes from properties to the accessor methods and backing fields. The cache is per-type because the properties make this more complicated. Being per-type is also more memory efficient because we don't have to keep track of all methods/fields that we looked at and found out they're not interesting (the majority of cases). Not interesting things are not tracked and that's cached at the type level. Vitek is working on the thing that consumes this. I already tested it a bit with Vitek's thing. Commit migrated from dotnet/linker@1ff7856
IFlowAnnotationSourcelets us abstract away the source of the annotations. We expect to have an attribute-based one and JSON-based one (the JSON based one mostly for internal purposes right now - it probably won't be public).FlowAnnotationsclass deals with caching and propagating the attributes from properties to the accessor methods and backing fields. The cache is per-type because the properties make this more complicated. Being per-type is also more memory efficient because we don't have to keep track of all methods/fields that we looked at and found out they're not interesting (the majority of cases). Not interesting things are not tracked and that's cached at the type level.Vitek is working on the thing that consumes this. I already tested it a bit with Vitek's thing.