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
2 changes: 1 addition & 1 deletion .github/workflows/ci_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
--filter ${GITHUB_WORKSPACE}/src \
--exclude ${GITHUB_WORKSPACE}/include/hibf/contrib \
--exclude ${GITHUB_WORKSPACE}/test/include/hibf/test/iterator_test_template.hpp \
--exclude-lines-by-pattern '^\s*}|^\s*};|^\s*HIBF_UNREACHABLE;' \
--exclude-lines-by-pattern '^\s*}|^\s*};|.*seqan::hibf::unreachable.*' \
--exclude-noncode-lines \
--exclude-throw-branches \
--exclude-unreachable-branches \
Expand Down
2 changes: 1 addition & 1 deletion doc/cookbook/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Search for keywords with `Strg + F`.
\include test/snippet/ibf/interleaved_bloom_filter_try_increase_bin_number_to.cpp
\include test/snippet/ibf/membership_agent_bulk_contains.cpp
\include test/snippet/ibf/membership_agent_construction.cpp
\include test/snippet/platform_unreachable.cpp
\include test/snippet/readme.cpp
\include test/snippet/snippet_main.cpp
\include test/snippet/test/tmp_directory.cpp
\include test/snippet/unreachable.cpp
41 changes: 41 additions & 0 deletions include/hibf/misc/unreachable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2006-2025, Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause

/*!\file
* \brief Provides seqan::hibf::unreachable.
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de>
*/

#pragma once

// IWYU pragma: begin_exports

#include <cassert> // for assert
#include <utility> // for std::unreachable

// IWYU pragma: end_exports

#include <hibf/platform.hpp>

namespace seqan::hibf
{

/*!\fn inline void seqan::hibf::unreachable()
* \brief Marks unreachable code paths.
* \details
* In debug mode, it triggers an assertion failure.
* In release mode, it calls `std::unreachable`.
* ### Example
* \include test/snippet/unreachable.cpp
*/
#ifndef NDEBUG
inline void unreachable() // GCOVR_EXCL_LINE
{
assert(false); // GCOVR_EXCL_LINE
}
#else
using std::unreachable;
#endif

} // namespace seqan::hibf
112 changes: 23 additions & 89 deletions include/hibf/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

// IWYU pragma: end_exports

// macro cruft
//!\cond
#define HIBF_STR_HELPER(x) #x
#define HIBF_STR(x) HIBF_STR_HELPER(x)
//!\endcond

// ============================================================================
// Documentation
// ============================================================================
Expand Down Expand Up @@ -51,11 +45,6 @@
# define HIBF_COMPILER_IS_GCC 0
#endif

#if HIBF_DOXYGEN_ONLY(1) 0
//!\brief This disables the warning you would get if your compiler is not known to work.
# define HIBF_DISABLE_COMPILER_CHECK
#endif // HIBF_DOXYGEN_ONLY(1)0

/*!\def HIBF_HAS_AVX512
* \brief Whether AVX512F and AVX512BW are available.
* \private
Expand All @@ -69,23 +58,31 @@
#endif

// ============================================================================
// Compiler support GCC
// Compiler support
// ============================================================================

#if HIBF_COMPILER_IS_GCC
# if (__GNUC__ < 12)
# error "At least GCC 12 is needed."
# endif
#else
# ifdef __INTEL_LLVM_COMPILER
# if __INTEL_LLVM_COMPILER < 20240000
# error "At least Intel OneAPI 2024 is needed."
# endif
# else
# if (_LIBCPP_VERSION < 170000)
# error "At least Clang 17 is needed."
# endif
# endif
#if HIBF_COMPILER_IS_GCC && (__GNUC__ < 12)
# error "At least GCC 12 is needed."
#endif

#if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER < 20240000)
# error "At least Intel OneAPI 2024 is needed."
#endif

#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ < 17)
# error "At least Clang 17 is needed."
#endif

// ============================================================================
// Standard library support
// ============================================================================

#if defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION < 170000)
# error "At least libc++ 17 is required."
#endif

#if defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 12)
# error "At least libstdc++ 12 is needed."
#endif

// ============================================================================
Expand All @@ -101,24 +98,6 @@
# error "This is not a C++ compiler."
#endif

/*!\brief Macro to mark unreachable code paths.
* \details
* In debug mode, it triggers an assertion failure.
* In release mode, it calls `std::unreachable`.
* ### Example
* \include test/snippet/platform_unreachable.cpp
*/
#ifndef HIBF_UNREACHABLE
// The do { ... } while (0) is a common pattern to enforce the semicolon after the macro.
// clang-format off
# ifndef NDEBUG
# define HIBF_UNREACHABLE do { assert(false); } while (0) // GCOVR_EXCL_LINE
# else
# define HIBF_UNREACHABLE do { std::unreachable(); } while (0)
# endif
#endif
// clang-format on

