-
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
Enable switch dispatch for is-expressions #65874
Changes from all commits
f9bfa39
fbe5bdb
b9de7e5
df09a7a
e6ac81b
5db93b1
7e6726d
7876a16
7dc7d08
ba2a4cb
f9ceb5f
aac7c83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,12 @@ public override BoundNode VisitIsPatternExpression(BoundIsPatternExpression node | |
result = isPatternRewriter.LowerIsPatternAsLinearTestSequence(node, decisionDag, whenTrueLabel: node.WhenTrueLabel, whenFalseLabel: node.WhenFalseLabel); | ||
isPatternRewriter.Free(); | ||
} | ||
else if (canProduceLinearSequence(decisionDag.RootNode, whenTrueLabel: node.WhenFalseLabel, whenFalseLabel: node.WhenTrueLabel)) | ||
else if (IsFailureNode(decisionDag.RootNode, node.WhenFalseLabel)) | ||
{ | ||
// If we can build a linear test sequence with the whenTrue and whenFalse labels swapped, then negate the | ||
// result. This would typically arise when the source contains `e is not pattern`. | ||
// If the given pattern always fails due to a constant input (see comments on BoundDecisionDag.SimplifyDecisionDagIfConstantInput), | ||
// we build a linear test sequence with the whenTrue and whenFalse labels swapped and then negate the result, to keep the result a constant. | ||
// Note that the positive case will be handled by canProduceLinearSequence above, however, we avoid to produce a full inverted linear sequence here | ||
// because we may be able to generate better code for a sequence of `or` patterns, using a switch dispatch, for example, which is done in the general rewriter. | ||
negated = !negated; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took me a while to understand what you were concerning about.
We still need to negate the result here because whenTrue and whenFalse are swapped for the linear rewriter as it expects whenTrue to be the "final" leaf node. Of course nothing about that has changed in this PR beyond limiting the scenario that leads to this code path. |
||
var isPatternRewriter = new IsPatternExpressionLinearLocalRewriter(node, this); | ||
result = isPatternRewriter.LowerIsPatternAsLinearTestSequence(node, decisionDag, whenTrueLabel: node.WhenFalseLabel, whenFalseLabel: node.WhenTrueLabel); | ||
|
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 inverted
canProduceLinearSequence
check - used to lower negated is-expressions - was preventing us to use the general rewriter which handles switch dispatch, but that is already accounted for: when IsNegated is true, the decision dag is created off of the inner pattern.roslyn/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
Lines 58 to 60 in 85712db
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.
Also filed #65876