Can't access proc state if it is a struct
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
Let's say i want to have a state in a proc that is more complicated. So I'd naturally put it in a
struct:
Let's assume the following change to [`xls/examples/passthrough.x`](https://github.com/google/xls/blob/main/xls/examples/passthrough.x#L38)
in which we replace the count with a struct that contains a count:
```diff
--- a/passthrough.x 2026-09-04 20:32:13.724012164 +0200
+++ b/passthroug.x 2026-09-04 20:34:48.517393354 +0200
@@ -35,23 +35,28 @@
}
}
+struct MyCount {
+ count: u32,
+}
+
#[test]
proc PassthroughTest {
terminator: chan out,
data_s: chan out,
data_r: chan in,
- count: u32,
+ my_state: MyCount,
}
impl PassthroughTest {
fn new(terminator: chan out) -> Self {
let (data_s, data_r) = chan("data");
Passthrough::new(data_r, data_s).spawn();
- PassthroughTest { terminator, data_s, data_r, count: u32:10 }
+ PassthroughTest { terminator, data_s, data_r,
+ my_state: MyCount { count: u32:10} }
}
fn next(self) {
- let count = read(self.count);
+ let count = read(self.my_state.count);
let tok: token = join();
let data_to_send = count * count;
let tok = send(tok, self.data_s, data_to_send);
@@ -59,6 +64,6 @@
assert_eq(data_to_send, received_data);
send_if(tok, self.terminator, count == u32:0, true);
- write(self.count, count - u32:1);
+ write(self.my_state.count, count - u32:1);
}
}
```
This complains with an error message:
```
$ bazel-bin/xls/dslx/interpreter_main passthrough.x
passthrough.x:59:40-59:45
0057:
0058: fn next(self) {
0059: let count = read(self.my_state.count);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^---^ TypeInferenceError: No member `count` in struct `BuiltinProcState`.
0060: let tok: token = join();
0061: let data_to_send = count * count;
```
There is no `BuiltinProcState` anywhere in this file. The struct type in question would be `MyCount`.
This is either something somewhat hardcoded to not be able to treat the fields as what they are, not ready yet, or I am holding it wrong :). If so, how do I hold it right ?
Contributor guide
Research direction
Reproduce the issue with the modified xls/examples/passthrough.x using bazel-bin/xls/dslx/interpreter_main. Start by tracing the type-inference path for self.my_state.count and the reported BuiltinProcState error. Done means the MyCount field is recognized correctly and the example runs without that TypeInferenceError.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100