Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dataflow analysis for GetNestedType #109814

Merged
merged 9 commits into from
Nov 20, 2024

Conversation

MichalStrehovsky
Copy link
Member

dotnet/linker#2133 adjusted rooting logic to keep .All on all nested types preserved with PublicNestedTypes/NonPublicNestedTypes. The PR resolved the bug and the analysis work that was identified in the review as necessary never happened. So we just uselessly preserve members.

This adds dataflow analysis to propagate this. Since we never had the dataflow analysis, I'm exposing this not as .All, but a subset of .All that doesn't do the worst part - doesn't provide reflectability of interface methods.

Opening as draft, we'll want to also adjust marking appropriately.

dotnet/linker#2133 adjusted rooting logic to keep `.All` on all nested types preserved with PublicNestedTypes/NonPublicNestedTypes. The PR resolved the bug and the analysis work that was identified in the review as necessary never happened. So we just uselessly preserve members.

This adds dataflow analysis to propagate this. Since we never had the dataflow analysis, I'm exposing this not as .All, but a subset of .All that doesn't do the worst part - doesn't require reflectability of interface methods.
@dotnet-issue-labeler dotnet-issue-labeler bot added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners new-api-needs-documentation labels Nov 14, 2024
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@MichalStrehovsky MichalStrehovsky added linkable-framework Issues associated with delivering a linker friendly framework area-Tools-ILLink .NET linker development as well as trimming analyzers and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 14, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Member Author

This pr currently has 3 parts:

  • Fix dataflow analysis to reflect what we do when marking things for DAMT.NestedTypes: we actually also keep members, so don't treat that as DAMT.None
  • Take advantage of this in EventSource. This should be a separate pr but i wanted measurements. It's a 0.3% size saving on webapiaot. I'll take it.
  • Adjust marking to not to keep .All, but just all members (afaik the only difference is that .All will also make members on implemented interfaces reflection-visible, potentially causing a ton of damage if it's a popular generic interface)

The third one is running into some weird test failures, I'm not sure we want to go there. Doesn't look to help much extra for webapiaot size so I'd scope it out, we can always revisit. Anyone have opinion?

@eerhardt
Copy link
Member

The third one is running into some weird test failures, I'm not sure we want to go there. Doesn't look to help much extra for webapiaot size so I'd scope it out, we can always revisit. Anyone have opinion?

Scoping it out for now sounds like a good plan to me.

@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review November 14, 2024 22:35
Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

Implementation LGTM, thanks!

I'm exposing this not as .All, but a subset of .All that doesn't do the worst part

Curious how you determined that this was sufficient - is it based on the EventSource usage? Would it be possible to leave out DAMT.Interfaces for example?

@MichalStrehovsky
Copy link
Member Author

I'm exposing this not as .All, but a subset of .All that doesn't do the worst part

Curious how you determined that this was sufficient - is it based on the EventSource usage? Would it be possible to leave out DAMT.Interfaces for example?

EventSource wouldn't need the interfaces. I chose this based on the discussion in dotnet/linker#1174 - if one wants to keep a nested type - they probably want to do something with it, so we should better allow all things and .Interfaces is one of the members on DAMT.

I'm indifferent on the .Interfaces - interface list is not a member. We just added it to DAMT because we needed it. If you'd like to first try without .Interfaces, I can make that change. We can always add that later based on feedback, I don't think that one would be breaking in any way.

@sbomer
Copy link
Member

sbomer commented Nov 18, 2024

I don't feel strongly about it either way. I was just curious about the reasoning - I don't think there will be much impact for .Interfaces, so probably doesn't hurt to keep it. I like that this at least leaves open the option to stop marking members of interfaces.

@MichalStrehovsky
Copy link
Member Author

/ba-g deadlettered wasm tests

@MichalStrehovsky MichalStrehovsky merged commit 0d62887 into dotnet:main Nov 20, 2024
106 of 112 checks passed
@MichalStrehovsky MichalStrehovsky deleted the nested branch November 20, 2024 06:20
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Nov 20, 2024
This takes advantage of dotnet#109814. This is in theory a breaking change in case someone took advantage
of our annotation and is doing their own reflection on `EventSource` descendants.

Someone else reflecting on EventSource is problematic however. We placed around various suppressions
due to our own annotations like this:

https://github.com/dotnet/runtime/blob/0d62887a30553b8177dc90f9e39559be0e6c7707/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L414-L424

It means that if someone else is reflection-accessing these, they would not get a trimming warning.
Hopefully, nobody does that. This PR also assumes that nobody does that (and the PR should therefore
not be breaking in practice).

We annotate the class for our purposes, but someone else could be taking advantage of that in their own code.
MichalStrehovsky added a commit that referenced this pull request Nov 21, 2024
This takes advantage of #109814. This is in theory a breaking change in case someone took advantage
of our annotation and is doing their own reflection on `EventSource` descendants.

Someone else reflecting on EventSource is problematic however. We placed around various suppressions
due to our own annotations like this:

https://github.com/dotnet/runtime/blob/0d62887a30553b8177dc90f9e39559be0e6c7707/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L414-L424

It means that if someone else is reflection-accessing these, they would not get a trimming warning.
Hopefully, nobody does that. This PR also assumes that nobody does that (and the PR should therefore
not be breaking in practice).

We annotate the class for our purposes, but someone else could be taking advantage of that in their own code.
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
dotnet/linker#2133 adjusted rooting logic to keep `.All` on all nested types preserved with PublicNestedTypes/NonPublicNestedTypes. The PR resolved the bug and the analysis work that was identified in the review as necessary never happened. So we just uselessly preserve members.

This adds dataflow analysis to propagate this. Since we never had the dataflow analysis, I'm exposing this not as .All, but a subset of .All that doesn't do the worst part - doesn't require reflectability of interface methods.
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
…10001)

This takes advantage of dotnet#109814. This is in theory a breaking change in case someone took advantage
of our annotation and is doing their own reflection on `EventSource` descendants.

Someone else reflecting on EventSource is problematic however. We placed around various suppressions
due to our own annotations like this:

https://github.com/dotnet/runtime/blob/0d62887a30553b8177dc90f9e39559be0e6c7707/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L414-L424

It means that if someone else is reflection-accessing these, they would not get a trimming warning.
Hopefully, nobody does that. This PR also assumes that nobody does that (and the PR should therefore
not be breaking in practice).

We annotate the class for our purposes, but someone else could be taking advantage of that in their own code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants