Skip to content

Type inference: Unify getABaseTypeMention and conditionSatisfiesConstraint#21850

Open
hvitved wants to merge 1 commit into
github:mainfrom
hvitved:type-inference-unify-base-type
Open

Type inference: Unify getABaseTypeMention and conditionSatisfiesConstraint#21850
hvitved wants to merge 1 commit into
github:mainfrom
hvitved:type-inference-unify-base-type

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented May 13, 2026

This PR removes getABaseTypeMention, and instead ensures that sub-type relations expressed in terms of conditionSatisfiesConstraint are taken into account when matching types of arguments against types of parameters containing type parameters:

class A<T> {
    public T Get() { ... } // the implicit `this` parameter has type `A<T>`
}

class B : A<int> { ... }

new B().Get() // `int` is matched against `T` to infer that the type of the call is `int`

getABaseTypeMention was not in use in Rust, so this PR has no semantic effect on Rust, but for languages with type hierarchies, such as Swift, it means that we can treat type hierarchies in the same way that traits are treated in Rust.

#21837 has been used to verify this PR.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label May 13, 2026
@hvitved hvitved force-pushed the type-inference-unify-base-type branch from 0940579 to 3f7b50e Compare May 13, 2026 14:25
@hvitved
Copy link
Copy Markdown
Contributor Author

hvitved commented May 13, 2026

@hvitved
Copy link
Copy Markdown
Contributor Author

hvitved commented May 13, 2026

Rerun has been triggered: 2 restarted 🚀

@hvitved hvitved added the no-change-note-required This PR does not need a change note label May 13, 2026
@hvitved hvitved marked this pull request as ready for review May 13, 2026 17:45
@hvitved hvitved requested a review from a team as a code owner May 13, 2026 17:45
Copilot AI review requested due to automatic review settings May 13, 2026 17:45
@hvitved hvitved requested a review from a team as a code owner May 13, 2026 17:45
Copy link
Copy Markdown
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 unifies type-hierarchy handling in the shared type inference library by removing getABaseTypeMention and relying on conditionSatisfiesConstraint for matching argument types against parameter types involving type parameters (covering both class hierarchies and Rust trait-style constraints).

Changes:

  • Removed getABaseTypeMention from the shared InputSig2 interface and deleted the associated base-type-mention traversal logic.
  • Reworked base-type matching to use the conditionSatisfiesConstraint hierarchy when inferring type arguments for accesses.
  • Updated Rust’s type inference instantiations of InputSig2 to match the new interface (removing now-defunct stubs).
Show a summary per file
File Description
shared/typeinference/codeql/typeinference/internal/TypeInference.qll Removes the base-type-mention API and routes base-type inference through conditionSatisfiesConstraint; updates related documentation/comments.
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll Drops getABaseTypeMention stub implementations to conform to the updated shared signature.

Copilot's findings

Comments suppressed due to low confidence (1)

shared/typeinference/codeql/typeinference/internal/TypeInference.qll:397

  • In the Rust examples explanation, the sentence says “condition and condition are identical”; the second identifier should be constraint. Also “seconds example” should be “second example”.
     * the meaning is "`T` implements `Trait`" where the constraint is only
     * valid for the specific `T`. Note that `condition` and `condition` are
     * identical in the two examples. To encode the difference, `abs` in the
     * first example should contain `T` whereas in the seconds example `abs`
     * should be empty.
  • Files reviewed: 2/2 changed files
  • Comments generated: 1

@@ -1839,7 +1715,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
directTypeMatch(a, e, target, path, t, tp)
or
// We can infer the type of `tp` by going up the type hiearchy
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.

2 participants