-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: extract hasImplementation on functions and consts
#19649
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
Conversation
When skipping bodies in library code, we lose the information whether a body was originally present. This can be important, for example when determining whether a trait method has a default implementation. With this change that information can be recovered via the `hasImplementation` predicate.
f88949a to
1110fea
Compare
hasImplementation on functionshasImplementation on functions and consts
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 has_implementation predicate to capture whether functions and constants originally had bodies (even when skipped in library code), updates the extractor to emit this information, and adds schema, upgrade/downgrade scripts, and codegen template fixes to support the new tables.
- Define
has_implementationinannotations.pyfor bothConstandFunction - Emit the new predicate in the extractor (
base.rs) when a body is present - Add new tables in
rust.dbscheme, upgrade/downgrade scripts, update.generated.list, and fix the codegen template for detached predicates
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/schema/annotations.py | Add has_implementation predicate with docs for Const and Function |
| rust/extractor/src/translate/base.rs | Call emit_*_has_implementation when bodies exist |
| rust/ql/lib/rust.dbscheme | Introduce const_has_implementation and function_has_implementation tables |
| rust/ql/lib/upgrades/.../upgrade.ql & upgrade.properties (and downgrades) | Backfill and remove the new tables via QL upgrade/downgrade scripts |
| rust/ql/.generated.list | Refresh generated file hashes for updated QLL files |
| misc/codegen/templates/rust_classes.mustache | Update template to generate predicate emit methods correctly |
Comments suppressed due to low confidence (2)
rust/extractor/src/translate/base.rs:774
- There are currently no extractor tests validating that
emit_function_has_implementationandemit_const_has_implementationfire correctly when bodies are present or absent. Consider adding tests covering both scenarios to ensure the new predicates are populated as expected.
if node.body().is_some() {
rust/ql/lib/rust.dbscheme:2993
- Consider adding a brief comment above the
function_has_implementationandconst_has_implementationtable definitions to describe their purpose and improve maintainability of the DB schema.
#keyset[id]
function_has_implementation(
|
sorry @aibaars, I had forgotten to update a test expectation, can you reapprove? |
When skipping bodies in library code, we were losing the information whether a body was originally present. This can be important, for example when determining whether a trait method has a default implementation.
With this change that information can now be recovered via the
hasImplementationpredicate.Finally, the above uncovered a bug in the rustgen templates, where a detached predicate property would not be handled correctly. That is fixed now.