Skip to content
Draft
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
38 changes: 34 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,40 @@ DerivePointerAlignment: false
PointerAlignment: Left
LineEnding: LF
InsertNewlineAtEOF: true
RequiresClausePosition: SingleLine
IndentRequiresClause: false
RequiresClausePosition: OwnLine
IndentRequiresClause: true
AttributeMacros: [CPP_member, CPP_auto_member, CPP_fun, CPP_auto_fun]
# TODO<joka921> Update to Clang-format-17 and then we can have much nicer CPP_... macros.
#Macros:
# - CPP_template_2(x)=template<x> requires
Macros:
- CPP_template(x)=template<x> requires
- CPP_template(x, y)=template<x, y> requires
- CPP_template(x, y, z)=template<x, y, z> requires
- CPP_template(x, y, z, a)=template<x, y, z, a> requires
- CPP_template(a, b, c, d, e)=template<a> requires
- CPP_template(a, b, c, d, e, f)=template<a> requires
#
- CPP_template_def(x)=template<x> requires
- CPP_template_def(x, y)=template<x, y> requires
- CPP_template_def(x, y, z)=template<x, y, z> requires
- CPP_template_def(x, y, z, a)=template<x, y, z, a> requires
- CPP_template_def(a, b, c, d, e)=template<a> requires
- CPP_template_def(a, b, c, d, e, f)=template<a> requires
#
- CPP_variadic_template(x)=template<x> requires
- CPP_variadic_template(x, y)=template<x, y> requires
- CPP_variadic_template(x, y, z)=template<x, y, z> requires
- CPP_variadic_template(x, y, z, a)=template<x, y, z, a> requires
- CPP_variadic_template(a, b, c, d, e)=template<a> requires
- CPP_variadic_template(a, b, c, d, e, f)=template<a> requires
#- requires=
#- CPP_and=and
- CPP_template_2(a)=template<a> requires
- CPP_template_2(a, b)=template<x> requires
- CPP_template_2(a, b, c)=template<x> requires
- CPP_template_2(a, b, c)=template<x> requires
- CPP_template_2(a, b, c, d)=template<x> requires
- CPP_template_2(a, b, c, d, e)=template<x> requires
- CPP_template_2(a, b, c, d, e, f)=template<x> requires
#
- CPP_ret(T)=T requires
...
4 changes: 2 additions & 2 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
sed 's/apt-key del/echo/' llvm.sh -iy
sudo ./llvm.sh 16
sudo apt install -y clang-format-16
sudo ./llvm.sh 19
sudo apt install -y clang-format-19

