-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Propagate marked attributes to synthesized fields. #76567
Propagate marked attributes to synthesized fields. #76567
Conversation
- From a parameter to a state machine field - From a parameter to a closure field - From a VB property/event to a backing field Related to dotnet#73920.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor reuse comment, otherwise looks good (commit 2)
src/Compilers/CSharp/Portable/Lowering/ClosureConversion/LambdaCapturedVariable.cs
Outdated
Show resolved
Hide resolved
@dotnet/roslyn-compiler Please review |
bool isThis = IsThis(captured, out ParameterSymbol? parameter); | ||
return parameter is not null && !isThis ? | ||
new LambdaCapturedVariableForRegularParameter(frame, TypeWithAnnotations.Create(type), fieldName, parameter) : | ||
new LambdaCapturedVariable(frame, TypeWithAnnotations.Create(type), fieldName, isThis); | ||
} | ||
|
||
private static bool IsThis(Symbol captured) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to not adjust existing consumers of this helper.
{ | ||
AddSynthesizedAttribute(ref attributes, attr); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block to copy attributes is repeated in several locations. Would it make sense to extract a helper method? #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block to copy attributes is repeated in several locations. Would it make sense to extract a helper method?
I do not think this is worth doing.
@@ -2487,5 +2487,283 @@ class Test | |||
} | |||
|
|||
#endregion | |||
|
|||
[Fact] | |||
public void CompilerLoweringPreserveAttribute_01() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the behavior of these two tests change with this PR?
No, the behavior did not change.
@@ -3026,5 +3026,74 @@ class C | |||
var property = compilation.GetMember<PropertySymbol>("C.P"); | |||
Assert.True(property.RequiresInstanceReceiver); | |||
} | |||
|
|||
[Fact] | |||
public void CompilerLoweringPreserveAttribute_01() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the behavior of these two tests change with this PR?
No, it didn't.
using System; | ||
|
||
[AttributeUsage(AttributeTargets.Field)] | ||
public class Preserve1Attribute : Attribute { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we testing with no
[CompilerLoweringPreserve]
attribute?
We are testing that the field:
target allows to apply any attribute to the field explicitly. Therefore, no special treatment around CompilerLoweringPreserve
is necessary.
(attributeType.GetAttributeUsageInfo().ValidTargets And System.AttributeTargets.Field) <> 0 Then | ||
AddSynthesizedAttribute(attributes, attr) | ||
End If | ||
Next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is used in a couple of locations. Would it make sense to extract a helper method? #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is used in a couple of locations. Would it make sense to extract a helper method?
I do not think this is worth doing.
bfa4f1a
into
dotnet:features/GeneratedCodeAttributes
Related to #73920.