Skip to content

Commit

Permalink
Merge branch 'explicitly-named-query' into libqlever
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/engine/CMakeLists.txt
  • Loading branch information
joka921 committed Feb 19, 2025
2 parents e845e79 + 50b7dc4 commit e5a80f5
Show file tree
Hide file tree
Showing 215 changed files with 7,044 additions and 5,077 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ LineEnding: LF
InsertNewlineAtEOF: true
RequiresClausePosition: SingleLine
IndentRequiresClause: false
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
...
71 changes: 36 additions & 35 deletions benchmark/JoinAlgorithmBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ static constexpr bool isValuePreservingCast(const Source& source) {
/*
@brief Return biggest possible value for the given arithmetic type.
*/
template <ad_utility::Arithmetic Type>
consteval Type getMaxValue() {
CPP_template(typename Type)(
requires ad_utility::Arithmetic<Type>) consteval Type getMaxValue() {
return std::numeric_limits<Type>::max();
}

Expand Down Expand Up @@ -408,10 +408,10 @@ static double calculateNextWholeExponent(const T& base,
@brief Generate a sorted, inclusive interval of exponents $base^x$, with $x$
always a natural number.
*/
template <ad_utility::Arithmetic T>
requires std::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
std::convertible_to<T, double>) static std::
vector<T> generateExponentInterval(T base, T inclusiveLowerBound,
T inclusiveUpperBound) {
std::vector<T> elements{};

/*
Expand Down Expand Up @@ -440,9 +440,9 @@ static std::vector<T> generateExponentInterval(T base, T inclusiveLowerBound,
@brief Generate a sorted,inclusive interval of all natural numbers inside
`[inclusiveLowerBound, inclusiveUpperBound]`.
*/
template <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 (std::floating_point<T>) {
inclusiveLowerBound = std::ceil(inclusiveLowerBound);
inclusiveUpperBound = std::floor(inclusiveUpperBound);
Expand All @@ -459,9 +459,8 @@ static std::vector<T> generateNaturalNumberSequenceInterval(

// Merge multiple sorted vectors into one sorted vector, where every element is
// unique.
template <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 @@ -770,27 +769,29 @@ class GeneralInterfaceImplementation : public BenchmarkInterface {
};
};
auto generateBiggerEqualLambdaDesc =
[](const ad_utility::isInstantiation<
ad_utility::ConstConfigOptionProxy> auto& option,
const auto& minimumValue, bool canBeEqual) {
return absl::StrCat("'", option.getConfigOption().getIdentifier(),
"' must be bigger than",
canBeEqual ? ", or equal to," : "", " ",
minimumValue, ".");
};
[]<typename OptionType,
typename = std::enable_if_t<ad_utility::isInstantiation<
OptionType, ad_utility::ConstConfigOptionProxy>>>(
const OptionType& option, const auto& minimumValue,
bool canBeEqual) {
return absl::StrCat("'", option.getConfigOption().getIdentifier(),
"' must be bigger than",
canBeEqual ? ", or equal to," : "", " ", minimumValue,
".");
};

// Object with a `operator()` for the `<=` operator.
auto lessEqualLambda = std::less_equal<size_t>{};
auto generateLessEqualLambdaDesc =
[](const ad_utility::isInstantiation<
ad_utility::ConstConfigOptionProxy> auto& lhs,
const ad_utility::isInstantiation<
ad_utility::ConstConfigOptionProxy> auto& rhs) {
return absl::StrCat("'", lhs.getConfigOption().getIdentifier(),
"' must be smaller than, or equal to, "
"'",
rhs.getConfigOption().getIdentifier(), "'.");
};
[]<typename OptionType,
typename = std::enable_if_t<ad_utility::isInstantiation<
OptionType, ad_utility::ConstConfigOptionProxy>>>(
const OptionType& lhs, const OptionType& rhs) {
return absl::StrCat("'", lhs.getConfigOption().getIdentifier(),
"' must be smaller than, or equal to, "
"'",
rhs.getConfigOption().getIdentifier(), "'.");
};

// Adding the validators.

Expand Down Expand Up @@ -1163,9 +1164,9 @@ class GeneralInterfaceImplementation : public BenchmarkInterface {
chance to be picked.) This adjusts the number of elements in the sample size
to `Amount of rows * ratio`, which affects the possibility of duplicates.
*/
template <ad_utility::InvocableWithExactReturnType<
bool, float, size_t, size_t, size_t, size_t, float, float>
StopFunction,
template <QL_CONCEPT_OR_TYPENAME(ad_utility::InvocableWithExactReturnType<
bool, float, size_t, size_t, size_t, size_t,
float, float>) StopFunction,
isTypeOrGrowthFunction<float> T1, isTypeOrGrowthFunction<float> T2,
isTypeOrGrowthFunction<size_t> T3,
isTypeOrGrowthFunction<size_t> T4,
Expand Down Expand Up @@ -1330,9 +1331,9 @@ class GeneralInterfaceImplementation : public BenchmarkInterface {
ResultTable* table,
const QL_CONCEPT_OR_NOTHING(
ad_utility::SameAsAny<float, size_t>) auto changingParameterValue,
ad_utility::InvocableWithExactReturnType<bool, float, size_t, size_t,
size_t, size_t, float,
float> auto stopFunction,
QL_CONCEPT_OR_NOTHING(ad_utility::InvocableWithExactReturnType<
bool, float, size_t, size_t, size_t, size_t, float,
float>) auto stopFunction,
const float overlap, const std::optional<size_t>& resultTableNumRows,
ad_utility::RandomSeed randomSeed, const bool smallerTableSorted,
const bool biggerTableSorted, const float& ratioRows,
Expand Down
4 changes: 2 additions & 2 deletions benchmark/infrastructure/BenchmarkMeasurementContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ class ResultTable : public BenchmarkMetadataGetter {
@param row, column Which table entry to read. Starts with `(0,0)`.
*/
template <ad_utility::SameAsAnyTypeIn<EntryType> T>
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
12 changes: 6 additions & 6 deletions benchmark/infrastructure/BenchmarkToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ provided translation function for the vector entries.
@tparam TranslationFunction Has to be a function, that takes `VectorType`
and returns a `nlohmann:json` object.
*/
template <typename VectorType, ad_utility::InvocableWithExactReturnType<
nlohmann::ordered_json, VectorType>
TranslationFunction>
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
10 changes: 6 additions & 4 deletions benchmark/util/ResultTableColumnOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ 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`.
*/
template <ad_utility::SameAsAnyTypeIn<ResultTable::EntryType> Type>
struct ColumnNumWithType {
CPP_template(typename Type)(
requires ad_utility::SameAsAnyTypeIn<
Type, ResultTable::EntryType>) struct ColumnNumWithType {
using ColumnType = Type;
const size_t columnNum_;
};

template <typename ColumnReturnType, typename... ColumnInputTypes>
requires(sizeof...(ColumnInputTypes) > 0) void generateColumnWithColumnInput(
ResultTable* const table,
ad_utility::InvocableWithSimilarReturnType<
ColumnReturnType, const ColumnInputTypes&...> auto&& generator,
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.
Expand Down
52 changes: 48 additions & 4 deletions src/backports/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#pragma once

#include <concepts/concepts.hpp>

#include "backports/cppTemplate2.h"
#ifndef QLEVER_CPP_17
#include <concepts>
#endif
Expand All @@ -19,6 +21,19 @@
// `QL_CONCEPT_OR_TYPENAME(arg)`: expands to `arg` in C++20 mode, and to
// `typename` in C++17 mode. Example usage:
//
// `CPP_lambda(capture)(arg)(requires ...)`: Expands lambda to use
// `requires` in C++20 mode and `std::enable_if_t` in C++17 mode.
//
// `CPP_lambda_mut(capture)(arg)(requires ...)`: Same as
// `CPP_lambda` but for mutable lambdas.
//
// `CPP_template_lambda(capture)(typenames...)(arg)(requires ...)`: Expands
// lambda with (C++20) explicit template parameters to use
// `requires` in C++20 mode and `std::enable_if_t` in C++17 mode.
//
// `CPP_template_lambda_mut(capture)(typenames...)(arg)(requires ...)`: Same as
// `CPP_template_lambda` but for mutable lambdas.
//
// Example usages:
//
// `QL_CONCEPT_OR_NOTHING(std::view) auto x = someFunction();`
Expand All @@ -29,27 +44,56 @@
//
// `template <QL_CONCEPT_OR_TYPENAME(ql::same_as<int>) T> void f(){...}`
//
// `auto myLambda = CPP_lambda(someCapture)(someArg)(requires
// ranges::same_as<decltype(someArg), int>) {...}`
//
// `auto myLambda2 = CPP_lambda(someCapture)(typename F)(F arg)(requires
// ranges::same_as<F, int>) {...}`
//
// NOTE: The macros are variadic to allow for commas in the argument, like in
// the second example above.

// Additionally define the macros `CPP_template_2` and `CPP_and_2` that can
// be used to constrain member functions of classes where the outer class
// has already been constrained with `CPP_template`. For a detailed example, see
// the `test/backports/ConceptsTest.cpp` file.

#ifdef QLEVER_CPP_17
#define QL_CONCEPT_OR_NOTHING(...)
#define QL_CONCEPT_OR_TYPENAME(...) typename
#define CPP_template_2 CPP_template_2_SFINAE
#define CPP_and_2 CPP_and_2_sfinae
#define CPP_and_def CPP_and_sfinae_def
#define CPP_and_2_def CPP_and_2_def_sfinae
#define CPP_variadic_template CPP_template_NO_DEFAULT_SFINAE
#define CPP_member_def CPP_member_def_sfinae
#define CPP_lambda CPP_lambda_sfinae
#define CPP_template_lambda CPP_template_lambda_sfinae
#define CPP_lambda_mut CPP_lambda_mut_sfinae
#define CPP_template_lambda_mut CPP_template_lambda_mut_sfinae
#else
#define QL_CONCEPT_OR_NOTHING(...) __VA_ARGS__
#define QL_CONCEPT_OR_TYPENAME(...) __VA_ARGS__
#define CPP_template_2 CPP_template
#define CPP_and_2 CPP_and
#define CPP_and_def CPP_and
#define CPP_and_2_def CPP_and
#define CPP_variadic_template CPP_template
#define CPP_member_def CPP_member
#define CPP_lambda CPP_LAMBDA_20
#define CPP_template_lambda CPP_TEMPLATE_LAMBDA_20
#define CPP_lambda_mut CPP_lambda_mut_20
#define CPP_template_lambda_mut CPP_TEMPLATE_LAMBDA_MUT_20
#endif

// The namespace `ql::concepts` includes concepts that are contained in the
// C++20 standard as well as in `range-v3`.
namespace ql {
namespace concepts {
namespace ql::concepts {

#ifdef QLEVER_CPP_17
using namespace ::concepts;
#else
using namespace std;
#endif

} // namespace concepts
} // namespace ql
} // namespace ql::concepts
Loading

0 comments on commit e5a80f5

Please sign in to comment.