Commit de02e37f authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

switch from assert to FOLLY_SAFE_DCHECK

Summary:
assert(x) doesn't mark x as used in prod builds, causing problems
for builds that warn on unused variables and promote warnings to errors.
This diff changes assert calls to FOLLY_SAFE_DCHECK, which is better in
this regard.

Reviewed By: phoad, shixiao

Differential Revision: D7291084

fbshipit-source-id: 1ae48a271f30182ac8a1c2cf126af0e6b4fd0a25
parent 79778122
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <folly/Traits.h> #include <folly/Traits.h>
#include <folly/functional/ApplyTuple.h> #include <folly/functional/ApplyTuple.h>
#include <folly/lang/Exception.h> #include <folly/lang/Exception.h>
#include <folly/lang/SafeAssert.h>
#include <folly/container/detail/F14Policy.h> #include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h> #include <folly/container/detail/F14Table.h>
...@@ -294,7 +295,7 @@ class F14BasicMap { ...@@ -294,7 +295,7 @@ class F14BasicMap {
template <class InputIt> template <class InputIt>
void initialInsert(InputIt first, InputIt last, std::size_t initialCapacity) { void initialInsert(InputIt first, InputIt last, std::size_t initialCapacity) {
assert(empty() && bucket_count() >= initialCapacity); FOLLY_SAFE_DCHECK(empty() && bucket_count() >= initialCapacity, "");
// It's possible that there are a lot of duplicates in first..last and // It's possible that there are a lot of duplicates in first..last and
// so we will oversize ourself. The common case, however, is that // so we will oversize ourself. The common case, however, is that
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
* @author Xiao Shi <xshi@fb.com> * @author Xiao Shi <xshi@fb.com>
*/ */
#include <folly/lang/SafeAssert.h>
#include <folly/container/detail/F14Policy.h> #include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h> #include <folly/container/detail/F14Table.h>
...@@ -269,7 +271,7 @@ class F14BasicSet { ...@@ -269,7 +271,7 @@ class F14BasicSet {
template <class InputIt> template <class InputIt>
void initialInsert(InputIt first, InputIt last, std::size_t initialCapacity) { void initialInsert(InputIt first, InputIt last, std::size_t initialCapacity) {
assert(empty() && bucket_count() >= initialCapacity); FOLLY_SAFE_DCHECK(empty() && bucket_count() >= initialCapacity, "");
// It's possible that there are a lot of duplicates in first..last and // It's possible that there are a lot of duplicates in first..last and
// so we will oversize ourself. The common case, however, is that // so we will oversize ourself. The common case, however, is that
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
#pragma once #pragma once
#include <cassert>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include <folly/Portability.h> #include <folly/Portability.h>
#include <folly/lang/SafeAssert.h>
namespace folly { namespace folly {
namespace f14 { namespace f14 {
...@@ -113,7 +113,7 @@ class TaggedPtr<T*> { ...@@ -113,7 +113,7 @@ class TaggedPtr<T*> {
TaggedPtr(T* p, uint8_t e) noexcept TaggedPtr(T* p, uint8_t e) noexcept
: raw_{(reinterpret_cast<uintptr_t>(p) << 8) | e} { : raw_{(reinterpret_cast<uintptr_t>(p) << 8) | e} {
assert(ptr() == p); FOLLY_SAFE_DCHECK(ptr() == p, "");
} }
/* implicit */ TaggedPtr(std::nullptr_t) noexcept : raw_{0} {} /* implicit */ TaggedPtr(std::nullptr_t) noexcept : raw_{0} {}
...@@ -137,7 +137,7 @@ class TaggedPtr<T*> { ...@@ -137,7 +137,7 @@ class TaggedPtr<T*> {
void setPtr(T* p) { void setPtr(T* p) {
*this = TaggedPtr{p, extra()}; *this = TaggedPtr{p, extra()};
assert(ptr() == p); FOLLY_SAFE_DCHECK(ptr() == p, "");
} }
uint8_t extra() const { uint8_t extra() const {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <folly/container/detail/F14Table.h> #include <folly/container/detail/F14Table.h>
#include <folly/hash/Hash.h> #include <folly/hash/Hash.h>
#include <folly/lang/SafeAssert.h>
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE #if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
...@@ -222,7 +223,7 @@ struct BasePolicy ...@@ -222,7 +223,7 @@ struct BasePolicy
// prefetchBeforeCopy(), and prefetchBeforeDestroy(). if they don't // prefetchBeforeCopy(), and prefetchBeforeDestroy(). if they don't
// override this method, because neither gcc nor clang can figure // override this method, because neither gcc nor clang can figure
// out that DenseMaskIter with an empty body can be elided. // out that DenseMaskIter with an empty body can be elided.
assert(false); FOLLY_SAFE_DCHECK(false, "should be disabled");
} }
}; };
...@@ -858,7 +859,7 @@ class VectorContainerPolicy : public BasePolicy< ...@@ -858,7 +859,7 @@ class VectorContainerPolicy : public BasePolicy<
VectorContainerPolicy& operator=(VectorContainerPolicy const& rhs) { VectorContainerPolicy& operator=(VectorContainerPolicy const& rhs) {
if (this != &rhs) { if (this != &rhs) {
assert(values_ == nullptr); FOLLY_SAFE_DCHECK(values_ == nullptr, "");
Super::operator=(rhs); Super::operator=(rhs);
} }
return *this; return *this;
...@@ -1006,7 +1007,7 @@ class VectorContainerPolicy : public BasePolicy< ...@@ -1006,7 +1007,7 @@ class VectorContainerPolicy : public BasePolicy<
VectorContainerPolicy const& rhs) { VectorContainerPolicy const& rhs) {
Alloc& a = this->alloc(); Alloc& a = this->alloc();
assert(values_ != nullptr); FOLLY_SAFE_DCHECK(values_ != nullptr, "");
Value const* src = std::addressof(rhs.values_[0]); Value const* src = std::addressof(rhs.values_[0]);
Value* dst = std::addressof(values_[0]); Value* dst = std::addressof(values_[0]);
...@@ -1038,16 +1039,18 @@ class VectorContainerPolicy : public BasePolicy< ...@@ -1038,16 +1039,18 @@ class VectorContainerPolicy : public BasePolicy<
std::size_t /*capacity*/, std::size_t /*capacity*/,
VectorContainerPolicy const& /*rhs*/) { VectorContainerPolicy const& /*rhs*/) {
// valueAtItemForCopy can be copied trivially, no failure should occur // valueAtItemForCopy can be copied trivially, no failure should occur
assert(success); FOLLY_SAFE_DCHECK(success, "");
} }
ValuePtr beforeRehash( ValuePtr beforeRehash(
std::size_t size, std::size_t size,
std::size_t oldCapacity, std::size_t oldCapacity,
std::size_t newCapacity) { std::size_t newCapacity) {
assert( FOLLY_SAFE_DCHECK(
size <= oldCapacity && ((values_ == nullptr) == (oldCapacity == 0)) && size <= oldCapacity && ((values_ == nullptr) == (oldCapacity == 0)) &&
newCapacity > 0 && newCapacity <= (std::numeric_limits<Item>::max)()); newCapacity > 0 &&
newCapacity <= (std::numeric_limits<Item>::max)(),
"");
Alloc& a = this->alloc(); Alloc& a = this->alloc();
ValuePtr before = values_; ValuePtr before = values_;
...@@ -1087,7 +1090,8 @@ class VectorContainerPolicy : public BasePolicy< ...@@ -1087,7 +1090,8 @@ class VectorContainerPolicy : public BasePolicy<
} }
void beforeClear(std::size_t size, std::size_t capacity) { void beforeClear(std::size_t size, std::size_t capacity) {
assert(size <= capacity && ((values_ == nullptr) == (capacity == 0))); FOLLY_SAFE_DCHECK(
size <= capacity && ((values_ == nullptr) == (capacity == 0)), "");
Alloc& a = this->alloc(); Alloc& a = this->alloc();
for (std::size_t i = 0; i < size; ++i) { for (std::size_t i = 0; i < size; ++i) {
AllocTraits::destroy(a, std::addressof(values_[i])); AllocTraits::destroy(a, std::addressof(values_[i]));
...@@ -1095,7 +1099,8 @@ class VectorContainerPolicy : public BasePolicy< ...@@ -1095,7 +1099,8 @@ class VectorContainerPolicy : public BasePolicy<
} }
void beforeReset(std::size_t size, std::size_t capacity) { void beforeReset(std::size_t size, std::size_t capacity) {
assert(size <= capacity && ((values_ == nullptr) == (capacity == 0))); FOLLY_SAFE_DCHECK(
size <= capacity && ((values_ == nullptr) == (capacity == 0)), "");
if (capacity > 0) { if (capacity > 0) {
beforeClear(size, capacity); beforeClear(size, capacity);
Alloc& a = this->alloc(); Alloc& a = this->alloc();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#pragma once #pragma once
#include <cassert>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
...@@ -223,9 +222,10 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -223,9 +222,10 @@ struct alignas(std::max_align_t) SSE2Chunk {
static SSE2Chunk* emptyInstance() { static SSE2Chunk* emptyInstance() {
auto rv = static_cast<SSE2Chunk*>(static_cast<void*>(&kEmptyTagVector)); auto rv = static_cast<SSE2Chunk*>(static_cast<void*>(&kEmptyTagVector));
assert( FOLLY_SAFE_DCHECK(
rv->occupiedMask() == 0 && rv->chunk0Capacity() == 0 && rv->occupiedMask() == 0 && rv->chunk0Capacity() == 0 &&
rv->outboundOverflowCount() == 0); rv->outboundOverflowCount() == 0,
"");
return rv; return rv;
} }
...@@ -238,7 +238,7 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -238,7 +238,7 @@ struct alignas(std::max_align_t) SSE2Chunk {
} }
void copyOverflowInfoFrom(SSE2Chunk const& rhs) { void copyOverflowInfoFrom(SSE2Chunk const& rhs) {
assert(hostedOverflowCount() == 0); FOLLY_SAFE_DCHECK(hostedOverflowCount() == 0, "");
control_ += rhs.control_ & 0xf0; control_ += rhs.control_ & 0xf0;
outboundOverflowCount_ = rhs.outboundOverflowCount_; outboundOverflowCount_ = rhs.outboundOverflowCount_;
} }
...@@ -264,9 +264,10 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -264,9 +264,10 @@ struct alignas(std::max_align_t) SSE2Chunk {
} }
void markEof(std::size_t c0c) { void markEof(std::size_t c0c) {
assert(this != emptyInstance()); FOLLY_SAFE_DCHECK(
assert(control_ == 0); this != emptyInstance() && control_ == 0 && c0c > 0 && c0c <= 0xf &&
assert(c0c > 0 && c0c <= 0xf && c0c <= kCapacity); c0c <= kCapacity,
"");
control_ = static_cast<uint8_t>(c0c); control_ = static_cast<uint8_t>(c0c);
} }
...@@ -291,8 +292,7 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -291,8 +292,7 @@ struct alignas(std::max_align_t) SSE2Chunk {
} }
void setTag(std::size_t index, uint8_t tag) { void setTag(std::size_t index, uint8_t tag) {
assert(this != emptyInstance()); FOLLY_SAFE_DCHECK(this != emptyInstance() && (tag & 0x80) != 0, "");
assert((tag & 0x80) != 0);
tags_[index] = tag; tags_[index] = tag;
} }
...@@ -305,7 +305,7 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -305,7 +305,7 @@ struct alignas(std::max_align_t) SSE2Chunk {
} }
unsigned tagMatchMask(uint8_t needle) const { unsigned tagMatchMask(uint8_t needle) const {
assert((needle & 0x80) != 0); FOLLY_SAFE_DCHECK((needle & 0x80) != 0, "");
auto tagV = _mm_load_si128(tagVector()); auto tagV = _mm_load_si128(tagVector());
auto needleV = _mm_set1_epi8(needle); auto needleV = _mm_set1_epi8(needle);
auto eqV = _mm_cmpeq_epi8(tagV, needleV); auto eqV = _mm_cmpeq_epi8(tagV, needleV);
...@@ -318,7 +318,7 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -318,7 +318,7 @@ struct alignas(std::max_align_t) SSE2Chunk {
} }
bool occupied(std::size_t index) const { bool occupied(std::size_t index) const {
assert(tags_[index] == 0 || (tags_[index] & 0x80) != 0); FOLLY_SAFE_DCHECK(tags_[index] == 0 || (tags_[index] & 0x80) != 0, "");
return tags_[index] != 0; return tags_[index] != 0;
} }
...@@ -331,7 +331,7 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -331,7 +331,7 @@ struct alignas(std::max_align_t) SSE2Chunk {
// assume + findLastSet results in optimal __builtin_clz on gcc // assume + findLastSet results in optimal __builtin_clz on gcc
folly::assume(m != 0); folly::assume(m != 0);
unsigned i = folly::findLastSet(m) - 1; unsigned i = folly::findLastSet(m) - 1;
assert(occupied(i)); FOLLY_SAFE_DCHECK(occupied(i), "");
return i; return i;
} }
...@@ -341,12 +341,12 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -341,12 +341,12 @@ struct alignas(std::max_align_t) SSE2Chunk {
} }
Item& item(std::size_t i) { Item& item(std::size_t i) {
assert(this->occupied(i)); FOLLY_SAFE_DCHECK(this->occupied(i), "");
return *folly::launder(itemAddr(i)); return *folly::launder(itemAddr(i));
} }
Item const& citem(std::size_t i) const { Item const& citem(std::size_t i) const {
assert(this->occupied(i)); FOLLY_SAFE_DCHECK(this->occupied(i), "");
return *folly::launder(itemAddr(i)); return *folly::launder(itemAddr(i));
} }
...@@ -355,7 +355,7 @@ struct alignas(std::max_align_t) SSE2Chunk { ...@@ -355,7 +355,7 @@ struct alignas(std::max_align_t) SSE2Chunk {
static_cast<uint8_t*>(static_cast<void*>(std::addressof(item))) - static_cast<uint8_t*>(static_cast<void*>(std::addressof(item))) -
offsetof(SSE2Chunk, rawItems_) - index * sizeof(Item); offsetof(SSE2Chunk, rawItems_) - index * sizeof(Item);
auto chunkAddr = static_cast<SSE2Chunk*>(static_cast<void*>(rawAddr)); auto chunkAddr = static_cast<SSE2Chunk*>(static_cast<void*>(rawAddr));
assert(std::addressof(item) == chunkAddr->itemAddr(index)); FOLLY_SAFE_DCHECK(std::addressof(item) == chunkAddr->itemAddr(index), "");
return *chunkAddr; return *chunkAddr;
} }
}; };
...@@ -371,7 +371,7 @@ class SparseMaskIter { ...@@ -371,7 +371,7 @@ class SparseMaskIter {
} }
unsigned next() { unsigned next() {
assert(hasNext()); FOLLY_SAFE_DCHECK(hasNext(), "");
unsigned i = __builtin_ctz(mask_); unsigned i = __builtin_ctz(mask_);
mask_ &= (mask_ - 1); mask_ &= (mask_ - 1);
return i; return i;
...@@ -390,7 +390,7 @@ class DenseMaskIter { ...@@ -390,7 +390,7 @@ class DenseMaskIter {
} }
unsigned next() { unsigned next() {
assert(hasNext()); FOLLY_SAFE_DCHECK(hasNext(), "");
if (LIKELY((mask_ & 1) != 0)) { if (LIKELY((mask_ & 1) != 0)) {
mask_ >>= 1; mask_ >>= 1;
return index_++; return index_++;
...@@ -431,7 +431,7 @@ class F14ItemIter { ...@@ -431,7 +431,7 @@ class F14ItemIter {
F14ItemIter(ChunkPtr chunk, std::size_t index) F14ItemIter(ChunkPtr chunk, std::size_t index)
: itemPtr_{std::pointer_traits<ItemPtr>::pointer_to(chunk->item(index))}, : itemPtr_{std::pointer_traits<ItemPtr>::pointer_to(chunk->item(index))},
index_{index} { index_{index} {
assert(index < Chunk::kCapacity); FOLLY_SAFE_DCHECK(index < Chunk::kCapacity, "");
folly::assume( folly::assume(
std::pointer_traits<ItemPtr>::pointer_to(chunk->item(index)) != std::pointer_traits<ItemPtr>::pointer_to(chunk->item(index)) !=
nullptr); nullptr);
...@@ -474,7 +474,7 @@ class F14ItemIter { ...@@ -474,7 +474,7 @@ class F14ItemIter {
for (std::size_t i = 1; i != 0; ++i) { for (std::size_t i = 1; i != 0; ++i) {
// exhausted the current chunk // exhausted the current chunk
if (UNLIKELY(c->eof())) { if (UNLIKELY(c->eof())) {
assert(index_ == 0); FOLLY_SAFE_DCHECK(index_ == 0, "");
itemPtr_ = nullptr; itemPtr_ = nullptr;
return; return;
} }
...@@ -504,7 +504,7 @@ class F14ItemIter { ...@@ -504,7 +504,7 @@ class F14ItemIter {
while (true) { while (true) {
// exhausted the current chunk // exhausted the current chunk
assert(!c->eof()); FOLLY_SAFE_DCHECK(!c->eof(), "");
--c; --c;
auto m = c->occupiedMask(); auto m = c->occupiedMask();
if (LIKELY(m != 0)) { if (LIKELY(m != 0)) {
...@@ -814,11 +814,11 @@ class F14Table : public Policy { ...@@ -814,11 +814,11 @@ class F14Table : public Policy {
std::size_t maxSizeWithoutRehash) { std::size_t maxSizeWithoutRehash) {
if (chunkCount == 1) { if (chunkCount == 1) {
auto n = offsetof(Chunk, rawItems_) + maxSizeWithoutRehash * sizeof(Item); auto n = offsetof(Chunk, rawItems_) + maxSizeWithoutRehash * sizeof(Item);
assert((maxSizeWithoutRehash % 2) == 0); FOLLY_SAFE_DCHECK((maxSizeWithoutRehash % 2) == 0, "");
if ((sizeof(Item) % 8) != 0) { if ((sizeof(Item) % 8) != 0) {
n = ((n - 1) | 15) + 1; n = ((n - 1) | 15) + 1;
} }
assert((n % 16) == 0); FOLLY_SAFE_DCHECK((n % 16) == 0, "");
return n; return n;
} else { } else {
return sizeof(Chunk) * chunkCount; return sizeof(Chunk) * chunkCount;
...@@ -994,7 +994,7 @@ class F14Table : public Policy { ...@@ -994,7 +994,7 @@ class F14Table : public Policy {
// and the two-arg find(F14HashToken,K) performs the rest of the search. // and the two-arg find(F14HashToken,K) performs the rest of the search.
template <typename K> template <typename K>
F14HashToken prehash(K const& key) const { F14HashToken prehash(K const& key) const {
assert(chunks_ != nullptr); FOLLY_SAFE_DCHECK(chunks_ != nullptr, "");
auto hp = splitHash(this->computeKeyHash(key)); auto hp = splitHash(this->computeKeyHash(key));
ChunkPtr firstChunk = chunks_ + (hp.first & chunkMask_); ChunkPtr firstChunk = chunks_ + (hp.first & chunkMask_);
prefetchAddr(firstChunk); prefetchAddr(firstChunk);
...@@ -1010,8 +1010,9 @@ class F14Table : public Policy { ...@@ -1010,8 +1010,9 @@ class F14Table : public Policy {
template <typename K> template <typename K>
FOLLY_ALWAYS_INLINE ItemIter FOLLY_ALWAYS_INLINE ItemIter
find(F14HashToken const& token, K const& key) const { find(F14HashToken const& token, K const& key) const {
assert( FOLLY_SAFE_DCHECK(
splitHash(this->computeKeyHash(key)) == static_cast<HashPair>(token)); splitHash(this->computeKeyHash(key)) == static_cast<HashPair>(token),
"");
return findImpl(static_cast<HashPair>(token), key); return findImpl(static_cast<HashPair>(token), key);
} }
...@@ -1089,14 +1090,14 @@ class F14Table : public Policy { ...@@ -1089,14 +1090,14 @@ class F14Table : public Policy {
index += delta; index += delta;
} }
unsigned itemIndex = fullness[index]++; unsigned itemIndex = fullness[index]++;
assert(!chunk->occupied(itemIndex)); FOLLY_SAFE_DCHECK(!chunk->occupied(itemIndex), "");
chunk->setTag(itemIndex, hp.second); chunk->setTag(itemIndex, hp.second);
chunk->adjustHostedOverflowCount(hostedOp); chunk->adjustHostedOverflowCount(hostedOp);
return ItemIter{chunk, itemIndex}; return ItemIter{chunk, itemIndex};
} }
void directCopyFrom(F14Table const& src) { void directCopyFrom(F14Table const& src) {
assert(src.size() > 0 && chunkMask_ == src.chunkMask_); FOLLY_SAFE_DCHECK(src.size() > 0 && chunkMask_ == src.chunkMask_, "");
Policy const& srcPolicy = src; Policy const& srcPolicy = src;
auto undoState = this->beforeCopy(src.size(), bucket_count(), srcPolicy); auto undoState = this->beforeCopy(src.size(), bucket_count(), srcPolicy);
...@@ -1168,7 +1169,7 @@ class F14Table : public Policy { ...@@ -1168,7 +1169,7 @@ class F14Table : public Policy {
} }
void rehashCopyFrom(F14Table const& src) { void rehashCopyFrom(F14Table const& src) {
assert(src.chunkMask_ > chunkMask_); FOLLY_SAFE_DCHECK(src.chunkMask_ > chunkMask_, "");
// 1 byte per chunk means < 1 bit per value temporary overhead // 1 byte per chunk means < 1 bit per value temporary overhead
std::array<uint8_t, 256> stackBuf; std::array<uint8_t, 256> stackBuf;
...@@ -1239,7 +1240,7 @@ class F14Table : public Policy { ...@@ -1239,7 +1240,7 @@ class F14Table : public Policy {
auto&& srcValue = src.valueAtItemForCopy(srcItem); auto&& srcValue = src.valueAtItemForCopy(srcItem);
auto const& srcKey = src.keyForValue(srcValue); auto const& srcKey = src.keyForValue(srcValue);
auto hp = splitHash(this->computeKeyHash(srcKey)); auto hp = splitHash(this->computeKeyHash(srcKey));
assert(hp.second == srcChunk->tag(i)); FOLLY_SAFE_DCHECK(hp.second == srcChunk->tag(i), "");
insertAtBlank( insertAtBlank(
allocateTag(fullness, hp), allocateTag(fullness, hp),
hp, hp,
...@@ -1256,7 +1257,7 @@ class F14Table : public Policy { ...@@ -1256,7 +1257,7 @@ class F14Table : public Policy {
} }
FOLLY_NOINLINE void copyFromF14Table(F14Table const& src) { FOLLY_NOINLINE void copyFromF14Table(F14Table const& src) {
assert(size() == 0); FOLLY_SAFE_DCHECK(size() == 0, "");
if (src.size() == 0) { if (src.size() == 0) {
return; return;
} }
...@@ -1277,7 +1278,7 @@ class F14Table : public Policy { ...@@ -1277,7 +1278,7 @@ class F14Table : public Policy {
FOLLY_NOINLINE void rehashImpl( FOLLY_NOINLINE void rehashImpl(
std::size_t newChunkCount, std::size_t newChunkCount,
std::size_t newMaxSizeWithoutRehash) { std::size_t newMaxSizeWithoutRehash) {
assert(newMaxSizeWithoutRehash > 0); FOLLY_SAFE_DCHECK(newMaxSizeWithoutRehash > 0, "");
auto origChunks = chunks_; auto origChunks = chunks_;
const auto origChunkCount = chunkMask_ + 1; const auto origChunkCount = chunkMask_ + 1;
...@@ -1361,7 +1362,7 @@ class F14Table : public Policy { ...@@ -1361,7 +1362,7 @@ class F14Table : public Policy {
Item& srcItem = srcChunk->item(srcI); Item& srcItem = srcChunk->item(srcI);
auto hp = splitHash( auto hp = splitHash(
this->computeItemHash(const_cast<Item const&>(srcItem))); this->computeItemHash(const_cast<Item const&>(srcItem)));
assert(hp.second == srcChunk->tag(srcI)); FOLLY_SAFE_DCHECK(hp.second == srcChunk->tag(srcI), "");
auto dstIter = allocateTag(fullness, hp); auto dstIter = allocateTag(fullness, hp);
this->moveItemDuringRehash(dstIter.itemAddr(), srcItem); this->moveItemDuringRehash(dstIter.itemAddr(), srcItem);
...@@ -1480,8 +1481,7 @@ class F14Table : public Policy { ...@@ -1480,8 +1481,7 @@ class F14Table : public Policy {
template <bool Reset> template <bool Reset>
void clearImpl() noexcept { void clearImpl() noexcept {
if (chunks_ == Chunk::emptyInstance()) { if (chunks_ == Chunk::emptyInstance()) {
assert(empty()); FOLLY_SAFE_DCHECK(empty() && bucket_count() == 0, "");
assert(bucket_count() == 0);
return; return;
} }
...@@ -1607,21 +1607,22 @@ class F14Table : public Policy { ...@@ -1607,21 +1607,22 @@ class F14Table : public Policy {
std::size_t n = 0; std::size_t n = 0;
ItemIter prev; ItemIter prev;
for (auto iter = begin(); iter != end(); iter.advance()) { for (auto iter = begin(); iter != end(); iter.advance()) {
assert(n == 0 || iter.pack() < prev.pack()); FOLLY_SAFE_DCHECK(n == 0 || iter.pack() < prev.pack(), "");
++n; ++n;
prev = iter; prev = iter;
} }
assert(n == size()); FOLLY_SAFE_DCHECK(n == size(), "");
} }
assert((chunks_ == Chunk::emptyInstance()) == (bucket_count() == 0)); FOLLY_SAFE_DCHECK(
(chunks_ == Chunk::emptyInstance()) == (bucket_count() == 0), "");
std::size_t n1 = 0; std::size_t n1 = 0;
std::size_t n2 = 0; std::size_t n2 = 0;
auto cc = bucket_count() == 0 ? 0 : chunkMask_ + 1; auto cc = bucket_count() == 0 ? 0 : chunkMask_ + 1;
for (std::size_t ci = 0; ci < cc; ++ci) { for (std::size_t ci = 0; ci < cc; ++ci) {
ChunkPtr chunk = chunks_ + ci; ChunkPtr chunk = chunks_ + ci;
assert(chunk->eof() == (ci == 0)); FOLLY_SAFE_DCHECK(chunk->eof() == (ci == 0), "");
auto mask = chunk->occupiedMask(); auto mask = chunk->occupiedMask();
n1 += folly::popcount(mask); n1 += folly::popcount(mask);
...@@ -1638,7 +1639,7 @@ class F14Table : public Policy { ...@@ -1638,7 +1639,7 @@ class F14Table : public Policy {
{ {
auto& item = chunk->citem(ii); auto& item = chunk->citem(ii);
auto hp = splitHash(this->computeItemHash(item)); auto hp = splitHash(this->computeItemHash(item));
assert(chunk->tag(ii) == hp.second); FOLLY_SAFE_DCHECK(chunk->tag(ii) == hp.second, "");
std::size_t dist = 1; std::size_t dist = 1;
std::size_t index = hp.first; std::size_t index = hp.first;
...@@ -1672,8 +1673,8 @@ class F14Table : public Policy { ...@@ -1672,8 +1673,8 @@ class F14Table : public Policy {
} }
} }
assert(n1 == size()); FOLLY_SAFE_DCHECK(n1 == size(), "");
assert(n2 == size()); FOLLY_SAFE_DCHECK(n2 == size(), "");
stats.policy = typeid(Policy).name(); stats.policy = typeid(Policy).name();
stats.size = size(); stats.size = size();
......
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