Skip to content

Add CompilerGeneratedAttribute to EqualityContract property#61993

Merged
jcouv merged 8 commits intodotnet:mainfrom
Youssef1313:patch-20
Jun 27, 2022
Merged

Add CompilerGeneratedAttribute to EqualityContract property#61993
jcouv merged 8 commits intodotnet:mainfrom
Youssef1313:patch-20

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

Closes #61991

@Youssef1313 Youssef1313 requested a review from a team as a code owner June 17, 2022 17:02
@ghost ghost added Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Jun 17, 2022
@AlekseyTs
Copy link
Copy Markdown
Contributor

I am not sure why this PR is supposed to close #61991. It looks like that issue discusses completely different scenario and, perhaps, should be closed "By Design" on its own. It is quite possible that the decision somehow contributes to a decision to make the change presented here, but they are still not the same.

@AlekseyTs
Copy link
Copy Markdown
Contributor

@Youssef1313 It looks like there are legitimate test failures

{
}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Jun 21, 2022

Choose a reason for hiding this comment

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

AddSynthesizedAttributes

Is there any harm from keeping the attribute on the accessor as well? #Closed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There shouldn't be any harm, it's just redundant. If the property is compiler-generated, then for sure the accessors are.

From the old PR:

image


This is also consistent with what's done in other compiler-generated symbols. For example:

// do not emit CompilerGenerated attributes for fields inside compiler generated types:

Here, a synthesized field will not have the attribute if the containing type already has it.

So the attribute is usually put on the outer most compiler-generated symbol.

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.

If the property is compiler-generated, then for sure the accessors are.

I don't think this is a safe assumption in general. For C# compiler, sure. But in metadata accessors and properties are distinct and each has its own set of attributes. I can easily imagine a synthesized property that uses user-defined methods as accessors.

do not emit CompilerGenerated attributes for fields inside compiler generated types

This isn't the same though, I think. In the type system (and I am not talking about C# exclusively), a field is contained by a type, it cannot be defined if there is no type. So, it is relatively safe to assume that a user cannot define a field in a compiler generated type. Accessors, however, are not contained by a property (despite what C# syntax might lead you to believe), properties and accessors are siblings, they are just linked in a special way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I see that from the metadata perspective. I'll add the attribute on both the property and the accessors.

@AlekseyTs
Copy link
Copy Markdown
Contributor

I think we need a clear explanation why do we want to make this change. It is quite possible I missed something, but I did not find it in the referenced issue.

@AlekseyTs
Copy link
Copy Markdown
Contributor

Done with review pass (commit 2)

@Youssef1313
Copy link
Copy Markdown
Member Author

I am not sure why this PR is supposed to close #61991. It looks like that issue discusses completely different scenario and, perhaps, should be closed "By Design" on its own. It is quite possible that the decision somehow contributes to a decision to make the change presented here, but they are still not the same.

Yeah the original issue can just be closed as by-design. It's just the conversation there led to revising where CompilerGeneratedAttribute is added.

@Youssef1313 Youssef1313 changed the title Move CompilerGeneratedAttribute from EqualityContract get accessor to the property itself Add CompilerGeneratedAttribute to EqualityContract property Jun 21, 2022
@AlekseyTs
Copy link
Copy Markdown
Contributor

Done with review pass (commit 4). It looks like there are legitimate test failures.

@AlekseyTs
Copy link
Copy Markdown
Contributor

Done with review pass (commit 6). It looks like there are still tests that require a baseline adjustment.

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 7)

@AlekseyTs
Copy link
Copy Markdown
Contributor

@jcouv, @dotnet/roslyn-compiler For the second review.

Copy link
Copy Markdown
Member

@jcouv jcouv 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 (iteration 8)

@jcouv jcouv self-assigned this Jun 25, 2022
@jcouv jcouv enabled auto-merge (squash) June 27, 2022 03:29
@jcouv jcouv disabled auto-merge June 27, 2022 16:41
@jcouv jcouv merged commit 55e5f53 into dotnet:main Jun 27, 2022
@ghost ghost added this to the Next milestone Jun 27, 2022
@Youssef1313 Youssef1313 deleted the patch-20 branch June 27, 2022 17:02
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revise CompilerGeneratedAttribute behavior when records are inherited

4 participants