diff --git a/xls/ir/BUILD b/xls/ir/BUILD index 32ffe6cc26..f651f4106c 100644 --- a/xls/ir/BUILD +++ b/xls/ir/BUILD @@ -647,6 +647,7 @@ cc_library( "//xls/data_structures:leaf_type_tree", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/base", + "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:fixed_array", "@com_google_absl//absl/container:flat_hash_map", diff --git a/xls/ir/function_base.h b/xls/ir/function_base.h index 17c2f43fb9..2dbcff4728 100644 --- a/xls/ir/function_base.h +++ b/xls/ir/function_base.h @@ -26,6 +26,8 @@ #include #include +#include "absl/algorithm/container.h" +#include "absl/base/no_destructor.h" #include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/log/check.h" @@ -228,6 +230,23 @@ class FunctionBase { const absl::btree_set& next_values( StateRead* state_read) const { + if (!next_values_by_state_read_.contains(state_read)) { + // This should be pretty rare. Basically this should only happen in the + // short time before the non-updated state element is replaced. Just + // returning what is actually there is nicer than crashing however. Do + // check that this is not just some sort of weird corruption however. + static const absl::NoDestructor< + absl::btree_set> + kEmptySet; + CHECK(absl::c_none_of(nodes(), + [state_read](Node* n) { + return n->Is() && + n->As()->state_read() == state_read; + })) + << "Invalid side table for next values. Missing " << state_read + << " in " << this; + return *kEmptySet; + } return next_values_by_state_read_.at(state_read); }