// ============================================================================
// Dependencies
// ============================================================================
Expand All @@ -130,36 +109,6 @@
# error "HIBF include directory not set correctly. Forgot to add -I ${INSTALLDIR}/include to your CXXFLAGS?"
#endif

// ============================================================================
// Deprecation Messages
// ============================================================================

//!\brief _Pragma requires a string-literal and # makes it a string
#ifndef HIBF_PRAGMA
# define HIBF_PRAGMA(non_string_literal) _Pragma(#non_string_literal)
#endif

//!\brief Deprecation message for deprecated header.
#ifndef HIBF_DEPRECATED_HEADER
# ifndef HIBF_DISABLE_DEPRECATED_WARNINGS
# define HIBF_DEPRECATED_HEADER(message) HIBF_PRAGMA(GCC warning message)
# else
# define HIBF_DEPRECATED_HEADER(message) /**/
# endif
#endif

//!\brief Deprecation message for release.
#ifndef HIBF_REMOVE_DEPRECATED_100
# ifndef HIBF_DEPRECATED_100
# ifndef HIBF_DISABLE_DEPRECATED_WARNINGS
# define HIBF_DEPRECATED_100 \
[[deprecated("This will be removed in version 1.0.0; please see the documentation.")]]
# else
# define HIBF_DEPRECATED_100 /**/
# endif
# endif
#endif

// ============================================================================
// Workarounds
// ============================================================================
Expand All @@ -182,21 +131,6 @@
# endif
#endif

//!\brief Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
#if defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L
# define HIBF_WORKAROUND_LITERAL constexpr
#else
# define HIBF_WORKAROUND_LITERAL inline
#endif

#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
# pragma message "We do not actively support compiler that have -D_GLIBCXX_USE_CXX11_ABI=0 set."
#endif // _GLIBCXX_USE_CXX11_ABI == 0

// ============================================================================
// Backmatter
// ============================================================================

// macro cruft undefine
#undef HIBF_STR
#undef HIBF_STR_HELPER
5 changes: 3 additions & 2 deletions src/interleaved_bloom_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <hibf/interleaved_bloom_filter.hpp> // for interleaved_bloom_filter, bin_count, bin_index, bin_size, hash_...
#include <hibf/misc/bit_vector.hpp> // for bit_vector
#include <hibf/misc/divide_and_ceil.hpp> // for divide_and_ceil
#include <hibf/misc/unreachable.hpp> // for unreachable
#include <hibf/platform.hpp> // for HIBF_COMPILER_IS_GCC
#include <hibf/sketch/hyperloglog.hpp> // for hyperloglog

Expand Down Expand Up @@ -212,9 +213,9 @@ interleaved_bloom_filter::membership_agent_type::bulk_contains(size_t const valu

// Removes case for bin_words_ == 0u. The same statment inside the switch-case wouldn't have that effect.
if (bin_words_ == 0u)
HIBF_UNREACHABLE;
seqan::hibf::unreachable();
if (hash_funs_ == 0u)
HIBF_UNREACHABLE;
seqan::hibf::unreachable();

for (size_t i = 0; i < hash_funs_; ++i)
bloom_filter_indices[i] = ibf_ptr->hash_and_fit(value, ibf_ptr->hash_seeds[i]) / 64u;
Expand Down
2 changes: 1 addition & 1 deletion test/documentation/hibf_doxygen_cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ CITE_BIB_FILES =
#---------------------------------------------------------------------------
# Configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = NO
WARN_IF_DOC_ERROR = YES
Expand Down
59 changes: 25 additions & 34 deletions test/header/generate_header_source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.20...3.31)

option (HEADER_FILE_ABSOLUTE "")
option (HEADER_FILE_INCLUDE "")
option (HEADER_TARGET_SOURCE "")
Expand All @@ -13,53 +11,46 @@ option (HEADER_SUB_TEST "")

file (WRITE "${HEADER_TARGET_SOURCE}" "") # write empty file

# cmake-format: off

if (HEADER_SUB_TEST STREQUAL "no-self-include")
# this test ensures that a header will not be included by itself later
file (READ "${HEADER_FILE_ABSOLUTE}" header_content)

string (REPLACE "#pragma once" "" header_content "${header_content}")

