interpreter crash when instantiating const in proc's next
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
when running a slightly modified version of https://github.com/google/xls/blob/main/xls/examples/protobuf/varint_streaming_decode.x (to remove the parametric top) thru the interpreter:
```
%%dslx --top=varint_streaming_u32_decode --pipeline_stages=8
import std
import xls.examples.protobuf.varint_decode
const INPUT_BYTES:u32 = u32:8;
const OUTPUT_WORDS:u32 = u32:2;
const SCRATCHPAD_BYTES:u32 = u32:8;
const INPUT_BYTES_WIDTH:u32 = std::clog2(INPUT_BYTES+u32:1);
const OUTPUT_WORDS_WIDTH:u32 = std::clog2(OUTPUT_WORDS+u32:1);
const SCRATCHPAD_BYTES_WIDTH:u32 = std::clog2(SCRATCHPAD_BYTES+u32:1);
struct State {
bytes: u8[NUM_BYTES],
len: uN[NUM_BYTES_WIDTH],
}
pub proc varint_streaming_u32_decode {
bytes_in: chan<(u8[INPUT_BYTES], uN[INPUT_BYTES_WIDTH])> in;
words_out: chan<(u32[OUTPUT_WORDS], uN[OUTPUT_WORDS_WIDTH])> out;
config(bytes_in: chan<(u8[INPUT_BYTES], uN[INPUT_BYTES_WIDTH])> in,
words_out: chan<(u32[OUTPUT_WORDS], uN[OUTPUT_WORDS_WIDTH])> out) {
(bytes_in, words_out)
}
init {
State {
bytes: u8[SCRATCHPAD_BYTES]:[u8:0, ...],
len: uN[SCRATCHPAD_BYTES_WIDTH]:0,
}
}
next(tok: token, state: State) {
const_assert!(SCRATCHPAD_BYTES >= INPUT_BYTES);
type ScratchpadSum = uN[SCRATCHPAD_BYTES_WIDTH + u32:1];
type OutputWordArray = u32[OUTPUT_WORDS];
type OutputIdx = uN[OUTPUT_WORDS_WIDTH];
type InputIdx = uN[INPUT_BYTES_WIDTH];
type ScratchpadIdx = uN[SCRATCHPAD_BYTES_WIDTH];
const MAX_NUM_BYTES_PER_WORD = std::clog2(u32:32);
let has_space =
(state.len as ScratchpadSum) + (INPUT_BYTES as ScratchpadSum) <=
(SCRATCHPAD_BYTES as ScratchpadSum);
type InputIdx= uN[INPUT_BYTES_WIDTH];
let (input_tok, (input_data, input_len), _) = recv_if_non_blocking(
tok, bytes_in, has_space, (u8[INPUT_BYTES]:[u8:0, ...], InputIdx:0));
let state = State {
bytes: for (i, updated): (u32, u8[SCRATCHPAD_BYTES]) in u32:0..INPUT_BYTES {
if (i as InputIdx) < input_len {
update(updated, state.len + (i as ScratchpadIdx), input_data[i])
} else {
updated
}
}(state.bytes),
len: state.len + (input_len as ScratchpadIdx),
};
let msbs =
// find msbs for valid (idx < state.len) bytes, false for the rest.
for (i, accum): (u32, bool[SCRATCHPAD_BYTES]) in u32:0..SCRATCHPAD_BYTES {
if (i as ScratchpadIdx) < state.len { accum } else {
update(accum, i, false)
}
}(map(state.bytes, std::is_unsigned_msb_set));
// Keep state.len MSBs and zero out the lower bits.
let num_bytes_with_msb_set =
std::popcount(std::convert_to_bits_msb0(msbs)) as ScratchpadIdx;
// each varint ends when a byte's msb is no longer set.
let num_words_in_state = state.len - num_bytes_with_msb_set;
let (output_words, num_output_words, bytes_taken) =
for (i, (output_words, num_output_words, bytes_taken)):
(u32, (OutputWordArray, OutputIdx, ScratchpadIdx)) in u32:0..OUTPUT_WORDS {
if i < num_words_in_state as u32 {
let taken_bytes =
for (i, accum): (u32, u8[MAX_NUM_BYTES_PER_WORD]) in
u32:0..MAX_NUM_BYTES_PER_WORD {
update(accum, i, state.bytes[i + (bytes_taken as u32)])
}(u8[MAX_NUM_BYTES_PER_WORD]:[u8:0, ...]);
let (decoded, this_bytes_taken) = varint_decode::varint_decode_u32(
taken_bytes);
(
update(output_words, i, decoded),
num_output_words + OutputIdx:1,
bytes_taken + (this_bytes_taken as ScratchpadIdx),
)
} else {
(output_words, num_output_words, bytes_taken)
}
}((zero!(), zero!(), zero!()));
let output_tok = send_if(
input_tok,
words_out,
num_output_words > OutputIdx:0,
(output_words, num_output_words));
State {
bytes: for (i, updated): (u32, u8[SCRATCHPAD_BYTES]) in
u32:0..SCRATCHPAD_BYTES {
if i + bytes_taken as u32 < SCRATCHPAD_BYTES {
update(updated, i, state.bytes[i + bytes_taken as u32])
} else { updated }
}(zero!()),
len: state.len - bytes_taken,
}
}
}
```
I get the following error:
```
E0830 16:38:21.895443 191163 verifier.cc:1755] INTERNAL: XLS_RET_CHECK failure (third_party/xls/ir/verifier.cc:1755) !name_set->contains(function_base->name()) Function/proc/block with name __std__clog2__32 is not unique within package user_module
=== Source Location Trace: ===
third_party/xls/common/status/status_builder.cc:170
0x558d97db1efe: xabsl::StatusBuilder::CreateStatusAndConditionallyLog()
0x558d94fcb748: xabsl::StatusBuilder::operator absl::Status()
0x558d9773da12: xls::VerifyPackage()
0x558d97426d1c: xls::dslx::(anonymous namespace)::ConvertCallGraph()
0x558d97424540: xls::dslx::ConvertModuleIntoPackage()
0x558d974270a2: xls::dslx::ConvertModuleToPackage()
0x558d9741ac41: xls::dslx::ParseAndTest()
0x558d94fc819b: main
0x7eff9e98c633: __libc_start_main
0x558d94fc702a: _start
```
Contributor guide
Assessment
This issue has not been assessed yet.