Skip to content
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

Conversation

AlekseyTs
Copy link
Contributor

  • 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 #73920.

- 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.
@AlekseyTs AlekseyTs requested a review from a team as a code owner December 26, 2024 17:47
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 26, 2024
Copy link
Member

@333fred 333fred left a 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)

@AlekseyTs AlekseyTs requested a review from 333fred December 27, 2024 17:09
@AlekseyTs
Copy link
Contributor Author

@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)
Copy link
Member

@cston cston Dec 30, 2024

Choose a reason for hiding this comment

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

IsThis

It looks like this overload is only used in one location, in GetCapturedVariableFieldName() below. Consider inlining the call there and removing this overload. #WontFix

Copy link
Contributor Author

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);
}
}
Copy link
Member

@cston cston Dec 31, 2024

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

Copy link
Contributor Author

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()
Copy link
Member

@cston cston Dec 31, 2024

Choose a reason for hiding this comment

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

CompilerLoweringPreserveAttribute_01

Did the behavior of these two tests change with this PR? #Resolved

Copy link
Contributor Author

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()
Copy link
Member

@cston cston Dec 31, 2024

Choose a reason for hiding this comment

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

CompilerLoweringPreserveAttribute_01

Did the behavior of these two tests change with this PR? #Resolved

Copy link
Contributor Author

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 { }
Copy link
Member

@cston cston Dec 31, 2024

Choose a reason for hiding this comment

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

Preserve1Attribute

What are we testing with no [CompilerLoweringPreserve] attribute? #Resolved

Copy link
Contributor Author

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
Copy link
Member

@cston cston Dec 31, 2024

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

Copy link
Contributor Author

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.

@AlekseyTs AlekseyTs requested a review from cston January 2, 2025 18:14
@AlekseyTs AlekseyTs merged commit bfa4f1a into dotnet:features/GeneratedCodeAttributes Jan 2, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants