-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Call Enter/LeaveRegion APIs for binary expressions #76412
Conversation
@@ -2553,6 +2553,7 @@ private void VisitBinaryOperatorChildren(BoundBinaryOperator node) | |||
protected virtual void VisitBinaryOperatorChildren(ArrayBuilder<BoundBinaryOperator> stack) | |||
{ | |||
var binary = stack.Pop(); | |||
EnterRegionIfNeeded(binary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't call 'VisitAlways' on the binary nodes themselves to avoid recursion. Therefore we need to take care to call Enter/LeaveRegion APIs appropriately when we start/finish with those nodes.
See also #74317 for a non-recursive visitor which makes similar calls.
Thanks. I can also hellp with adding an ExtractMethod test if you need it. |
@@ -2541,6 +2541,7 @@ private void VisitBinaryOperatorChildren(BoundBinaryOperator node) | |||
do | |||
{ | |||
stack.Push(binary); | |||
EnterRegionIfNeeded(binary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to take care that Enter is called for all the binary ops, from outermost to innermost, and then Leave is called from innermost to outermost. Most convenient way to do this is to call Enter right after Push, then Leave right before "Pop or exit".
@CyrusNajmabadi If you have some time feel free to push an ExtractMethod test to this PR. |
@dotnet/roslyn-compiler for review of a small fix |
Does VB have the same issue? |
VB implementation appears to be accounting for this when visiting binary expressions. roslyn/src/Compilers/VisualBasic/Portable/Analysis/FlowAnalysis/AbstractFlowPass.vb Lines 2135 to 2160 in fe3a243
But, at a glance, I didn't find a test in RegionAnalysisTests.vb which is doing a dataflow analysis on a nested binary operator. |
Consider adding a test |
Done with review pass (commit 7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 8)
Closes #38087