Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Oct 9, 2025

This PR follows up on #20282, by implementing support for identifying invalid blanket implementation targets.

A blanket implementation target can be dismissed when the constraint on the type parameter is not satisfied, and this has to be defined in a monotonic way, just like we had to for non-blanket implementations in #20282.

DCA shows that we recover performance on gluon, and partially on peace.

@github-actions github-actions bot added documentation Rust Pull requests that update Rust code labels Oct 9, 2025
@hvitved hvitved force-pushed the rust/type-inference-blanket-non-satisfaction branch 2 times, most recently from da7efb8 to 2c6e29a Compare October 10, 2025 11:56
@hvitved hvitved force-pushed the rust/type-inference-blanket-non-satisfaction branch 2 times, most recently from 9976877 to 9e0f977 Compare October 23, 2025 09:34
@hvitved hvitved force-pushed the rust/type-inference-blanket-non-satisfaction branch from 9e0f977 to 0e885e9 Compare October 24, 2025 09:43
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 24, 2025
@hvitved hvitved marked this pull request as ready for review October 24, 2025 13:10
@hvitved hvitved requested review from a team as code owners October 24, 2025 13:10
@Copilot Copilot AI review requested due to automatic review settings October 24, 2025 13:10
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

This PR implements support for identifying invalid blanket implementation targets in Rust type inference by introducing a monotonic approximation to determine when a type tree does not satisfy implementation constraints.

Key changes:

  • Added isNotInstantiationOf and satisfiesNotConstraint predicates to provide monotonic approximations for ruling out incompatible implementations
  • Extended method and function resolution to check blanket-like implementations against constraint satisfaction
  • Added comprehensive test cases for blanket-like implementations including edge cases with multiple trait bounds

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
shared/typeinference/codeql/typeinference/internal/TypeInference.qll Added core logic for monotonic constraint negation checking with isNotInstantiationOf, hasNotConstraintMention, and satisfiesNotConstraint predicates
rust/ql/lib/codeql/rust/internal/TypeInference.qll Updated method and function resolution to handle blanket-like implementations by renaming predicates and adding incompatibility checks
rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll Added satisfiesNotBlanketConstraint predicate to identify when argument types fail blanket constraints
rust/ql/test/library-tests/type-inference/blanket_impl.rs Added test module with scenarios covering trait implementations, blanket implementations, and edge cases
rust/ql/test/library-tests/type-inference/type-inference.expected Updated expected test results with new type inference entries for blanket-like implementations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

/**
* Holds if function `f` with the name `name` and the arity `arity` exists in
* blanket implementation `impl` of `trait`, and the type at position
* blanket (like) implementation `impl` of `trait`, and the type at position
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The term 'blanket (like)' is used inconsistently throughout the file. Consider defining this term clearly in a top-level comment or using a more precise descriptor (e.g., 'blanket or blanket-like').

Suggested change
* blanket (like) implementation `impl` of `trait`, and the type at position
* blanket or blanket-like implementation `impl` of `trait`, and the type at position

Copilot uses AI. Check for mistakes.
Comment on lines +1042 to +1043
functionInfoBlanketLike(m, name, arity, impl, trait, pos, selfType, blanketPath,
blanketTypeParam) and
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The line break in the middle of the function call arguments reduces readability. Consider keeping all parameters on the same line or formatting consistently with other similar calls in the file.

Suggested change
functionInfoBlanketLike(m, name, arity, impl, trait, pos, selfType, blanketPath,
blanketTypeParam) and
functionInfoBlanketLike(m, name, arity, impl, trait, pos, selfType, blanketPath, blanketTypeParam) and

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