fix(resolution): Rust field receivers resolve by field type, not by name - #1587
Closed
Dshuishui wants to merge 1 commit into
Closed
fix(resolution): Rust field receivers resolve by field type, not by name#1587Dshuishui wants to merge 1 commit into
Dshuishui wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Author
|
Closing in favour of #1599 — it covers this case and goes further than this PR did: the native kernel path ( Thanks for the quick turnaround on both reports. |
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.
Fixes #1585.
A Rust method call on a field —
self.inner.run()— resolves to whatever same-named method sits nearest, because the receiver is dropped and the call becomes a barerun. Rust has no implicitself, so every call on a field is written this way, and it is worst when the field's type is external (Vec,Arc<…>, another crate) — there the nearest project method is never the right answer.This follows the shape of the Go field-chain fix (#1276): the receiver is kept, the field's declared type is read from the enclosing type's own declaration, and the method is validated on it. A field whose type cannot be established stays unresolved rather than being guessed.
Field types:
Box/Rc/Arcresolve through to what they wrap;Option/Mutex/Veckeep their own methods; a generic type answers with its constructor;dyn Traitresolves to the trait; tuple structs index by position.Verified by indexing ripgrep and tokio: self-recursive edges the source never had are roughly halved, and several hundred more edges move from the wrong type to the right one. Sampling the call sites that lost their edge and checking them by hand, the large majority were wrong before.
Deeper chains (
self.a.b.method()), receivers rooted at a local, and method chains keep their existing behavior — each was implemented and measured, and each removed fewer wrong edges than it cost correct ones.Coverage is also limited by generic impls qualifying their methods with the trait rather than the type (
impl<T> Stream for Empty<T>→Stream::poll_next). That is a separate bug, filed as #1588.Other languages are unaffected — indexing TypeScript, Python and Erlang corpora before and after produces byte-identical nodes, edges and unresolved refs, with no change in indexing time.
The suite passes; the three new tests fail on
mainand pass here.