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

Hold Receiver directly in bound node for implicit indexer access #58009

Merged
merged 2 commits into from
Nov 30, 2021

Conversation

AlekseyTs
Copy link
Contributor

@AlekseyTs AlekseyTs commented Nov 29, 2021

Related to #57855.

Relates to test plan #51289

@AlekseyTs AlekseyTs requested a review from jcouv November 29, 2021 15:08
@AlekseyTs AlekseyTs requested a review from a team as a code owner November 29, 2021 15:08
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 1), just a minor spelling touchup.

@AlekseyTs
Copy link
Contributor Author

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

@jcouv jcouv self-assigned this Nov 29, 2021

internal partial class BoundDeconstructValuePlaceholder
{
public sealed override bool IsEquivalentToThisReference => false; // Preserving old behavior
Copy link
Member

Choose a reason for hiding this comment

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

nit: I found the comment confusing. If the behavior is incorrect, should we file an issue instead?
Same for BoundAwaitableValuePlaceholder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the behavior is incorrect, should we file an issue instead?

That is not something that I intend to pursue, given that this only affects warnings. If you think we have to follow up anyway, I can open an issue. Let me know.

@jcouv
Copy link
Member

jcouv commented Nov 29, 2021

            if (!(receiver is BoundThisReference))

Should we check IsEquivalentToThisReference instead?
Never mind, I can't think of a way of using a placeholder receiver to access a field.


In reply to: 981967541


In reply to: 981967541


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:858 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Nov 29, 2021

                ReportDiagnosticsIfObsolete(diagnostics, setMethod, node, receiver?.Kind == BoundKind.BaseReference);

Do we need some abstraction for placeholder receivers here? (there's a couple more places that check for BoundKind.BaseReference below to consider as well)


In reply to: 981972509


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:1138 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Nov 29, 2021

            case BoundKind.ThisReference:

I'm assuming we never need to get the ref-escape scope for a placeholder. If that's correct, could we assert that?


In reply to: 981975586


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:2047 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Nov 29, 2021

            case BoundKind.ThisReference:

Should placeholders that are equivalent to this fall into this case?
Same question applies to CheckValEscape


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:2588 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

{
if (_awaitablePlaceholdersOpt != null && _awaitablePlaceholdersOpt.TryGetValue((BoundAwaitableValuePlaceholder)expression, out var value))
if (_resultForPlaceholdersOpt != null && _resultForPlaceholdersOpt.TryGetValue(placeholder, out var value))
Copy link
Member

@jcouv jcouv Nov 29, 2021

Choose a reason for hiding this comment

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

nit: Thanks for renaming the map to something more general. Along those lines, we may want to add a helper methods for placeholder replacement (here, VisitPlaceholderWithReplacement for replacements, and in VisitAwaitExpression and other places for registering replacements) #WontFix

VisitRvalue(node.Argument);

EnsurePlaceholdersToResultMap();
_resultForPlaceholdersOpt.Add(node.ReceiverPlaceholder, (node.Receiver, receiverResult));
Copy link
Member

@jcouv jcouv Nov 29, 2021

Choose a reason for hiding this comment

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

Consider extracting to NullableWalker.AddPlaceholderReplacement and RemovePlaceholderReplacement #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider extracting to NullableWalker.AddPlaceholderReplacement and RemovePlaceholderReplacement

I prefer to keep the churn to a minimum.

VisitRvalue(node.IndexerOrSliceAccess);
RemovePlaceholder(node.ArgumentPlaceholders[0]);
_resultForPlaceholdersOpt.Remove(node.ReceiverPlaceholder);
Copy link
Member

@jcouv jcouv Nov 29, 2021

Choose a reason for hiding this comment

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

Not blocking this PR, since it's not the main purpose, but consider adding the visit for LengthAccess too, now that we can. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not blocking this PR, since it's not the main purpose, but consider adding the visit for LengthAccess too, now that we can.

I am not sure if that would be the right thing to do. The length is not always evaluated and I prefer to not deal with the logic to figure that out here. The receiver is checked already, there is pretty much nothing else we can learn.

@@ -2069,21 +2070,21 @@
<Node Name="BoundImplicitIndexerAccess" Base="BoundExpression" SkipInNullabilityRewriter="true" HasValidate="true">
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow" />

<!-- The target of the index operation -->
<Field Name="Receiver" Type="BoundExpression" Null="disallow" />
Copy link
Member

@jcouv jcouv Nov 29, 2021

Choose a reason for hiding this comment

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

I'm very glad we're able to move back to this design with the confidence that the ValueCheck logic only needs to be abstracted for placeholders that might be "this" (not as bad as we feared).
Thanks a lot! #Resolved

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

@AlekseyTs
Copy link
Contributor Author

                ReportDiagnosticsIfObsolete(diagnostics, setMethod, node, receiver?.Kind == BoundKind.BaseReference);

Do we need some abstraction for placeholder receivers here? (there's a couple more places that check for BoundKind.BaseReference below to consider as well)

A base expression cannot be used as a stand-alone expression. So, I do not think there is a scenario that can benefit from this abstraction today.


In reply to: 981972509


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:1138 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

@AlekseyTs
Copy link
Contributor Author

            case BoundKind.ThisReference:

I'm assuming we never need to get the ref-escape scope for a placeholder. If that's correct, could we assert that?

Figuring out abstractions necessary for ref-safety checks is out of scope of this PR, including placing asserts. The PR doesn't close the issue.


In reply to: 981975586


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:2047 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

@AlekseyTs
Copy link
Contributor Author

            case BoundKind.ThisReference:

Should placeholders that are equivalent to this fall into this case?

This is out of scope as well. The only placeholder that could be affected today is ImplicitIndexerReceiverPlaceholder, which is explicitly handled below


In reply to: 981977750


Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:2588 in 455e6af. [](commit_id = 455e6af, deletion_comment = False)

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.

LGTM Thanks (iteration 2)

@AlekseyTs AlekseyTs merged commit 03f6adf into dotnet:main Nov 30, 2021
@ghost ghost added this to the Next milestone Nov 30, 2021
@allisonchou allisonchou modified the milestones: Next, 17.1.P2 Nov 30, 2021
333fred added a commit to 333fred/roslyn that referenced this pull request Dec 3, 2021
…rovements

* upstream/main: (310 commits)
  Read SourceLink info and call service to retrieve source from there (dotnet#57978)
  Add new parser/lexer to the StackTraceAnalyzer (dotnet#57598) (dotnet#58050)
  Snap 17.1 P2 (dotnet#58041)
  Make it possible to analyze the dataflow of `ConstructorInitializerSyntax` and `PrimaryConstructorBaseTypeSyntax` (dotnet#57576)
  Shorten paths in VS installation (dotnet#57726)
  Add comments
  Add new parser/lexer to the StackTraceAnalyzer (dotnet#57598)
  Fix await completion for expression body lambda
  Add tests
  Fix comment
  Honor option, and also improve formatting with comment
  Skip TestLargeStringConcatenation (dotnet#58035)
  Log runtime framework of remote host
  Mark EqualityContract property accessor as not auto-implemented (dotnet#57917)
  Fix typo in XML doc for GeneratorExtensions (dotnet#58020)
  Hold Receiver directly in bound node for implicit indexer access (dotnet#58009)
  Pass AnalysisKind instead of int
  Enable nullable reference types for TableDataSource
  Simplify 'interpolation' data, and move to an easier to consume System.Range approach for it (dotnet#57966)
  Add missing test for CallerArgumentExpression (dotnet#57805)
  ...
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