- name: Run the format checker
run: ${{github.workspace}}/misc/format-check.sh
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
repos:
# Uses a packaged version of clang-format from https://github.com/ssciwr/clang-format-wheel
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v16.0.6'
rev: 'v19.1.7'
hooks:
- id: clang-format
'types_or': [ c++, c ]
Expand Down
66 changes: 31 additions & 35 deletions benchmark/JoinAlgorithmBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,18 @@ namespace ad_benchmark {
@brief Return true, iff, the given value is unchanged, when casting to type
`Target`
*/
CPP_template(typename Target, typename Source)(
requires ql::concepts::convertible_to<
Source,
Target>) static constexpr bool isValuePreservingCast(const Source&
source) {
CPP_template(
typename Target,
typename Source) (requires ql::concepts::convertible_to<Source, Target>)
static constexpr bool isValuePreservingCast(const Source& source) {
return static_cast<Source>(static_cast<Target>(source)) == source;
}

/*
@brief Return biggest possible value for the given arithmetic type.
*/
CPP_template(typename Type)(requires ad_utility::Arithmetic<Type>)
QL_CONSTEVAL Type getMaxValue() {
CPP_template(typename Type) (requires ad_utility::Arithmetic<Type>)
QL_CONSTEVAL Type getMaxValue() {
return std::numeric_limits<Type>::max();
}

Expand Down Expand Up @@ -371,8 +370,8 @@ enum struct GeneratedTableColumn : unsigned long {
/*
Convert the given enum value into the underlying type.
*/
CPP_template(typename Enum)(requires std::is_enum_v<Enum>) auto toUnderlying(
const Enum& e) {
CPP_template(typename Enum) (requires std::is_enum_v<Enum>)
auto toUnderlying(const Enum& e) {
return static_cast<std::underlying_type_t<Enum>>(e);
}

Expand Down Expand Up @@ -416,12 +415,9 @@ struct IsGrowthFunction {
@brief Calculates the smallest whole exponent $n$, so that $base^n$ is equal, or
bigger, than the `startingPoint`.
*/
CPP_template(typename T)(
requires ql::concepts::convertible_to<
T,
double>) static double calculateNextWholeExponent(const T& base,
const T&
startingPoint) {
CPP_template(typename T) (requires ql::concepts::convertible_to<T, double>)
static double calculateNextWholeExponent(const T& base,
const T& startingPoint) {
// This is a rather simple calculation: We calculate
// $log_(base)(startingPoint)$ and round up.
AD_CONTRACT_CHECK(isValuePreservingCast<double>(startingPoint));
Expand All @@ -434,11 +430,10 @@ CPP_template(typename T)(
@brief Generate a sorted, inclusive interval of exponents $base^x$, with $x$
always a natural number.
*/
CPP_template(typename T)(
requires ad_utility::Arithmetic<T> CPP_and
ql::concepts::convertible_to<T, double>) static std::
vector<T> generateExponentInterval(T base, T inclusiveLowerBound,
T inclusiveUpperBound) {
CPP_template(typename T) (requires ad_utility::Arithmetic<T> CPP_and
ql::concepts::convertible_to<T, double>)
static std::vector<T> generateExponentInterval(T base, T inclusiveLowerBound,
T inclusiveUpperBound) {
std::vector<T> elements{};

/*
Expand Down Expand Up @@ -467,9 +462,9 @@ CPP_template(typename T)(
@brief Generate a sorted,inclusive interval of all natural numbers inside
`[inclusiveLowerBound, inclusiveUpperBound]`.
*/
CPP_template(typename T)(requires ad_utility::Arithmetic<T>) static std::vector<
T> generateNaturalNumberSequenceInterval(T inclusiveLowerBound,
T inclusiveUpperBound) {
CPP_template(typename T) (requires ad_utility::Arithmetic<T>)
static std::vector<T> generateNaturalNumberSequenceInterval(
T inclusiveLowerBound, T inclusiveUpperBound) {
if constexpr (ql::concepts::floating_point<T>) {
inclusiveLowerBound = std::ceil(inclusiveLowerBound);
inclusiveUpperBound = std::floor(inclusiveUpperBound);
Expand All @@ -486,8 +481,9 @@ CPP_template(typename T)(requires ad_utility::Arithmetic<T>) static std::vector<

// Merge multiple sorted vectors into one sorted vector, where every element is
// unique.
CPP_template(typename T)(requires ad_utility::Arithmetic<T>) static std::vector<
T> mergeSortedVectors(const std::vector<std::vector<T>>& intervals) {
CPP_template(typename T) (requires ad_utility::Arithmetic<T>)
static std::vector<T> mergeSortedVectors(
const std::vector<std::vector<T>>& intervals) {
std::vector<T> mergedVector{};

// Merge.
Expand Down Expand Up @@ -1652,10 +1648,10 @@ argument of the function and $x$ being $log_base(startingPoint)$ rounded up.
CPP_template(typename ReturnType)(requires
ql::concepts::convertible_to<ReturnType, double>
CPP_and ql::concepts::convertible_to<double, ReturnType>)
// clang-format on
auto createDefaultGrowthLambda(const ReturnType& base,
const ReturnType& startingPoint,
std::vector<ReturnType> prefixValues = {}) {
// clang-format on
auto createDefaultGrowthLambda(const ReturnType& base,
const ReturnType& startingPoint,
std::vector<ReturnType> prefixValues = {}) {
return [base, prefixValues = std::move(prefixValues),
startingExponent{calculateNextWholeExponent(base, startingPoint)}](
const size_t& rowIdx) {
Expand Down Expand Up @@ -2202,12 +2198,12 @@ class BmSmallerTableGrowsBiggerTableRemainsSameSize final
given benchmarking table row?
@param biggerTableNumRows Number of rows in the bigger table.
*/
CPP_template(typename Function)(requires(growthFunction<Function, size_t>))
ResultTable& makeSmallerTableGrowsAndBiggerTableSameSizeBenchmarkTable(
BenchmarkResults* results, const std::string& tableDescriptor,
const bool smallerTableSorted, const bool biggerTableSorted,
const Function& smallerTableNumRows,
const size_t biggerTableNumRows) const {
CPP_template(typename Function) (requires(growthFunction<Function, size_t>))
ResultTable& makeSmallerTableGrowsAndBiggerTableSameSizeBenchmarkTable(
BenchmarkResults* results, const std::string& tableDescriptor,
const bool smallerTableSorted, const bool biggerTableSorted,
const Function& smallerTableNumRows,
const size_t biggerTableNumRows) const {
// For creating a new random seed for every new row.
RandomSeedGenerator seedGenerator{getConfigVariables().randomSeed()};

Expand Down
6 changes: 3 additions & 3 deletions benchmark/infrastructure/Benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class BenchmarkResults {
* Most of the time a lambda, that calls the actual function to benchmark
* with the needed parameters.
*/
CPP_template(typename Function)(requires(ql::concepts::invocable<Function>))
ResultEntry& addMeasurement(const std::string& descriptor,
const Function& functionToMeasure) {
CPP_template(typename Function) (requires(ql::concepts::invocable<Function>))
ResultEntry& addMeasurement(const std::string& descriptor,
const Function& functionToMeasure) {
return addEntryToContainerVector(singleMeasurements_, descriptor,
functionToMeasure);
}
Expand Down
38 changes: 17 additions & 21 deletions benchmark/infrastructure/BenchmarkMeasurementContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ namespace ad_benchmark {
@param functionToMeasure Must be a function, or callable.
@param measurementSubjectName A description/name of what is being measured.
*/
CPP_template(typename Function)(requires(
ql::concepts::invocable<
Function>)) static float measureTimeOfFunction(const Function&
functionToMeasure,
std::string_view
measurementSubjectIdentifier) {
CPP_template(typename Function) (requires(ql::concepts::invocable<Function>))
static float measureTimeOfFunction(
const Function& functionToMeasure,
std::string_view measurementSubjectIdentifier) {
AD_LOG_INFO << "Running measurement \"" << measurementSubjectIdentifier
<< "\" ..." << std::endl;

Expand Down Expand Up @@ -95,8 +93,8 @@ class ResultEntry : public BenchmarkMetadataGetter {
@param functionToMeasure The function, who's execution time will be
measured and saved.
*/
CPP_template(typename F)(requires(ql::concepts::invocable<F>))
ResultEntry(const std::string& descriptor, const F& functionToMeasure)
CPP_template(typename F) (requires(ql::concepts::invocable<F>))
ResultEntry(const std::string& descriptor, const F& functionToMeasure)
: descriptor_{descriptor},
measuredTime_{measureTimeOfFunction(functionToMeasure, descriptor)} {}

Expand All @@ -111,9 +109,9 @@ class ResultEntry : public BenchmarkMetadataGetter {
@param functionToMeasure The function, who's execution time will be
measured and saved.
*/
CPP_template(typename F)(requires(ql::concepts::invocable<F>))
ResultEntry(const std::string& descriptor,
std::string_view descriptorForLog, const F& functionToMeasure)
CPP_template(typename F) (requires(ql::concepts::invocable<F>))
ResultEntry(const std::string& descriptor, std::string_view descriptorForLog,
const F& functionToMeasure)
: descriptor_{descriptor},
measuredTime_{
measureTimeOfFunction(functionToMeasure, descriptorForLog)} {}
Expand Down Expand Up @@ -199,11 +197,9 @@ class ResultTable : public BenchmarkMetadataGetter {
Starts with `(0,0)`.
@param functionToMeasure The function, which execution time will be measured.
*/
CPP_template(typename Function)(requires(
ql::concepts::invocable<
Function>)) void addMeasurement(const size_t& row,
const size_t& column,
const Function& functionToMeasure) {
CPP_template(typename Function) (requires(ql::concepts::invocable<Function>))
void addMeasurement(const size_t& row, const size_t& column,
const Function& functionToMeasure) {
AD_CONTRACT_CHECK(row < numRows() && column < numColumns());
entries_.at(row).at(column) = measureTimeOfFunction(
functionToMeasure,
Expand Down Expand Up @@ -231,8 +227,8 @@ class ResultTable : public BenchmarkMetadataGetter {

@param row, column Which table entry to read. Starts with `(0,0)`.
*/
CPP_template(typename T)(requires ad_utility::SameAsAnyTypeIn<T, EntryType>) T
getEntry(const size_t row, const size_t column) const {
CPP_template(typename T) (requires ad_utility::SameAsAnyTypeIn<T, EntryType>)
T getEntry(const size_t row, const size_t column) const {
AD_CONTRACT_CHECK(row < numRows() && column < numColumns());
static_assert(!ad_utility::isSimilar<T, std::monostate>);

Expand Down Expand Up @@ -331,9 +327,9 @@ class ResultGroup : public BenchmarkMetadataGetter {
@param functionToMeasure The function, who's execution time will be
measured and saved.
*/
CPP_template(typename Function)(requires(ql::concepts::invocable<Function>))
ResultEntry& addMeasurement(const std::string& descriptor,
const Function& functionToMeasure) {
CPP_template(typename Function) (requires(ql::concepts::invocable<Function>))
ResultEntry& addMeasurement(const std::string& descriptor,
const Function& functionToMeasure) {
resultEntries_.push_back(ad_utility::make_copyable_unique<ResultEntry>(
descriptor, absl::StrCat(descriptor, " of group ", descriptor_),
functionToMeasure));
Expand Down
13 changes: 7 additions & 6 deletions benchmark/infrastructure/BenchmarkToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ provided translation function for the vector entries.
@tparam TranslationFunction Has to be a function, that takes `VectorType`
and returns a `nlohmann:json` object.
*/
CPP_template(typename VectorType, typename TranslationFunction)(
requires ad_utility::InvocableWithExactReturnType<
TranslationFunction, nlohmann::ordered_json,
VectorType>) static nlohmann::json
transformIntoJsonArray(const std::vector<VectorType>& vec,
TranslationFunction translationFunction) {
CPP_template(
typename VectorType,
typename TranslationFunction) (requires ad_utility::InvocableWithExactReturnType<
TranslationFunction, nlohmann::ordered_json, VectorType>)
static nlohmann::json transformIntoJsonArray(
const std::vector<VectorType>& vec,
TranslationFunction translationFunction) {
/*
Without explicit instantiation, `nlohmann::nlohmann::ordered_json` is not
guaranteed, to always interpret a `push_back` correctly. For instance,
Expand Down
32 changes: 16 additions & 16 deletions benchmark/util/ResultTableColumnOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ Column number together with the type of value, that can be found inside the
column. Note, that **all** entries in the column must have the same type,
because of `ResultTable::getEntry`.
*/
CPP_template(typename Type)(
requires ad_utility::SameAsAnyTypeIn<
Type, ResultTable::EntryType>) struct ColumnNumWithType {
CPP_template(
typename Type) (requires ad_utility::SameAsAnyTypeIn<Type, ResultTable::EntryType>)
struct ColumnNumWithType {
using ColumnType = Type;
const size_t columnNum_;
};

// clang-format off
CPP_variadic_template(typename ColumnReturnType, typename... ColumnInputTypes)
(requires(sizeof...(ColumnInputTypes) > 0))
// clang-format on
void generateColumnWithColumnInput(
ResultTable* const table,
QL_CONCEPT_OR_NOTHING(
ad_utility::InvocableWithSimilarReturnType<
ColumnReturnType, const ColumnInputTypes&...>) auto&& generator,
const ColumnNumWithType<ColumnReturnType>& columnToPutResultIn,
const ColumnNumWithType<ColumnInputTypes>&... inputColumns) {
// clang-format on
void generateColumnWithColumnInput(
ResultTable* const table,
QL_CONCEPT_OR_NOTHING(
ad_utility::InvocableWithSimilarReturnType<
ColumnReturnType, const ColumnInputTypes&...>) auto&& generator,
const ColumnNumWithType<ColumnReturnType>& columnToPutResultIn,
const ColumnNumWithType<ColumnInputTypes>&... inputColumns) {
// Using a column more than once is the sign of an error.
std::array<size_t, sizeof...(ColumnInputTypes)> allColumnNums{
{inputColumns.columnNum_...}};
Expand All @@ -63,11 +63,11 @@ CPP_variadic_template(typename ColumnReturnType,
typename... ColumnInputTypes)
(requires((ql::concepts::same_as<ColumnInputTypes, ColumnNumWithType<ColumnReturnType>> && ...)
&& sizeof...(ColumnInputTypes) > 1))
// clang-format on
void sumUpColumns(
ResultTable* const table,
const ColumnNumWithType<ColumnReturnType>& columnToPutResultIn,
const ColumnInputTypes&... columnsToSumUp) {
// clang-format on
void sumUpColumns(
ResultTable* const table,
const ColumnNumWithType<ColumnReturnType>& columnToPutResultIn,
const ColumnInputTypes&... columnsToSumUp) {
// We can simply pass this to `generateColumnWithColumnInput`.
generateColumnWithColumnInput(
table,
Expand Down
4 changes: 2 additions & 2 deletions misc/format-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ done <sourcelist

ERROR=0
for source in "${SOURCE_FILES[@]}" ;do
clang-format-16 -output-replacements-xml $source | grep "<replacement " &> /dev/null
clang-format-19 -output-replacements-xml $source | grep "<replacement " &> /dev/null
HAS_WRONG_FILES=$?
if [ $HAS_WRONG_FILES -ne 1 ] ; then
# Print an error and exit
printf "\x1b[31mError: "
printf "The source file \x1b[m$source\x1b[31m does not match the code style\n"
printf "Use clang-format with the .clang-format provided in the QLever\n"
printf "repository's root to ensure all code files are formatted "
printf "properly. We currently use clang-format 16\n"
printf "properly. We currently use clang-format 17\n"
printf "(See '.github/workflows/format-check.yml' for instructions on how to install it.\n"
printf "\x1b[m"
ERROR=1
Expand Down
Loading