google / google/xls

[enhancement] Disambiguate whether `configured_value_or` is intended to be a global declaration or usage

Open
#3,922 0 comments 0 reactions 0 assignees View on GitHub
dslx enhancement
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

### What's hard to do? (limit 100 words)

Right now, `configured_values` are specified that sets a given label anywhere in the DSLX src ~~(even transitively)~~ (edit: this turned out to be incorrect information), which suggest they represent globals like absl flags.

However, `configured_value_or` can be specified at any scoping *and* any number of times for the same label. This makes them more like usages of implicitly declared globals, except that the types are not even required to be the same.

E.g. this is fine:

```
fn foo() -> u2 { configured_value_or("my_value", 0) }

fn bar() -> u32 { configured_value_or("my_value", 0) }

#[test]
fn test_collision() {
let x = foo();
let y = bar();
let z = configured_value_or("my_value", 0);

assert_eq(x, 1);
assert_eq(y, 1);
assert_eq(z, 1);
}
```

until the value you set is out of range in one of these contexts.

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

Be careful about reusing `configured_value_or` labels since DSLX will attempt to set the same value everywhere without warning.

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

It seems like either these should have better scoping rules, e.g. `configured_values = {"github_issue.foo.my_value": "1", "github_issue.test_collision.my_value": "4"}` or we'd benefit from separating things like absl flags.

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.