-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: introduce ExtractedFile::hasSemantics and ::isSkippedByCompilation
#20655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 |
File::hasSemantics and File::isSkippedByCompilationExtractedFile::hasSemantics and ::isSkippedByCompilation
There was a problem hiding this 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 | |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) orsrc/main.rs(for binaries) - for a
mod xin those, it will load eithersrc/x.rsorsrc/x/mod.rs - from then on, for each submodule
mod zin ax::ymodule, it will look for eithersrc/x/y/z.rsorsrc/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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
No description provided.