Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Feb 10, 2026

When resolving calls like Trait::function(...) we need to take all possible implementations of function into account, which can be a very large set.

However, with #21217:

As for calls to methods, we now also always check the Self type for calls to associated non-methods f

which means that we can strictly reduce this set up front, by only looking at implementations for types that might match the Self type inferred at the call site, similar to what we already do for method calls.

DCA looks good; a significant speedup.

Fixes timeout on ArmchairDevelopers/Glacier.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Feb 10, 2026
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Feb 10, 2026
@hvitved hvitved marked this pull request as ready for review February 10, 2026 19:16
@hvitved hvitved requested a review from a team as a code owner February 10, 2026 19:16
@hvitved hvitved requested review from Copilot and paldepind February 10, 2026 19:16
Copy link
Contributor

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

Speeds up Rust type inference for UFCS-style calls like Trait::function(...) by reducing the number of candidate implementations considered upfront using inferred Self-type information, addressing observed analysis timeouts (e.g., ArmchairDevelopers/Glacier).

Changes:

  • Introduces helper predicates to compute/require relevant type mentions for trait function resolution.
  • Adds Self-type–based filtering for non-method trait function call target candidate selection.
  • Adjusts non-blanket target compatibility checks to leverage the refined candidate set.
Comments suppressed due to low confidence (1)

rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll:3061

  • This doc comment could be more precise about what pos/path refer to (argument vs return position) and what “matches” means here (e.g., after substituteLookupTraits). Tightening the wording would make it easier to maintain.
      /**
       * Holds if this call is of the form `Trait::function(args)`, and the type at `pos` and
       * `path` matches the `Self` type parameter of `Trait`.
       */

traitFunctionResolutionDependsOnArgument0(trait, traitFunction, pos, impl, implFunction, path,
traitTp) and
// Exclude functions where we cannot resolve all relevant type mentions; this allows
// for blanket implementations to be applied in those cases
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The inline comment ends without punctuation and could be clearer as a complete sentence. Consider adding a period (and optionally rephrasing) to improve readability (e.g., make explicit that this is to allow blanket impls when type mentions can’t be resolved).

This issue also appears on line 3058 of the same file.

Suggested change
// for blanket implementations to be applied in those cases
// blanket implementations to be applied in those cases when type mentions cannot be resolved.

Copilot uses AI. Check for mistakes.
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