Skip to content

Rust: Distinguish internal/external items in path resolution #20191

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Aug 8, 2025

This PR addresses @paldepind's comment

The way I think of it now, the successor relation in the item graph kinda conflates two different things:
1/ the items that are available locally in the scope of an item
2/ the items that are available externally for qualified paths that resolve to the item.

from #20096. The goal is to reduce path resolution ambiguities, which in turn helps avoiding type inference blowup.

DCA looks fine: We significantly reduce the number of path resolution and type inference inconsistencies, get a marginal speedup, but at the cost of a small decrease in percentage of resolvable calls (down 61.28 % from 61.61 %).

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Aug 8, 2025
@hvitved hvitved force-pushed the rust/path-resolution-successor-kind branch 7 times, most recently from 31aeb97 to b059956 Compare August 14, 2025 10:38
@hvitved hvitved force-pushed the rust/path-resolution-successor-kind branch 4 times, most recently from b42b737 to 79c1c5b Compare August 14, 2025 13:10
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 14, 2025
@hvitved hvitved marked this pull request as ready for review August 14, 2025 18:41
@hvitved hvitved requested a review from a team as a code owner August 14, 2025 18:42
@hvitved hvitved requested review from Copilot and geoffw0 and removed request for a team August 14, 2025 18:42
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

This PR introduces a distinction between internal and external items in Rust path resolution to reduce ambiguities and improve type inference performance. The changes modify the item graph's successor relation to separate locally available items from externally available items for qualified paths.

Key changes:

  • Introduces SuccessorKind enumeration to distinguish internal, external, and both visibility types
  • Updates path resolution logic to consider successor kinds when resolving paths
  • Refactors various edge predicates to include successor kind information

Reviewed Changes

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

Show a summary per file
File Description
rust/ql/lib/codeql/rust/internal/PathResolution.qll Core implementation adding SuccessorKind and updating path resolution logic
rust/ql/lib/codeql/rust/internal/TypeInference.qll Updates type inference consistency checks to work with new path resolution
rust/ql/lib/codeql/rust/internal/TypeInferenceConsistency.qll Adds query predicate for non-unique certain types
rust/ql/lib/codeql/rust/internal/CachedStages.qll Updates cached stages to reference new successor method signature
Multiple .expected files Test expectation updates reflecting improved path resolution consistency

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

ModuleItemNode rust
|
stdOrCore.getName() = stdOrCoreName and
stdOrCoreName = ["std", "core"] and
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The variable stdOrCoreName is redundant as it's immediately assigned from stdOrCore.getName(). Consider removing this intermediate variable and using stdOrCore.getName() directly in the condition.

Suggested change
stdOrCoreName = ["std", "core"] and
Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude,
ModuleItemNode rust
|
stdOrCore.getName() = ["std", "core"] and

Copilot uses AI. Check for mistakes.

@@ -580,7 +617,7 @@ class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {

Path getTraitPath() { result = super.getTrait().(PathTypeRepr).getPath() }

ItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }
TypeItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The return type has been changed from ItemNode to TypeItemNode, which is a breaking change. Ensure that all callers of this method can handle the more restrictive return type.

Copilot uses AI. Check for mistakes.

@@ -669,7 +706,7 @@ class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
}
}

private class ImplTraitTypeReprItemNode extends ItemNode instanceof ImplTraitTypeRepr {
private class ImplTraitTypeReprItemNode extends TypeItemNode instanceof ImplTraitTypeRepr {
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The parent class has been changed from ItemNode to TypeItemNode, which is a breaking change. Verify that this change is compatible with all existing usage patterns.

Suggested change
private class ImplTraitTypeReprItemNode extends TypeItemNode instanceof ImplTraitTypeRepr {
private class ImplTraitTypeReprItemNode extends ItemNode instanceof ImplTraitTypeRepr {

Copilot uses AI. Check for mistakes.

@hvitved hvitved force-pushed the rust/path-resolution-successor-kind branch from 79c1c5b to a07e357 Compare August 14, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant