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

Readonly members metadata #34260

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Mar 19, 2019

Related to #32911

@RikkiGibson RikkiGibson requested a review from a team as a code owner March 19, 2019 19:58
@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Mar 19, 2019

Note that MethodSymbol.IsEffectivelyReadOnly now always returns false for a static method. #Resolved

@RikkiGibson RikkiGibson added this to the 16.1.P1 milestone Mar 19, 2019
@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Mar 19, 2019

Could I get a second review please @dotnet/roslyn-compiler #Closed

@jcouv jcouv self-assigned this Mar 20, 2019
@@ -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;
Copy link
Member

@jcouv jcouv Mar 20, 2019

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

Copy link
Contributor Author

@RikkiGibson RikkiGibson Mar 20, 2019

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

Copy link
Member

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?

Copy link
Member

@jcouv jcouv Mar 20, 2019

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

Copy link
Contributor Author

@RikkiGibson RikkiGibson Mar 20, 2019

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)

@jcouv
Copy link
Member

jcouv commented Mar 20, 2019

    internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)

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)

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

Done with review pass (iteration 4).

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

🕐

@RikkiGibson
Copy link
Contributor Author

    internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)

Not certain. There's a few requirements for this to provide a benefit:

  1. must be an instance method on a struct type
  2. must be called on a ref readonly/in variable

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)

@RikkiGibson RikkiGibson requested a review from jaredpar March 20, 2019 23:14
@RikkiGibson RikkiGibson requested a review from a team March 20, 2019 23:14
@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Mar 20, 2019

Finished the requested changes. Please have a look. @jaredpar #Closed

@jaredpar
Copy link
Member

jaredpar commented Mar 20, 2019

Done with review pass (iteration 7). Some minor feedback. #Closed

@RikkiGibson RikkiGibson requested a review from jaredpar March 20, 2019 23:59
Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

:shipit:

@RikkiGibson RikkiGibson merged commit c2b2777 into dotnet:features/readonly-members Mar 21, 2019
@RikkiGibson RikkiGibson deleted the readonly-members-metadata branch March 21, 2019 18:00
@RikkiGibson RikkiGibson mentioned this pull request Mar 21, 2019
52 tasks
@jcouv
Copy link
Member

jcouv commented Mar 21, 2019

    internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants