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

Library trimming steps should support feature switch substitutions #95429

Closed
agocke opened this issue Nov 29, 2023 · 7 comments · Fixed by #96363
Closed

Library trimming steps should support feature switch substitutions #95429

agocke opened this issue Nov 29, 2023 · 7 comments · Fixed by #96363
Assignees
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Milestone

Comments

@agocke
Copy link
Member

agocke commented Nov 29, 2023

Our recommended way to get all warnings from a library is to use a sample app that references the library with the 'copy' action, as described in https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming

Unfortunately, it doesn't seem like feature switches work as expected in this scenario. Specifically, the properties don't get replaced and the warnings don't get suppressed.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 29, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 29, 2023
@agocke agocke added this to the 9.0.0 milestone Nov 29, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 29, 2023
@agocke agocke added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Nov 29, 2023
@ghost
Copy link

ghost commented Nov 29, 2023

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

Issue Details

Our recommended way to get all warnings from a library is to use a sample app that references the library with the 'copy' action, as described in https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming

Unfortunately, it doesn't seem like feature switches work as expected in this scenario. Specifically, the properties don't get replaced and the warnings don't get suppressed.

Author: agocke
Assignees: sbomer
Labels:

area-Tools-ILLink, needs-area-label

Milestone: 9.0.0

@agocke agocke added this to AppModel Nov 29, 2023
@vcsjones vcsjones removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 30, 2023
@sbomer sbomer changed the title Linker doesn't substitute feature switches when used with 'copy' Library trimming steps should support feature switch substitutions Dec 29, 2023
@sbomer
Copy link
Member

sbomer commented Jan 4, 2024

TrimmerRootAsembly maps to -a, which has long used the copy action under the hood, and copy is designed to make no modifications to the assembly, but instead copy it as-is to the output.

To fix this I think -a should change behavior so that it roots every method/member in the assembly, but allows modifications. This is a potentially risky change if people were relying on TrimmerRootAssembly for behavior other than rooting. I suggest we change the default, but add an escape hatch that goes back to the "copy" behavior. Any opinion on this @vitek-karas @MichalStrehovsky?

@MichalStrehovsky
Copy link
Member

The current behavior causes us to unnecessarily root facade assemblies (System.Runtime, netstandard, etc.) because we're not allowed to rewrite typeforwards to their definition in assemblies rooted with TrimmerRootAssembly. I think making this change would be overall goodness. I assume our C++/CLI logic doesn't depend on TrimmerRootAssembly.

This is a potentially risky change if people were relying on TrimmerRootAssembly for behavior other than rooting

Trying to think about where this would break, the only scenario I can think about is if this was an assembly full of type forwards - we should make sure type forwards are also kept. Looks like people like to TrimmerRootAssembly mscorlib 🤦.

but add an escape hatch that goes back to the "copy" behavior.

Would setting the TrimMode metadata on ManagedAssemblyToLink work as the escape hatch?

@vitek-karas
Copy link
Member

If I understand this correctly - we will still root everything in the assembly, so the only changes are:

  • Method body edits (like branch removal, constant prop and so on)
  • Metadata edits (probably just type ref resolution/rewrite due to type forwarders)
  • Metadata optimizations (removal of parameter names on non-reflectable methods)
  • Type forwards (see Michal's comment)
  • Global removals - like removal of some attributes as dictated by substitution XML

These all sound relatively minor. I agree we should give this a try - if we merge this into 9 relatively soon, we should have a long window of validation.

@MichalStrehovsky
Copy link
Member

Metadata optimizations (removal of parameter names on non-reflectable methods)

I think TrimmerRootAssembly should assume everything is a reflection target (otherwise why root it?) so I'd not expect that one to happen.

@vitek-karas
Copy link
Member

That's a good point - and it should work that way already.

@sbomer
Copy link
Member

sbomer commented Jan 4, 2024

Would setting the TrimMode metadata on ManagedAssemblyToLink work as the escape hatch?

Good point, we already have an escape hatch, even if it's not as simple as setting some boolean flag. Sounds good to me!

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 4, 2024
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants