google / google/xls

[enhancement] Early return in DSLX functions

Open
#1,567 6 comments 0 reactions 0 assignees View on GitHub
dslx enhancement
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)

Code can often be simpler and more readable (reduced nesting and/or eliminate extraneous computations) if you can early return with some guard statement.

For example:

https://github.com/google/xls/blob/052a2a3dfd71ea190a9862355c80346b44203fa8/xls/dslx/stdlib/apfloat.x#L1367-L1372 was intended to simplify the code but is actually thrown away since these cases match a later condition: https://github.com/google/xls/blob/052a2a3dfd71ea190a9862355c80346b44203fa8/xls/dslx/stdlib/apfloat.x#L1379-L1380

If the developer could instead have written an early return, they can systematically handle the simpler cases and return, properly ignoring them in later parts of the function.

### Current best alternative workaround (limit 100 words)

The refactored code in the example above was turned into a giant `if`/`else if`/`else`:

https://github.com/google/xls/commit/414e6b49ee3dbb81706bb45dc15ae72c62eb31db#diff-215bf4395c04c579d061e991f09dcc1e551d5b7920699eaa91c82898fe1e76cf

### Your view of the "best case XLS enhancement" (limit 100 words)

Add the `return` keyword which can be used in an `if` block like in Rust: https://doc.rust-lang.org/std/keyword.return.html

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.