Improve Rust callgraph resolution for direct self fields - #196
Open
onedotmint wants to merge 5 commits into
Open
Improve Rust callgraph resolution for direct self fields#196onedotmint wants to merge 5 commits into
onedotmint wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While testing Rust callgraph output, I ran into a case where
Holder::checkcallsPathBuf::as_path, but AFT could still produce an approximate edge to an unrelatedPrinterPath::as_pathelsewhere in the project. So i create this pr and explain what I do.The existing
name_matchfallback is useful when the receiver type is genuinely unknown, so I didn't want to remove or weaken that behavior. The issue here is that for a simple field receiver likeself.path, we can sometimes recover enough local type information to make a better decision — and when we can't, guessing by method name can be misleading.What changed
This adds a conservative path for direct
self.field.method()calls.When the field can be tied to a concrete local type in the same lexical scope, AFT uses the existing precise
type_matchpath. For example, ifself.engineis known to be anEngine,Car::run -> Engine::startis resolved precisely.If the field is clearly present but its type can't be resolved safely, the call is left unresolved instead of being connected to an unrelated same-named method. Precise candidates are also checked against the field type's lexical module scope, so a same-named type inside a nested module can't accidentally become the target.
I intentionally kept this narrow. This isn't meant to add general Rust type or module resolution. Imported or scoped types, nested fields, generics, trait impls, references, aliases, wrappers, deref/coercion, and cross-file type identities stay conservative unless AFT already knows how to resolve them.
Tests
The tests cover the original
PathBuf/PrinterPathcase, precise resolution for a local field type, preservation of the existingname_matchfallback for genuinely unknown receivers, and the scoped/imported/nested-module cases that could otherwise create false precise edges.The relevant unit and integration tests pass, along with:
The full crate suite still has four failures in this local environment. I reproduced all four against a clean worktree at the same HEAD with the same failure signatures, so they appear to be baseline/environment-related rather than introduced by this change.(I guess it's because of my base environment.)
Thanks for your project. It helps a lot in my coding time.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Improves Rust callgraph accuracy for direct
self.field.method()calls, including spaced forms likeself .engine.start(). Resolves only when the field’s type is a proven local concrete struct in the same file and module, and suppresses name-only matches when the field is known but unsafe to resolve.type_matchonly when the field’s type is a concrete, local, non-generic struct in the same file and lexical module; validates inherentimplby checking the candidate’sstart_line, file, and module scope; rejects trait and generic impls.receiver_expression, so forms likeself .engineandself. engineare detected.name_match; genuinely unknown receivers keep the fallback.Written for commit 952522a. Summary will update on new commits.
Greptile Summary
The PR improves Rust callgraph resolution for direct
self.field.method()calls while preserving conservative behavior when the field type cannot be proven.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Reviews (5): Last reviewed commit: "Clarify unresolved Rust field test names" | Re-trigger Greptile