Skip to content

Rust: Take trait visibility into account when resolving paths and methods#20321

Merged
paldepind merged 2 commits intogithub:mainfrom
paldepind:rust/trait-method-scope-2
Sep 2, 2025
Merged

Rust: Take trait visibility into account when resolving paths and methods#20321
paldepind merged 2 commits intogithub:mainfrom
paldepind:rust/trait-method-scope-2

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Aug 30, 2025

In Rust a trait method can only be invoked if the trait is visible/in scope, but currently all traits are treated as globally visible.

With this PR, for a path Type::method we only consider method methods on traits that are visible. Similarly, for method calls foo.bar(...) we only consider bar methods on traits that are visible.

This PR is motived by a type explosion in Deno that is magnified by #20133. Accounting for visible traits in #20133 in the same way as in this PR should also reduce false positives for blanket implementations.

DCA shows:

  • Insignificant change to analysis time. I struggled a bit with getting acceptable performance, but it seem ok now.
  • Path resolution inconsistencies are down by around 25%. I think this is explained by a reduction in multipleCallTargets violations.
  • Nodes with type at length limit is reduced by a small amount.
  • We loose call targets for 0.381% of all calls. I've inspected a bunch of lost targets, and they looked like false targets. Looking at the data, e.g., for databend we loose targets for 1020 calls and path resolution inconsistencies is down 5191. One plausible interpretation is that there where 5191 calls where we found the correct target plus a wrong one and 1020 calls where we only found a wrong one.

Loading
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.

3 participants