Hold Receiver directly in bound node for implicit indexer access#58009
Hold Receiver directly in bound node for implicit indexer access#58009AlekseyTs merged 2 commits intodotnet:mainfrom
Conversation
333fred
left a comment
There was a problem hiding this comment.
LGTM (commit 1), just a minor spelling touchup.
|
@jcouv, @dotnet/roslyn-compiler Please review. |
|
|
||
| internal partial class BoundDeconstructValuePlaceholder | ||
| { | ||
| public sealed override bool IsEquivalentToThisReference => false; // Preserving old behavior |
There was a problem hiding this comment.
nit: I found the comment confusing. If the behavior is incorrect, should we file an issue instead?
Same for BoundAwaitableValuePlaceholder
There was a problem hiding this comment.
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.
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) |
Do we need some abstraction for placeholder receivers here? (there's a couple more places that check for In reply to: 981972509 Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:1138 in 455e6af. [](commit_id = 455e6af, deletion_comment = False) |
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) |
| if (expression is BoundValuePlaceholderBase placeholder) | ||
| { | ||
| if (_awaitablePlaceholdersOpt != null && _awaitablePlaceholdersOpt.TryGetValue((BoundAwaitableValuePlaceholder)expression, out var value)) | ||
| if (_resultForPlaceholdersOpt != null && _resultForPlaceholdersOpt.TryGetValue(placeholder, out var value)) |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Consider extracting to NullableWalker.AddPlaceholderReplacement and RemovePlaceholderReplacement #WontFix
There was a problem hiding this comment.
Consider extracting to NullableWalker.AddPlaceholderReplacement and RemovePlaceholderReplacement
I prefer to keep the churn to a minimum.
| _resultForPlaceholdersOpt.Add(node.ReceiverPlaceholder, (node.Receiver, receiverResult)); | ||
| VisitRvalue(node.IndexerOrSliceAccess); | ||
| RemovePlaceholder(node.ArgumentPlaceholders[0]); | ||
| _resultForPlaceholdersOpt.Remove(node.ReceiverPlaceholder); |
There was a problem hiding this comment.
Not blocking this PR, since it's not the main purpose, but consider adding the visit for LengthAccess too, now that we can. #Resolved
There was a problem hiding this comment.
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.
| <Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow" /> | ||
|
|
||
| <!-- The target of the index operation --> | ||
| <Field Name="Receiver" Type="BoundExpression" Null="disallow" /> |
There was a problem hiding this comment.
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
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 2)
A In reply to: 981972509 Refers to: src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs:1138 in 455e6af. [](commit_id = 455e6af, deletion_comment = False) |
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) |
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) |
…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) ...
Related to #57855.
Relates to test plan #51289