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

List-patterns: add a few tests and add HasValidate flag #57914

Merged
merged 12 commits into from
Nov 24, 2021

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Nov 22, 2021

Additional validation:

Test plan: #51289


if (hasValidate)
{
WriteLine("private partial void Validate();");
Copy link
Member

@alrz alrz Nov 22, 2021

Choose a reason for hiding this comment

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

💡 Would be nice to add something like [Conditional("DEBUG")] partial void Validate(); for all nodes

Copy link
Contributor

@RikkiGibson RikkiGibson Nov 24, 2021

Choose a reason for hiding this comment

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

I agree, it feels like the design of partial methods is such that we shouldn't need to introduce new flags to BoundNodes.xml or branches in this logic. Just unconditionally emit the declaration part and the call, then trust the compiler to eliminate the methods and calls to methods that lack implementations.

That said, it's fine with me if the desire is to use a flag in the xml to reduce clutter in the PR.

@jcouv jcouv marked this pull request as ready for review November 22, 2021 20:17
@jcouv jcouv requested review from a team as code owners November 22, 2021 20:17
@jcouv jcouv requested a review from AlekseyTs November 23, 2021 18:30
@@ -238,7 +238,6 @@ private BoundExpression BindSwitchExpression(SwitchExpressionSyntax node, Bindin
pattern = BindPattern(node.Pattern, sliceType, GetValEscape(sliceType, inputValEscape), permitDesignations, hasErrors, diagnostics);
}

Debug.Assert(GetIndexerOrImplicitIndexerSymbol(indexerAccess) is var _);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

GetIndexerOrImplicitIndexerSymbol

I think we should keep this assert, unless we are removing this method or changing how it is used. I see that this line got moved to Validate method. #Closed

@@ -317,7 +316,6 @@ private BoundExpression BindSwitchExpression(SwitchExpressionSyntax node, Bindin
inputValEscape, permitDesignations, typeSyntax: null, diagnostics, ref hasErrors,
out Symbol? variableSymbol, out BoundExpression? variableAccess);

Debug.Assert(GetIndexerOrImplicitIndexerSymbol(indexerAccess) is var _);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

GetIndexerOrImplicitIndexerSymbol

Same comment here as well. #Closed

@@ -108,6 +108,10 @@ public override bool IsEquivalentTo(BoundDagEvaluation obj)
return base.IsEquivalentTo(obj) &&
this.Index == ((BoundDagIndexerEvaluation)obj).Index;
}
private partial void Validate()
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

private partial void Validate()

Consider adding some space between declarations. #Closed


private partial void Validate()
{
Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

BoundPropertyAccess or BoundLocal

It looks like CheckValue can return a BoundBadExpression. We might want to be prepared to deal with that. #Closed

private partial void Validate()
{
Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal);
Debug.Assert(IndexerOrSliceAccess is BoundIndexerAccess or BoundCall);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

IndexerOrSliceAccess is BoundIndexerAccess or BoundCall

This is going to "conflict" with the array PR (#57918). Consider adding BoundArrayAccess into the list. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 23, 2021

                Debug.Assert(indexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess or BoundBadExpression or BoundDynamicIndexerAccess);

I think this line should move to Validate.


In reply to: 977085556


In reply to: 977085556


Refers to: src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs:226 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 23, 2021

        Debug.Assert(indexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess or BoundBadExpression or BoundDynamicIndexerAccess);

I think this line should move to Validate.


In reply to: 977090678


Refers to: src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs:372 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False)

var csCompilation = CreateCompilation(csSource, parseOptions: TestOptions.RegularWithListPatterns, references: new[] { vbCompilation.EmitToImageReference() });
// PROTOTYPE(list-patterns) Unsupported because the lookup fails not that the indexer is static
var csCompilation = CreateCompilation(csSource, references: new[] { vbCompilation.EmitToImageReference() });
// Note: the VB indexer's name is "Item" but C# looks for "this[]", but we can't put Default on Shared indexer declaration
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

but we can't put Default on Shared indexer declaration

Can we do that in IL? Is it worth testing a property like that? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

We have a test with a static indexer from IL, see SlicePattern_LengthAndIndexAndSliceAreStatic

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 23, 2021

Public Shared ReadOnly Property Item(i As System.Index) As Integer

Are we testing scenarios with an instance property like that (expected name but not Default member)?
Are we testing scenarios with Default property named differently?


In reply to: 977102228 #Closed


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs:1396 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Nov 23, 2021

Public Shared ReadOnly Property Item(i As System.Index) As Integer

I don't know how to do the first suggestion (C# looks for this[] as the name)


In reply to: 977102228


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs:1396 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False)

@jcouv jcouv requested a review from AlekseyTs November 23, 2021 21:27
private partial void Validate()
{
Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal or BoundBadExpression);
Debug.Assert(IndexerOrSliceAccess is BoundIndexerAccess or BoundCall or BoundArrayAccess or BoundBadExpression);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

or BoundBadExpression

The addition of a BoundBadExpression for IndexerOrSliceAccess feels unexpected. We don't call CheckValue on it and we don't handle BoundBadExpression in various helpers. For example in GetReceiver above. #Closed

private partial void Validate()
{
Debug.Assert(LengthAccess is null or BoundPropertyAccess or BoundBadExpression);
Debug.Assert(IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess or BoundBadExpression or BoundDynamicIndexerAccess);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

IndexerAccess

Can it be null? #Closed

{
private partial void Validate()
{
Debug.Assert(IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess or BoundBadExpression or BoundDynamicIndexerAccess);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

Can it be null? #Closed

switch (a)
{
case [..[1],2,3]:
case [1,2,3]: // no error
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 23, 2021

Choose a reason for hiding this comment

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

case [1,2,3]: // no error

Why is there a behavior difference? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we inject a null test for reference types (int[] vs. Span<int>) that we get back from the slice operation. We're having an email thread with LDM on this.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 9)

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 (commit 10)

@@ -53,6 +53,14 @@ try {
}
}

# Verify no TODO2 marker left
Copy link
Contributor

Choose a reason for hiding this comment

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

@jcouv is this something we expect to be useful on an ongoing basis? should we do something like flip the existing TODO comments over to TODO2 and change this to prevent introduction of new TODO comments to main?

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 don't think we can do much about existing TODO comments. I've been using TODO2 comments to track things within a PR and having this helps me ensure I don't let any into the main branch or feature branches.

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.

4 participants