Skip to content

Deduplicate warnings for attribute on property dataflow#127254

Open
eduardo-vp wants to merge 2 commits intodotnet:mainfrom
eduardo-vp:ilc-dup-warning-2
Open

Deduplicate warnings for attribute on property dataflow#127254
eduardo-vp wants to merge 2 commits intodotnet:mainfrom
eduardo-vp:ilc-dup-warning-2

Conversation

@eduardo-vp
Copy link
Copy Markdown
Member

@eduardo-vp eduardo-vp commented Apr 22, 2026

Avoid processing the custom attributes of properties/events more than once by using a HashSet of (EcmaModule, DefinitionHandle).

Fixes #120004.

Copilot AI review requested due to automatic review settings April 22, 2026 00:31
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Apr 22, 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 fixes NativeAOT duplicate trim-analysis warnings emitted when analyzing custom attributes on properties/events (dataflow/capability warnings), aligning NativeAOT behavior with the analyzer/ILLink and addressing #120004.

Changes:

  • Add a deduplication mechanism in the NativeAOT metadata manager to ensure property/event custom attributes are analyzed only once per metadata handle.
  • Update NativeAOT linker/analyzer test cases by removing UnexpectedWarning annotations that were tracking the duplicate-warning bug.

Reviewed changes

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

File Description
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnAttribute.cs Removes NativeAOT-only UnexpectedWarning entries now that warnings should not be duplicated.
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs Removes NativeAOT-only UnexpectedWarning entries for attribute-on-property/event dataflow scenarios.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs Tracks processed property/event custom attribute handles to support deduplication.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CustomAttributeBasedDependencyAlgorithm.cs Uses the new tracking to skip re-analyzing the same property/event custom attributes (and re-emitting the same diagnostics).

@eduardo-vp
Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +78 to +80
if (mdManager.TryRegisterPropertyCustomAttributesProcessed(method.Module, propertyHandle))
AddDependenciesDueToCustomAttributes(ref dependencies, propertyCondition, factory, method.Module, property.GetCustomAttributes(), new PropertyPseudoDesc(method.OwningType, propertyHandle));
}
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.

We don't model things like this because when looking at the dependency graph, the first accessor gets to be blamed for bringing these dependencies into the graph whereas all accessors are to blame. It also runs the risk of being non-determinsitic in the presence of threading within the compiler.

We'd want to instead address the comment block above: "We don't model properties and events as separate entities within the compiler, so ensuring we can generate custom attributes for the associated events and properties from here is as good as any other place.". Instead of each accessor bringing in dependencies for custom attributes on the property definition, each accessor should just bring a dependency on the property.

We'd only scan the property once (because it's just one node in the graph) so the rest will fall out and we can still attribute each dependency in the graph to what really depends on it.

So add a PropertyMetadataNode (will look similar to the existing FieldMetadataNode). Remove the call to AddDependenciesDueToCustomAttributes from here (instead we'll call it in the new PropertyMetadataNode.GetConditionalStaticDependencies, same as FieldMetadataNode does). We also remove property/method handling from here completely and instead do this in MethodMetadataNode.GetStaticDependencies (check if the method is an accessor and if it is, add a dependencies.Add(factory.PropertyMetadata(new PropertyPseudoDesc(method.OwningType, propertyHandle)) into the graph).

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

Labels

area-NativeAOT-coreclr linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ILC: Duplicate warnings for attribute on property dataflow

3 participants