-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Proposal: API for fetching trimming information #109696
Comments
Trimming is done by https://github.com/dotnet/runtime/tree/main/src/tools/illink, not in Roslyn. |
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas |
Unfortunately there's no way to use Roslyn for this. Trimming analysis requires actual IL, and it requires all the IL in the program. That's why trimming/Native AOT are post-passes that operate on self-contained apps. Trimming and Native AOT can output DGML files that contain a lot of dependency information. I don't know what more info we could provide. |
Background and Motivation
Per today, the C# compiler has a lot of functionality for trimming compiler output to a minimum based on static analysis. E.g. for a Native AOT project.
It's a long shot, but worth asking, would it be feasible to expose some of that functionality to the Roslyn API's? E.g. to use the semantics model to list the static dependencies of a method to other symbols: Method1 depends on Console.WriteLine, String.StartsWith and T:PublicMethods.
It's quite easy to find all symbols referenced by a method, but tracking assignments to e.g. figure out that a statically resolvable Type local needs its public properties preserved from trimming is harder.
I have to admit I have a use-case that is quite special as I've written a C# => Javascript transpiler using Roslyn that is now becoming quite functional with most features to C#11 / .NET7. Being able to use existing functionality to enable users to trim the JS output to a minimum would help :). If not, I might be able to publish it natively with trimming enabled, and enumerate the trimmed DLL symbols to find out what I should include in my JS output. But using an API for this would be cleaner.
Thanks. If there are not other impactful use-cases for this request, feel free to ignore it.
Proposed API
No concrete proposal at this point.
The text was updated successfully, but these errors were encountered: