Skip to content

Commit

Permalink
Remove C++17 support
Browse files Browse the repository at this point in the history
The CMake parameters for C++ standard and concepts are removed, and the
code is updated accordingly. We use `[[likely]]` and `[[unlikely]]`
instead of a macro. We also remove the macros for concepts, and use
unconditional `static_assert` and `require`.

Changelog-changed: C++17 is no longer supported
Signed-off-by: Michal Siedlaczek <[email protected]>
  • Loading branch information
elshize committed Dec 9, 2024
1 parent c4d8503 commit 8101f44
Show file tree
Hide file tree
Showing 51 changed files with 136 additions and 247 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ cmake_policy(SET CMP0074 NEW)
project(PISA CXX C)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(NOT CMAKE_CXX_STANDARD EQUAL 17)
add_compile_definitions(PISA_ENABLE_CONCEPTS=1)
add_compile_definitions(PISA_CXX20=1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts-diagnostics-depth=2")
endif()
add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE=1)

option(PISA_BUILD_TOOLS "Build command line tools." ON)
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/perftest_interpolative.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include <algorithm>
#include <iostream>
#include <numeric>

#include "spdlog/spdlog.h"

#include "codec/block_codecs.hpp"
#include "util/do_not_optimize_away.hpp"
#include "util/util.hpp"

