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 symbol display #34876

Merged

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Apr 9, 2019

Part of #34650

@RikkiGibson RikkiGibson requested a review from a team as a code owner April 9, 2019 19:26
@RikkiGibson RikkiGibson added Area-Compilers Area-IDE IDE-IntelliSense Completion, Signature Help, Quick Info labels Apr 9, 2019
@@ -168,6 +173,11 @@ public override void VisitEvent(IEventSymbol symbol)
AddAccessibilityIfRequired(symbol);
AddMemberModifiersIfRequired(symbol);

if ((symbol.AddMethod ?? symbol.RemoveMethod)?.IsReadOnly == true)
Copy link
Member

@cston cston Apr 10, 2019

Choose a reason for hiding this comment

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

(symbol.AddMethod ?? symbol.RemoveMethod)?.IsReadOnly == true [](start = 16, length = 61)

What if add is readonly but remove is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't provide a way to declare such a combination of event accessors in the language, so I'd write it off as a malformed symbol that we can't display reliably--we just need to avoid crashing.

@RikkiGibson RikkiGibson requested a review from a team as a code owner April 10, 2019 21:42
@RikkiGibson
Copy link
Contributor Author

So it looks like a lot of modifiers such as public, virtual, static, etc. don't show in Quick Info for members. I decided that readonly should show because it affects the ref kind of the this parameter and we show ref modifiers on parameter and return types in general. Let me know what you think.

@RikkiGibson RikkiGibson requested a review from jmarolf April 10, 2019 21:45
@RikkiGibson
Copy link
Contributor Author

Looks like changing symbol display might have broken a bunch of IL tests?

@jaredpar
Copy link
Member

Part of the print out of IL includes symbol display and the methods used here have some readonly in them. Not members so it's suprising that this broke.


In reply to: 481947213 [](ancestors = 481947213)

@RikkiGibson
Copy link
Contributor Author

Putting this on hold until we have a chance to discuss the design

@RikkiGibson
Copy link
Contributor Author

We concluded in design that "explicitly readonly" members should show a 'readonly' keyword in Quick Info. If the member is only readonly due to the containing struct being 'readonly', then we don't show the keyword. /cc @sharwell @jasonmalinowski. Will revise accordingly when I get the chance (focusing on #34778 first)

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 6)

@jcouv jcouv self-assigned this Apr 18, 2019
@jcouv jcouv added this to the 16.2 milestone Apr 23, 2019
@jcouv
Copy link
Member

jcouv commented Apr 23, 2019

Marked PR as "private" for now. Remove the tag once ready for another look. Thanks

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Apr 23, 2019
@@ -367,7 +367,7 @@ .maxstack 2
IL_0003: stfld ""int S.<X>k__BackingField""
IL_0008: ldarg.0
IL_0009: ldarg.0
IL_000a: call ""int S.X.get""
IL_000a: call ""readonly int S.X.get""
Copy link
Contributor Author

@RikkiGibson RikkiGibson Apr 30, 2019

Choose a reason for hiding this comment

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

One quirk of this work: after a property is emitted we have no decent way of knowing whether it was implicitly readonly in source. So when the member is in a non-readonly type we just display readonly if the IsReadOnlyAttribute is present on the member.

I tried to avoid displaying readonly where it was not present in source, and for members of readonly types, because it minimizes test churn and limits showing the keyword to cases where its presence or absence will be more informative.

@@ -68,6 +68,8 @@ public enum SymbolDisplayMemberOptions

/// <summary>
/// Includes the <c>ref</c>, <c>ref readonly</c>, <c>ByRef</c> keywords for ref-returning methods and properties/indexers.
/// Also includes the <c>readonly</c> keyword on methods, properties/indexers, and events due to the keyword
/// changing the <c>this</c> parameter's ref kind from <c>ref</c> to <c>ref readonly</c>.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @jcouv

Copy link
Member

Choose a reason for hiding this comment

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

This seems fishy. Is this a name we regret and should fix?

@RikkiGibson RikkiGibson removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label May 2, 2019
@RikkiGibson
Copy link
Contributor Author

PTAL @dotnet/roslyn-compiler @dotnet/roslyn-ide

@RikkiGibson RikkiGibson closed this May 2, 2019
@RikkiGibson RikkiGibson reopened this May 2, 2019
@RikkiGibson RikkiGibson closed this May 3, 2019
@RikkiGibson RikkiGibson reopened this May 3, 2019
Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

IDE parts look fine; there's some suspicious bits in the compiler code to me. Also tagging @sharwell since I know he was doing some work on quick info tests. If this is the new structure, great; if not then maybe there's work needed.

return false;
}

if (method is SourcePropertyAccessorSymbol sourceAccessor && propertyOpt is SourcePropertySymbol sourceProperty)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be using method.AssociatedSymbol to get the source property instead? My guess being one of three things are true:

  1. ShouldMethodDisplayReadOnly gets called directly with an accessor and not just from ShouldPropertyDisplayReadOnly, at which point the callers are having to get the source property,
  2. This is only being passed by ShouldPropertyDisplayReadOnly, at which point we could just inline this into that, or:
  3. We're trying to do something fancier here, and we probably should have a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe (1) is the answer here. See the AddAccessor method in this file.

@@ -68,6 +68,8 @@ public enum SymbolDisplayMemberOptions

/// <summary>
/// Includes the <c>ref</c>, <c>ref readonly</c>, <c>ByRef</c> keywords for ref-returning methods and properties/indexers.
/// Also includes the <c>readonly</c> keyword on methods, properties/indexers, and events due to the keyword
/// changing the <c>this</c> parameter's ref kind from <c>ref</c> to <c>ref readonly</c>.
Copy link
Member

Choose a reason for hiding this comment

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

This seems fishy. Is this a name we regret and should fix?

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented May 3, 2019

Responding to @jasonmalinowski's comment:

This seems fishy. Is this a name we regret and should fix?

Maybe! I approached the situation by looking for an existing SymbolDisplayMemberOption which would:

  • make the keyword get displayed in the contexts I wanted (quick info)
  • basically fit in the category implied by the option

I felt throwing it under the IncludeRef category made enough sense because the display of both ref readonly and ref are affected by it today, and the readonly keyword on methods/properties/events has a similar effect of changing the RefKind of a parameter.

It's possible that the name of the option should change, but I can't readily think of a more appropriate name. (I think it would also be a breaking change to rename it.)

@RikkiGibson
Copy link
Contributor Author

It sounds like I'm using the right pattern for Quick Info tests. Are there any remaining concerns about the use or documentation of SymbolDisplayMemberOptions.IncludeRef?

@RikkiGibson
Copy link
Contributor Author

I'm going to merge now as it feels like we've resolved the concerns. Please let me know if there's anything that should be revised in a separate PR.

@RikkiGibson RikkiGibson merged commit f99a821 into dotnet:master May 6, 2019
@RikkiGibson RikkiGibson deleted the readonly-members-symbol-display branch May 6, 2019 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Area-IDE IDE-IntelliSense Completion, Signature Help, Quick Info
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants