Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Oct 21, 2025

Adds Callable.getBody() as a convenient way of getting the body of a function or a closure. To do this, the existing getBody() predicates on Function and ClosureExpr had to be renamed.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Oct 21, 2025
toBeTested(x) and not x.isUnknown() and getBody = x.getBody()
}

query predicate getClosureBody(ClosureExpr x, Expr getClosureBody) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
toBeTested(x) and not x.isUnknown() and getParam = x.getParam(index)
}

query predicate getBody(Function x, Expr getBody) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.

query predicate getBody(Function x, BlockExpr getBody) {
toBeTested(x) and not x.isUnknown() and getBody = x.getBody()
query predicate getFunctionBody(Function x, BlockExpr getFunctionBody) {

Check warning

Code scanning / CodeQL

Predicates starting with "get" or "as" should return a value Warning generated test

This predicate starts with 'get' but does not return a value.
@hvitved hvitved force-pushed the rust/callable-get-body branch 2 times, most recently from 93fcd75 to 0ba8f4e Compare October 22, 2025 14:38
@hvitved hvitved force-pushed the rust/callable-get-body branch from 0ba8f4e to 4b6c390 Compare October 22, 2025 14:41
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 22, 2025
@hvitved hvitved marked this pull request as ready for review October 22, 2025 15:08
@hvitved hvitved requested a review from a team as a code owner October 22, 2025 15:08
Copilot AI review requested due to automatic review settings October 22, 2025 15:08
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 adds a getBody() method to the Callable class that provides a unified way to access the body of both functions and closures. To implement this, the existing getBody() methods on Function and ClosureExpr were renamed to getFunctionBody() and getClosureBody() respectively, and the Callable class now provides a new getBody() method that delegates to these renamed methods.

Key changes:

  • Renamed Function.getBody() to Function.getFunctionBody() and ClosureExpr.getBody() to ClosureExpr.getClosureBody()
  • Added Callable.getBody() as a synthesized property that returns the appropriate body expression
  • Updated all references throughout the codebase to use the new method names
  • Added database schema migrations (upgrades and downgrades) to handle the renamed relations

Reviewed Changes

Copilot reviewed 18 out of 33 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/schema/prelude.py Added body synthesized property to Callable class
rust/schema/ast.py Renamed body to closure_body in ClosureExpr and to function_body in Function
rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected Updated test expectations to use new method names getFunctionBody() and getClosureBody()
rust/ql/lib/upgrades/dfade44a27bd44db996ae8c5095a11effc883aba/upgrade.ql Created upgrade query to migrate from old relation names to new ones
rust/ql/lib/upgrades/dfade44a27bd44db996ae8c5095a11effc883aba/upgrade.properties Defined upgrade properties for relation renaming
rust/ql/lib/rust.dbscheme Renamed database relations from closure_expr_bodies/function_bodies to closure_expr_closure_bodies/function_function_bodies
rust/ql/lib/codeql/rust/internal/TypeInference.qll Updated references to use getFunctionBody() and getClosureBody()
rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll Simplified parameter scope check to use Callable.getBody()
rust/ql/lib/codeql/rust/elements/internal/FunctionImpl.qll Added override for getBody() that delegates to getFunctionBody()
rust/ql/lib/codeql/rust/elements/internal/ClosureExprImpl.qll Added override for getBody() that delegates to getClosureBody()
rust/ql/lib/codeql/rust/elements/Callable.qll Added import for Expr type
rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll Simplified CallableScope to use Callable.hasBody() and removed redundant getBody() method
rust/ql/lib/codeql/rust/controlflow/internal/CfgConsistency.qll Simplified consistency check to use Callable.hasBody()
rust/ql/.generated.list Updated generated file hashes
rust/extractor/src/translate/generated.rs Renamed variables from body to closure_body and function_body in code generation
rust/downgrades/30a0713e5bf69c60d003e4994e5abd1c78a36826/upgrade.properties Defined downgrade properties for relation renaming
rust/downgrades/30a0713e5bf69c60d003e4994e5abd1c78a36826/downgrade.ql Created downgrade query to migrate from new relation names to old ones
rust/ast-generator/src/main.rs Added property name mappings to ensure correct field names during code generation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

LGTM, pending successful DCA run.

I also assume the upgrade/downgrade scripts have been minimally tested. They look good and aren't overly complex, I have more confidence than normal.

@hvitved hvitved merged commit c84cec9 into github:main Oct 22, 2025
23 checks passed
@hvitved hvitved deleted the rust/callable-get-body branch October 22, 2025 17:57
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