Describe the bug
I am trying to use impl to model a ring buffer as an example type; let's call this ringbuffer.x
import std;
type Number = u32;
pub struct RingBuffer<SIZE: u32, BUF_SZ: u32 = {std::next_pow2(SIZE + 1)}> {
buffer: Number[BUF_SZ],
write_pos: uN[std::clog2(BUF_SZ)],
}
impl RingBuffer<SIZE, BUF_SZ> {
fn default() -> RingBuffer<SIZE, BUF_SZ> {
RingBuffer<SIZE, BUF_SZ> { ..zero!<RingBuffer<SIZE, BUF_SZ>>() }
}
fn ReadAtOffset(self, offset: u32) -> Number {
type CountType = uN[std::clog2(BUF_SZ)];
self.buffer[self.write_pos - SIZE as CountType + offset as CountType]
}
fn PushValue(self, v: Number) -> RingBuffer<SIZE, BUF_SZ> {
RingBuffer<SIZE, BUF_SZ> {
buffer: update(self.buffer, self.write_pos, v),
write_pos: self.write_pos + uN[std::clog2(BUF_SZ)]:1,
}
}
}
fn top(b: RingBuffer<u32:32, u32:32>) -> Number {
b.PushValue(u32:42);
b.ReadAtOffset(0)
}
Previously, I had functions such as RingBuffer_ReadAtOffset(), but I now wanted to try the impl feature that has landed in the meantime.
The examples in the XLS code base are a bit thin though, but I was happy that the change compiled and my unit test worked when run through the xls-interepreter
(The change in the context of my toy project can be seen here, where it also passes the unit test
https://github.com/hzeller/xls-convolve/pull/3/changes
)
... however converting this to IR failed
To Reproduce
$ bazel build -c dbg xls/dslx/ir_convert:ir_converter_main
$ bazel-bin/xls/dslx/ir_convert/ir_converter_main --top=top ringbuffer.x
[symbolize_elf.inc : 356] RAW: Unable to get high fd: rc=0, limit=1024
Error: INTERNAL: XLS_RET_CHECK failure (xls/dslx/ir_convert/function_converter.cc:916) proc_id_.has_value() SIZE
=== Source Location Trace: ===
xls/dslx/ir_convert/function_converter.cc:916
xls/dslx/ir_convert/function_converter.cc:1153
xls/dslx/ir_convert/function_converter.cc:338
xls/dslx/ir_convert/function_converter.cc:358
xls/dslx/ir_convert/function_converter.cc:338
xls/dslx/ir_convert/function_converter.cc:358
xls/dslx/ir_convert/function_converter.cc:2346
xls/dslx/ir_convert/function_converter.cc:678
xls/dslx/ir_convert/function_converter.cc:5000
xls/dslx/ir_convert/function_converter.cc:4972
xls/dslx/ir_convert/function_converter.cc:3591
xls/dslx/ir_convert/ir_converter.cc:365
xls/dslx/ir_convert/ir_converter.cc:486
xls/dslx/ir_convert/ir_converter.cc:660
xls/dslx/ir_convert/ir_converter.cc:734
xls/dslx/ir_convert/ir_converter_main.cc:159
Expected behavior
Not crashing and producing IR (or at least: with error message explaining how I am holding it wrong).
Environment (this can be helpful for troubleshooting):
Compiled from current head (on NixOS)
Describe the bug
I am trying to use
implto model a ring buffer as an example type; let's call thisringbuffer.xPreviously, I had functions such as
RingBuffer_ReadAtOffset(), but I now wanted to try theimplfeature that has landed in the meantime.The examples in the XLS code base are a bit thin though, but I was happy that the change compiled and my unit test worked when run through the xls-interepreter
(The change in the context of my toy project can be seen here, where it also passes the unit test
https://github.com/hzeller/xls-convolve/pull/3/changes
)
... however converting this to IR failed
To Reproduce
Expected behavior
Not crashing and producing IR (or at least: with error message explaining how I am holding it wrong).
Environment (this can be helpful for troubleshooting):
Compiled from current head (on NixOS)