Files
codeql/rust
Tom Hvitved 63aac1babb Rust: Fix bad join in getCanonicalPath
Before
```
Pipeline standard for PathResolution::ItemNode.getCanonicalPath/1#dispred#f52ac1c6@5132b1w8 was evaluated in 107 iterations totaling 1217ms (delta sizes total: 870557).
           568160   ~1%    {2} r1 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::AssocItemNode.hasCanonicalPath/1#dispred#120fa1ad_project#PathResolution::ItemNode.__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
           564597   ~1%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

            68670   ~1%    {2} r2 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::VariantItemNode.hasCanonicalPath/1#dispred#12012145_project#PathResolution::ItemNod__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
            68670   ~0%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#5` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

            49047   ~1%    {2} r3 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::StructItemNode.hasCanonicalPath/1#dispred#f482e99c_project#PathResolution::ItemNode__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
            49047   ~2%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#2` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

              229   ~0%    {2} r4 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::UnionItemNode.hasCanonicalPath/1#dispred#f67c4b73_project#PathResolution::ItemNode.__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
              229   ~0%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#4` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

            12207   ~0%    {2} r5 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::EnumItemNode.hasCanonicalPath/1#dispred#03ce35b1_project#PathResolution::ItemNode.g__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
            12207   ~0%    {3}    | JOIN WITH `__PathResolution::EnumItemNode.getName/0#dispred#f21ce0ed_PathResolution::ItemNode.getCanonicalPathP__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

            26698   ~2%    {2} r6 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::ModuleItemNode.hasCanonicalPath/1#dispred#2fee2540_project#PathResolution::ItemNode__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
            26698   ~0%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#1` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

             6315   ~1%    {2} r7 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::TraitItemNode.hasCanonicalPath/1#dispred#824f98e3_project#PathResolution::ItemNode.__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
             6315   ~1%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#3` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

           112374   ~0%    {3} r8 = JOIN `PathResolution::ImplItemNode.getCanonicalPathTraitPart/1#dispred#009a7fd0#prev_delta` WITH `_PathResolution::ImplItemNode.getTraitPath/0#dispred#3b7d1cb6_PathResolution::ImplItemNode.hasCanoni__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, _
           112374   ~3%    {3}    | REWRITE WITH Out.2 := 3

           872046   ~1%    {2} r9 = SCAN `PathResolution::ItemNode.getCanonicalPath/1#dispred#f52ac1c6#prev_delta` OUTPUT In.1, In.0
        777662505   ~2%    {3}    | JOIN WITH `PathResolution::ImplItemNode.hasCanonicalPath/1#dispred#4e7c51c6_10#join_rhs` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0
           150127   ~1%    {3}    | JOIN WITH `PathResolution::ImplItemNode.resolveSelfTy/0#dispred#cf157d04` ON FIRST 2 OUTPUT Lhs.0, Lhs.2, _
           150127   ~0%    {3}    | REWRITE WITH Out.2 := 1

           262501   ~1%    {3} r10 = r8 UNION r9

           230996   ~1%    {5} r11 = JOIN r10 WITH `PathResolution::ImplItemNode.getTraitPath/0#dispred#3b7d1cb6` ON FIRST 1 OUTPUT Lhs.0, Lhs.1, Lhs.2, _, _
           230996   ~0%    {5}    | REWRITE WITH Out.3 := 4, Out.4 := 0

                           {3} r12 = r10 AND NOT `PathResolution::ImplItemNode.getTraitPath/0#dispred#3b7d1cb6_0#antijoin_rhs`(FIRST 1)
            31487   ~0%    {5}    | SCAN OUTPUT In.0, In.1, In.2, _, _
            31487   ~1%    {5}    | REWRITE WITH Out.3 := 2, Out.4 := 0

           262483   ~0%    {5} r13 = r11 UNION r12
           262483   ~0%    {5}    | JOIN WITH PRIMITIVE range#bbb ON Lhs.4,Lhs.3,Lhs.2
           262483   ~0%    {3}    | SCAN OUTPUT In.3, In.0, In.1
           142807   ~1%    {3}    | JOIN WITH `__PathResolution::ImplItemNode.getCanonicalPathTraitPart/1#dispred#009a7fd0#prev_PathResolution::Imp__#join_rhs` ON FIRST 3 OUTPUT Lhs.1, Lhs.2, Rhs.3

           870570   ~1%    {3} r14 = r1 UNION r2 UNION r3 UNION r4 UNION r5 UNION r6 UNION r7 UNION r13
           870566   ~1%    {3}    | AND NOT `PathResolution::ItemNode.getCanonicalPath/1#dispred#f52ac1c6#prev`(FIRST 3)
                           return r14
