Skip to content

Rust: Type inference for macro expressions #19751

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

Merged
merged 2 commits into from
Jun 13, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jun 13, 2025

DCA shows a nice 1 percentage point increase in resolvable calls.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 13, 2025
@hvitved hvitved marked this pull request as ready for review June 13, 2025 09:33
@Copilot Copilot AI review requested due to automatic review settings June 13, 2025 09:34
@hvitved hvitved requested a review from a team as a code owner June 13, 2025 09:34
Copy link
Contributor

@Copilot 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

Adds support for inferring types from macro expressions in the Rust CodeQL type inference engine.

  • Extended the typeEquality predicate to treat MacroExpr expansions as equivalent nodes.
  • Added a new macros test module with a format! invocation in main.rs.
  • Updated the type-inference.expected file to include expected entries for macro expressions and their expansions.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
rust/ql/lib/codeql/rust/internal/TypeInference.qll Added an or clause in typeEquality to equate macro expressions with their expansions.
rust/ql/test/library-tests/type-inference/main.rs Introduced a macros module and a format! call to exercise macro-based type inference.
rust/ql/test/library-tests/type-inference/type-inference.expected Updated expected output to list MacroExpr nodes and their expanded types for the tests.
Comments suppressed due to low confidence (2)

rust/ql/test/library-tests/type-inference/main.rs:1808

  • [nitpick] The module name macros could be confused with Rust's built-in macros. Consider renaming it to something more descriptive like macro_tests or macro_expr_tests.
mod macros {

rust/ql/test/library-tests/type-inference/main.rs:1810

  • This inline TODO references an open PR. Remove or update this comment once that change is merged to avoid stale test markers.
let x = format!("Hello, {}", "World!"); // $ MISSING: type=x:String -- needs https://github.com/github/codeql/pull/19658

@@ -265,6 +265,8 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
n1 = be.getLhs() and
n2 = be.getRhs()
)
or
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a brief comment above this clause explaining why macro expressions require special handling here, improving future maintainability.

Suggested change
or
or
// Macro expressions require special handling because they can expand into multiple
// expressions or statements, which affects type inference.

Copilot uses AI. Check for mistakes.

@hvitved hvitved requested a review from paldepind June 13, 2025 10:59
@hvitved hvitved force-pushed the rust/type-inference-macro-expr branch from 60ea89b to 2f698d1 Compare June 13, 2025 11:11
Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

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

👍

@hvitved hvitved merged commit 7051ad5 into github:main Jun 13, 2025
17 checks passed
@hvitved hvitved deleted the rust/type-inference-macro-expr branch June 13, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants