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

Improve DisplayNameHelpers for NativeAOT #70084

Merged
merged 4 commits into from
Jun 2, 2022

Conversation

vitek-karas
Copy link
Member

@vitek-karas vitek-karas commented Jun 1, 2022

These helpers are used to report names of things in warnings. The functional changes are:

  • For method parameters, use the parameter name if available (and only if not fallback to the # 1 notation)
  • For property accessor methods, use the C# naming scheme, so for example Type.Property.get instead of Type.get_Property.

Both of these changes are in preparation to bring NativeAOT closer in behavior to ILLink and the trim analyzers.

For this I moved some of the helpers to the common shared code.

Some unrelated code cleanup as well.

These helpers are used to report names of things in warnings. The functional changes are:
* For method parameters, use the parameter name if available (and only if not fallback to the #1 notation)
* For property accessor methods, use the C# naming scheme, so for example Type.Property.get instead of Type.get_Property.

Both of these changes are in preparation to bring NativeAOT closer in behavior to ILLink and the trim analyzers.

For this I moved some of the helpers to the common shared code.

Some unrelated code cleanup as well.
{
sb.Append(property.Name);
sb.Append('.');
sb.Append(property.GetMethod.Name == method.Name ? "get" : "set");
Copy link
Member

Choose a reason for hiding this comment

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

If we want to match C# syntax, should this also handle init?
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/init

(Not necessary to fix in this PR.)

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 created dotnet/linker#2816 to add this to linker/analyzer/aot (They are going to share tests soon, so we will need to do it in all 3).

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be better to just standardize on however reflection displays these. This is the same issue as with interpreting ref/in/out in method signatures. C# tends to come up with new things every release. Do we want to be in a position where we need to play catch up, or in the position of reflection that just doesn't care?

dotnet/linker#2158 (comment) (ref/in/out comment here)

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 must admit I thought about it - but I was lazy to fix probably 100s of places in the linker tests to change this.
Another way would be to implement some smarts to the test validation system to let it allow a difference here - probably doable - didn't try.


var type = (EcmaType)ecmaAccessor.OwningType;
var reader = type.MetadataReader;
var module = type.EcmaModule;
Copy link
Contributor

Choose a reason for hiding this comment

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

The module seems to be unused in this method

Copy link
Contributor

@tlakollo tlakollo left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thanks!

src/coreclr/tools/Common/Compiler/DisplayNameHelpers.cs Outdated Show resolved Hide resolved
using System.Text;

using Internal.TypeSystem;

using Internal.TypeSystem.Ecma;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we tend to split using Foo = ... from the regular usings with a newline.

@vitek-karas vitek-karas merged commit 1b4a9c4 into dotnet:main Jun 2, 2022
@vitek-karas vitek-karas deleted the ImproveDisplayNameHelpers branch June 2, 2022 14:22
@ghost ghost locked as resolved and limited conversation to collaborators Jul 2, 2022
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.

4 participants