-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Add Callable.getBody()
#20664
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
Rust: Add Callable.getBody()
#20664
Conversation
| 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
| 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
|
|
||
| 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
93fcd75 to
0ba8f4e
Compare
0ba8f4e to
4b6c390
Compare
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.
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()toFunction.getFunctionBody()andClosureExpr.getBody()toClosureExpr.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.
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.
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.
Adds
Callable.getBody()as a convenient way of getting the body of a function or a closure. To do this, the existinggetBody()predicates onFunctionandClosureExprhad to be renamed.