-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C#: Implement CFG for not patterns
#4724
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
Conversation
c729a06 to
0ac516d
Compare
965f1a5 to
4f69a37
Compare
9fa3857 to
ad002ef
Compare
tamasvajk
left a comment
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
csharp/ql/src/semmle/code/csharp/controlflow/internal/Completion.qll
Outdated
Show resolved
Hide resolved
2b6d534 to
221aebc
Compare
|
Rebased and added two new commits. |
|
Fixed a join-order regression caused by 355edcb, and started a new differences job. |
| c = | ||
| any(NestedCompletion nc | | ||
| this.lastFinally(last, nc.getAnInnerCompatibleCompletion(), nc.getOuterCompletion(), | ||
| nc.getNestLevel()) | ||
| ) | ||
| exists(int nestLevel | | ||
| c = | ||
| any(NestedCompletion nc | | ||
| this.lastFinally(last, nc.getAnInnerCompatibleCompletion(), nc.getOuterCompletion(), | ||
| nestLevel) and | ||
| // unbind | ||
| nc.getNestLevel() >= nestLevel and | ||
| nc.getNestLevel() <= nestLevel | ||
| ) | ||
| ) |
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.
This seems overly complicated. Can you show me what perf issue was solved by this?
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.
You are right, it is complicated. It solves a bad-join order that was also there before this PR, but which I spotted when fixing the other bad join-order:
1986 ~0% {5} r84 = SCAN ControlFlowGraphImpl::Statements::TryStmtTree::lastFinally_dispred#fffff#prev_delta AS I OUTPUT I.<4>, I.<0> 'this', I.<1> 'last', I.<2> 'c', I.<3>
29295324 ~1% {5} r85 = JOIN r84 WITH Completion::TNestedCompletion#ffff_23#join_rhs AS R ON FIRST 1 OUTPUT R.<1> 'c', r84.<4>, r84.<1> 'this', r84.<2> 'last', r84.<3>
10451 ~0% {4} r86 = JOIN r85 WITH Completion::NestedCompletion::getOuterCompletion_dispred#ff AS R ON FIRST 2 OUTPUT r85.<0> 'c', r85.<4>, r85.<2> 'this', r85.<3> 'last'
499 ~3% {3} r87 = JOIN r86 WITH Completion::NestedCompletion::getAnInnerCompatibleCompletion_dispred#ff AS R ON FIRST 2 OUTPUT r86.<3> 'last', r86.<0> 'c', r86.<2> 'this'
The rewrite avoids joining first on getNestLevel(), so it instead becomes
1986 ~0% {5} r93 = SCAN ControlFlowGraphImpl::Statements::TryStmtTree::lastFinally_dispred#fffff#prev_delta AS I OUTPUT I.<3>, I.<0> 'this', I.<1> 'last', I.<2> 'c', I.<4>
28433 ~0% {5} r94 = JOIN r93 WITH Completion::NestedCompletion::getOuterCompletion_dispred#ff_10#join_rhs AS R ON FIRST 1 OUTPUT R.<1> 'c', r93.<3>, r93.<1> 'this', r93.<2> 'last', r93.<4>
1497 ~7% {4} r95 = JOIN r94 WITH Completion::NestedCompletion::getAnInnerCompatibleCompletion_dispred#ff AS R ON FIRST 2 OUTPUT r94.<0> 'c', r94.<2> 'this', r94.<3> 'last', r94.<4>
1497 ~0% {7} r96 = JOIN r95 WITH Completion::TNestedCompletion#ffff_3012#join_rhs AS R ON FIRST 1 OUTPUT r95.<1> 'this', r95.<2> 'last', r95.<3>, r95.<0> 'c', R.<1>, R.<2>, R.<3>
1497 ~0% {7} r97 = SELECT r96 ON r96.<6> >= r96.<2>
499 ~0% {7} r98 = SELECT r97 ON r97.<6> <= r97.<2>
499 ~3% {3} r99 = SCAN r98 OUTPUT r98.<1> 'last', r98.<3> 'c', r98.<0> 'this'
This PR changes the CFG for pattern expressions (including
notexpressions). Example:CFG before:
CFG after:
https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/782/https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/799/https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/804/