[enhancement] DSLX should support "where" clauses to get parametric derived expression out of parametric position
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 130
Description
### What's hard to do? (limit 100 words)
This is more of a syntactic nicety so marking as long-term-enhancement, but wanted to file so I had an issue to point people at. For a signature like:
```
fn replicate(x: bits[M]) -> bits[O] {
```
Ideally we'd be able to specify the output bit count outside the parameter list when it's really just inferred from the input side parameters; something like:
```
fn replicate(x: bits[M]) -> bits[O]
where O: u32 = {N * M} {
```
### Current best alternative workaround (limit 100 words)
Just putting the "derived" parametric expression in the normal parametric list, as shown in the first snippet.
### Your view of the "best case XLS enhancement" (limit 100 words)
The where clauses could help us make the function signatures a little more readable by getting the derived things more out of the way. It would be nice if we implemented them, Rust has a similar facility for getting type trait bounds out of the main signature; i.e. https://doc.rust-lang.org/rust-by-example/generics/where.html
Contributor guide
Research direction
Start by locating the DSLX parser and function-signature handling, then compare the existing parametric-list syntax with the proposed where-clause examples. Review the Rust where-clause reference for relevant syntax ideas. Done means derived parameters can be written outside the main parameter list while preserving the existing behavior of signatures such as replicate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100