file (APPEND "${HEADER_TARGET_SOURCE}" "${header_content}\n")
file (APPEND "${HEADER_TARGET_SOURCE}"
"// hibf-header-test-no-self-include-start\n"
"${header_content}\n"
"// hibf-header-test-no-self-include-end\n\n")
else ()
# this test ensures that a header guard is in place
file (APPEND "${HEADER_TARGET_SOURCE}" #
"#include <${HEADER_FILE_INCLUDE}>\n" #
"#include <${HEADER_FILE_INCLUDE}>\n")
file (APPEND "${HEADER_TARGET_SOURCE}"
"// hibf-header-test-header-guard-start\n"
"#include <${HEADER_FILE_INCLUDE}>\n"
"#include <${HEADER_FILE_INCLUDE}>\n"
"// hibf-header-test-header-guard-end\n\n")
endif ()

# these includes are required by some headers (note that they follow)
file (APPEND "${HEADER_TARGET_SOURCE}" #
"#include <gtest/gtest.h>\n" #
"#include <benchmark/benchmark.h>\n" #
"TEST(${HEADER_TEST_NAME_SAFE}) {}\n")
file (APPEND "${HEADER_TARGET_SOURCE}"
"// hibf-header-test-dependencies-start\n"
"#include <gtest/gtest.h>\n"
"#include <benchmark/benchmark.h>\n"
"TEST(${HEADER_TEST_NAME_SAFE}) {}\n"
"// hibf-header-test-dependencies-end\n\n")

# test that hibf headers include platform.hpp
if ("${HEADER_COMPONENT}" MATCHES "hibf")

# exclude hibf/std/* and hibf/contrib/* from platform test
if (NOT HEADER_FILE_INCLUDE MATCHES "hibf/(std|contrib)/")
file (APPEND "${HEADER_TARGET_SOURCE}" #
"#ifndef HIBF_DOXYGEN_ONLY\n" #
"#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include <hibf/platform.hpp>\"\n" #
"#endif\n")
file (APPEND "${HEADER_TARGET_SOURCE}"
"// hibf-header-test-platform-start\n"
"#ifndef HIBF_DOXYGEN_ONLY\n"
"#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include <hibf/platform.hpp>\"\n"
"#endif\n"
"// hibf-header-test-platform-end\n\n")
endif ()

# hibf/std/* must not include platform.hpp (and therefore any other hibf header)
# See https://github.com/seqan/product_backlog/issues/135
if (HEADER_FILE_INCLUDE MATCHES "hibf/std/")
file (APPEND "${HEADER_TARGET_SOURCE}" #
"#ifdef HIBF_DOXYGEN_ONLY" #
"#error \"The standard header '${HEADER_FILE_INCLUDE}' file MUST NOT include any other " #
"hibf header (except for hibf/contrib)\"\n" #
"#endif\n")
endif ()

# test whether hibf has the visibility bug on lower gcc versions
# https://github.com/seqan/hibf/issues/1317
file (APPEND "${HEADER_TARGET_SOURCE}" #
"#include <hibf/platform.hpp>\n\n" #
"class A{ int i{5}; };\n\n" #
"template <typename t>\n" #
"concept private_bug = requires(t a){a.i;};\n\n" #
"static_assert(!private_bug<A>, \"See https://github.com/seqan/hibf/issues/1317\");\n")
endif ()

# cmake-format: on
2 changes: 1 addition & 1 deletion test/scripts/add_snippets_to_cookbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ head -n ${LINE_NUMBER_OF_KEY_LINE} ${COOKBOOK} > ${TMP_FILE}
# Iterate through all files in test/snippet/*
# Order of results from find is not fixed, so we sort the results alphabetically.
# Snippets of doc would be: find ./doc/ -type f -name "*.cpp" -and -not -path "./doc/cookbook/*"
for snippet in $(find test/snippet/ -type f -name "*.cpp" | sort); do
for snippet in $(find test/snippet -type f -name "*.cpp" | sort); do
echo "\include ${snippet}" >> ${TMP_FILE}
done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0

#include <utility> // for unreachable

#include <hibf/platform.hpp> // for HIBF_UNREACHABLE
#include <hibf/misc/unreachable.hpp> // for unreachable

int foo(int const i)
{
Expand All @@ -17,6 +15,6 @@ int foo(int const i)
case 1:
return 3;
default:
HIBF_UNREACHABLE; // HIBF_UNREACHABLE must be followed by a semicolon.
seqan::hibf::unreachable();
}
}
Loading