Add missing custom attribute marking to ILTrim TokenBased nodes#127369
Open
Add missing custom attribute marking to ILTrim TokenBased nodes#127369
Conversation
…traint, and ManifestResource nodes; update expected failures Add AddDependenciesDueToCustomAttributes calls to ParameterNode, GenericParameterNode, GenericParameterConstraintNode, and ManifestResourceNode so that custom attributes on these metadata tables are correctly preserved during ILTrim. Skip InterfaceImpl, StandAloneSig, and TypeSpec as requested (problematic). Update ILTrimExpectedFailures.txt: remove 20 now-passing tests, add 5 new expected failures (OnlyKeepUsed tests that expect unused attribute removal, not yet implemented in ILTrim). All 915 tests pass (358 passed, 557 skipped, 0 failed). Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/aa76f39a-b849-4fbe-a977-e9c4df50939f Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
…al line ordering Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ca9868d9-9404-4b98-8ba9-a2d5e04076d7 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
MichalStrehovsky
April 24, 2026 05:08
View session
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
…butes only once Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/61b20371-b1f0-4b46-8e29-d5211b24471a Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
MichalStrehovsky
approved these changes
Apr 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes ILTrim TokenBasedNode subclasses that weren’t marking dependencies from metadata custom attributes, which caused those attributes (and their referenced constructors/types) to be silently dropped during trimming.
Changes:
- Added
CustomAttributeNode.AddDependenciesDueToCustomAttributesmarking to additional token-based metadata nodes (Parameter, GenericParameter, GenericParameterConstraint, ManifestResource). - Refactored affected nodes to return a single dependency list while integrating custom attribute marking.
- Updated
ILTrimExpectedFailures.txtto reflect newly passing tests and to add new expected failures forOnlyKeepUsedscenarios that require--used-attrs-only.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt | Updates expected-failure baselines to reflect the new custom-attribute marking behavior. |
| src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/ParameterNode.cs | Marks dependencies introduced by parameter custom attributes. |
| src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/ManifestResourceNode.cs | Consolidates dependency collection and adds manifest resource custom-attribute dependency marking. |
| src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/GenericParameterNode.cs | Switches from yield to an explicit dependency list to integrate generic-parameter custom-attribute marking. |
| src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/GenericParameterConstraintNode.cs | Switches from yield to an explicit dependency list to integrate constraint custom-attribute marking. |
Member
|
@copilot apply the code review feedback |
… return bypassing CA marking Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/25d36104-0c73-4530-85ca-cdf871c5c846 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Contributor
Author
Applied both code review items in eb50492:
|
This was referenced Apr 27, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Several
TokenBasedNodesubclasses in ILTrim were not callingCustomAttributeNode.AddDependenciesDueToCustomAttributes, causing custom attributes on those metadata tables to be silently dropped during trimming.Nodes fixed
ParameterNode— was returningnullfromGetStaticDependencies; now marks parameter custom attributesGenericParameterNode— converted fromyield returnto lazily-initializedDependencyListto integrate CA marking without unnecessary allocationsGenericParameterConstraintNode— same patternManifestResourceNode— refactored to have a singleAddDependenciesDueToCustomAttributescall and single return at the end; removed earlyreturn nullin theIgnoreDescriptorspath so CA marking is never bypassedIntentionally skipped (problematic)
InterfaceImpl, StandAloneSig, TypeSpec — along with the already-excluded MethodSpec, TypeRef, AssemblyRef, MemberRef, ModuleRef.
Test impact
ILTrimExpectedFailures.txt)OnlyKeepUsedtests that assert unused attribute removal, which requires--used-attrs-only(not yet implemented in ILTrim)ILTrimExpectedFailures.txtby preserving original line ordering (undoing unintended sort)Example of the change pattern applied to each node: