Skip to content

Rust: introduce ExtractedFile::hasSemantics and ::isSkippedByCompilation - #20655

Merged
redsun82 merged 4 commits into
mainfrom
redsun82/rust-file-semantics-predicates
Oct 21, 2025
Merged

Rust: introduce ExtractedFile::hasSemantics and ::isSkippedByCompilation#20655
redsun82 merged 4 commits into
mainfrom
redsun82/rust-file-semantics-predicates

Conversation

@redsun82

Copy link
Copy Markdown
Contributor

No description provided.

@redsun82
redsun82 requested a review from geoffw0October 16, 2025 15:08
@redsun82
redsun82 requested a review from a team as a code ownerOctober 16, 2025 15:08
CopilotAI review requested due to automatic review settings October 16, 2025 15:08

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
rust/ql/lib/codeql/files/FileSystem.qllImplements the two new predicates using diagnostic information
rust/ql/test/extractor-tests/File/File.qlUpdates test query to validate the new predicates
rust/ql/test/extractor-tests/File/File.expectedUpdates expected test results with new predicate outputs
rust/ql/test/extractor-tests/File/bad_cargo/Cargo.tomlAdds test file with invalid Cargo.toml content
rust/ql/test/extractor-tests/File/bad_cargo/.gitignoreAdds gitignore for test scenario
rust/ql/lib/change-notes/2025-10-16-new-extracted-file-methods.mdDocuments the new predicates in change notes

@github-actionsgithub-actionsBot added documentation Rust Pull requests that update Rust code labels Oct 16, 2025
@redsun82redsun82 changed the title Rust: introduce File::hasSemantics and File::isSkippedByCompilationRust: introduce ExtractedFile::hasSemantics and ::isSkippedByCompilationOct 16, 2025
Comment threadrust/ql/lib/codeql/files/FileSystem.qll Fixed
geoffw0
geoffw0 previously approved these changes Oct 16, 2025

@geoffw0geoffw0 left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

@redsun82redsun82Oct 17, 2025

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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 mainOct 21, 2025
20 checks passed
@redsun82
redsun82 deleted the redsun82/rust-file-semantics-predicates branch October 21, 2025 15:02
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationRustPull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@redsun82@geoffw0@github-advanced-security