Skip to content

Rust: Implement enclosing callable #17921

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

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

paldepind
Copy link
Contributor

Fills out some more of the data flow implementation, including an implementation of nodeGetEnclosingCallable. This fixes a good deal of the uniqueEnclosingCallable inconsistencies. There is only 7 left post this PR.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Nov 6, 2024
@paldepind paldepind force-pushed the rust-df-enclosing-callable branch from af5561c to 75e055c Compare November 6, 2024 15:15
@paldepind paldepind force-pushed the rust-df-enclosing-callable branch from 75e055c to dadc605 Compare November 6, 2024 15:23
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

/** Gets the underlying source code call, if any. */
abstract CallCfgNode asCall();

abstract string toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add QL doc: Gets a textual representation of this call.

RustDataFlow::ReturnKind getKind() { none() }
/** A data flow node that represents a value returned by a callable. */
final class ReturnNode extends ExprNode {
ReturnNode() { this.getCfgNode().getASuccessor() instanceof ExitCfgNode }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be ReturnExprs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so we don't want to include implicit returns like fn foo() { 12 }?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we need to include that as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reinstated the old implementation again :). If we want to include implicit returns then I think just looking at edges into the exit node handles all cases.

  • return goes directly to the exit node
  • In the absence of explicit returns, the BlockExpr is last both in a function and in a closure and it lets the final expression flow through if there is no ; at the end.
  • For a lambda without braces |a| a + 1 the single expression has an edge to the exit node.

@paldepind paldepind merged commit f2569c4 into github:main Nov 8, 2024
14 checks passed
@paldepind paldepind deleted the rust-df-enclosing-callable branch November 8, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants