xls icon indicating copy to clipboard operation
xls copied to clipboard

dslx should deduce function parametric from type of lhs of assignement expression

Open proppy opened this issue 1 year ago • 1 comments

It would be nice if dslx could deduce parametric function params from the type of left-hand, like in:

fn foo<SZ: u32>() -> uN[SZ] {
    uN[SZ]:42
}
#[test]
fn foo_test() {
  let foo42: u8 = foo();
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ TypeInferenceError: uN[SZ] Instantiated return type did not have all parametrics resolved.
  assert_eq(foo42, u8:42);
}

proppy avatar Jan 25 '24 01:01 proppy

This would require either context-dependent type inference (i.e. an outside-to-inside propagation step from the let's type annotation to an expectation of the expression on the RHS of the let, where the expression inference would need to know there was an expectation) or perhaps unification of the parameterized return type with the let binding's annotated type to implicitly propagate information to the "foo()" invocation site.

Right now all the type deduction happens strictly "inside out" and without unification to simplify the type system complexity. See also #193

I'll probably mark this as "long term enhancement" just because I think it's nice-to-have but we have a lot that'd be prioritized before this.

cdleary avatar Jan 25 '24 01:01 cdleary