-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix gaps in type inference #394
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
Comments
i'm interested. where should i start? |
Hi @gfreezy, I'd suggest starting with tuples. Basically you need to do the following things:
you need to add something like
Once #386 is done, the big match expression in |
Can I try this? |
@h-michael I have no idea if @gfreezy already started with this, but since they didn't write anything I'd consider it free ;) You could of course also start with array expressions or string literals. |
i haven't started with it. @h-michael you may start with it. |
I'm working on inference for primitive literals (integers, floats, |
Are any of you working on other types, @gfreezy @h-michael? Otherwise I can do these too. |
I'm trying tuple and array now. |
I'll leave those to you then ;-) |
698: Added support for primitive types type inference with std::ops::Not r=flodiebold a=WizardOfMenlo On the guideline of #544 , this allows for type inference for all primitive types implementing [std::ops::Not](https://doc.rust-lang.org/beta/std/ops/trait.Not.html). I think this should be relevant #394 as well? Co-authored-by: WizardOfMenlo <giacomofenzi@outlook.com>
It seems that array repeat expressions like |
Hm. Actually, I think they're kind of working accidentally, because we just ignore the repeat number and treat them as an array expression with one element (so we handle |
I wonder what would be the best way to handle the array repeat expressions when the expression is a more complex expression rather than a simple usize, e.g. const fn foo() -> usize { 6 }
let y = [0u32; 6];
let w = [0u32; { 3 + 3 }];
let x = [0u32; foo()]; All should be inferred to be const fn foo() -> usize { 6 }
let y: [u32; 6] = [0u32; 6];
let w: [u32; 6] = [0u32; { 3 + 3 }];
let x: [u32; 6] = [0u32; foo()]; This seems like it would require some evaluation during inference. Additionally, don't all arrays have a fixed length e.g. ? let x = [1, 2, 3];
// is the same as
let x: [i32; 3] = [1, 2, 3] Meaning we could have a new |
@vipentti We currently completely ignore array lengths, because const evaluation would be a whole other can of worms, and they're not that interesting for our current use cases (it's unlikely that |
What kind of inference result would we like to get for let y = [0u32; 6];
let w = [0u32; { 3 + 3 }]; Something like y = [u32; <inferred>?];
w = [u32; <inferred>?]; |
See here -- our array types don't contain any length. So the inferred type currently just looks like (We could consider changing the display pattern for array types to be something like |
Broken link. |
Try now ;) |
1103: Array inference r=flodiebold a=Lapz Fixes the final item in #394. The only problem is that infering the repeat cause some types to be infered twices. i.e ```rust fn test() { let y = unknown; [y, &y]; } ``` results in the following diff: ```diff [11; 48) '{ ...&y]; }': () [21; 22) 'y': &{unknown} [25; 32) 'unknown': &{unknown} -[38; 45) '[y, &y]': [&&{unknown}] +[38; 45) '[y, &y]': [&&{unknown};usize] [39; 40) 'y': &{unknown} +[39; 40) 'y': &{unknown} [42; 44) '&y': &&{unknown} [43; 44) 'y': &{unknown} ``` Should the code produce two inference results for 'y' and if not could any tell me what needs to change. Co-authored-by: Lenard Pratt <l3np27@gmail.com>
I think this issue can be closed |
Indeed. |
This is a 'kitchen sink' issue for various small things we don't currently handle in type inference 😄
All of these involve changing
infer_expr
inty.rs
; some also need improvements to the AST defined inast.rs
/grammar.ron
, and it may make sense to wait forhir::Expr
(#386) for these.TupleExpr
), e.g.(1, 2, 3)
[1, 2, 3]
[1; 99]
(same; note that we currently ignore the length of an array in type inference.)-
and!
at least for primitive types (see also Implement type inference for binary operators #390)The text was updated successfully, but these errors were encountered: