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
geoffw0
left a comment
There was a problem hiding this comment.
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.
Out of interest, how are these different? i.e. why is just one TypeParameter() type insufficient?
There was a problem hiding this comment.
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>.
geoffw0
left a comment
There was a problem hiding this comment.
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 theIndextrait, but instead we only supportVec. Slice and array types are modeled correctly.DCA confirms that we are now able to resolve more calls.