Skip to content

[MilCodeGen] Declare Equals/GetHashCode and property getters for fields as readonly #10618

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented Mar 22, 2025

Description

Modifies MilCodeGen to generate readonly getters for fields where SkipProperties="false", in case the properties are skipped (SkipProperties="true") they live in the non-generated area and thus were modified manually.

  • The Equals override uses new syntax and is readonly.
  • The non-override Equals is now readonly.
  • GetHashCode is readonly and all the supporting props (IsEmpty, IsDistinguishedIdentity) are readonly to prevent copies in the particular call chain.

Rest of the members that were not in the impact zone are left untouched and shall be done separately in subsequent PRs.

Customer Impact

Increased performance/better codegen.

Regression

No.

Testing

Local build, most of the generated structs have unit tests already including Equals/GetHashCode checks.

Risk

Low. The point to consider is whether we could make any of the members that are to become readonly mutate the struct in the future, for me that answer is no. Equals/GetHashCode should never modify the state, even on mutable structs.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners March 22, 2025 11:20
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Mar 22, 2025

[[resource.Name]] value = ([[resource.Name]])o;
return [[resource.Name]].Equals(this,value);
return o is [[resource.Name]] other && [[resource.Name]].Equals(this, other);
Copy link
Member Author

@h3xds1nz h3xds1nz Mar 22, 2025

Choose a reason for hiding this comment

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

We could use [[lowerName]] (which is the resource name in lower-camelCase) if desirable instead of other.

I'm fine eitherway.

Copy link

codecov bot commented Mar 22, 2025

Codecov Report

Attention: Patch coverage is 27.77778% with 13 lines in your changes missing coverage. Please review.

Project coverage is 11.46188%. Comparing base (b6914d7) to head (46b2614).
Report is 16 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #10618         +/-   ##
===================================================
+ Coverage   11.45872%   11.46188%   +0.00316%     
===================================================
  Files           3214        3214                 
  Lines         648458      648410         -48     
  Branches       71511       71511                 
===================================================
+ Hits           74305       74320         +15     
+ Misses        572989      572927         -62     
+ Partials        1164        1163          -1     
Flag Coverage Δ
Debug 11.46188% <27.77778%> (+0.00316%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dipeshmsft dipeshmsft self-assigned this Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Change Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants