-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Simple type inference for index expressions #19657
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: Simple type inference for index expressions #19657
Conversation
214079f
to
2652887
Compare
* [1]: https://doc.rust-lang.org/reference/expressions/array-expr.html#r-expr.array.index | ||
*/ | ||
pragma[nomagic] | ||
private Type inferIndexExprType(IndexExpr ie, TypePath path) { |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
351a981
to
d8161df
Compare
d8161df
to
133aca0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DCA report is certainly an improvement.
Code LGTM, though it's my first time looking at the type inference library.
TRefTypeParameter() or | ||
TSelfTypeParameter(Trait t) | ||
TSelfTypeParameter(Trait t) or | ||
TSliceTypeParameter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, how are these different? i.e. why is just one TypeParameter()
type insufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We model slice types as if there was a special struct Slice<T> = ...
type, and TSliceTypeParameter
corresponds to the T
. So e.g. [i64]
translates to Slice<i64>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy, up to you if you want to wait for a review from @paldepind as well or not.
This PR adds simple type inference for index expressions like
x[0]
. Support is simple because we do not properly model theIndex
trait, but instead we only supportVec
. Slice and array types are modeled correctly.DCA confirms that we are now able to resolve more calls.