IL Trim attributes with a feature flag in all assemblies#126094
IL Trim attributes with a feature flag in all assemblies#126094pavelsavara wants to merge 4 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
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.xmlfiles to removeMetadataUpdateHandlerAttributeinstances when the feature switch isfalse. - Wire the new link-attributes files into the affected library projects via
ILLinkLinkAttributesXmls. - Add a new
System.Runtimetrimming 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. |
8bfadf3 to
8018fac
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
cc @tmat for MetadataUpdateHandlerAttribute, related dotnet/aspnetcore#65903 |
What are the assemblies that define these attributes outside CoreLib? |
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
| </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"> |
There was a problem hiding this comment.
I would expect <assembly fullname="System.Private.CoreLib" to be defining identify of the attribute, so * does not make sense.
There are many in aspnetcore https://github.com/search?q=repo%3Adotnet%2Faspnetcore+MetadataUpdateHandler&type=code |
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. |
MetadataUpdateHandlerAttributeDebuggableAttribute
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