Rust: Add Impl::getSelf() and Impl::getTrait()#21918
Conversation
|
|
||
| query predicate getTrait(Impl x, TypeRepr getTrait) { | ||
| toBeTested(x) and not x.isUnknown() and getTrait = x.getTrait() | ||
| query predicate getTraitTy(Impl x, TypeRepr getTraitTy) { |
19e004c to
d5f9447
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends the Rust Impl API by adding higher-level predicates Impl::getSelf() and Impl::getTrait(), while renaming the existing Impl::getTrait() (which returned a TypeRepr) to Impl::getTraitTy() to better align with getSelfTy(). The change is wired through the Rust schema/extractor, dbscheme (including upgrade/downgrade metadata), and updated/regenerated tests/expected outputs.
Changes:
- Rename the
Impltrait type field/predicate fromtrait_/getTrait()totrait_ty/getTraitTy()across schema, extractor, and QL libraries. - Add
Impl::getSelf()andImpl::getTrait()convenience predicates on top of the existing type-repr accessors. - Update extractor tests, expected output, and generated lists to reflect the rename.
Show a summary per file
| File | Description |
|---|---|
| rust/schema/ast.py | Renames the Impl AST child from trait_ to trait_ty. |
| rust/schema/annotations.py | Fixes a docstring typo in the Impl annotation docs. |
| rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected | Updates expected AST print output to use getTraitTy(). |
| rust/ql/test/extractor-tests/generated/Impl/Impl.ql | Updates generated extractor test query predicate from getTrait to getTraitTy. |
| rust/ql/test/extractor-tests/generated/Impl/Impl.expected | Updates expected extractor test output to match getTraitTy. |
| rust/ql/test/extractor-tests/generated/Impl/gen_impl.rs | Regenerates generated Rust test fixture comment text. |
| rust/ql/test/extractor-tests/generated/.generated_tests.list | Updates generated test list hashes for the Impl fixture. |
| rust/ql/test/extractor-tests/canonical_path/canonical_paths.ql | Updates trait-presence check to hasTraitTy(). |
| rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll | Updates trait-impl detection to hasTraitTy(). |
| rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/upgrade.properties | Adds dbscheme upgrade rules for renaming impl_traits to impl_trait_ties. |
| rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/rust.dbscheme | Adds the new dbscheme snapshot for the upgrade step (generated). |
| rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/old.dbscheme | Adds the prior dbscheme snapshot for the upgrade step (generated). |
| rust/ql/lib/rust.dbscheme | Renames the relation impl_traits to impl_trait_ties and column trait to trait_ty. |
| rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll | Updates uses of getTrait()/hasTrait() on Impl to getTraitTy()/hasTraitTy(). |
| rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll | Updates blanket-impl checks to hasTraitTy(). |
| rust/ql/lib/codeql/rust/internal/PathResolution.qll | Updates trait path resolution to use getTraitTy(). |
| rust/ql/lib/codeql/rust/elements/internal/ImplImpl.qll | Adds Impl::getSelf() and Impl::getTrait(), and aligns inherent-impl logic with hasTraitTy(). |
| rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll | Regenerates raw accessors to expose getTraitTy() via impl_trait_ties (generated). |
| rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll | Regenerates parent/child indexing for trait_ty (generated). |
| rust/ql/lib/codeql/rust/elements/internal/generated/Impl.qll | Regenerates the public Impl element API to rename getTrait()→getTraitTy() (generated). |
| rust/ql/lib/codeql/rust/elements/Impl.qll | Regenerates public Impl wrapper docs (generated). |
| rust/ql/.generated.list | Updates generated file hashes for the regen set. |
| rust/extractor/src/translate/generated.rs | Updates extractor translation variable/field naming to trait_ty. |
| rust/extractor/src/generated/top.rs | Updates trap emission to output impl_trait_ties instead of impl_traits. |
| rust/extractor/src/generated/.generated.list | Updates generated extractor file hashes. |
| rust/downgrades/77e9a70be4b0cf5ecb1d4c1d841b2d970715a912/upgrade.properties | Adds downgrade rules to rename impl_trait_ties back to impl_traits. |
| rust/ast-generator/src/main.rs | Maps the parser field name trait_ to the schema property trait_ty. |
Copilot's findings
- Files reviewed: 16/29 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
geoffw0
left a comment
There was a problem hiding this comment.
LGTM, one question about the upgrade / downgrade scripts.
| * impl MyTrait for MyType { ... } | ||
| * ``` | ||
| * | ||
| * the trait being implemented is in the second case `MyTrait`. |
There was a problem hiding this comment.
The examples are nice and clear. 👍
| description: Renamed `impl_traits` to `impl_trait_ties` | ||
| compatibility: full | ||
|
|
||
| impl_trait_ties.rel: reorder impl_traits(@impl id, @type_repr trait_ty) id trait_ty |
There was a problem hiding this comment.
What do the parameter names id and trait_ty mean in the context of a reorder? I notice both the upgrade and downgrade script specify the new parameter name trait_ty, neither gives the original name trait.
There was a problem hiding this comment.
It's just a convoluted way of writing a rename (much like en eta expansion).
There was a problem hiding this comment.
Yes, my question is about the parameter names in particular. Compare the reorder from the downgrades script:
impl_traits.rel: reorder impl_trait_ties(@impl id, @type_repr trait_ty) id trait_ty
to the upgrade script:
impl_trait_ties.rel: reorder impl_traits(@impl id, @type_repr trait_ty) id trait_ty
The table names impl_traits and impl_trait_ties have swapped places between the two, as we'd expect. However the parameter name is trait_ty in all cases, I was expecting the name trait from the old .dbscheme in two of these positions.
There was a problem hiding this comment.
I don't think the names necessarily have to match those in the DB scheme (I would have expected a CI failure if that was the case), but I can change it.
Does what the PR title says.
I had to rename the existing
Impl::getTrait()predicate toImpl::getTraitTy(), which aligns with the already existingImpl::getSelfTy()predicate.