-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Enable trim analyzer #41683
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
Enable trim analyzer #41683
Conversation
@sbomer this looks early given dotnet/linker#2718 and #41016 remain open. But I'm adding @JamesNK as a reviewer… |
Sorry, I forgot to close dotnet/linker#2718 - but the issues there have been fixed and I checked that the analyzer no longer throws on aspnetcore. As @JamesNK noticed in #41021 (comment) there are some new analyzer warnings that ILLink didn't report. One reason this might be happening is for dead code that the linker removes (whereas the analyzer will report warnings for all code). But we need to go through these warnings and identify any that are unexpected. |
I've fixed warnings in Kestrel, Http.Extensions and middleware. The remaining warnings are in components and JSInterop. I'm not familiar with that code or the existing trimming attributes. @mkArtakMSFT Could someone on the Blazor team contribute to this PR and fix up these warnings? Remaining warnings:
|
Thanks @JamesNK. |
Ok, I've fixed the warnings on justifiable cases, but I think the analyzer may have pointed out some real potential issues. @SteveSandersonMS, would you be able to look over these remaining warning locations and confirm whether my concerns are valid? If so, I can do a follow-up commit with some fixes.
I suppose it's safe to assume that routeable component types won't get completely trimmed away, but what about their
I see we have a
The
It seems like there could be a legitimate issue here that could be fixed by annotating the |
You raise a good point about the If there is some way for the
I suspect you're right that the existing annotation is ineffective. It was put there in reaction to trimmer warnings (IIRC). Regarding the AddAttribute overload proposal, I'm not certain how/if it would work. The point of <DynamicComponent Type="typeof(SomeComponent)" /> ... they commonly write: <DynamicComponent Type="@chosenComponentType" />
@code {
Type chosenComponentType;
} So isn't this still an unknowable type as far as the trimmer is concerned? It's not performing some more sophisticated static analysis to work out the possible range of values for If I'm understanding, it seems like:
If I'm wrong about this, please let me know as that would be great news :)
The trimmer's concern (based on the warning) seems not to be about line 59, but about line 60, because the I would have thought we should be annotating Please let me know if I'm misinterpreting all of this!
Right, yes! It seems like you're stating the same thing I was suggesting above. So maybe the constructor parameter annotation could solve both of these last two cases. As long as the routable page component itself is preserved, then |
Thanks for taking a look, @SteveSandersonMS!
Aha! This is something I wasn't aware of, and it drove a lot of the concerns I brought up in my last comment, so this is great to hear.
I'll go ahead and dismiss the warnings then since the framework doesn't contain routable components, as you stated.
Yeah, the AddAttribute overload wouldn't handle this case. And again, since application code doesn't get trimmed, we're probably safe here.
Everything you said about these seems right to me. Annotating the I'll make these final changes and push a commit with them soon, possibly tomorrow. |
@MackinnonBuck Please rebase this before merging. A few more projects support trimming since this PR was started. Hopefully, they don't introduce any new warnings, but we don't want to break the build if they do. I'll handle any new trimming errors that show up. |
I think we should be able to remove the workaround added for #41016 now.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@JamesNK @SteveSandersonMS Are we good to merge this now? |
@SteveSandersonMS Could you review the components changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
I think we should be able to remove this workaround now.
Fixes #41016.