Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Apr 24, 2025

Written with the help from Copilot chat.

DCA looks great; the Missing call targets metric goes down for all projects, without significant analysis slowdown.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Apr 24, 2025
@hvitved hvitved force-pushed the rust/crate-graph-self-param branch from ffbe31b to 6df5a1e Compare April 24, 2025 13:30
@hvitved hvitved marked this pull request as ready for review April 25, 2025 12:54
Copilot AI review requested due to automatic review settings April 25, 2025 12:54
@hvitved hvitved requested a review from a team as a code owner April 25, 2025 12:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the function emitting logic to extract the self parameter separately from the other parameters in Rust functions. Key changes include:

  • Introducing a new variable to hold function_data via db.function_data(function).
  • Refactoring the parameter iteration to use .enumerate() with filter_map to extract the self parameter when present.
  • Updating the generated ParamList to include the extracted self parameter.
Files not reviewed (4)
  • rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll: Language not supported
  • rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected: Language not supported
  • rust/ql/test/library-tests/type-inference/type-inference.ql: Language not supported
  • rust/ql/test/query-tests/security/CWE-089/CONSISTENCY/PathResolutionConsistency.expected: Language not supported

pat: None,
})

if idx == 0 && function_data.has_self_param() {
Copy link

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

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

Consider extracting the self parameter logic into a separate helper function to improve clarity and reduce complexity in the parameter iteration block.

Copilot uses AI. Check for mistakes.
@hvitved hvitved requested a review from aibaars April 28, 2025 06:52
@paldepind
Copy link
Contributor

I'm not sure if it's related or orthogonal or already fixed in this PR, but FWIW it seems to me that functions from dependencies also have one additional non-self parameter. When f is from a dependency doing f.getParamList().getNumberOfParams() seems to be 1 bigger than it should be, as if the self parameter is counted alongside normal parameters.

This just bit me as I added an arity check in method resolution and lost a bunch of results.

Comment on lines +413 to +414
lifetime: None,
name: None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the name be simply self? Is it possible to populate the lifetime field, or is it not important?

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 decided to not populate the name, since we also don't do that for non-self parameters. Lifetimes are currently not important.

Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'm wondering whether we should populate the name and lifetime fields.

@hvitved
Copy link
Contributor Author

hvitved commented Apr 29, 2025

I'm not sure if it's related or orthogonal or already fixed in this PR, but FWIW it seems to me that functions from dependencies also have one additional non-self parameter. When f is from a dependency doing f.getParamList().getNumberOfParams() seems to be 1 bigger than it should be, as if the self parameter is counted alongside normal parameters.

That should be resolved by this PR as well.

@hvitved hvitved merged commit 64145ab into github:main Apr 29, 2025
17 checks passed
@hvitved hvitved deleted the rust/crate-graph-self-param branch April 29, 2025 19:23
@paldepind
Copy link
Contributor

That should be resolved by this PR as well.

Nice! Thanks.

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.

3 participants