Skip to content

Share CoreCLR CustomAttributeData with native AOT - #133338

Open
MichalStrehovsky wants to merge 13 commits into
mainfrom
share-customattribute-data
Open

Share CoreCLR CustomAttributeData with native AOT#133338
MichalStrehovsky wants to merge 13 commits into
mainfrom
share-customattribute-data

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Stack created with GitHub Stacks CLIGive Feedback 💬

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

🟡 Changes recommended

The NativeAOT Handle.ParseConstantValue change drops enum constant handling, which breaks default-value parsing for enum-backed constants by throwing BadImageFormatException.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors NativeAOT reflection custom-attribute handling to reuse the CoreCLR RuntimeCustomAttributeData implementation, replacing the prior NativeAOT-specific RuntimeCustomAttributeData/NativeFormatCustomAttributeData types and plumbing NativeAOT reflection objects to provide MetadataReader + CustomAttributeHandleCollection.

Changes:

  • Share System.Reflection.RuntimeCustomAttributeData with NativeAOT via #if NATIVEAOT paths and a ResolutionScope alias, including a NativeFormat attribute parser.
  • Update NativeAOT reflection types (Type/Method/Field/Event/Property/Module/Assembly/Parameter) to route GetCustomAttributesData() through the shared implementation and provide metadata accessors.
  • Remove the NativeAOT-only System.Reflection.Runtime.CustomAttributes.* implementations and update the NativeAOT CoreLib project file accordingly.
File summaries
File Description
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs Adds NativeAOT support paths and NativeFormat parsing to share CoreCLR implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs Routes NativeAOT RuntimeType.GetCustomAttributesData() to shared implementation; adds metadata accessors.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs Routes GetCustomAttributesData() to shared implementation; adds virtual metadata accessors.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs Adds virtual metadata accessors for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs Removes CustomAttributes abstraction and adds metadata accessors used by shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeNamedTypeInfo.cs Removes CustomAttributes implementation previously combining true+pseudo attributes.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs Removes CustomAttributes override returning empty.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs Removes now-unneeded CustomAttributes namespace usage.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeFunctionPointerTypeInfo.cs Removes CustomAttributes override returning empty.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs Delegates metadata accessors to generic type definition.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeNamedTypeInfo.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/PropertyInfos/RuntimePropertyInfo.cs Routes GetCustomAttributesData() to shared implementation; adds metadata accessors.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/PropertyInfos/NativeFormat/NativeFormatRuntimePropertyInfo.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimeThinMethodParameterInfo.cs Removes CustomAttributes override returning empty.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimeSyntheticParameterInfo.cs Removes CustomAttributes override returning empty.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimePropertyIndexParameterInfo.cs Delegates metadata accessors to backing parameter for shared retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimeParameterInfo.cs Routes GetCustomAttributesData() to shared implementation; adds metadata accessors.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimeFatMethodParameterInfo.cs Removes prior CustomAttributes/TrueCustomAttributes layering.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/NativeFormat/NativeFormatMethodParameterInfo.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Modules/RuntimeModule.cs Routes GetCustomAttributesData() to shared implementation; adds metadata accessors; changes IsResource() to false.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Modules/NativeFormat/NativeFormatRuntimeModule.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeSyntheticMethodInfo.cs Removes CustomAttributes override returning empty.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeSyntheticConstructorInfo.cs Removes CustomAttributes override returning empty.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimePlainConstructorInfo.cs Delegates metadata accessors to method common implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeNamedMethodInfo.cs Replaces CustomAttributes implementation with metadata accessors for shared retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeDummyMethodInfo.cs Removes CustomAttributes override throwing NotImplemented.ByDesign.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeConstructorInfo.cs Routes GetCustomAttributesData() to shared implementation; adds metadata accessors.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeConstructedGenericMethodInfo.cs Delegates metadata accessors to generic method definition.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/NativeFormat/NativeFormatMethodCommon.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/IRuntimeMethodCommon.cs Replaces TrueCustomAttributes with metadata accessors contract.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs Simplifies constant parsing and removes array/enum/type constant support helpers.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Dispensers.NativeFormat.cs Removes NativeAOT RuntimeCustomAttributeData factory previously used for attributes.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs Routes GetCustomAttributesData() to shared implementation; adds metadata accessors; adjusts explicit-layout offset exposure.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/FieldInfos/NativeFormat/NativeFormatRuntimeFieldInfo.cs Exposes metadata reader + attribute handles + explicit offset for shared retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/EventInfos/RuntimeEventInfo.cs Routes GetCustomAttributesData() to shared implementation; adds metadata accessors.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/EventInfos/NativeFormat/NativeFormatRuntimeEventInfo.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/RuntimePseudoCustomAttributeData.cs Deleted: old NativeAOT pseudo CustomAttributeData implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/RuntimeCustomAttributeData.cs Deleted: old NativeAOT CustomAttributeData base implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/CustomAttributes/NativeFormat/NativeFormatCustomAttributeData.cs Deleted: old NativeAOT NativeFormat-backed CustomAttributeData implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/RuntimeAssemblyInfo.cs Routes GetCustomAttributesData() to shared implementation.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.cs Exposes metadata reader + attribute handles for shared attribute retrieval.
src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Adds shared CoreCLR RuntimeCustomAttributeData.cs compile item and removes deleted NativeAOT custom-attribute files.
Review details
  • Files reviewed: 43/43 changed files
  • Comments generated: 1
  • Review effort level: Lite

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

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.

🟡 Changes recommended

The NativeAOT fixed-argument parsing currently doesn’t reject extra fixed arguments (malformed metadata) and the new NativeAOT CustomAttributeData path lacks dedicated test coverage to guard against regressions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 43/43 changed files
  • Comments generated: 2
  • Review effort level: Lite

Base automatically changed from copilot/share-listbuilder-coreclr-native-aot to main September 7, 2026 12:37
MichalStrehovsky and others added 13 commits September 7, 2026 21:39
Compile the CoreCLR-owned implementation in NativeAOT and keep the metadata-specific behavior behind NATIVEAOT conditionals. Remove the duplicated NativeAOT custom attribute data hierarchy and align the namespace with CoreCLR.

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

Copilot-Session: 104a8c3f-92e7-4fe4-8e14-8cde7b18f20a
NativeAOT stores custom attribute constructors as qualified method definitions. Treat other handle kinds as malformed metadata instead of retaining dead MemberReference handling.

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

Copilot-Session: 104a8c3f-92e7-4fe4-8e14-8cde7b18f20a
Compile CoreCLR's pseudo custom attribute data construction for NativeAOT and use attribute instances at the NativeAOT call sites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0005a0aa-9ff2-4b11-bed7-ea205ad136b1
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0005a0aa-9ff2-4b11-bed7-ea205ad136b1
Also brings back the `ResolveAttributeConstructor` with the bugfix in the ParameterInfo/Type .Equals comparison.

This reverts commit ea41324.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Don't like it but it's a start.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7bea1165-1cff-4510-b92f-6b4f822033ce

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.

🟡 Changes recommended

The critical named-argument discriminator bug can produce incorrect attribute data and instantiation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 43/43 changed files
  • Comments generated: 1
  • Review effort level: Balanced

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants