Call Enter/LeaveRegion APIs for binary expressions#76412
Call Enter/LeaveRegion APIs for binary expressions#76412RikkiGibson merged 8 commits intodotnet:mainfrom
Conversation
| protected virtual void VisitBinaryOperatorChildren(ArrayBuilder<BoundBinaryOperator> stack) | ||
| { | ||
| var binary = stack.Pop(); | ||
| EnterRegionIfNeeded(binary); |
There was a problem hiding this comment.
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. |
| do | ||
| { | ||
| stack.Push(binary); | ||
| EnterRegionIfNeeded(binary); |
There was a problem hiding this comment.
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) |
Closes #38087