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

Handle custom modifiers on copy ctor #45136

Merged
merged 4 commits into from
Jun 17, 2020
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jun 13, 2020

Fixes #44902

return member is MethodSymbol { IsStatic: false, ParameterCount: 1, Arity: 0 } method &&
method.Parameters[0].Type.Equals(containingType, TypeCompareKind.CLRSignatureCompareOptions) &&
method.Parameters[0].Type.Equals(containingType, TypeCompareKind.AllIgnoreOptions) &&
Copy link
Member Author

@jcouv jcouv Jun 13, 2020

Choose a reason for hiding this comment

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

📝 this seems more correct, although doesn't affect behavior. #Resolved

Copy link
Contributor

Choose a reason for hiding this comment

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

although doesn't affect behavior.

Of course, comparison makes a difference. For example, when there is a custom modifier within the type.


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

@@ -211,7 +211,7 @@ public sealed class NotNullIfNotNullAttribute : Attribute
protected const string IsExternalInitTypeDefinition = @"
namespace System.Runtime.CompilerServices
{
public sealed class IsExternalInit
public static class IsExternalInit
Copy link
Member Author

@jcouv jcouv Jun 13, 2020

Choose a reason for hiding this comment

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

Thanks @RikkiGibson for adding the BCL API. I see that you've changed the type to static there, to match other similar compiler types. So I'm updating in our tests to match. #Resolved

@jcouv jcouv marked this pull request as ready for review June 15, 2020 05:52
@jcouv jcouv requested a review from a team as a code owner June 15, 2020 05:52
return member;
// If one has fewer custom modifiers, that is better
// (see OverloadResolution.BetterFunctionMember)
var memberModCount = member.CustomModifierCount();
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 16, 2020

Choose a reason for hiding this comment

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

var memberModCount = member.CustomModifierCount(); [](start = 20, length = 50)

Consider doing this only when we detected possible ambiguity, otherwise it is a wasted work to deal with a very uncommon case. #Resolved

@@ -4662,6 +4713,166 @@ public void CopyCtor_InaccessibleInMetadata()
);
}

[Fact, WorkItem(45077, "https://github.com/dotnet/roslyn/issues/45077")]
public void CopyCtor_AmbiguitiesInMetadata()
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 16, 2020

Choose a reason for hiding this comment

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

CopyCtor_AmbiguitiesInMetadata [](start = 20, length = 30)

It is impossible to follow what this test is doing. I believe clarity of tests is more important than brevity and extreme code reuse. #Closed

public void CopyCtor_AmbiguitiesInMetadata()
{
// IL for a minimal `public record B { }` with injected copy constructors
var ilSource_template = @"
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 16, 2020

Choose a reason for hiding this comment

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

ilSource_template [](start = 16, length = 17)

This constant is used only in one place. Consider inlining, I think this will make the test code easier to follow #WontFix

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 think it's helpful to see what we're going to compile (even if contains holes) towards the start of the test. Added comment


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

}
";

var source = @"
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 16, 2020

Choose a reason for hiding this comment

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

source [](start = 16, length = 6)

This variable is used only in one place. Consider inlining, I think this will make the test code easier to follow #WontFix

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 1), modulo the lack of test for the change around TypeCompareKind

@@ -3881,6 +3881,57 @@ .maxstack 2
}");
}

[Fact, WorkItem(44902, "https://github.com/dotnet/roslyn/issues/44902")]
public void CopyCtor_NotInRecordType()
Copy link
Member

@cston cston Jun 16, 2020

Choose a reason for hiding this comment

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

CopyCtor_NotInRecordType [](start = 20, length = 24)

What is this testing? It looks like the changes in the PR are specific to records. #Resolved

Copy link
Member Author

@jcouv jcouv Jun 16, 2020

Choose a reason for hiding this comment

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

This is not related to the current PR, but I realized that I didn't test that scenario in previous PR. A constructor that looks like a copy constructor, but isn't in a record, isn't affected by change to skip initializer portion (MethodCompiler). #Resolved

{
bestModifierCountSoFar = bestCandidate.CustomModifierCount();
}

var memberModCount = member.CustomModifierCount();
if (bestModifierCountSoFar >= 0 && memberModCount > bestModifierCountSoFar)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't bestModifierCountSoFar >= 0 always true here?

}

bestCandidate = member;
bestModifierCountSoFar = memberModCount;
Copy link
Member

@cston cston Jun 16, 2020

Choose a reason for hiding this comment

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

bestModifierCountSoFar = memberModCount [](start = 20, length = 39)

bestModiferCountSoFar is only a short cut if there are 3 copy constructors which is pretty unlikely. Consider simplifying and calling CustomModiferCount() each time.

if (bestCandidate.CustomModifierCount() > member.CustomModifierCount())
{
    bestCandidate = member;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

In a scenario with 3 overload, the first two having the same modifier count, we need to remember what that modifier count was when we consider the last overload. We need that state.

THROW
");

// .ctor(modeopt1 B) vs. .ctor(modopt2 B)
Copy link
Member

Choose a reason for hiding this comment

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

modeopt [](start = 21, length = 7)

Typo

@jcouv jcouv merged commit d702fa6 into dotnet:master Jun 17, 2020
@ghost ghost added this to the Next milestone Jun 17, 2020
@jcouv jcouv deleted the custom-modifiers branch June 17, 2020 04:13
@dibarbet dibarbet modified the milestones: Next, 16.7.P4 Jun 30, 2020
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.

Record copy constructor should leverage base copy constructor
4 participants