google / google/xls

Parametric function arg type inference fails due to nested unresolved type

Open
#1,679 1 comment 0 reactions 1 assignee Claimed by @richmckeever View on GitHub
dslx 🧦 sox
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

**Describe the bug**
It feels like type inference goes "too far" and generates a type inference error when the arg is a parametric struct, because the struct member can't be fully resolved, even though the parametric function is fully specified from the struct type.

```
0009: foo(s);
~~~~~~~~~~~~~~^ XlsTypeError: Mismatch between parameter and argument types (after instantiation).
Type mismatch:
SomeParamStruct { x: uN[width(T)] }
vs SomeParamStruct { x: uN[3] }
```

**To Reproduce**
```
struct SomeParamStruct { x: bits[std::clog2(T)] }

fn foo(s: SomeParamStruct) -> bits[T] { s.x }

fn main() {
let s = SomeParamStruct { x: u3:5 };
foo(s);
}
```

**Expected behavior**
Since the specialization of `foo` is known to be for `SomeParamStruct` it feels like this should work. You get a similar error if you don't specify the parametrics for `s`, but that makes more sense since you would need to back out the `clog2` for the type of member `x`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.