Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions xls/ir/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions xls/ir/function_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <utility>
#include <vector>

#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"
Expand Down Expand Up @@ -228,6 +230,23 @@ class FunctionBase {

const absl::btree_set<Next*, Node::NodeIdLessThan>& 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<Next*, Node::NodeIdLessThan>>
kEmptySet;
CHECK(absl::c_none_of(nodes(),
[state_read](Node* n) {
return n->Is<Next>() &&
n->As<Next>()->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);
}

Expand Down