Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Nov 22, 2024

No description provided.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Nov 22, 2024
@hvitved hvitved force-pushed the rust/canonical-path-dataflow branch from 1eac6aa to 143d7e2 Compare November 22, 2024 12:23
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 25, 2024
@hvitved hvitved marked this pull request as ready for review November 25, 2024 08:26
@hvitved hvitved requested a review from paldepind November 25, 2024 08:26
Copy link
Contributor

@paldepind paldepind left a 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 :)

Comment on lines +428 to +442
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()
Copy link
Contributor

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:

Suggested change
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)

Copy link
Contributor Author

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.

@hvitved hvitved merged commit e6161a5 into github:main Nov 25, 2024
39 checks passed
@hvitved hvitved deleted the rust/canonical-path-dataflow branch November 25, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants