Skip to content

Share Attribute implementation with NativeAOT - #132821

Merged
MichalStrehovsky merged 5 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-share-attribute-implementation
Sep 1, 2026
Merged

Share Attribute implementation with NativeAOT#132821
MichalStrehovsky merged 5 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-share-attribute-implementation

Conversation

@MichalStrehovsky

@MichalStrehovsky MichalStrehovsky commented Aug 27, 2026

Copy link
Copy Markdown
Member

Deletes 600+ lines of native AOT specific code.

Fixes #73356

Use the CoreCLR Attribute implementation in NativeAOT and align the runtime reflection custom attribute layering. Remove the duplicated NativeAOT facade, legacy API aggregation, and generic searcher hierarchy.

Use the CoreCLR Attribute implementation in NativeAOT and align the runtime reflection custom attribute layering. Remove the duplicated NativeAOT facade, legacy API aggregation, and generic searcher hierarchy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: cdfa51d4-b08c-4fc4-836d-ad41d04d3c15
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.
@MichalStrehovsky

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).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 160e0b66-0384-4c50-b528-c9cd36496cee
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 69dacc0c-3e1b-4730-b772-f4e6132650a4
@MichalStrehovsky
MichalStrehovsky marked this pull request as ready for review August 28, 2026 05:16
Copilot AI lite review requested due to automatic review settings August 28, 2026 05:16
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors NativeAOT’s reflection custom-attribute stack to reuse the CoreCLR Attribute implementation and a shared matching/instantiation helper, removing duplicated NativeAOT-only attribute searcher/facade layers. It also re-enables the previously skipped System.Reflection.Context tests on NativeAOT by addressing the underlying attribute-layering mismatch.

Changes:

  • Switch NativeAOT to compile and use System/Attribute.CoreCLR.cs, exposing Attribute.InternalGetAttributeUsage for the shared attribute matching logic.
  • Introduce RuntimeCustomAttribute for NativeAOT and route GetCustomAttributes*/IsDefined/GetCustomAttributesData overrides through it across reflection runtime types.
  • Delete legacy NativeAOT custom attribute aggregation/searcher infrastructure and re-enable previously skipped tests tied to #73356.

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Reflection.Context/tests/CustomReflectionContextTests.cs Removes NativeAOT ActiveIssue gate so the fixed scenario runs on NativeAOT.
src/libraries/System.Reflection.Context/tests/CustomReflectionContext.Examples.cs Removes NativeAOT ActiveIssue gate for the example-based test.
src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs Makes InternalGetAttributeUsage accessible for reuse and adds helper for attribute array creation; adds NativeAOT-specific usings.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttribute.NativeAot.cs New shared helper for matching/instantiating attributes (including inheritance walk where applicable).
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/PropertyInfos/RuntimePropertyInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute (desktop-compat “inherit ignored” behavior preserved).
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimeParameterInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute (desktop-compat “inherit ignored” behavior preserved).
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Modules/RuntimeModule.cs Routes custom-attribute APIs through RuntimeCustomAttribute (inherit meaningless).
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeMethodInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute; updates base-definition traversal to the new override helper.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeConstructorInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/LegacyCustomAttributeApis.cs Deletes legacy NativeAOT per-type “older-style” custom-attribute API implementations.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Helpers.cs Removes the old InstantiateAsArray helper now superseded by the new attribute pipeline.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/EventInfos/RuntimeEventInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute (desktop-compat “inherit ignored” behavior preserved).
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/Shared.cs Reworks implicit-override discovery into a MethodInfo-focused helper with suppression for reflection analysis.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/PropertyPolicies.cs Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/NestedTypePolicies.cs Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/MethodPolicies.cs Adjusts override detection entrypoint to a static helper for the new override discovery flow.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs Removes abstract members that were only required for the legacy generic override/member enumeration path.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/FieldPolicies.cs Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/EventPolicies.cs Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/ConstructorPolicies.cs Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/RuntimeAssemblyInfo.cs Routes custom-attribute APIs through RuntimeCustomAttribute (inherit meaningless).
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Attribute.NativeAot.cs Deletes the NativeAOT-specific Attribute implementation in favor of the shared CoreCLR one.
src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Includes CoreCLR Attribute.CoreCLR.cs, adds RuntimeCustomAttribute.NativeAot.cs, and removes legacy custom-attribute sources.
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeSearcher.cs Deletes the legacy generic searcher hierarchy.
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs Deletes legacy matching/inheritance extension layer superseded by the shared implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs Removes wrappers that depended on the old generic override/member discovery APIs.
@MichalStrehovsky

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).
@MichalStrehovsky

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 thread src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs Outdated
Copilot AI review requested due to automatic review settings August 31, 2026 05:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Review details
  • Files reviewed: 29/29 changed files
  • Comments generated: 0 new
  • Review effort level: Lite
@MichalStrehovsky
MichalStrehovsky merged commit ab5af9e into dotnet:main Sep 1, 2026
125 of 127 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-share-attribute-implementation branch September 1, 2026 01:04
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants