-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: CompilerLoweringPreserveAttribute #103430
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
Want to make sure we've marked this so that it's a |
Should this be tracked as a C# / Roslyn feature in dotnet/roslyn or dotnet/csharplang? Discussion in runtime would subsequently just be about naming. |
dotnet/roslyn#73920 is the tracking issue for Roslyn, is that what you're looking for? |
Is |
I put |
Background and motivation
Context: dotnet/roslyn#73920
In short, we need a way to indicate that the compiler should flow attributes from C# code to compiler-generated symbols, to aid downstream IL-based analysis tools. This behavior will be opt-in per attribute type, when the attribute type is annotated with
CompilerLoweringPreserveAttribute
.API Proposal
API Usage
CompilerLoweringPreserveAttribute
shall be placed on an attribute definition to indicate that this attribute should flow to compiler-generated symbols:For example, when the compiler generates fields for primary constructor parameters, attributes flow from source parameters to compiler-generated fields.
Original:
Generated IL (pseudo-C#)
(Note this does not specify whether the compiler generates a field - just that if it does, the attribute flows as long as it has compatible AttributeTargets. See discussion in dotnet/roslyn#73920).
CompilerLoweringPreserveAttribute
will be applied toDynamicallyAccessedMembersAttribute
, to allow primary constructors, and other constructs that lower to compiler-generated types/members, to be annotated for trimming without requiring ILLink to do as much reverse-engineering of the compiler-generated constructs.Alternative Designs
CompilerLoweringPreserveAttribute
) with compatible AttributeTargets. This would lead to metadata bloat and possible unexpected semantics for attributes that have different meanings for different AttributeTargets.Risks
There is some risk that this will lead to more downstream tools taking a dependency on the compiler-generated code. We should make it clear that this is not a guarantee of any particular rewrite strategy from C# to IL. Any tooling which looks for
CompilerLoweringPreserveAttribute
-annotated attributes should not rely on the lowering strategy and may need to be adjusted in response to compiler changes.@agocke @jaredpar @dotnet/appmodel
The text was updated successfully, but these errors were encountered: