Commit d26b6250 by Evan Brown Committed by Copybara-Service

Use ABSL_RAW_LOG and ABSL_PREDICT_* for all debug checks in swisstable including…

Use ABSL_RAW_LOG and ABSL_PREDICT_* for all debug checks in swisstable including sanitizer mode checks.

Sanitizer mode can be used for canaries so performance is still relevant. This change also makes the code more uniform.

PiperOrigin-RevId: 570438923
Change-Id: I62859160eb9323e6420680a43fd23e97e8a62389
parent 22dc7911
...@@ -187,7 +187,6 @@ ...@@ -187,7 +187,6 @@
#include <iterator> #include <iterator>
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <string>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
...@@ -1213,17 +1212,17 @@ inline void AssertIsFull(const ctrl_t* ctrl, GenerationType generation, ...@@ -1213,17 +1212,17 @@ inline void AssertIsFull(const ctrl_t* ctrl, GenerationType generation,
operation); operation);
} }
if (SwisstableGenerationsEnabled()) { if (SwisstableGenerationsEnabled()) {
if (generation != *generation_ptr) { if (ABSL_PREDICT_FALSE(generation != *generation_ptr)) {
ABSL_INTERNAL_LOG(FATAL, ABSL_RAW_LOG(FATAL,
std::string(operation) + "%s called on invalid iterator. The table could have "
" called on invalid iterator. The table could have " "rehashed since this iterator was initialized.",
"rehashed since this iterator was initialized."); operation);
} }
if (!IsFull(*ctrl)) { if (ABSL_PREDICT_FALSE(!IsFull(*ctrl))) {
ABSL_INTERNAL_LOG( ABSL_RAW_LOG(
FATAL, FATAL,
std::string(operation) + "%s called on invalid iterator. The element was likely erased.",
" called on invalid iterator. The element was likely erased."); operation);
} }
} else { } else {
if (ABSL_PREDICT_FALSE(!IsFull(*ctrl))) { if (ABSL_PREDICT_FALSE(!IsFull(*ctrl))) {
...@@ -1245,13 +1244,13 @@ inline void AssertIsValidForComparison(const ctrl_t* ctrl, ...@@ -1245,13 +1244,13 @@ inline void AssertIsValidForComparison(const ctrl_t* ctrl,
const bool ctrl_is_valid_for_comparison = const bool ctrl_is_valid_for_comparison =
ctrl == nullptr || ctrl == EmptyGroup() || IsFull(*ctrl); ctrl == nullptr || ctrl == EmptyGroup() || IsFull(*ctrl);
if (SwisstableGenerationsEnabled()) { if (SwisstableGenerationsEnabled()) {
if (generation != *generation_ptr) { if (ABSL_PREDICT_FALSE(generation != *generation_ptr)) {
ABSL_INTERNAL_LOG(FATAL, ABSL_RAW_LOG(FATAL,
"Invalid iterator comparison. The table could have " "Invalid iterator comparison. The table could have "
"rehashed since this iterator was initialized."); "rehashed since this iterator was initialized.");
} }
if (!ctrl_is_valid_for_comparison) { if (ABSL_PREDICT_FALSE(!ctrl_is_valid_for_comparison)) {
ABSL_INTERNAL_LOG( ABSL_RAW_LOG(
FATAL, "Invalid iterator comparison. The element was likely erased."); FATAL, "Invalid iterator comparison. The element was likely erased.");
} }
} else { } else {
...@@ -1307,30 +1306,30 @@ inline void AssertSameContainer(const ctrl_t* ctrl_a, const ctrl_t* ctrl_b, ...@@ -1307,30 +1306,30 @@ inline void AssertSameContainer(const ctrl_t* ctrl_a, const ctrl_t* ctrl_b,
if (a_is_default && b_is_default) return; if (a_is_default && b_is_default) return;
if (SwisstableGenerationsEnabled()) { if (SwisstableGenerationsEnabled()) {
if (generation_ptr_a == generation_ptr_b) return; if (ABSL_PREDICT_TRUE(generation_ptr_a == generation_ptr_b)) return;
const bool a_is_empty = IsEmptyGeneration(generation_ptr_a); const bool a_is_empty = IsEmptyGeneration(generation_ptr_a);
const bool b_is_empty = IsEmptyGeneration(generation_ptr_b); const bool b_is_empty = IsEmptyGeneration(generation_ptr_b);
if (a_is_empty != b_is_empty) { if (a_is_empty != b_is_empty) {
ABSL_INTERNAL_LOG(FATAL, ABSL_RAW_LOG(FATAL,
"Invalid iterator comparison. Comparing iterator from " "Invalid iterator comparison. Comparing iterator from a "
"a non-empty hashtable with an iterator from an empty " "non-empty hashtable with an iterator from an empty "
"hashtable."); "hashtable.");
} }
if (a_is_empty && b_is_empty) { if (a_is_empty && b_is_empty) {
ABSL_INTERNAL_LOG(FATAL, ABSL_RAW_LOG(FATAL,
"Invalid iterator comparison. Comparing iterators from " "Invalid iterator comparison. Comparing iterators from "
"different empty hashtables."); "different empty hashtables.");
} }
const bool a_is_end = ctrl_a == nullptr; const bool a_is_end = ctrl_a == nullptr;
const bool b_is_end = ctrl_b == nullptr; const bool b_is_end = ctrl_b == nullptr;
if (a_is_end || b_is_end) { if (a_is_end || b_is_end) {
ABSL_INTERNAL_LOG(FATAL, ABSL_RAW_LOG(FATAL,
"Invalid iterator comparison. Comparing iterator with " "Invalid iterator comparison. Comparing iterator with an "
"an end() iterator from a different hashtable."); "end() iterator from a different hashtable.");
} }
ABSL_INTERNAL_LOG(FATAL, ABSL_RAW_LOG(FATAL,
"Invalid iterator comparison. Comparing non-end() " "Invalid iterator comparison. Comparing non-end() iterators "
"iterators from different hashtables."); "from different hashtables.");
} else { } else {
ABSL_HARDENING_ASSERT( ABSL_HARDENING_ASSERT(
AreItersFromSameContainer(ctrl_a, ctrl_b, slot_a, slot_b) && AreItersFromSameContainer(ctrl_a, ctrl_b, slot_a, slot_b) &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment