Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

[feature/dataflow] Implement FlowAnnotations helper class - #1024

Merged
MichalStrehovsky merged 4 commits into
dotnet:feature/dataflowfrom
MichalStrehovsky:flowAnnotations
Mar 27, 2020
Merged

MichalStrehovsky merged 4 commits into
dotnet:feature/dataflowfrom
MichalStrehovsky:flowAnnotations

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member
  • 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.

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).
@MichalStrehovsky MichalStrehovsky changed the title Implement FlowAnnotations helper class [feature/dataflow] Implement FlowAnnotations helper class Mar 26, 2020

namespace Mono.Linker.Dataflow
{
// TODO: enforce virtual methods have consistent annotations

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File a tracking issue for this - just in case :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

found = field;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vitek-karas vitek-karas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MichalStrehovsky
MichalStrehovsky merged commit 1ff7856 into dotnet:feature/dataflow Mar 27, 2020
@MichalStrehovsky
MichalStrehovsky deleted the flowAnnotations branch March 27, 2020 10:11
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants