-
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
Readonly members metadata #34260
Readonly members metadata #34260
Conversation
Note that |
Could I get a second review please @dotnet/roslyn-compiler #Closed |
@@ -315,7 +315,7 @@ internal virtual bool IsExplicitInterfaceImplementation | |||
/// Indicates whether the method is effectively readonly, | |||
/// by either the method or the containing type being marked readonly. | |||
/// </summary> | |||
internal bool IsEffectivelyReadOnly => (IsDeclaredReadOnly || ContainingType?.IsReadOnly == true) && MethodKind != MethodKind.Constructor; | |||
internal bool IsEffectivelyReadOnly => (IsDeclaredReadOnly || ContainingType?.IsReadOnly == true) && MethodKind != MethodKind.Constructor && !IsStatic; |
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.
!IsStatic; [](start = 149, length = 10)
should we also check that the containing type isn't a value type, as we do in PEMethodSymbol.IsDeclaredReadOnly
? #Closed
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.
PEMethodSymbol.IsDeclaredReadOnly
is meant to avoid traversing attributes in cases where readonly
can be ruled out, in the vein of PEMethodSymbol.IsExtensionMethod
. One thing I'm curious about is to what extent the existing concessions/optimizations around IsExtensionMethod
are necessary for IsReadOnly
.
It also appears that ContainingType.IsReadOnly
returns false
on a readonly class
declaration due to the design of SourceMemberContainerSymbol.MakeModifiers()
. #Resolved
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.
Not sure I understand the IsStatic
addition here. Shouldn't all static
methods be implicitly readonly since they can't modify this
?
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 looked at it the other way: "readonly" is not even a valid concept for static
methods, so we can say they are not "readonly".
I could go either way. #Closed
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.
Seems like it depends on what you want the API to mean. Do you want it to mean "this
is not writable" or do you want it to mean "this
is a ref readonly
parameter"?
In other words, this
cannot even be read in the static method, so to say that the static method is "effectively readonly" is maybe wrong.
In reply to: 267528694 [](ancestors = 267528694)
something to consider for a follow-up: I see that we're only adding the attribute for source method symbols. I wonder if there are other method symbols we should consider (some synthesized ones in particular). #Closed Refers to: src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs:1617 in c9bd1b6. [](commit_id = c9bd1b6, deletion_comment = False) |
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenReadonlyStructTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
Outdated
Show resolved
Hide resolved
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.
Done with review pass (iteration 4).
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.
🕐
Not certain. There's a few requirements for this to provide a benefit:
Might be useful to enumerate any cases where (1) is true and then determine if (2) could be true for it. In reply to: 474958652 [](ancestors = 474958652) Refers to: src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs:1617 in c9bd1b6. [](commit_id = c9bd1b6, deletion_comment = False) |
Finished the requested changes. Please have a look. @jaredpar #Closed |
Done with review pass (iteration 7). Some minor feedback. #Closed |
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 added a note to the test plan In reply to: 474994280 [](ancestors = 474994280,474958652) Refers to: src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs:1617 in c9bd1b6. [](commit_id = c9bd1b6, deletion_comment = False) |
Related to #32911
This makes it easier to track the relationship between the specification evolving and the implementation changing for the purpose of feature development.