-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Expression breakpoints for switch expression. #42711
Expression breakpoints for switch expression. #42711
Conversation
f347d44
to
1d3ef40
Compare
1d3ef40
to
2053f1e
Compare
@dotnet/roslyn-compiler @tmat Please have a look at this implementation of support for breakpoints inside switch expressions. #Resolved |
@dotnet/roslyn-ide Could I also please have some eyes on this from the IDE perspective? #Resolved |
@gafter On it :) #Resolved |
src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs
Outdated
Show resolved
Hide resolved
IDE LGTM. Minor cleanup nits. #Resolved |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_SwitchExpression.cs
Show resolved
Hide resolved
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.
Done with review pass (iteration 1)
@jcouv I think I've addressed all of your comments. Do you have any others? #Resolved |
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.
Compiler changes LGTM Thanks (iteration 2)
@dotnet/roslyn-compiler May I have a second review please? |
@agocke @RikkiGibson @dotnet/roslyn-compiler May I have a second review please? |
src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs
Outdated
Show resolved
Hide resolved
…into patterns3-expr-breakpoints
Looks good. A couple of questions:
|
This work is on a branch that differs substantially from master in the area of the changes.
Up to you. I'm still waiting on a second review from the compiler team. I will aim to get that today so you can target the fixes to the |
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 although some docs would be nice.
@@ -53,3 +53,5 @@ Both the `BoundRestorePreviousSequencePoint` and `BoundStepThroughSequencePoint` | |||
This can be seen, for example, in test `SwitchExpressionSequencePoints` | |||
|
|||
The purpose of this instruction sequence is to cause there to be an unreachable IL opcode (the `nop`) having a sequence point, followed by a hidden sequence point to prevent the debugger from stopping at the following location. However, once it is executing the following code, the debugger's idea of the program's "current source location" will appear to be that location mentioned in the sequence point. | |||
|
|||
A `BoundStepThroughSequencePoint` also modifies the debugger's view of the "enclosing statement", but without creating a location where a breakpoint can be set. While evaluating the state machine of a *switch expression*, this is used to make the "current statement" appear to be the *switch expression*. |
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.
@gafter Just to confirm: in var x = i switch { 1 => Method(); ... }
, if I have a breakpoint inside Method
, I expect the call stack will highlight the branch of the switch expression Method()
. Is that the current behavior?
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.
Yes
_builder.EmitConstantValue(ConstantValue.Create(true)); | ||
_builder.EmitBranch(ILOpCode.Brtrue, label); | ||
EmitSequencePoint(syntaxTree, span); | ||
_builder.EmitOpCode(ILOpCode.Nop); |
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.
@gafter Just curious if sequence points can be empty w/o instructions, why having EmitSequencePoint() followed by EmitHiddenSequencePoint() is not sufficient?
I'm asking because coverage tools show uncovered statements, for example: https://developercommunity.visualstudio.com/content/problem/1140065/coverage-on-switch-expression-dropped-in-167.html , and now they should always ignore the unreachable SP in ldc.i4.1
brtrue.s 1
nop
pattern. Is there a guarantee the user's code will never produce such IL?
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.
The user's code can indeed produce such IL:
https://sharplab.io/#v2:C4LglgNgNAJiDUAfAAgJgIwFgBQyDMABGgQMIEDeOB1RhYAdsAQLIAUAlBVTTwG4CGAJwJMAvCMEBXAKYBubj2pgAZgVbBO87IprIA7AXRaeAXxwmgA=
So how do we get this shipped? |
@KirillOsenkov This was shipped a year ago. I've observed that new behavior in VS for a while now. |
Fixes #22016
Fixes #37805
Fixes #42579