From f2dcbb3d994d333b4c3046c23ce62ef82b03804f Mon Sep 17 00:00:00 2001 From: Valery Mironov <32071355+MBkkt@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:40:00 +0100 Subject: [PATCH] Fix warnings (#551) * Fix unused/unreachable code * Fix other warnings --- .clang-tidy | 1 + core/CMakeLists.txt | 6 +- core/analysis/delimited_token_stream.cpp | 5 +- core/analysis/minhash_token_stream.cpp | 2 +- core/analysis/nearest_neighbors_stream.cpp | 2 +- core/analysis/ngram_token_stream.cpp | 4 +- core/analysis/segmentation_token_stream.cpp | 3 - .../text_token_normalizing_stream.cpp | 6 +- core/analysis/text_token_stream.cpp | 9 +- core/analysis/token_stream.hpp | 1 - core/error/error.hpp | 6 +- core/formats/columnstore.cpp | 43 ++-------- core/formats/columnstore2.cpp | 14 ++-- core/formats/formats.hpp | 2 - core/formats/formats_10.cpp | 15 +--- core/formats/formats_burst_trie.cpp | 27 ++---- core/formats/skip_list.cpp | 4 +- core/formats/skip_list.hpp | 2 +- core/formats/sparse_bitmap.cpp | 7 +- core/index/buffered_column.cpp | 2 +- core/index/directory_reader_impl.cpp | 13 ++- core/index/merge_writer.cpp | 10 +-- core/index/norm.cpp | 4 +- core/index/segment_reader_impl.hpp | 2 +- core/search/bm25.cpp | 11 ++- core/search/collectors.cpp | 2 +- core/search/levenshtein_filter.cpp | 2 +- core/search/nested_filter.cpp | 6 +- core/search/ngram_similarity_filter.cpp | 3 +- core/search/phrase_filter.cpp | 6 -- core/search/phrase_iterator.hpp | 4 +- core/search/score_function.hpp | 2 +- core/search/scorer.hpp | 23 +++-- core/search/terms_filter.cpp | 2 +- core/search/wildcard_filter.cpp | 2 - core/store/fs_directory.cpp | 8 +- core/store/store_avg_utils.hpp | 9 +- core/store/store_utils.cpp | 4 +- core/utils/bitpack.hpp | 2 +- core/utils/file_utils.cpp | 26 +----- core/utils/file_utils.hpp | 1 - core/utils/fstext/fst_string_ref_weight.hpp | 2 +- core/utils/fstext/fst_string_weight.hpp | 2 +- core/utils/fstext/immutable_fst.hpp | 27 ++---- core/utils/index_utils.cpp | 84 +++++++++---------- core/utils/levenshtein_utils.cpp | 8 +- core/utils/levenshtein_utils.hpp | 2 +- core/utils/memory.hpp | 18 ++-- core/utils/minhash_utils.hpp | 4 +- core/utils/numeric_utils.hpp | 16 ---- core/utils/register.hpp | 2 +- core/utils/timer_utils.cpp | 11 +-- core/utils/timer_utils.hpp | 2 +- core/utils/type_id.hpp | 2 +- core/utils/type_utils.hpp | 28 ++----- core/utils/wildcard_utils.cpp | 1 + external/CMakeLists.txt | 1 + microbench/column_writer_benchmark.cpp | 2 +- microbench/top_term_collector_benchmark.cpp | 37 ++++---- tests/CMakeLists.txt | 4 +- .../analysis/delimited_token_stream_tests.cpp | 1 - tests/analysis/pipeline_stream_tests.cpp | 1 - tests/formats/formats_15_tests.cpp | 3 +- tests/formats/formats_test_case_base.hpp | 2 +- tests/formats/skip_list_test.cpp | 18 +--- tests/formats/sparse_bitmap_test.cpp | 9 -- tests/index/assert_format.cpp | 3 - tests/index/field_meta_test.cpp | 1 - tests/index/index_column_tests.cpp | 46 +++------- tests/index/index_death_tests.cpp | 11 --- tests/index/index_tests.cpp | 16 +--- tests/index/segment_writer_tests.cpp | 3 +- tests/search/boolean_filter_tests.cpp | 10 +-- tests/search/filter_test_case_base.hpp | 18 ++-- tests/search/scorers_tests.cpp | 8 +- tests/search/sort_tests.cpp | 2 - tests/search/wand_test.cpp | 5 -- tests/store/directory_test_case.cpp | 22 ----- tests/tests_shared.hpp | 1 - tests/utils/directory_utils_tests.cpp | 2 - tests/utils/encryption_test.cpp | 4 - tests/utils/numeric_utils_test.cpp | 3 + tests/utils/object_pool_tests.cpp | 4 +- tests/utils/ref_counter_tests.cpp | 4 +- tests/utils/type_utils_tests.cpp | 10 +-- utils/CMakeLists.txt | 12 +-- utils/index-put.cpp | 1 - utils/main.cpp | 8 +- 88 files changed, 268 insertions(+), 516 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 02da5fd1d..f830933f9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,6 +7,7 @@ Checks: '*, -mpi-*, -objc-*, -openmp-*, + -fuchsia-trailing-return, -fuchsia-default-arguments-*, -fuchsia-overloaded-operator, -readability-identifier-length, diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 4fb6100c2..eae1f6700 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -290,11 +290,7 @@ set(IRESEARCH_EXTERNAL_INCLUDES ${Fasttext_INCLUDE_DIR} ${FROZEN_INCLUDE_DIR}) -if (SUPPRESS_EXTERNAL_WARNINGS) - include_directories(SYSTEM ${IRESEARCH_EXTERNAL_INCLUDES}) -else () - include_directories(${IRESEARCH_EXTERNAL_INCLUDES}) -endif () +include_directories(SYSTEM ${IRESEARCH_EXTERNAL_INCLUDES}) add_library(iresearch-static STATIC diff --git a/core/analysis/delimited_token_stream.cpp b/core/analysis/delimited_token_stream.cpp index bb3942d9a..ba59fa9cf 100644 --- a/core/analysis/delimited_token_stream.cpp +++ b/core/analysis/delimited_token_stream.cpp @@ -125,8 +125,9 @@ bool parse_vpack_options(const VPackSlice slice, std::string& delimiter) { delimiter = delim_type_slice.stringView(); return true; } - default: { - } // fall through + break; + default: + break; } IRS_LOG_ERROR(absl::StrCat( diff --git a/core/analysis/minhash_token_stream.cpp b/core/analysis/minhash_token_stream.cpp index 2bc2e2d06..31e39ff2b 100644 --- a/core/analysis/minhash_token_stream.cpp +++ b/core/analysis/minhash_token_stream.cpp @@ -103,7 +103,7 @@ static uint64_t HashLen0to16(const char* s, size_t len) { uint8_t b = s[len >> 1]; uint8_t c = s[len - 1]; uint32_t y = static_cast(a) + (static_cast(b) << 8); - uint32_t z = len + (static_cast(c) << 2); + uint32_t z = static_cast(len) + (static_cast(c) << 2); return ShiftMix(y * k2 ^ z * k0) * k2; } return k2; diff --git a/core/analysis/nearest_neighbors_stream.cpp b/core/analysis/nearest_neighbors_stream.cpp index 7334d0b7e..89b993639 100644 --- a/core/analysis/nearest_neighbors_stream.cpp +++ b/core/analysis/nearest_neighbors_stream.cpp @@ -265,7 +265,7 @@ bool nearest_neighbors_stream::reset(std::string_view data) { std::istream ss{&buf}; model_dict_->getLine(ss, line_token_ids_, line_token_label_ids_); - n_tokens_ = line_token_ids_.size(); + n_tokens_ = static_cast(line_token_ids_.size()); current_token_ind_ = 0; neighbors_.clear(); diff --git a/core/analysis/ngram_token_stream.cpp b/core/analysis/ngram_token_stream.cpp index 4f9d4d729..976af63d5 100644 --- a/core/analysis/ngram_token_stream.cpp +++ b/core/analysis/ngram_token_stream.cpp @@ -399,8 +399,8 @@ void ngram_token_stream_base::emit_original() noexcept { : EmitOriginal::WithEndMarker; inc.value = next_inc_val_; break; - default: - IRS_ASSERT(false); // should not be called when None + case EmitOriginal::None: + IRS_ASSERT(false); break; } next_inc_val_ = 0; diff --git a/core/analysis/segmentation_token_stream.cpp b/core/analysis/segmentation_token_stream.cpp index f5a2d8993..82e7eb1d1 100644 --- a/core/analysis/segmentation_token_stream.cpp +++ b/core/analysis/segmentation_token_stream.cpp @@ -275,9 +275,6 @@ bool accept_token(Iterator begin, Iterator end, word_break_t wb) { return std::find_if_not(begin, end, utf8_utils::CharIsWhiteSpace) != end; case word_break_t::ALPHA: return std::find_if(begin, end, utf8_utils::CharIsAlphanumeric) != end; - default: - IRS_ASSERT(false); - return false; } } diff --git a/core/analysis/text_token_normalizing_stream.cpp b/core/analysis/text_token_normalizing_stream.cpp index 242fa613c..13e818bd6 100644 --- a/core/analysis/text_token_normalizing_stream.cpp +++ b/core/analysis/text_token_normalizing_stream.cpp @@ -401,9 +401,9 @@ bool normalizing_token_stream::reset(std::string_view data) { case UPPER: state_->token.toUpper(state_->options.locale); // inplace case-conversion break; - default: { - } // NOOP - }; + case NONE: + break; + } // collate value, e.g. remove accents if (state_->transliterator) { diff --git a/core/analysis/text_token_stream.cpp b/core/analysis/text_token_stream.cpp index c14b2a1eb..943f4eb28 100644 --- a/core/analysis/text_token_stream.cpp +++ b/core/analysis/text_token_stream.cpp @@ -374,9 +374,9 @@ bool process_term(analysis::text_token_stream::state_t& state, case analysis::text_token_stream::UPPER: state.token.toUpper(state.options.locale); // inplace case-conversion break; - default: { - } // NOOP - }; + case analysis::text_token_stream::NONE: + break; + } // collate value, e.g. remove accents if (state.transliterator) { @@ -399,7 +399,8 @@ bool process_term(analysis::text_token_stream::state_t& state, const sb_symbol* value = reinterpret_cast(word_utf8.c_str()); - value = sb_stemmer_stem(state.stemmer.get(), value, (int)word_utf8.size()); + value = sb_stemmer_stem(state.stemmer.get(), value, + static_cast(word_utf8.size())); if (value) { static_assert(sizeof(byte_type) == sizeof(sb_symbol)); diff --git a/core/analysis/token_stream.hpp b/core/analysis/token_stream.hpp index d5e50a09c..b4a3d3789 100644 --- a/core/analysis/token_stream.hpp +++ b/core/analysis/token_stream.hpp @@ -33,7 +33,6 @@ class token_stream : public attribute_provider { public: using ptr = std::unique_ptr; - virtual ~token_stream() = default; virtual bool next() = 0; }; diff --git a/core/error/error.hpp b/core/error/error.hpp index 745a7d544..6d93afd2c 100644 --- a/core/error/error.hpp +++ b/core/error/error.hpp @@ -46,9 +46,9 @@ enum class ErrorCode : uint32_t { undefined_error }; -#define DECLARE_ERROR_CODE(class_name) \ - static constexpr ErrorCode CODE = ErrorCode::class_name; \ - ::irs::ErrorCode code() const noexcept final { return CODE; } +#define DECLARE_ERROR_CODE(class_name) \ + ::irs::ErrorCode code() const noexcept final { return CODE; } \ + static constexpr ErrorCode CODE = ErrorCode::class_name ////////////////////////////////////////////////////////////////////////////// /// @struct error_base diff --git a/core/formats/columnstore.cpp b/core/formats/columnstore.cpp index 7bb28d063..b0fd63870 100644 --- a/core/formats/columnstore.cpp +++ b/core/formats/columnstore.cpp @@ -79,26 +79,16 @@ irs::bytes_view kDummy; // placeholder for visiting logic in columnstore struct column_meta { public: column_meta() = default; - column_meta(column_meta&& rhs) noexcept - : name(std::move(rhs.name)), id(rhs.id) { - rhs.id = field_limits::invalid(); - } + column_meta(column_meta&&) = delete; column_meta(const column_meta&) = delete; + column_meta& operator=(column_meta&&) = delete; column_meta& operator=(const column_meta&) = delete; - column_meta& operator=(column_meta&& rhs) noexcept = delete; - - bool operator==(const column_meta& rhs) const noexcept { - return name == rhs.name; - } std::string name; field_id id{field_limits::invalid()}; }; -static_assert(std::is_nothrow_move_constructible_v, - "default move constructor expected"); - struct format_traits { IRS_FORCE_INLINE static void pack32(const uint32_t* IRS_RESTRICT decoded, uint32_t* IRS_RESTRICT encoded, @@ -256,23 +246,6 @@ void read_compact(irs::index_input& in, irs::encryption::stream* cipher, } } -struct ColumnMetaEq : ValueRefEq { - using is_transparent = void; - using Self::operator(); - - bool operator()(const Ref& lhs, - const hashed_string_view& rhs) const noexcept { - return lhs.ref->name == rhs; - } - - bool operator()(const hashed_string_view& lhs, - const Ref& rhs) const noexcept { - return this->operator()(rhs, lhs); - } -}; - -using name_to_column_map = flat_hash_set; - class meta_writer final { public: static constexpr std::string_view FORMAT_NAME = "iresearch_10_columnmeta"; @@ -686,7 +659,7 @@ class writer final : public irs::columnstore_writer { // do not take into account last block const auto blocks_count = std::max(1U, column_index_.total()); avg_block_count_ = block_index_.flushed() / blocks_count; - avg_block_size_ = length_ / blocks_count; + avg_block_size_ = static_cast(length_ / blocks_count); // we don't care of tail block size prev_block_size_ = block_buf_.size(); @@ -1131,7 +1104,7 @@ class dense_block : util::noncopyable { return false; } - value_ = base_ + std::distance(begin_, it_); + value_ = base_ + static_cast(std::distance(begin_, it_)); next_value(); return true; @@ -1200,7 +1173,7 @@ class dense_block : util::noncopyable { encode::avg::visit_block_packed_tail( in, size, reinterpret_cast(buf.data()), [begin](uint64_t offset) mutable { - *begin = offset; + *begin = static_cast(offset); ++begin; }); @@ -1669,9 +1642,7 @@ class column : public irs::column_reader, private util::noncopyable { using ptr = std::unique_ptr; explicit column(field_id id, ColumnProperty props) noexcept - : props_(props), id_{id}, encrypted_(0 != (props & CP_COLUMN_ENCRYPT)) {} - - virtual ~column() = default; + : id_{id}, encrypted_(0 != (props & CP_COLUMN_ENCRYPT)) {} field_id id() const final { return id_; } @@ -1704,7 +1675,6 @@ class column : public irs::column_reader, private util::noncopyable { bool empty() const noexcept { return 0 == size(); } uint32_t avg_block_size() const noexcept { return avg_block_size_; } uint32_t avg_block_count() const noexcept { return avg_block_count_; } - ColumnProperty props() const noexcept { return props_; } compression::decompressor* decompressor() const noexcept { return decomp_.get(); } @@ -1719,7 +1689,6 @@ class column : public irs::column_reader, private util::noncopyable { uint32_t count_{}; uint32_t avg_block_size_{}; uint32_t avg_block_count_{}; - ColumnProperty props_{CP_SPARSE}; field_id id_; std::optional name_; bool encrypted_{false}; // cached encryption mark diff --git a/core/formats/columnstore2.cpp b/core/formats/columnstore2.cpp index d9c200315..dc2884cb2 100644 --- a/core/formats/columnstore2.cpp +++ b/core/formats/columnstore2.cpp @@ -768,7 +768,7 @@ doc_iterator::ptr dense_fixed_length_column::iterator(ColumnHint hint) const { payload_reader> operator()( index_input::ptr&& stream, encryption::stream& cipher) const { return {ctx->data_, ctx->len_, std::move(stream), &cipher, ctx->data_}; - }; + } payload_reader> operator()( index_input::ptr&& stream) const { @@ -966,7 +966,7 @@ doc_iterator::ptr fixed_length_column::iterator(ColumnHint hint) const { index_input::ptr&& stream, encryption::stream& cipher) const { return {ctx->blocks_.data(), ctx->len_, std::move(stream), &cipher, ctx->len_}; - }; + } payload_reader> operator()( index_input::ptr&& stream) const { @@ -1263,7 +1263,7 @@ doc_iterator::ptr sparse_column::iterator(ColumnHint hint) const { payload_reader> operator()( index_input::ptr&& stream, encryption::stream& cipher) const { return {ctx->blocks_.data(), std::move(stream), &cipher, size_t{0}}; - }; + } payload_reader> operator()( index_input::ptr&& stream) const { @@ -1291,14 +1291,14 @@ constexpr column_factory_f kFactories[]{ &dense_fixed_length_column::read}; bool less(std::string_view lhs, std::string_view rhs) noexcept { - if (IsNull(lhs)) { - return !IsNull(rhs); - } - if (IsNull(rhs)) { return false; } + if (IsNull(lhs)) { + return true; + } + return lhs < rhs; } diff --git a/core/formats/formats.hpp b/core/formats/formats.hpp index 8c100179f..b3cb3c3e1 100644 --- a/core/formats/formats.hpp +++ b/core/formats/formats.hpp @@ -321,8 +321,6 @@ enum class ColumnHint : uint32_t { ENABLE_BITMASK_ENUM(ColumnHint); struct column_reader : public memory::Managed { - virtual ~column_reader() = default; - // Returns column id. virtual field_id id() const = 0; diff --git a/core/formats/formats_10.cpp b/core/formats/formats_10.cpp index 86d730f3e..45f77b25a 100644 --- a/core/formats/formats_10.cpp +++ b/core/formats/formats_10.cpp @@ -191,14 +191,6 @@ struct doc_buffer : skip_buffer { last = doc; } - void reset() noexcept { - skip_buffer::reset(); - doc = docs.begin(); - freq = freqs.begin(); - last = doc_limits::invalid(); - block_last = doc_limits::min(); - } - std::span docs; std::span freqs; uint32_t* skip_doc; @@ -1586,7 +1578,7 @@ class position final : public irs::position, value_t seek(value_t target) final { const uint32_t freq = *this->freq_; if (this->pend_pos_ > freq) { - skip(this->pend_pos_ - freq); + skip(static_cast(this->pend_pos_ - freq)); this->pend_pos_ = freq; } while (value_ < target && this->pend_pos_) { @@ -1620,7 +1612,7 @@ class position final : public irs::position, const uint32_t freq = *this->freq_; if (this->pend_pos_ > freq) { - skip(this->pend_pos_ - freq); + skip(static_cast(this->pend_pos_ - freq)); this->pend_pos_ = freq; } @@ -1956,6 +1948,7 @@ auto ResolveExtent(uint8_t extent, Func&& func) { if constexpr (PossibleMin <= 0) { return std::forward(func)(Extent<0>{}); } + [[fallthrough]]; default: return std::forward(func)(DynamicExtent{extent}); } @@ -4130,7 +4123,7 @@ template struct format_traits_sse4 { using align_type = __m128i; - static constexpr bool wand() noexcept { return Wand; }; + static constexpr bool wand() noexcept { return Wand; } static constexpr uint32_t pos_min() noexcept { return PosMin; } static constexpr uint32_t block_size() noexcept { return SIMDBlockSize; } static_assert(block_size() <= doc_limits::eof()); diff --git a/core/formats/formats_burst_trie.cpp b/core/formats/formats_burst_trie.cpp index 8fc19c1ff..524fe1d4f 100644 --- a/core/formats/formats_burst_trie.cpp +++ b/core/formats/formats_burst_trie.cpp @@ -263,16 +263,6 @@ struct block_t : private util::noncopyable { label(rhs.label), meta(rhs.meta) {} - block_t& operator=(block_t&& rhs) noexcept { - if (this != &rhs) { - index = std::move(rhs.index); - start = rhs.start; - label = rhs.label; - meta = rhs.meta; - } - return *this; - } - ~block_t() { index.Visit([](prefixed_output& output) { // output.~prefixed_output(); @@ -399,10 +389,6 @@ class entry : private util::noncopyable { entry& operator=(entry&& rhs) noexcept; ~entry() noexcept; - const version10::term_meta& term() const noexcept { - return *mem_.as(); - } - version10::term_meta& term() noexcept { return *mem_.as(); } @@ -943,7 +929,7 @@ class fst_buffer : public vector_byte_fst { }; fst_buffer(IResourceManager& rm) - : vector_byte_fst(ManagedTypedAllocator(rm)){}; + : vector_byte_fst(ManagedTypedAllocator(rm)) {} using fst_byte_builder = fst_builder; @@ -1538,7 +1524,8 @@ void term_reader_base::prepare(burst_trie::Version version, index_input& in, max_term_ = read_string(in); if (IndexFeatures::NONE != (field_.index_features & IndexFeatures::FREQ)) { - freq_.value = in.read_vlong(); + // TODO(MBkkt) for what reason we store uint64_t if we read to uint32_t + freq_.value = static_cast(in.read_vlong()); } if (IRS_LIKELY(version >= burst_trie::Version::WAND)) { @@ -1632,7 +1619,6 @@ class block_iterator : util::noncopyable { // assume such blocks have terms return sub_count_ != UNDEFINED_COUNT && !block_meta::terms(meta()); } - uint64_t size() const noexcept { return ent_count_; } template SeekResult scan_to_term(bytes_view term, Reader&& reader) { @@ -2173,8 +2159,6 @@ class term_iterator_base : public seek_term_iterator { return std::get(attrs_).value; } - index_input& terms_input() const; - irs::encryption::stream* terms_cipher() const noexcept { return terms_cipher_; } @@ -2210,8 +2194,6 @@ class term_iterator_base : public seek_term_iterator { } void reset_value() noexcept { std::get(attrs_).value = {}; } - const field_meta& field() const noexcept { return field_->meta(); } - mutable attributes attrs_; const term_reader_base* field_; postings_reader* postings_; @@ -3494,6 +3476,8 @@ irs::field_iterator::ptr field_reader::iterator() const { fields_); } +/* + // Implements generalized visitation logic for term dictionary template class term_reader_visitor { @@ -3576,7 +3560,6 @@ class term_reader_visitor { encryption::stream* terms_in_cipher_; }; -/* // "Dumper" visitor for term_reader_visitor. Suitable for debugging needs. class dumper : util::noncopyable { public: diff --git a/core/formats/skip_list.cpp b/core/formats/skip_list.cpp index 581e9484b..286bc84b4 100644 --- a/core/formats/skip_list.cpp +++ b/core/formats/skip_list.cpp @@ -133,8 +133,8 @@ void SkipReaderBase::Prepare(index_input::ptr&& in, doc_id_t left) { }; // skip step of the level - size_t step = - skip_0_ * static_cast(std::pow(skip_n_, --max_levels)); + uint32_t step = + skip_0_ * static_cast(std::pow(skip_n_, --max_levels)); // load levels from n down to 1 for (; max_levels; --max_levels) { diff --git a/core/formats/skip_list.hpp b/core/formats/skip_list.hpp index a19a67520..ddfd510d8 100644 --- a/core/formats/skip_list.hpp +++ b/core/formats/skip_list.hpp @@ -245,7 +245,7 @@ doc_id_t SkipReader::Seek(doc_id_t target) { } auto& level_0 = levels_.back(); - return level_0.left + level_0.step; + return static_cast(level_0.left + level_0.step); } } // namespace irs diff --git a/core/formats/sparse_bitmap.cpp b/core/formats/sparse_bitmap.cpp index aec4981d4..a3e62fd70 100644 --- a/core/formats/sparse_bitmap.cpp +++ b/core/formats/sparse_bitmap.cpp @@ -252,7 +252,7 @@ struct container_iterator { } } ctx.popcnt = self->index_ + popcnt + std::popcount(ctx.word); - ctx.word_idx = word_idx; + ctx.word_idx = static_cast(word_idx); } uint32_t word_delta = target_word_idx - ctx.word_idx; @@ -394,8 +394,9 @@ struct container_iterator { } } - return self->block_ + (word_idx + 1) * bits_required() - - std::countl_zero(word) - 1; + return self->block_ + + static_cast((word_idx + 1) * bits_required() - + std::countl_zero(word) - 1); } }; diff --git a/core/index/buffered_column.cpp b/core/index/buffered_column.cpp index 615b38346..a04d097e7 100644 --- a/core/index/buffered_column.cpp +++ b/core/index/buffered_column.cpp @@ -150,7 +150,7 @@ bool BufferedColumn::FlushDense(column_output& writer, DocMapView docmap, WriteValue(writer, new_value); index_.emplace_back(new_value); } - }; + } return true; } diff --git a/core/index/directory_reader_impl.cpp b/core/index/directory_reader_impl.cpp index 2bc535371..4e0fa2903 100644 --- a/core/index/directory_reader_impl.cpp +++ b/core/index/directory_reader_impl.cpp @@ -43,8 +43,6 @@ DirectoryReaderImpl::Init::Init(const directory& dir, const DirectoryMeta& meta) { const bool has_segments_file = !meta.filename.empty(); - auto& [file_refs, docs_count, live_docs_count] = *this; - file_refs.reserve(meta.index_meta.segments.size() + size_t{has_segments_file}); @@ -211,8 +209,8 @@ DirectoryReaderImpl::DirectoryReaderImpl(Init&& init, const directory& dir, std::shared_ptr DirectoryReaderImpl::Open( const directory& dir, const IndexReaderOptions& opts, format::ptr codec, const std::shared_ptr& cached) { - IndexMeta meta; - index_file_refs::ref_t meta_file_ref = LoadNewestIndexMeta(meta, dir, codec); + IndexMeta index_meta; + auto meta_file_ref = LoadNewestIndexMeta(index_meta, dir, codec); if (!meta_file_ref) { throw index_not_found{}; @@ -220,7 +218,7 @@ std::shared_ptr DirectoryReaderImpl::Open( IRS_ASSERT(codec); - if (cached && cached->meta_.index_meta == meta) { + if (cached && cached->meta_.index_meta == index_meta) { return cached; // no changes to refresh } @@ -241,7 +239,7 @@ std::shared_ptr DirectoryReaderImpl::Open( } } - const auto& segments = meta.segments; + const auto& segments = index_meta.segments; ReadersType readers(segments.size()); auto reader = readers.begin(); @@ -272,7 +270,8 @@ std::shared_ptr DirectoryReaderImpl::Open( return std::make_shared( dir, std::move(codec), opts, - DirectoryMeta{.filename = *meta_file_ref, .index_meta = std::move(meta)}, + DirectoryMeta{.filename = *meta_file_ref, + .index_meta = std::move(index_meta)}, std::move(readers)); } diff --git a/core/index/merge_writer.cpp b/core/index/merge_writer.cpp index b17e1a0c7..d73bf09a4 100644 --- a/core/index/merge_writer.cpp +++ b/core/index/merge_writer.cpp @@ -139,11 +139,6 @@ class ProgressTracker { explicit operator bool() const noexcept { return valid_; } - void reset() noexcept { - hits_ = 0; - valid_ = true; - } - private: const MergeWriter::FlushProgress* progress_; const size_t count_; // call progress callback each `count_` hits @@ -405,8 +400,6 @@ class CompoundColumnIterator final { iterator_mask_.reserve(size); } - size_t size() const { return iterators_.size(); } - void add(const SubReader& reader, const doc_map_f& doc_map) { auto it = reader.columns(); IRS_ASSERT(it); @@ -1805,7 +1798,8 @@ bool MergeWriter::FlushSorted(TrackingDirectory& dir, SegmentMeta& segment, // Handle empty values greater than the last document in sort column for (auto it = itrs.begin(); auto& reader : readers_) { if (!fill_doc_map(reader.doc_id_map, *it, - doc_limits::min() + reader.reader->docs_count())) { + doc_limits::min() + + static_cast(reader.reader->docs_count()))) { return false; // progress callback requested termination } ++it; diff --git a/core/index/norm.cpp b/core/index/norm.cpp index 629ce28f1..496adca6d 100644 --- a/core/index/norm.cpp +++ b/core/index/norm.cpp @@ -85,8 +85,8 @@ bool Norm2ReaderContext::Reset(const ColumnProvider& reader, field_id column_id, const auto hdr = Norm2Header::Read(header); if (hdr.has_value()) { auto& value = hdr.value(); - num_bytes = value.NumBytes(); - max_num_bytes = value.MaxNumBytes(); + num_bytes = static_cast(value.NumBytes()); + max_num_bytes = static_cast(value.MaxNumBytes()); return true; } } diff --git a/core/index/segment_reader_impl.hpp b/core/index/segment_reader_impl.hpp index e818e5627..5f6249eca 100644 --- a/core/index/segment_reader_impl.hpp +++ b/core/index/segment_reader_impl.hpp @@ -40,7 +40,7 @@ class SegmentReaderImpl final : public SubReader { public: SegmentReaderImpl(PrivateTag, IResourceManager& rm) noexcept - : docs_mask_{{rm}} {}; + : docs_mask_{{rm}} {} static std::shared_ptr Open( const directory& dir, const SegmentMeta& meta, diff --git a/core/search/bm25.cpp b/core/search/bm25.cpp index ef33ef108..a5cd395a4 100644 --- a/core/search/bm25.cpp +++ b/core/search/bm25.cpp @@ -353,7 +353,8 @@ struct MakeScoreFunctionImpl> { *res = c0 - c0 / (1.f + tf * inv_c1); } else { const float_t c1 = - state.norm_const + state.norm_length * state.norm(); + state.norm_const + + state.norm_length * static_cast(state.norm()); *res = c0 - c0 * c1 / (c1 + tf); } @@ -377,8 +378,9 @@ void BM25::collect(byte_type* stats_buf, const irs::FieldCollector* field, const auto total_term_freq = field_ptr ? field_ptr->total_term_freq : 0; // precomputed idf value - stats->idf += float_t(std::log1p((docs_with_field - docs_with_term + 0.5) / - (docs_with_term + 0.5))); + stats->idf += float_t( + std::log1p((static_cast(docs_with_field - docs_with_term) + 0.5) / + (static_cast(docs_with_term) + 0.5))); IRS_ASSERT(stats->idf >= 0.f); // - stats were already initialized @@ -392,7 +394,8 @@ void BM25::collect(byte_type* stats_buf, const irs::FieldCollector* field, stats->norm_const = k_ - kb; if (total_term_freq && docs_with_field) { - const float_t avg_dl = float_t(total_term_freq) / docs_with_field; + const auto avg_dl = static_cast(total_term_freq) / + static_cast(docs_with_field); stats->norm_length = kb / avg_dl; } else { stats->norm_length = kb; diff --git a/core/search/collectors.cpp b/core/search/collectors.cpp index 3b4c8e1ce..1d1ac9712 100644 --- a/core/search/collectors.cpp +++ b/core/search/collectors.cpp @@ -198,7 +198,7 @@ size_t term_collectors::push_back() { void term_collectors::finish(byte_type* stats_buf, size_t term_idx, const field_collectors& field_collectors, - const IndexReader& index) const { + const IndexReader& /*index*/) const { const auto bucket_count = buckets_.size(); switch (bucket_count) { diff --git a/core/search/levenshtein_filter.cpp b/core/search/levenshtein_filter.cpp index 3e9b9fdce..80cc6f242 100644 --- a/core/search/levenshtein_filter.cpp +++ b/core/search/levenshtein_filter.cpp @@ -49,7 +49,7 @@ IRS_FORCE_INLINE score_t similarity(uint32_t distance, uint32_t size) noexcept { static_assert(sizeof(score_t) == sizeof(uint32_t)); - return 1.f - score_t(distance) / size; + return 1.f - static_cast(distance) / static_cast(size); } template diff --git a/core/search/nested_filter.cpp b/core/search/nested_filter.cpp index 43a7ca971..533375dfd 100644 --- a/core/search/nested_filter.cpp +++ b/core/search/nested_filter.cpp @@ -259,7 +259,7 @@ class NoneMatcher : public NoopAggregator { private: score_t boost_; - size_t size_; + uint32_t size_; }; template @@ -654,8 +654,8 @@ doc_iterator::ptr ByNestedQuery::execute(const ExecutionContext& ctx) const { if constexpr (std::is_same_v) { if (doc_limits::eof(child->value())) { // Match all parents if constexpr (!std::is_same_v) { - auto func = - ScoreFunction::Constant(none_boost_, ord.buckets().size()); + auto func = ScoreFunction::Constant( + none_boost_, static_cast(ord.buckets().size())); auto* score = irs::get_mutable(parent.get()); if (IRS_UNLIKELY(!score)) { return memory::make_managed(std::move(parent), diff --git a/core/search/ngram_similarity_filter.cpp b/core/search/ngram_similarity_filter.cpp index 82bc46042..0e1b3a6b5 100644 --- a/core/search/ngram_similarity_filter.cpp +++ b/core/search/ngram_similarity_filter.cpp @@ -44,7 +44,8 @@ filter::prepared::ptr by_ngram_similarity::Prepare( threshold = std::clamp(threshold, 0.f, 1.f); const auto min_match_count = - std::clamp(static_cast(std::ceil(terms_count * threshold)), + std::clamp(static_cast( + std::ceil(static_cast(terms_count) * threshold)), size_t{1}, terms_count); if (ctx.scorers.empty() && 1 == min_match_count) { irs::by_terms_options options; diff --git a/core/search/phrase_filter.cpp b/core/search/phrase_filter.cpp index 8a5c7050c..ea1aad616 100644 --- a/core/search/phrase_filter.cpp +++ b/core/search/phrase_filter.cpp @@ -76,12 +76,6 @@ struct GetVisitor { return by_range::visit(segment, field, *range, visitor); }; } - - template - result_type operator()(const T&) const { - IRS_ASSERT(false); - return [](const SubReader&, const term_reader&, filter_visitor&) {}; - } }; struct PrepareVisitor : util::noncopyable { diff --git a/core/search/phrase_iterator.hpp b/core/search/phrase_iterator.hpp index 819d40d0b..6f2732881 100644 --- a/core/search/phrase_iterator.hpp +++ b/core/search/phrase_iterator.hpp @@ -230,8 +230,8 @@ class VariadicPhraseFrequency { if constexpr (VolatileBoost) { if (phrase_freq_.value) { - phrase_boost_.value = - phrase_boost_.value / (phrase_size_ * phrase_freq_.value); + phrase_boost_.value /= + static_cast(phrase_size_ * phrase_freq_.value); } } diff --git a/core/search/score_function.hpp b/core/search/score_function.hpp index 224f7156a..7524a1921 100644 --- a/core/search/score_function.hpp +++ b/core/search/score_function.hpp @@ -53,7 +53,7 @@ class ScoreFunction : util::noncopyable { const auto size = reinterpret_cast(ctx); std::memset(res, 0, size); } - static void DefaultMin(score_ctx* ctx, score_t min) noexcept {} + static void DefaultMin(score_ctx* /*ctx*/, score_t /*min*/) noexcept {} // Returns default scoring function setting `size` score buckets to 0. static ScoreFunction Default(size_t count) noexcept { diff --git a/core/search/scorer.hpp b/core/search/scorer.hpp index 1ab0ad803..1b061d854 100644 --- a/core/search/scorer.hpp +++ b/core/search/scorer.hpp @@ -312,19 +312,19 @@ Scorers Scorers::Prepare(Iterator begin, Iterator end) { return scorers; } -inline constexpr size_t kBufferRuntimeSize = std::numeric_limits::max(); +inline constexpr uint32_t kBufferRuntimeSize = 0; struct NoopAggregator { - constexpr size_t size() const noexcept { return 0; } + constexpr uint32_t size() const noexcept { return 0; } }; -template +template struct ScoreBuffer { static_assert(Size > 0); - ScoreBuffer(size_t = 0) noexcept {} + ScoreBuffer(uint32_t = 0) noexcept {} - constexpr size_t size() const noexcept { return Size; } + constexpr uint32_t size() const noexcept { return Size; } constexpr score_t* temp() noexcept { return buf_.data(); } @@ -344,7 +344,9 @@ struct ScoreBuffer { IRS_ASSERT(size); } - size_t size() const noexcept { return buf_.get_deleter().size(); } + uint32_t size() const noexcept { + return static_cast(buf_.get_deleter().size()); + } score_t* temp() noexcept { return buf_.get(); } @@ -359,7 +361,7 @@ struct Aggregator : ScoreBuffer { using Buffer::Buffer; IRS_FORCE_INLINE size_t byte_size() const noexcept { - return this->size() * sizeof(score_t); + return static_cast(this->size()) * sizeof(score_t); } IRS_FORCE_INLINE void Merge(score_t& dst, score_t src) const noexcept { @@ -367,7 +369,7 @@ struct Aggregator : ScoreBuffer { } void operator()(score_t* dst, const score_t* src) const noexcept { - for (size_t i = 0; i != this->size(); ++i) { + for (uint32_t i = 0; i != this->size(); ++i) { merger_(dst, src); ++dst; ++src; @@ -448,9 +450,6 @@ auto ResoveMergeType(ScoreMergeType type, size_t num_buckets, return impl.template operator()(); case ScoreMergeType::kMin: return impl.template operator()(); - default: - IRS_ASSERT(false); - return visitor(NoopAggregator{}); } } @@ -458,7 +457,7 @@ auto ResoveMergeType(ScoreMergeType type, size_t num_buckets, template class ScorerBase : public Scorer { public: - static_assert(std::is_same_v || + static_assert(std::is_void_v || std::is_trivially_constructible_v); WandWriter::ptr prepare_wand_writer(size_t) const override { return nullptr; } diff --git a/core/search/terms_filter.cpp b/core/search/terms_filter.cpp index af5cf8f54..82cbdd364 100644 --- a/core/search/terms_filter.cpp +++ b/core/search/terms_filter.cpp @@ -70,7 +70,7 @@ class terms_visitor { } void visit(score_t boost) { - size_t stat_index = collector_.stat_index(); + auto stat_index = collector_.stat_index(); collector_.visit(boost); collector_.stat_index(++stat_index); } diff --git a/core/search/wildcard_filter.cpp b/core/search/wildcard_filter.cpp index 0dd9002f8..b08ebd886 100644 --- a/core/search/wildcard_filter.cpp +++ b/core/search/wildcard_filter.cpp @@ -73,8 +73,6 @@ auto ExecuteWildcard(bstring& buf, bytes_view term, Term&& t, Prefix&& p, } case WildcardType::kWildcard: return w(term); - default: - ABSL_UNREACHABLE(); } } diff --git a/core/store/fs_directory.cpp b/core/store/fs_directory.cpp index 073d89afa..b446fdb23 100644 --- a/core/store/fs_directory.cpp +++ b/core/store/fs_directory.cpp @@ -160,7 +160,7 @@ class fs_lock : public index_lock { class fs_index_output : public buffered_index_output { public: - DEFINE_FACTORY_INLINE(index_output) // cppcheck-suppress unknownMacro + DEFINE_FACTORY_INLINE(index_output); // cppcheck-suppress unknownMacro static index_output::ptr open(const path_char_t* name, const ResourceManagementOptions& rm) noexcept @@ -225,7 +225,9 @@ class fs_index_output : public buffered_index_output { buffered_index_output::reset(buf_, sizeof buf_); } - ~fs_index_output() { rm_.transactions->Decrease(sizeof(fs_index_output)); } + ~fs_index_output() override { + rm_.transactions->Decrease(sizeof(fs_index_output)); + } byte_type buf_[1024]; file_utils::handle_t handle_; @@ -378,7 +380,7 @@ class fs_index_input : public buffered_index_input { fs_index_input(const fs_index_input& rhs); - ~fs_index_input(); + ~fs_index_input() override; fs_index_input& operator=(const fs_index_input&) = delete; diff --git a/core/store/store_avg_utils.hpp b/core/store/store_avg_utils.hpp index e07b9198a..d890a3021 100644 --- a/core/store/store_avg_utils.hpp +++ b/core/store/store_avg_utils.hpp @@ -37,8 +37,9 @@ inline std::tuple encode(uint64_t* begin, const uint64_t base = *begin; const std::ptrdiff_t distance = std::distance(begin, end); - const uint64_t avg = std::lround(static_cast(*end - base) / - (distance > 0 ? distance : 1)); + const uint64_t avg = + std::lround(static_cast(*end - base) / + (distance > 0 ? static_cast(distance) : 1.0)); uint64_t value = 0; *begin++ = 0; // zig_zag_encode64(*begin - base - avg*0) == 0 @@ -61,8 +62,8 @@ inline std::pair encode(uint32_t* begin, const std::ptrdiff_t distance = std::distance(begin, end); // prevent division by 0 - const uint32_t avg = std::lround(static_cast(*end - base) / - (distance > 0 ? distance : 1)); + const auto avg = static_cast(std::lround( + (*end - base) / (distance > 0 ? static_cast(distance) : 1.0))); *begin++ = 0; // zig_zag_encode32(*begin - base - avg*0) == 0 for (uint32_t avg_base = base; begin <= end; ++begin) { diff --git a/core/store/store_utils.cpp b/core/store/store_utils.cpp index 8348a34b4..d62f900c0 100644 --- a/core/store/store_utils.cpp +++ b/core/store/store_utils.cpp @@ -75,7 +75,7 @@ void write_zvdouble(data_output& out, double_t v) { } else { const float_t fv = static_cast(v); - if (fv == static_cast(v)) { + if (static_cast(fv) == v) { out.write_byte(0xFE); out.write_int(numeric_utils::ftoi32(fv)); } else if (!std::signbit(v)) { @@ -97,7 +97,7 @@ double_t read_zvdouble(data_input& in) { return numeric_utils::i64tod(in.read_long()); } else if (0xFE == b) { // float value - return numeric_utils::i32tof(in.read_int()); + return static_cast(numeric_utils::i32tof(in.read_int())); } else if (0 != (b & 0x80)) { // small signed value return double_t((b & 0x7F) - 1); diff --git a/core/utils/bitpack.hpp b/core/utils/bitpack.hpp index dbb16c767..241568a35 100644 --- a/core/utils/bitpack.hpp +++ b/core/utils/bitpack.hpp @@ -129,7 +129,7 @@ uint32_t write_block64(PackFunc&& pack, data_output& out, if (simd::all_equal(decoded, size)) { out.write_byte(ALL_EQUAL); - out.write_vint(*decoded); + out.write_vlong(*decoded); return ALL_EQUAL; } diff --git a/core/utils/file_utils.cpp b/core/utils/file_utils.cpp index b07cb8236..b504a85d8 100644 --- a/core/utils/file_utils.cpp +++ b/core/utils/file_utils.cpp @@ -104,7 +104,7 @@ namespace irs { namespace file_utils { void file_deleter::operator()(void* f) const noexcept { -#if _WIN32 +#ifdef _WIN32 if (f != nullptr && f != INVALID_HANDLE_VALUE) { CloseHandle(f); } @@ -136,7 +136,7 @@ void lock_file_deleter::operator()(void* handle) const { } } -bool exists(const path_char_t* file) { +static bool exists(const path_char_t* file) { #ifdef _WIN32 return TRUE == ::PathFileExists(file); #else @@ -591,24 +591,6 @@ bool block_size(file_blksize_t& result, const path_char_t* file) noexcept { #endif // _WIN32 } -#ifdef _WIN32 -bool block_size(file_blksize_t& result, void* fd) noexcept { - // TODO FIXME find a workaround - IRS_IGNORE(fd); - result = 512; - return true; -} -#else -bool block_size(file_blksize_t& result, int fd) noexcept { - file_stat_t info; - if (0 != file_fstat(fd, &info)) { - return false; - } - result = info.st_blksize; - return true; -} -#endif // _WIN32 - bool byte_size(uint64_t& result, const path_char_t* file) noexcept { IRS_ASSERT(file != nullptr); file_stat_t info; @@ -872,8 +854,8 @@ handle_t open(void* file, OpenMode mode, int advice) noexcept { // under /proc/self/fd the link is guaranteed to point to the original inode // even if the original file was removed auto fd = handle_cast(file); - char path[strlen("/proc/self/fd/") + sizeof(fd) * 3 + - 1]; // approximate maximum number of chars, +1 for \0 + // approximate maximum number of chars, +1 for \0 + char path[14 + sizeof(fd) * 3 + 1]; if (0 > fd || 0 > sprintf(path, "/proc/self/fd/%d", fd)) { IRS_LOG_ERROR(absl::StrCat( diff --git a/core/utils/file_utils.hpp b/core/utils/file_utils.hpp index 628aa24c8..fafd5500e 100644 --- a/core/utils/file_utils.hpp +++ b/core/utils/file_utils.hpp @@ -130,7 +130,6 @@ bool verify_lock_file(const path_char_t* file); bool absolute(bool& result, const path_char_t* path) noexcept; bool block_size(file_blksize_t& result, const path_char_t* file) noexcept; -bool block_size(file_blksize_t& result, void* fd) noexcept; bool byte_size(uint64_t& result, const path_char_t* file) noexcept; bool byte_size(uint64_t& result, int fd) noexcept; bool byte_size(uint64_t& result, void* fd) noexcept; diff --git a/core/utils/fstext/fst_string_ref_weight.hpp b/core/utils/fstext/fst_string_ref_weight.hpp index ab974e636..308475583 100644 --- a/core/utils/fstext/fst_string_ref_weight.hpp +++ b/core/utils/fstext/fst_string_ref_weight.hpp @@ -91,7 +91,7 @@ class StringRefWeight : public StringRefWeightTraits