```

After
```
Pipeline standard for PathResolution::ItemNode.getCanonicalPath/1#dispred#f52ac1c6@90aba2wd was evaluated in 100 iterations totaling 28ms (delta sizes total: 870531).
        568160   ~0%    {2} r1 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::AssocItemNode.hasCanonicalPath/1#dispred#120fa1ad_project#PathResolution::ItemNode.__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
        564597   ~1%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

         68670   ~0%    {2} r2 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::VariantItemNode.hasCanonicalPath/1#dispred#12012145_project#PathResolution::ItemNod__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
         68670   ~1%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#5` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

         49047   ~0%    {2} r3 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::StructItemNode.hasCanonicalPath/1#dispred#f482e99c_project#PathResolution::ItemNode__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
         49047   ~1%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#2` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

           229   ~0%    {2} r4 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::UnionItemNode.hasCanonicalPath/1#dispred#f67c4b73_project#PathResolution::ItemNode.__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
           229   ~0%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#4` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

         12207   ~1%    {2} r5 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::EnumItemNode.hasCanonicalPath/1#dispred#03ce35b1_project#PathResolution::ItemNode.g__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
         12207   ~0%    {3}    | JOIN WITH `__PathResolution::EnumItemNode.getName/0#dispred#f21ce0ed_PathResolution::ItemNode.getCanonicalPathP__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

         26698   ~0%    {2} r6 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::ModuleItemNode.hasCanonicalPath/1#dispred#2fee2540_project#PathResolution::ItemNode__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
         26698   ~4%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#1` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

          6315   ~1%    {2} r7 = JOIN `PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_delta` WITH `_PathResolution::TraitItemNode.hasCanonicalPath/1#dispred#824f98e3_project#PathResolution::ItemNode.__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1
          6315   ~2%    {3}    | JOIN WITH `__PathResolution::ItemNode.getCanonicalPathPrefix/1#dispred#a1d9332d#prev_PathResolution::ItemNode.g__#join_rhs#3` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2

        150127   ~0%    {3} r8 = JOIN `PathResolution::ImplItemNode.getSelfCanonicalPath/1#dispred#8ed81fbe#prev_delta` WITH `PathResolution::ImplItemNode.hasCanonicalPath/1#dispred#4e7c51c6` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, _
        150127   ~0%    {3}    | REWRITE WITH Out.2 := 1

        112374   ~1%    {3} r9 = JOIN `PathResolution::ImplItemNode.getCanonicalPathTraitPart/1#dispred#009a7fd0#prev_delta` WITH `_PathResolution::ImplItemNode.getTraitPath/0#dispred#3b7d1cb6_PathResolution::ImplItemNode.hasCanoni__#join_rhs` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, _
        112374   ~0%    {3}    | REWRITE WITH Out.2 := 3

        262501   ~0%    {3} r10 = r8 UNION r9

        230996   ~1%    {5} r11 = JOIN r10 WITH `PathResolution::ImplItemNode.getTraitPath/0#dispred#3b7d1cb6` ON FIRST 1 OUTPUT Lhs.0, Lhs.1, Lhs.2, _, _
        230996   ~1%    {5}    | REWRITE WITH Out.3 := 4, Out.4 := 0

                        {3} r12 = r10 AND NOT `PathResolution::ImplItemNode.getTraitPath/0#dispred#3b7d1cb6_0#antijoin_rhs`(FIRST 1)
         31487   ~0%    {5}    | SCAN OUTPUT In.0, In.1, In.2, _, _
         31487   ~0%    {5}    | REWRITE WITH Out.3 := 2, Out.4 := 0

        262483   ~1%    {5} r13 = r11 UNION r12
        262483   ~1%    {5}    | JOIN WITH PRIMITIVE range#bbb ON Lhs.4,Lhs.3,Lhs.2
        262483   ~0%    {3}    | SCAN OUTPUT In.3, In.0, In.1
        142772   ~0%    {3}    | JOIN WITH `__PathResolution::ImplItemNode.getCanonicalPathTraitPart/1#dispred#009a7fd0#prev_PathResolution::Imp__#join_rhs` ON FIRST 3 OUTPUT Lhs.1, Lhs.2, Rhs.3

        870535   ~1%    {3} r14 = r1 UNION r2 UNION r3 UNION r4 UNION r5 UNION r6 UNION r7 UNION r13
        870531   ~1%    {3}    | AND NOT `PathResolution::ItemNode.getCanonicalPath/1#dispred#f52ac1c6#prev`(FIRST 3)
                        return r14
```
2025-06-11 09:15:13 +02:00
..
2025-04-25 16:16:49 +02:00
2025-06-11 09:15:13 +02:00
2024-11-21 10:21:11 +01:00
2025-02-20 10:39:14 +01:00

Rust on CodeQL

Warning

Rust support for CodeQL is experimental. No support is offered. QL and database interfaces will change and break without notice or deprecation periods.

Development

Dependencies

If you don't have the semmle-code repo you may need to install Bazel manually, e.g. from https://github.com/bazelbuild/bazelisk.

Building the Rust Extractor

This approach uses a released codeql version and is simpler to use for QL development. From anywhere under your semmle-code or codeql directory you can run:

bazel run @codeql//rust:install

You can use shorter versions of the above command:

bazel run //rust:install  # if under the `codeql` checkout
bazel run rust:install  # if at the root of the `codeql` checkout
bazel run :install  # if at the `rust` directory of the `codeql` checkout

You now need to create a per-user CodeQL configuration file and specify the option:

--search-path PATH/TO/semmle-code/ql

(wherever the codeql checkout is on your system)

You can now use the Rust extractor e.g. to run Rust tests from the command line or in VSCode.

Building the Rust Extractor (as a sembuild target)

This approach allows you to build a Rust extractor with a CLI built from source. From your semmle-code directory run:

./build target/intree/codeql-rust

You can now invoke it directly, for example to run some tests:

./target/intree/codeql-rust/codeql test run ql/rust/ql/test/PATH/TO/TEST/

Building a Database

TODO

Code Generation

If you make changes to either

  • ast-generator/, or
  • schema/*.py

you'll need to regenerate code. You can do so running

bazel run @codeql//rust/codegen

Sometimes, especially if resolving conflicts on generated files, you might need to run

bazel run @codeql//rust/codegen -- --force

for code generation to succeed.