Files
codeql/rust
Tom Hvitved 9f5b8141f0 Rust: Fix bad join
Before
```
Pipeline standard for TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc@be110b6w was evaluated in 512 iterations totaling 114ms (delta sizes total: 10942).
            8395   ~0%    {5} r1 = JOIN `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev_delta` WITH `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev` ON FIRST 3 OUTPUT Lhs.1, Lhs.2, _, Lhs.0, Lhs.3
            8395   ~0%    {4}    | REWRITE WITH Tmp.2 := 1, Out.2 := (Tmp.2 + In.4) KEEPING 4
            8448   ~0%    {5}    | JOIN WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2_0132#join_rhs` ON FIRST 3 OUTPUT Lhs.3, Rhs.3, Lhs.0, Lhs.1, Lhs.2
            7440   ~0%    {5}    | JOIN WITH TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::MkCallAndPos#53e3fb94#prev ON FIRST 2 OUTPUT Rhs.2, Lhs.2, Lhs.0, Lhs.3, Lhs.4
               0   ~0%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::ArgIsInstantiationOfToIndex::ArgSubstIsInstantiationOf::isInstantiationOf/3#5154f0d6#prev` ON FIRST 2 OUTPUT Lhs.2, Lhs.1, Lhs.3, Lhs.4

            2937   ~0%    {5} r2 = JOIN TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::MkCallAndPos#53e3fb94#prev_delta WITH `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev` ON FIRST 1 OUTPUT Lhs.2, Rhs.1, Lhs.0, Lhs.1, Rhs.2
               0   ~0%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::ArgIsInstantiationOfToIndex::ArgSubstIsInstantiationOf::isInstantiationOf/3#5154f0d6#prev` ON FIRST 2 OUTPUT Lhs.1, Lhs.4, Lhs.3, Lhs.2

               0   ~0%    {6} r3 = JOIN r2 WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 3 OUTPUT Lhs.3, Lhs.2, Lhs.0, Lhs.1, Rhs.3, _
                          {5}    | REWRITE WITH Tmp.5 := 0, TEST InOut.4 = Tmp.5 KEEPING 5
               0   ~0%    {5}    | SCAN OUTPUT In.2, In.3, In.1, _, In.0
               0   ~0%    {5}    | REWRITE WITH Out.3 := 0
               0   ~0%    {4}    | JOIN WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 4 OUTPUT Lhs.4, Lhs.0, Lhs.1, _
               0   ~0%    {4}    | REWRITE WITH Out.3 := 0

           12463   ~0%    {2} r4 = SCAN `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::ArgIsInstantiationOfToIndex::ArgSubstIsInstantiationOf::isInstantiationOf/3#5154f0d6#prev_delta` OUTPUT In.1, In.0
        22532135   ~0%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#reorder_1_0_2#prev` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0, Rhs.2
           12463   ~0%    {4}    | JOIN WITH TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::MkCallAndPos#53e3fb94#reorder_0_2_1#prev ON FIRST 2 OUTPUT Lhs.2, Lhs.3, Rhs.2, Lhs.0

           12463   ~2%    {6} r5 = JOIN r4 WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 3 OUTPUT Lhs.0, Lhs.3, Lhs.1, Lhs.2, Rhs.3, _
                          {5}    | REWRITE WITH Tmp.5 := 0, TEST InOut.4 = Tmp.5 KEEPING 5
            4285   ~0%    {5}    | SCAN OUTPUT In.0, In.2, In.3, _, In.1
            4285   ~0%    {5}    | REWRITE WITH Out.3 := 0
            4285   ~1%    {4}    | JOIN WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 4 OUTPUT Lhs.4, Lhs.0, Lhs.1, _
            4285   ~1%    {4}    | REWRITE WITH Out.3 := 0

               0   ~0%    {4} r6 = JOIN r2 WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 3 OUTPUT Lhs.3, Lhs.0, Lhs.1, Rhs.3
               0   ~0%    {6}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Lhs.3, Rhs.3, _
                          {6}    | REWRITE WITH Tmp.5 := 1, Out.5 := (InOut.3 - Tmp.5), TEST Out.5 = InOut.4
               0   ~0%    {4}    | SCAN OUTPUT In.0, In.1, In.2, In.3

           12463  ~45%    {4} r7 = JOIN r4 WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 3 OUTPUT Lhs.3, Lhs.0, Lhs.1, Rhs.3
            8178  ~50%    {6}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev` ON FIRST 3 OUTPUT Lhs.1, Lhs.0, Lhs.2, Lhs.3, Rhs.3, _
                          {6}    | REWRITE WITH Tmp.5 := 1, Out.5 := (InOut.3 - Tmp.5), TEST Out.5 = InOut.4
            7428  ~58%    {4}    | SCAN OUTPUT In.1, In.0, In.2, In.3

            4264   ~0%    {3} r8 = SCAN `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev_delta` OUTPUT In.1, In.2, In.0

            4312   ~0%    {5} r9 = JOIN r8 WITH `_project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/__#join_rhs#1` ON FIRST 2 OUTPUT Lhs.0, Lhs.1, Rhs.2, _, Lhs.2
            4312   ~0%    {5}    | REWRITE WITH Out.3 := 0
            4312   ~0%    {5}    | JOIN WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 4 OUTPUT Lhs.4, Lhs.2, Lhs.0, Lhs.1, _
            4312   ~0%    {5}    | REWRITE WITH Out.4 := 0

           12760   ~0%    {5} r10 = JOIN r8 WITH `project#TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::toCheckRanked/5#52f6d5e0#2` ON FIRST 2 OUTPUT Lhs.2, Lhs.0, Lhs.1, Rhs.2, Rhs.3
               0   ~0%    {7}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev` ON FIRST 3 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.0, Rhs.3, _
                          {7}    | REWRITE WITH Tmp.6 := 1, Out.6 := (InOut.3 - Tmp.6), TEST Out.6 = InOut.5
               0   ~0%    {5}    | SCAN OUTPUT In.4, In.2, In.0, In.1, In.3

            4312   ~0%    {5} r11 = r9 UNION r10
            4288   ~0%    {5}    | JOIN WITH TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::MkCallAndPos#53e3fb94#prev ON FIRST 2 OUTPUT Rhs.2, Lhs.2, Lhs.3, Lhs.4, Lhs.0
               0   ~0%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::ArgIsInstantiationOfToIndex::ArgSubstIsInstantiationOf::isInstantiationOf/3#5154f0d6#prev` ON FIRST 2 OUTPUT Lhs.4, Lhs.1, Lhs.2, Lhs.3

           11713  ~36%    {4} r12 = r1 UNION r3 UNION r5 UNION r6 UNION r7 UNION r11
           10942  ~39%    {4}    | AND NOT `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev`(FIRST 4)
                          return r12
