Skip to content

IL Trim attributes with a feature flag in all assemblies#126094

Closed
pavelsavara wants to merge 4 commits intodotnet:mainfrom
pavelsavara:trim_hot_reload
Closed

IL Trim attributes with a feature flag in all assemblies#126094
pavelsavara wants to merge 4 commits intodotnet:mainfrom
pavelsavara:trim_hot_reload

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

@pavelsavara pavelsavara commented Mar 25, 2026

  • Trim attributes with a feature flag in all assemblies, not just corelib
  • test it on MetadataUpdateHandlerAttribute

DebuggableAttribute
DebuggerBrowsableAttribute
DebuggerDisplayAttribute
DebuggerHiddenAttribute
DebuggerNonUserCodeAttribute
DebuggerStepperBoundaryAttribute
DebuggerStepThroughAttribute
DebuggerTypeProxyAttribute
DebuggerVisualizerAttribute
Tracing.EventAttribute
Tracing.EventDataAttribute
Tracing.EventFieldAttribute
Tracing.EventIgnoreAttribute
Tracing.EventSourceAttribute
Tracing.NonEventAttribute
MetadataUpdateHandlerAttribute
ClassInterfaceAttribute
ComDefaultInterfaceAttribute
ComEventInterfaceAttribute
ComSourceInterfacesAttribute
ComVisibleAttribute
DispIdAttribute
InterfaceTypeAttribute
ProgIdAttribute
TypeMapAssemblyTargetAttribute
TypeMapAssociationAttribute
TypeMapAttribute

@pavelsavara pavelsavara added this to the 11.0.0 milestone Mar 25, 2026
@pavelsavara pavelsavara self-assigned this Mar 25, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Mar 25, 2026
Copilot AI review requested due to automatic review settings March 25, 2026 15:39
@pavelsavara pavelsavara added area-System.Reflection.Metadata size-reduction Issues impacting final app size primary for size sensitive workloads os-browser Browser variant of arch-wasm labels Mar 25, 2026
@dotnet-policy-service dotnet-policy-service Bot added linkable-framework Issues associated with delivering a linker friendly framework labels Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds ILLink link-attributes to remove MetadataUpdateHandlerAttribute instances (and enable trimming of their referenced handler types) when System.Reflection.Metadata.MetadataUpdater.IsSupported is disabled, and adds a trimming test to validate the behavior.

Changes:

  • Add per-library ILLink.LinkAttributes.xml files to remove MetadataUpdateHandlerAttribute instances when the feature switch is false.
  • Wire the new link-attributes files into the affected library projects via ILLinkLinkAttributesXmls.
  • Add a new System.Runtime trimming test console app that disables the feature switch and verifies the attribute + handler types are absent.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/libraries/System.Text.Json/src/System.Text.Json.csproj Embeds ILLink link-attributes for conditional removal of MetadataUpdateHandlerAttribute instances.
src/libraries/System.Text.Json/src/ILLink/ILLink.LinkAttributes.xml Removes MetadataUpdateHandlerAttribute instances when MetadataUpdater.IsSupported is disabled.
src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj Adds a new trimming test app and disables the MetadataUpdater.IsSupported feature switch for it.
src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/MetadataUpdateHandlerTrimmed.cs New trimming test app validating attribute + handler types are trimmed under the disabled switch.
src/libraries/System.ComponentModel.TypeConverter/src/System.ComponentModel.TypeConverter.csproj Embeds ILLink link-attributes for conditional removal of MetadataUpdateHandlerAttribute instances.
src/libraries/System.ComponentModel.TypeConverter/src/ILLink/ILLink.LinkAttributes.xml Removes MetadataUpdateHandlerAttribute instances when MetadataUpdater.IsSupported is disabled.
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/Microsoft.Extensions.DependencyInjection.Abstractions.csproj Embeds ILLink link-attributes for conditional removal of MetadataUpdateHandlerAttribute instances.
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ILLink/ILLink.LinkAttributes.xml Removes MetadataUpdateHandlerAttribute instances when MetadataUpdater.IsSupported is disabled.

Copilot AI review requested due to automatic review settings March 26, 2026 07:55
@pavelsavara pavelsavara changed the title IL trim MetadataUpdateHandlerAttribute and types which it keeps alive IL Trim attributes with a feature flag in all assemblies Mar 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 31, 2026 10:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@pavelsavara
Copy link
Copy Markdown
Member Author

pavelsavara commented Mar 31, 2026

cc @tmat for MetadataUpdateHandlerAttribute, related dotnet/aspnetcore#65903

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Mar 31, 2026

Trim attributes with a feature flag in all assemblies, not just corelib

What are the assemblies that define these attributes outside CoreLib?

@jkotas jkotas added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed area-System.Reflection.Metadata labels Mar 31, 2026
@jkotas jkotas requested a review from sbomer March 31, 2026 13:39
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

</assembly>
<!-- The following attributes are only necessary when debugging is supported -->
<assembly fullname="System.Private.CoreLib" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false">
<assembly fullname="*" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false">
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.

I would expect <assembly fullname="System.Private.CoreLib" to be defining identify of the attribute, so * does not make sense.

@pavelsavara
Copy link
Copy Markdown
Member Author

Trim attributes with a feature flag in all assemblies, not just corelib

What are the assemblies that define these attributes outside CoreLib?

[assembly: System.Reflection.Metadata.MetadataUpdateHandler(typeof(Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ActivatorUtilitiesUpdateHandler))]

[assembly: MetadataUpdateHandler(typeof(ReflectionCachesUpdateHandler))]

There are many in aspnetcore

https://github.com/search?q=repo%3Adotnet%2Faspnetcore+MetadataUpdateHandler&type=code

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Mar 31, 2026

What are the assemblies that define these attributes outside CoreLib?

These are uses of the attributes. You should not need the wildcard for those. The wildcard should be only needed for compiler injected local copies of the attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework os-browser Browser variant of arch-wasm size-reduction Issues impacting final app size primary for size sensitive workloads

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants