-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Use extended canonical paths to resolve calls in data flow #18070
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
1eac6aa to
143d7e2
Compare
paldepind
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.
Looks great to me. I've suggested a refactor, but you can decide whether that makes sense :)
| private predicate resolvesExtendedCanonicalPath( | ||
| DataFlowCall c, CrateOriginOption crate, string path | ||
| ) { | ||
| exists(Resolvable r | | ||
| path = r.getResolvedPath() and | ||
| ( | ||
| r = c.asMethodCallExprCfgNode().getExpr() | ||
| or | ||
| r = c.asCallExprCfgNode().getExpr().(PathExprCfgNode).getPath() | ||
| ) | ||
| | | ||
| crate.asSome() = r.getResolvedCrateOrigin() | ||
| or | ||
| crate.isNone() and | ||
| not r.hasResolvedCrateOrigin() |
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 only thing resolvesExtendedCanonicalPath needs from DataFlowCall is the corresponding Resolvable. So what about factoring out that logic in a getResolvable predicate on DataFlowCall:
Resolvable getResolvable() {
result = this.asMethodCallExprCfgNode().getExpr()
or
result = this.asCallExprCfgNode().getExpr().(PathExprCfgNode).getPath()
}and changing resolvesExtendedCanonicalPath so it no longer knows about DataFlowCall:
| private predicate resolvesExtendedCanonicalPath( | |
| DataFlowCall c, CrateOriginOption crate, string path | |
| ) { | |
| exists(Resolvable r | | |
| path = r.getResolvedPath() and | |
| ( | |
| r = c.asMethodCallExprCfgNode().getExpr() | |
| or | |
| r = c.asCallExprCfgNode().getExpr().(PathExprCfgNode).getPath() | |
| ) | |
| | | |
| crate.asSome() = r.getResolvedCrateOrigin() | |
| or | |
| crate.isNone() and | |
| not r.hasResolvedCrateOrigin() | |
| private predicate resolvesExtendedCanonicalPath(Resolvable r, CrateOriginOption crate, string path) { | |
| path = r.getResolvedPath() and | |
| ( | |
| crate.asSome() = r.getResolvedCrateOrigin() | |
| or | |
| crate.isNone() and not r.hasResolvedCrateOrigin() |
And then changing the call to it:
- resolvesExtendedCanonicalPath(call, crate, path)
+ resolvesExtendedCanonicalPath(call.getResolvable(), crate, path)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 will actually be done as part of #18078.
No description provided.