Skip to content

Conversation

@redsun82
Copy link
Contributor

No description provided.

@redsun82 redsun82 requested a review from geoffw0 October 16, 2025 15:08
@redsun82 redsun82 requested a review from a team as a code owner October 16, 2025 15:08
@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 15:08
Copy link
Contributor

Copilot AI left a 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 introduces two new predicates to the ExtractedFile class in Rust CodeQL: hasSemantics() and isSkippedByCompilation(). These predicates help determine whether semantic information is available for a file and whether a file was skipped during conditional compilation.

  • Added hasSemantics() predicate to check if semantic information (macro expansion, conditional compilation) is available
  • Added isSkippedByCompilation() predicate to identify files skipped by conditional compilation
  • Updated test files to validate the new functionality with various file scenarios

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/ql/lib/codeql/files/FileSystem.qll Implements the two new predicates using diagnostic information
rust/ql/test/extractor-tests/File/File.ql Updates test query to validate the new predicates
rust/ql/test/extractor-tests/File/File.expected Updates expected test results with new predicate outputs
rust/ql/test/extractor-tests/File/bad_cargo/Cargo.toml Adds test file with invalid Cargo.toml content
rust/ql/test/extractor-tests/File/bad_cargo/.gitignore Adds gitignore for test scenario
rust/ql/lib/change-notes/2025-10-16-new-extracted-file-methods.md Documents the new predicates in change notes

@github-actions github-actions bot added documentation Rust Pull requests that update Rust code labels Oct 16, 2025
@redsun82 redsun82 changed the title Rust: introduce File::hasSemantics and File::isSkippedByCompilation Rust: introduce ExtractedFile::hasSemantics and ::isSkippedByCompilation Oct 16, 2025
geoffw0
geoffw0 previously approved these changes Oct 16, 2025
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for doing this so quickly!

| lib.rs:0:0:0:0 | lib.rs | fromSource: yes | hasSemantics: yes | isSkippedByCompilation: no |
| nested.rs:0:0:0:0 | nested.rs | fromSource: yes | hasSemantics: yes | isSkippedByCompilation: no |
| nested/file.rs:0:0:0:0 | nested/file.rs | fromSource: yes | hasSemantics: yes | isSkippedByCompilation: no |
| nested/not_compiled.rs:0:0:0:0 | nested/not_compiled.rs | fromSource: yes | hasSemantics: no | isSkippedByCompilation: yes |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education: what (in the Cargo setup) makes file.rs compiled while not_compiled.rs is not?

Copy link
Contributor Author

@redsun82 redsun82 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not pulled in as a module.

By default:

  • cargo loads src/lib.rs (for libraries) or src/main.rs (for binaries)
  • for a mod x in those, it will load either src/x.rs or src/x/mod.rs
  • from then on, for each submodule mod z in a x::y module, it will look for either src/x/y/z.rs or src/x/y/z/mod.rs (i.e. submodules are loaded from a directory recreating the module nesting)

If a file is not mentioned by a mod, or if its mention is not compiled because of a cfg setting, then the file is never loaded. There are ways to bypass the default paths (path settings in cargo.toml or path attributes of mod in code), but that's the gist of the file compilation strategy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so it's File/ in the path that identifies file.rs as special.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's mod file; in nested.rs that includes that

@redsun82 redsun82 merged commit a0d2005 into main Oct 21, 2025
20 checks passed
@redsun82 redsun82 deleted the redsun82/rust-file-semantics-predicates branch October 21, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants