Rust: extract hasImplementation on functions and consts#19649
Merged
Conversation
added 4 commits
June 3, 2025 10:41
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
Contributor
There was a problem hiding this comment.
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(
aibaars
previously approved these changes
Jun 12, 2025
Contributor
Author
|
sorry @aibaars, I had forgotten to update a test expectation, can you reapprove? |
hvitved
approved these changes
Jun 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.