```

After
```
Pipeline standard for TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc@07309ry7 was evaluated in 168 iterations totaling 145ms (delta sizes total: 8395).
        12517   ~0%    {6} r1 = SCAN `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argIsInstantiationOf/5#efdc1fbb#reorder_0_2_3_4_1#prev_delta` OUTPUT In.0, In.1, In.2, In.3, In.4, _
         4337   ~0%    {5}    | REWRITE WITH Tmp.5 := 0, TEST InOut.3 = Tmp.5 KEEPING 5
         4285   ~1%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, _
         4285   ~1%    {4}    | REWRITE WITH Out.3 := 0

            0   ~0%    {4} r2 = JOIN `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev_delta` WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argIsInstantiationOf/5#efdc1fbb#reorder_0_2_3_4_1#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Rhs.3

            0   ~0%    {5} r3 = SCAN r2 OUTPUT In.0, In.1, In.2, In.3, _
                       {4}    | REWRITE WITH Tmp.4 := 0, TEST InOut.3 = Tmp.4 KEEPING 4
            0   ~0%    {4}    | SCAN OUTPUT In.0, In.1, In.2, _
            0   ~0%    {4}    | REWRITE WITH Out.3 := 0

         8395   ~0%    {5} r4 = JOIN `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev_delta` WITH `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, _, Lhs.3
         8395   ~0%    {4}    | REWRITE WITH Tmp.3 := 1, Out.3 := (Tmp.3 + In.4) KEEPING 4
            0   ~0%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argIsInstantiationOf/5#efdc1fbb#reorder_0_2_3_4_1#prev` ON FIRST 4 OUTPUT Lhs.0, Lhs.1, Lhs.2, Lhs.3

            0   ~0%    {6} r5 = JOIN r2 WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Lhs.3, Rhs.3, _
                       {6}    | REWRITE WITH Tmp.5 := 1, Out.5 := (InOut.3 - Tmp.5), TEST Out.5 = InOut.4
            0   ~0%    {4}    | SCAN OUTPUT In.0, In.1, In.2, In.3

        12517  ~18%    {4} r6 = SCAN `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argIsInstantiationOf/5#efdc1fbb#reorder_0_2_3_4_1#prev_delta` OUTPUT In.0, In.1, In.2, In.3
        11759  ~12%    {4}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodCall.resolveCallTargetBlanketCand/1#dispred#f8b86f2d#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Lhs.3
         9874  ~12%    {6}    | JOIN WITH `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Lhs.3, Rhs.3, _
                       {6}    | REWRITE WITH Tmp.5 := 1, Out.5 := (InOut.3 - Tmp.5), TEST Out.5 = InOut.4
         7476  ~18%    {4}    | SCAN OUTPUT In.0, In.1, In.2, In.3

        11761  ~12%    {4} r7 = r1 UNION r3 UNION r4 UNION r5 UNION r6
         8395   ~0%    {4}    | AND NOT `TypeInference::NonMethodResolution::NonMethodArgsAreInstantiationsOfBlanket::argsAreInstantiationsOfToIndex/4#f6ff35dc#prev`(FIRST 4)
                       return r7