int main()
{
int main() {
using namespace pisa;
static const size_t size = interpolative_block::block_size;
static const size_t runs = 1 << 20;
Expand Down
3 changes: 1 addition & 2 deletions include/pisa/accumulator/lazy_accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cstddef>
#include <vector>

#include "concepts.hpp"
#include "partial_score_accumulator.hpp"
#include "topk_queue.hpp"

Expand Down Expand Up @@ -58,7 +57,7 @@ class LazyAccumulator {
public:
explicit LazyAccumulator(std::size_t size)
: m_size(size), m_accumulators((size + counters_in_descriptor - 1) / counters_in_descriptor) {
PISA_ASSERT_CONCEPT(PartialScoreAccumulator<decltype(*this)>);
static_assert(PartialScoreAccumulator<decltype(*this)>);
}

void reset() {
Expand Down
6 changes: 0 additions & 6 deletions include/pisa/accumulator/partial_score_accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@

#pragma once

#ifdef PISA_ENABLE_CONCEPTS

#include <concepts>
#include <cstdint>
#include <iterator>
#include <vector>

#include "topk_queue.hpp"

Expand Down Expand Up @@ -56,5 +52,3 @@ concept PartialScoreAccumulator = requires(T a, std::uint32_t docid, float score
}; // namespace pisa

// clang-format on

#endif
3 changes: 1 addition & 2 deletions include/pisa/accumulator/simple_accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License. */
#include <cstdint>
#include <vector>

#include "concepts.hpp"
#include "partial_score_accumulator.hpp"
#include "topk_queue.hpp"

Expand All @@ -33,7 +32,7 @@ namespace pisa {
class SimpleAccumulator: public std::vector<float> {
public:
explicit SimpleAccumulator(std::size_t size) : std::vector<float>(size) {
PISA_ASSERT_CONCEPT(PartialScoreAccumulator<decltype(*this)>);
static_assert(PartialScoreAccumulator<decltype(*this)>);
}

void reset() { std::fill(begin(), end(), 0.0); }
Expand Down
15 changes: 7 additions & 8 deletions include/pisa/block_inverted_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include "bit_vector.hpp"
#include "codec/block_codec.hpp"
#include "codec/block_codecs.hpp"
#include "concepts.hpp"
#include "concepts/inverted_index.hpp"
#include "concepts/posting_cursor.hpp"
#include "global_parameters.hpp"
#include "mappable/mappable_vector.hpp"
#include "mappable/mapper.hpp"
Expand Down Expand Up @@ -50,7 +49,7 @@ class BlockInvertedIndexCursor {
m_universe(universe),
m_block_codec(block_codec),
m_block_size(block_codec->block_size()) {
PISA_ASSERT_CONCEPT(
static_assert(
(concepts::FrequencyPostingCursor<BlockInvertedIndexCursor>
&& concepts::SortedPostingCursor<BlockInvertedIndexCursor>)
);
Expand All @@ -68,7 +67,7 @@ class BlockInvertedIndexCursor {

void PISA_ALWAYSINLINE next() {
++m_pos_in_block;
if PISA_UNLIKELY (m_pos_in_block == m_cur_block_size) {
if (m_pos_in_block == m_cur_block_size) [[unlikely]] {
if (m_cur_block + 1 == m_blocks) {
m_cur_docid = m_universe;
return;
Expand All @@ -87,7 +86,7 @@ class BlockInvertedIndexCursor {
* to the current document ID, the position will not change.
*/
void PISA_ALWAYSINLINE next_geq(uint64_t lower_bound) {
if PISA_UNLIKELY (lower_bound > m_cur_block_max) {
if (lower_bound > m_cur_block_max) [[unlikely]] {
// binary search seems to perform worse here
if (lower_bound > block_max(m_blocks - 1)) {
m_cur_docid = m_universe;
Expand All @@ -111,7 +110,7 @@ class BlockInvertedIndexCursor {
void PISA_ALWAYSINLINE move(uint64_t pos) {
assert(pos >= position());
uint64_t block = pos / m_block_size;
if PISA_UNLIKELY (block != m_cur_block) {
if (block != m_cur_block) [[unlikely]] {
decode_docs_block(block);
}
while (position() < pos) {
Expand Down Expand Up @@ -338,8 +337,8 @@ class ProfilingBlockInvertedIndex: public BlockInvertedIndex {

ProfilingBlockInvertedIndex(MemorySource source, BlockCodecPtr block_codec);

[[nodiscard]] auto operator[](std::size_t term_id
) const -> BlockInvertedIndexCursor<Profiling::On>;
[[nodiscard]] auto operator[](std::size_t term_id) const
-> BlockInvertedIndexCursor<Profiling::On>;
};

namespace index::block {
Expand Down
7 changes: 7 additions & 0 deletions include/pisa/codec/VarIntG8IU.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
* This code is released under the
* Apache License Version 2.0 http://www.apache.org/licenses/.
*/

#include <cstdint>
#include <cstring>
#include <string>
#include <stdexcept>
#include <vector>

#if defined(_MSC_VER)
#include <intrin.h>
#else
Expand Down
5 changes: 0 additions & 5 deletions include/pisa/codec/block_codecs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

#include <array>

#include "FastPFor/headers/optpfor.h"
#include "FastPFor/headers/variablebyte.h"

#include "VarIntG8IU.h"
#include "interpolative_coding.hpp"
#include "util/compiler_attribute.hpp"
#include "util/likely.hpp"
#include "util/util.hpp"

namespace pisa {
Expand Down
19 changes: 9 additions & 10 deletions include/pisa/codec/compact_elias_fano.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "global_parameters.hpp"
#include "util/compiler_attribute.hpp"
#include "util/likely.hpp"
#include "util/util.hpp"

namespace pisa {
Expand Down Expand Up @@ -164,9 +163,9 @@ struct compact_elias_fano {

uint64_t skip = position - m_position;
// optimize small forward skips
if PISA_LIKELY (position > m_position && skip <= linear_scan_threshold) {
if (position > m_position && skip <= linear_scan_threshold) [[likely]] {
m_position = position;
if PISA_UNLIKELY (m_position == size()) {
if (m_position == size()) [[unlikely]] {
m_value = m_of.universe;
} else {
bit_vector::unary_enumerator he = m_high_enumerator;
Expand All @@ -193,13 +192,13 @@ struct compact_elias_fano {
uint64_t cur_high = m_value >> m_of.lower_bits;
uint64_t high_diff = high_lower_bound - cur_high;

if PISA_LIKELY (lower_bound > m_value && high_diff <= linear_scan_threshold) {
if (lower_bound > m_value && high_diff <= linear_scan_threshold) [[likely]] {
// optimize small skips
next_reader next_value(*this, m_position + 1);
uint64_t val;
do {
m_position += 1;
if PISA_LIKELY (m_position < size()) {
if (m_position < size()) [[likely]] {
val = next_value();
} else {
m_position = size();
Expand All @@ -220,7 +219,7 @@ struct compact_elias_fano {
m_position += 1;
assert(m_position <= size());

if PISA_LIKELY (m_position < size()) {
if (m_position < size()) [[likely]] {
m_value = read_next();
} else {
m_value = m_of.universe;
Expand All @@ -234,7 +233,7 @@ struct compact_elias_fano {
}

uint64_t prev_high = 0;
if PISA_LIKELY (m_position < size()) {
if (m_position < size()) [[likely]] {
prev_high = m_bv->predecessor1(m_high_enumerator.position() - 1);
} else {
prev_high = m_bv->predecessor1(m_of.lower_bits_offset - 1);
Expand All @@ -253,7 +252,7 @@ struct compact_elias_fano {

private:
value_type PISA_NOINLINE slow_move(uint64_t position) {
if PISA_UNLIKELY (position == size()) {
if (position == size()) [[unlikely]] {
m_position = position;
m_value = m_of.universe;
return value();
Expand All @@ -279,7 +278,7 @@ struct compact_elias_fano {
}

value_type PISA_NOINLINE slow_next_geq(uint64_t lower_bound) {
if PISA_UNLIKELY (lower_bound >= m_of.universe) {
if (lower_bound >= m_of.universe) [[unlikely]] {
return move(size());
}

Expand Down Expand Up @@ -309,7 +308,7 @@ struct compact_elias_fano {

next_reader read_value(*this, m_position);
while (true) {
if PISA_UNLIKELY (m_position == size()) {
if (m_position == size()) [[unlikely]] {
m_value = m_of.universe;
return value();
}
Expand Down
17 changes: 8 additions & 9 deletions include/pisa/codec/compact_ranked_bitvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "global_parameters.hpp"
#include "util/compiler_attribute.hpp"
#include "util/likely.hpp"
#include "util/util.hpp"

namespace pisa {
Expand Down Expand Up @@ -139,9 +138,9 @@ struct compact_ranked_bitvector {

// optimize small forward skips
uint64_t skip = position - m_position;
if PISA_LIKELY (position > m_position && skip <= linear_scan_threshold) {
if (position > m_position && skip <= linear_scan_threshold) [[likely]] {
m_position = position;
if PISA_UNLIKELY (m_position == size()) {
if (m_position == size()) [[unlikely]] {
m_value = m_of.universe;
} else {
bit_vector::unary_enumerator he = m_enumerator;
Expand All @@ -164,13 +163,13 @@ struct compact_ranked_bitvector {
}

uint64_t diff = lower_bound - m_value;
if PISA_LIKELY (lower_bound > m_value && diff <= linear_scan_threshold) {
if (lower_bound > m_value && diff <= linear_scan_threshold) [[likely]] {
// optimize small skips
bit_vector::unary_enumerator he = m_enumerator;
uint64_t val;
do {
m_position += 1;
if PISA_LIKELY (m_position < size()) {
if (m_position < size()) [[likely]] {
val = he.next() - m_of.bits_offset;
} else {
m_position = size();
Expand All @@ -190,7 +189,7 @@ struct compact_ranked_bitvector {
m_position += 1;
assert(m_position <= size());

if PISA_LIKELY (m_position < size()) {
if (m_position < size()) [[likely]] {
m_value = read_next();
} else {
m_value = m_of.universe;
Expand All @@ -206,7 +205,7 @@ struct compact_ranked_bitvector {
}

uint64_t pos = 0;
if PISA_LIKELY (m_position < size()) {
if (m_position < size()) [[likely]] {
pos = m_bv->predecessor1(m_enumerator.position() - 1);
} else {
pos = m_bv->predecessor1(m_of.end - 1);
Expand All @@ -218,7 +217,7 @@ struct compact_ranked_bitvector {
private:
value_type PISA_NOINLINE slow_move(uint64_t position) {
uint64_t skip = position - m_position;
if PISA_UNLIKELY (position == size()) {
if (position == size()) [[unlikely]] {
m_position = position;
m_value = m_of.universe;
return value();
Expand All @@ -245,7 +244,7 @@ struct compact_ranked_bitvector {
value_type PISA_NOINLINE slow_next_geq(uint64_t lower_bound) {
using broadword::popcount;

if PISA_UNLIKELY (lower_bound >= m_of.universe) {
if (lower_bound >= m_of.universe) [[unlikely]] {
return move(size());
}

Expand Down
31 changes: 0 additions & 31 deletions include/pisa/concepts.hpp

This file was deleted.

4 changes: 0 additions & 4 deletions include/pisa/concepts/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#pragma once

#ifdef PISA_ENABLE_CONCEPTS

#include <concepts>

namespace pisa::concepts {
Expand All @@ -35,5 +33,3 @@ concept SizedContainer = requires(T const container) {
}; // namespace pisa

// clang-format on

#endif
4 changes: 0 additions & 4 deletions include/pisa/concepts/inverted_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

// clang-format off

#ifdef PISA_ENABLE_CONCEPTS

#include <concepts>
#include <cstdint>

Expand Down Expand Up @@ -48,5 +46,3 @@ concept SortedInvertedIndex = InvertedIndex<T, Cursor> && SortedPostingCursor<Cu
}; // namespace pisa

// clang-format on

#endif
Loading

0 comments on commit 8101f44

Please sign in to comment.