Skip to content

Add CompilerLoweringPreserveAttribute #117729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Jul 16, 2025

And apply it to DynamicallyAccessedMembersAttribute. This ensures that DAM flows to compiler-generated code.

Fixes #103430
Fixes #101861 (tests are in a separate PR: #117624)

And apply it to DynamicallyAccessedMembersAttribute.
This ensures that DAM flows to compiler-generated code.
@sbomer sbomer requested review from a team and Copilot July 16, 2025 18:33
Copy link
Contributor

@Copilot 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 introduces a new CompilerLoweringPreserveAttribute and applies it to DynamicallyAccessedMembersAttribute to ensure that dynamically accessed members information flows correctly to compiler-generated code. This addresses issue #103430 where the DAM attribute was not being preserved during compiler lowering transformations.

Key changes:

  • Adds a new CompilerLoweringPreserveAttribute class for marking attributes that should be preserved during compiler lowering
  • Applies this attribute to DynamicallyAccessedMembersAttribute to fix the flow issue
  • Updates project files to include the new attribute in builds targeting older frameworks

Reviewed Changes

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

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CompilerLoweringPreserveAttribute.cs New attribute class definition with conditional visibility
src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMembersAttribute.cs Applies the new preserve attribute to DAM
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems Includes new attribute in shared project items
src/libraries/System.Runtime/ref/System.Runtime.cs Adds reference API surface for the new attribute and decorates DAM
src/libraries/System.Text.Json/src/System.Text.Json.csproj Includes new attribute for non-.NET Core builds
src/libraries/System.Text.Json/ref/System.Text.Json.csproj Includes new attribute in reference assembly

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 16, 2025
Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@tannergooding tannergooding added area-System.Runtime.CompilerServices and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 17, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices
See info in area-owners.md if you want to be subscribed.

@sbomer
Copy link
Member Author

sbomer commented Jul 18, 2025

/ba-g "timeout"

@sbomer sbomer merged commit 757fb9d into dotnet:main Jul 18, 2025
140 of 145 checks passed
@sbomer sbomer deleted the compilerLoweringPreserve branch July 21, 2025 23:09
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.

[API Proposal]: CompilerLoweringPreserveAttribute Erroneous linker error when using DAM attributes + primary constructors
3 participants