```
2026-02-11 16:11:30 +01:00
..
2025-04-25 16:16:49 +02:00
2026-01-20 11:56:20 +00:00
2026-02-11 16:11:30 +01:00
2026-01-13 10:20:47 +01:00
2026-01-20 08:50:58 +01:00
2024-11-21 10:21:11 +01:00
2025-02-20 10:39:14 +01:00
2025-09-12 09:01:13 +01:00

Rust on CodeQL

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.

Updating rust-analyzer

Here's a rundown of the typical actions to perform to do a rust-analyzer (and other dependencies) update. A one-time setup consists in installing cargo-edit with cargo install cargo-edit. On Ubuntu that also requires sudo apt install libssl-dev pkg-config.

  1. From the root of the codeql repo checkout, run a Cargo upgrade:

    cargo upgrade --incompatible --pinned
    
  2. Look at a diff of the Cargo.toml files: if all ra_ap_ prefixed dependencies have been updated to the same number, go on to the next step. Otherwise, it means the latest rust-analyzer update has not been fully rolled out to all its crates in crates.io. All ra_ap_ versions must agree! Downgrade by hand to the minimum one you see, and run a cargo update after that to fix the Cargo.lock file.

  3. Commit the changes, skipping pre-commit hooks if you have them enabled:

    git commit -am 'Cargo: upgrade dependencies' --no-verify
    
  4. Regenerate vendored bazel files (these allow faster builds, particularly on CI where it has to start from scratch each time), commit the changes:

    misc/bazel/3rdparty/update_tree_sitter_extractors_deps.sh
    git add .
    git commit -am 'Bazel: regenerate vendored cargo dependencies' --no-verify
    
  5. Run codegen

    bazel run //rust/codegen
    

    Take note whether rust/schema/ast.py was changed. That might need tweaks, new tests and/or downgrade/upgrade scripts down the line.

  6. Try compiling

    bazel run //rust:install
    
    • if it succeeds: good! You can move on to the next step.
    • if it fails while compiling rust-analyzer dependencies, you need to update the rust toolchain. Sometimes the error will tell you so explicitly, but it may happen that the error is more obscure. To update the rust toolchain:
      • you will need to open a PR on the internal repo updating RUST_VERSION in MODULE.bazel. In general you can have this merged independently of the changes in codeql.
      • in codeql, update both RUST_VERSION in MODULE.bazel and rust-toolchain.toml files. You may want to also update the nightly toolchain in rust/extractor/src/nightly-toolchain/rust-toolchain.toml to a more recent date while you're at it.
    • if it fails while compiling rust extractor code, you will need to adapt it to the new library version.
      • for example updating annotations in annotations.py, adding / removing generated tests.

    If you had to do any changes, commit them. If you updated the rust toolchain, running rust/lint.py might reformat or apply new lints to the code.

  7. Check with CI if everything is in order.

  8. Run DCA with database caching disabled. Iterate on the code if needed.

  9. If in step 5 the schema was updated, add upgrade/downgrade scripts and a change note. This is best done last to reduce the chance of merge conflicts (none of the other testing depends on having upgrade and downgrade scripts in place). See Upgrading a language database schema.