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

Finalize the design for the shape of the BaseTypeSyntax for records and implement SemanticModel APIs around it. #45351

Merged
merged 2 commits into from
Jun 23, 2020

Conversation

AlekseyTs
Copy link
Contributor

Closes #44795.

@AlekseyTs
Copy link
Contributor Author

@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review.

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review.

@@ -8,16 +8,11 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
public partial class RecordDeclarationSyntax
{
internal SimpleBaseTypeSyntax? BaseWithArguments
internal PrimaryConstructorBaseTypeSyntax? PrimaryConstructorBaseTypeSyntax
Copy link
Member

@gafter gafter Jun 23, 2020

Choose a reason for hiding this comment

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

PrimaryConstructorBaseTypeSyntax [](start = 51, length = 32)

To be consistent with the way properties on syntax nodes are named, you should drop the Syntax suffix. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be consistent with the way properties on syntax nodes are named, you should drop the Syntax suffix.

Renamed


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

@@ -1197,6 +1197,8 @@ private static BoundExpression MakeLiteral(SyntaxNode syntax, ConstantValue cons
case SyntaxKind.BaseConstructorInitializer:
case SyntaxKind.ThisConstructorInitializer:
return new SourceLocation(((ConstructorInitializerSyntax)syntax).ArgumentList.OpenParenToken);
case SyntaxKind.PrimaryConstructorBaseType:
Copy link
Member

@gafter gafter Jun 23, 2020

Choose a reason for hiding this comment

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

SyntaxKind [](start = 21, length = 10)

Is this tested? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this tested?

The need to test this code path is recorder in the test plan issue.


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

Copy link
Member

Choose a reason for hiding this comment

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

Can you please link to the test plan issue?


In reply to: 443928479 [](ancestors = 443928479,443927180)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please link to the test plan issue?

#40726, several items, right above "Productivity" section.


In reply to: 443929342 [](ancestors = 443929342,443928479,443927180)

nodeToBind.Kind() == SyntaxKind.SimpleBaseType || // initializer for a record constructor
nodeToBind.Kind() == SyntaxKind.ArgumentList && nodeToBind.Parent is ConstructorInitializerSyntax ||
nodeToBind.Kind() == SyntaxKind.PrimaryConstructorBaseType || // initializer for a record constructor
nodeToBind.Kind() == SyntaxKind.ArgumentList && (nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Parent is PrimaryConstructorBaseTypeSyntax) ||
Copy link
Member

@gafter gafter Jun 23, 2020

Choose a reason for hiding this comment

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

PrimaryConstructorBaseTypeSyntax [](start = 143, length = 32)

Is this tested? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this tested?

Yes, this scenario is exercised by speculative operations.


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

Copy link
Member

Choose a reason for hiding this comment

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

Can you please identify a test which exercises this?


In reply to: 443929018 [](ancestors = 443929018,443927699)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please identify a test which exercises this?

BaseArguments_19, GetSpeculativeSymbolInfo for an initializer with a an out var in an argument.


In reply to: 443929431 [](ancestors = 443929431,443929018,443927699)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line as well Assert.Equal("Base..ctor(System.Int32 X)", speculativeModel!.GetSymbolInfo((SyntaxNode)speculativePrimaryInitializer).Symbol.ToTestDisplayString());


In reply to: 443930921 [](ancestors = 443930921,443929431,443929018,443927699)

public Base() {}
}

record C(int X, int Y) : Base(GetInt(X, out var xx) + xx, Y), I
Copy link
Member

@gafter gafter Jun 23, 2020

Choose a reason for hiding this comment

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

Base [](start = 25, length = 4)

This should also be tested with a class (not record) as the base, as permitted by https://github.com/dotnet/csharplang/blob/master/proposals/records.md #Closed

Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 23, 2020

Choose a reason for hiding this comment

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

This should also be tested with a class (not record) as the base, as permitted by https://github.com/dotnet/csharplang/blob/master/proposals/records.md

Any particular aspect you have in mind? There were some existing tests with classes with the old representation.


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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BaseArguments_12 for example.


In reply to: 443929594 [](ancestors = 443929594,443928983)

Copy link
Member

Choose a reason for hiding this comment

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

That addresses my concern.


In reply to: 443930063 [](ancestors = 443930063,443929594,443928983)

@gafter
Copy link
Member

gafter commented Jun 23, 2020

record C(int X, int Y) : Base(X, Y)

This should also be tested with a class (not record) as the base, as permitted by https://github.com/dotnet/csharplang/blob/master/proposals/records.md #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:7029 in b65a77f. [](commit_id = b65a77f, deletion_comment = False)

_nodeBinder.BindConstructorInitializer(ctorInitializer, diagnostics);
break;
case PrimaryConstructorBaseTypeSyntax ctorInitializer:
_nodeBinder.BindConstructorInitializer(ctorInitializer, diagnostics);
Copy link
Member

@gafter gafter Jun 23, 2020

Choose a reason for hiding this comment

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

BindConstructorInitializer [](start = 44, length = 26)

Can you please identify a test for this code path? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please identify a test for this code path?

For example, sBaseArguments_19, OutVarTests.VerifyModelForOutVar(speculativeModel, xxDecl, xxRef);


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

@AlekseyTs
Copy link
Contributor Author

@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review.

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@AlekseyTs
Copy link
Contributor Author

@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review, need a second sign-off..

var diagnostics = DiagnosticBag.GetInstance();
binder = new ExecutableCodeBinder(constructorInitializer, binder.ContainingMemberOrLambda, binder);

BoundExpressionStatement bnode = binder.BindConstructorInitializer(constructorInitializer, diagnostics);
Copy link
Member

@333fred 333fred Jun 23, 2020

Choose a reason for hiding this comment

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

I believe we need to do a nullable rewrite of these nodes. #Closed

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 we need to do a nullable rewrite of these nodes.

It doesn't look like we do this for any GetSpeculativeXXX APIs. Please open an issue if you think they should do the rewrite.


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

Copy link
Member

Choose a reason for hiding this comment

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

Added a note to #35038.


In reply to: 444537180 [](ancestors = 444537180,444528944)

nodeToBind.Kind() == SyntaxKind.SwitchExpressionArm ||
nodeToBind.Kind() == SyntaxKind.ArgumentList && nodeToBind.Parent is ConstructorInitializerSyntax ||
nodeToBind.Kind() == SyntaxKind.ArgumentList && (nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Parent is PrimaryConstructorBaseTypeSyntax) ||
Copy link
Member

@333fred 333fred Jun 23, 2020

Choose a reason for hiding this comment

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

nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Parent is PrimaryConstructorBaseTypeSyntax [](start = 65, length = 106)

This is used a couple of times. Consider making a helper. #WontFix

symbolInfo = model.GetSymbolInfo((SyntaxNode)baseWithargs);
Assert.Equal(SymbolInfo.None, symbolInfo);
symbolInfo = model.GetSymbolInfo(baseWithargs);
Assert.Equal(SymbolInfo.None, symbolInfo);
Copy link
Member

@333fred 333fred Jun 23, 2020

Choose a reason for hiding this comment

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

Why don't we get a list of failed candidates here? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why don't we get a list of failed candidates here?

Because there are no candidates, the PrimaryConstructorBaseTypeSyntax is never bound for anything other than a record.


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

@333fred
Copy link
Member

333fred commented Jun 23, 2020

Done review pass (commit 2). A couple of questions. I don't see any tests involving nullability for these, is there an item in the test plan tracking nullable public API testing for record constructors? #Closed

@AlekseyTs
Copy link
Contributor Author

A couple of questions

Answered.

I don't see any tests involving nullability for these, is there an item in the test plan tracking nullable public API testing for record constructors?

This isn't really related to the shape of the syntax. Added a note to the Test Plan #40726.


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

@333fred
Copy link
Member

333fred commented Jun 23, 2020

This isn't really related to the shape of the syntax. Added a note to the Test Plan #40726.

Thanks.


In reply to: 648458952 [](ancestors = 648458952,648452941)

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 2)

@AlekseyTs AlekseyTs merged commit 09db48d into dotnet:master Jun 23, 2020
@ghost ghost added this to the Next milestone Jun 23, 2020
@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.

Finalize the design for the shape of the BaseTypeSyntax in relation to the argument list for records
4 participants