Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved include-macro identification and path-handling defects can resolve modules from the wrong directory or break previously valid lookups.
5 open issues
Exclude user-defined macros from include path detection · New Stop include traversal at unsupported include invocations · New Resolve absolute include paths from the filesystem root · New Normalize backslashes before deriving nested include directories · New Use the included file's directory for path attributes · New
What changed in this PR
This PR improves Rust module resolution in CodeQL by using the included file’s directory for modules declared inside literal-path include! expansions, without changing extractor locations.
Changes:
- Extracts token-tree text and exposes it through
TokenTree.getText(), with schema upgrade and downgrade support. - Adds include-aware module lookup for direct, nested, and macro-generated includes.
- Adds regression fixtures and updates generated extractor expectations.
| File | Description |
|---|---|
rust/schema/ast.py |
Adds optional token-tree text. |
rust/ql/test/library-tests/path-resolution-include/main.rs |
Checks paths through included modules. |
rust/ql/test/library-tests/path-resolution-include/including/source.rs |
Exercises direct, raw, local, and wrapped includes. |
rust/ql/test/library-tests/path-resolution-include/including/local.rs |
Declares a local included module. |
rust/ql/test/library-tests/path-resolution-include/including/local_child.rs |
Supplies the local module target. |
rust/ql/test/library-tests/path-resolution-include/include.qlref |
Configures test-result postprocessing. |
rust/ql/test/library-tests/path-resolution-include/include.ql |
Checks resolution, imported files, and token text. |
rust/ql/test/library-tests/path-resolution-include/include.expected |
Records expected resolution results. |
rust/ql/test/library-tests/path-resolution-include/foo/sibling.rs |
Supplies a sibling module target. |
rust/ql/test/library-tests/path-resolution-include/foo/nested/nested_child.rs |
Supplies a nested include’s module target. |
rust/ql/test/library-tests/path-resolution-include/foo/nested/more.rs |
Declares a module within a nested include. |
rust/ql/test/library-tests/path-resolution-include/foo/inline/child.rs |
Supplies an inline module’s child target. |
rust/ql/test/library-tests/path-resolution-include/foo/directory/mod.rs |
Supplies a directory-style module target. |
rust/ql/test/library-tests/path-resolution-include/foo/bar.rs |
Combines module declarations and a nested include. |
rust/ql/test/library-tests/path-resolution-include/Cargo.lock |
Records the test fixture package. |
rust/ql/test/extractor-tests/generated/TokenTree/TokenTree.ql |
Adds generated token-text checks. |
rust/ql/test/extractor-tests/generated/TokenTree/TokenTree.expected |
Records expected token-tree text. |
rust/ql/lib/upgrades/7980434ec600632010dc150cdd85c23a95b922fb/upgrade.properties |
Declares the schema upgrade. |
rust/ql/lib/upgrades/7980434ec600632010dc150cdd85c23a95b922fb/old.dbscheme |
Preserves the pre-upgrade schema. |
rust/ql/lib/rust.dbscheme |
Adds the token-tree text relation. |
rust/ql/lib/codeql/rust/internal/PathResolution.qll |
Adds include-aware module lookup. |
rust/ql/lib/codeql/rust/elements/internal/generated/TokenTree.qll |
Exposes token-text accessors. |
rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll |
Reads token text from the database. |
rust/ql/lib/change-notes/2026-11-25-include-module-paths.md |
Documents resolution and API changes. |
rust/ql/.generated.list |
Updates generated QL file hashes. |
rust/extractor/src/translate/mappings.rs |
Extracts token-tree syntax text. |
rust/extractor/src/translate/generated.rs |
Includes text in token-tree translation. |
rust/extractor/src/generated/top.rs |
Emits token-tree text tuples. |
rust/extractor/src/generated/.generated.list |
Updates generated extractor hashes. |
rust/downgrades/172741cc1dc33e5c03ec0412a3c877cc830dc99e/upgrade.properties |
Removes token text during downgrade. |
rust/downgrades/172741cc1dc33e5c03ec0412a3c877cc830dc99e/rust.dbscheme |
Supplies the downgrade target schema. |
rust/ast-generator/src/main.rs |
Adds token text to generated AST fields. |
Review effort: Balanced (adaptive)
There was a problem hiding this comment.
🟡 Changes recommended
Rust include-path resolution still mishandles unindexed files, relative includes inside computed expansions, commented arguments, and library-mode dependencies, leaving modules unresolved or resolved against the wrong directory.
4 open issues
5 resolved since last review
Review effort: Max
6b57792 to
650c30a
Compare
650c30a to
e95da9d
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep include token trees in library mode and ensure included files get File entities and are added to the source archive. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
b0a7237 to
028c838
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
028c838 to
4f6e84b
Compare
paldepind
left a comment
There was a problem hiding this comment.
Looks good overall.
I do think that including the token tree as a string is a bit of a workaround. It would be cleaner to extract the token tree properly as AST nodes. I think it's fine, since it's good enough for the purpose here. But maybe explicitly calling out TokenTree.getText() in the change note is a step too far?
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Agreed; I removed the |

Modules declared in files loaded by
include!should resolve relative to the included file, rather than the file containing the macro call.The solution in this PR is to extract token-tree text for macro invocations (which may also become useful elsewhere) and use literal
include!paths to determine the base directory for module resolution, without changing extractor locations. Computed include paths, ordinary strings containing escapes, and absolute Windows paths retain the existing behavior.Alternative considered: Copilot first came up with a solution where the locations of included entities were changed to be the locations inside the included file. I rejected that approach since (a) it was very complex, and (b) it is weird to have an AST where sub parts of the tree have locations in a different file, and it is also not how we generate locations for other macro expansions.
Commit-by-commit review is suggested.
DCA looks fine; there is a performance regression on
ruff, but running locally I didn't see any issues, so I suspect this is because we extract more stuff. DCA also confirms that extracting macro arguments does not result in significantly larger TRAP and extraction time hasn't increased (in fact, it has decreased 🤷).