Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Adjustments to type inference #19081

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

paldepind
Copy link
Contributor

@paldepind paldepind commented Mar 20, 2025

This PR attempts to address most of @aschackmull's comments over in #18632, plus a few additional tweaks to the type inference implementation.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 20, 2025
@paldepind paldepind marked this pull request as ready for review March 20, 2025 15:55
@Copilot Copilot bot review requested due to automatic review settings March 20, 2025 15:55

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 addresses adjustments to type inference by updating generic parameter names for improved consistency.

  • Renamed the generic parameter in struct MyThing from A to T.
  • Renamed the generic parameters in traits MyTrait1, MyTrait2, and MyTrait3 to Tr1, Tr2, and Tr3 respectively.
Files not reviewed (8)
  • rust/ql/lib/codeql/rust/elements/internal/FieldExprImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll: Language not supported
  • rust/ql/lib/codeql/rust/internal/Type.qll: Language not supported
  • rust/ql/lib/codeql/rust/internal/TypeInference.qll: Language not supported
  • rust/ql/test/library-tests/type-inference/type-inference.expected: Language not supported
  • rust/ql/test/library-tests/type-inference/type-inference.ql: Language not supported
  • shared/typeinference/codeql/typeinference/internal/TypeInference.qll: Language not supported

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

@paldepind paldepind added the no-change-note-required This PR does not need a change note label Mar 20, 2025
@@ -387,12 +387,12 @@ mod method_supertraits {
#[derive(Debug)]
struct S2;

trait MyTrait1<A> {
fn m1(self) -> A;
trait MyTrait1<Tr1> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The expected file contained some duplicated lines, making it a bit hard to se what was what. So this renames some generics s.t. fewer names are identical.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes. I have some mostly nitpicking comments.

* the type parameter `tp` in `target`.
* the type parameter `tp` in `target`, if any.
*
* Note, that this predicate crucially does not depend on type inference,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: No comma after Note

Comment on lines 622 to 623
* where the method call is an access and `new Sub<int>()` is an access
* position , which is the receiver of a method call, we have:
Copy link
Contributor

Choose a reason for hiding this comment

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

new Sub<int>() in not an access position, but it is at an access position.

@@ -605,19 +614,21 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
*
* class Sub<T4> : Mid<C<T4>> { }
*
* new Sub<int>().ToString();
* new Sub<int>().ToString();
* // ^^^^^^^^^^^^^^ `apos`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite right, see comment below.

@@ -635,28 +646,36 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
}
}

/**
* Holds if the type of `a` at `apos` has the base type `base`, and when
* viewed as an element of that type has at `path` the type `t`.
Copy link
Contributor

Choose a reason for hiding this comment

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

has at path the type t -> has the type t at path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, let's change it. I was trying to phrase this to match the order of the parameters, but it is clumpsy.

*/
pragma[nomagic]
private predicate baseTypeMatch(
Access a, Declaration target, TypePath path, Type t, TypeParameter tp
) {
not exists(getTypeArgument(a, target, tp, _)) and
target = a.getTarget() and
Copy link
Contributor

Choose a reason for hiding this comment

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

This may or may not introduce a bad join, let's see what DCA says.

@paldepind paldepind requested a review from aschackmull March 21, 2025 13:15
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