Navigation Menu

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

Sprinkle some more readonly around #81297

Merged
merged 4 commits into from Feb 14, 2023
Merged

Conversation

stephentoub
Copy link
Member

No description provided.

@ghost
Copy link

ghost commented Jan 27, 2023

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: stephentoub
Assignees: stephentoub
Labels:

area-Meta

Milestone: -

@KirillKornienko
Copy link

All the time I'd like to ask if there's a performance/gc difference between a "read-only" or non-read-only field? Can this be optimized at runtime (e.g. null-checking if readonly field is already set and can never be null after that)? Or is it just syntax to reflect the programmer's intent?

@stephentoub
Copy link
Member Author

if there's a performance/gc difference between a "read-only" or non-read-only field?

There can be a perf benefit, in particular for static fields.

Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

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

Changes to types in my ownership area look correct.

Generally scanned the other changes too and they also look sensible, but should likely get secondary eyes from the respective owners.

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Scanning through, this all looks straightforward and I presume the compiler would have yelled if anything was amiss.

@stephentoub I'm curious how you went about identifying these sites. Are there more layers of sprinkles to add?

@stephentoub
Copy link
Member Author

I presume the compiler would have yelled if anything was amiss.

Mostly. The main risk would be making a field containing a mutable struct readonly; the compiler wouldn't complain but it could have bad behavioral impact.

I'm curious how you went about identifying these sites. Are there more layers of sprinkles to add?

IDE0044. Unfortunately it's currently too noisy for us to enable outright, but I did locally and addressed many of the valid cases.

@@ -11,7 +11,7 @@ namespace System.Globalization
public sealed class SortVersion : IEquatable<SortVersion?>
{
private readonly int m_NlsVersion; // Do not rename (binary serialization)
private Guid m_SortId; // Do not rename (binary serialization)
private readonly Guid m_SortId; // Do not rename (binary serialization)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not this break serialization support?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe it does. @GrabYourPitchforks?

@stephentoub stephentoub merged commit 58d1ecb into dotnet:main Feb 14, 2023
@stephentoub stephentoub deleted the morereadonly branch February 14, 2023 20:33
@dotnet dotnet locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants