C#: Remove some unbounded TC computations#21348
Open
hvitved wants to merge 4 commits intogithub:mainfrom
Open
Conversation
6ccee8f to
be9a579
Compare
3f36bbd to
3d93e01
Compare
8c9fb8c to
acd6f41
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces expensive unbounded transitive-closure (TC) computations in the C# QL libraries by replacing *-closure patterns with explicit recursive helper predicates (often pragma[nomagic]) and more targeted reachability, improving analysis performance on large projects.
Changes:
- Introduces reusable recursive descendant helpers (e.g., pattern-expression descendants) and wires them into expression/dataflow logic.
- Refactors CFG
AstNodeand control-flow reachability scope handling to avoid computing “full” TCs that are later filtered. - Updates guard/dereferenceability plumbing to use a dedicated recursive predicate rather than applying
getNullEquivParent*inline.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/lib/semmle/code/csharp/exprs/internal/Expr.qll | Adds isPatternExprDescendant helper predicate to avoid getAChildExpr*() usage. |
| csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll | Replaces getAChildExpr+() usage in isImplicit and updates tuple construction logic to call the new helper. |
| csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/ControlFlowReachability.qll | Refactors scope/basic-block reachability with a combined newtype and doublyBoundedFastTC. |
| csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll | Adds isAssignExprLValueDescendant helper and replaces star-closure pattern usages with helpers. |
| csharp/ql/lib/semmle/code/csharp/dataflow/internal/ControlFlowReachability.qll | Same reachability refactor as rangeanalysis variant to avoid non-fast TC patterns. |
| csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll | Replaces getAChild*-based AstNode characterization with explicit recursion via astNode. |
| csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll | Introduces dereferenceableExpr helper predicate and uses it in DereferenceableExpr. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We are in some cases computing (more or less) full non-fast TCs, which can be very expensive in cases like this one.
For example, the charpred of
AstNodeinControlFlowGraphImpl.qllwould previously result in the following DIL:That is, we would compute a full TC only to afterwards filter away the target column via the
any#expr#.DCA is excellent; analysis time on
microsoft__CryptoNetsis reduced from1379sto80s.