Skip to content

Commit

Permalink
Update style of clang-format (#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang authored Aug 26, 2021
1 parent c495d93 commit 1b50582
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .ci/build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ catchError {
stage("Build & Upload") {
timeout(time: 70, unit: 'MINUTES') {
container("builder") {
sh "NPROC=5 BUILD_BRANCH=${ghprbTargetBranch} release-centos7/build/build-tiflash-ci.sh"
sh "NPROC=5 BUILD_BRANCH=${ghprbTargetBranch} ENABLE_FORMAT_CHECK=true release-centos7/build/build-tiflash-ci.sh"
sh "PULL_ID=${ghprbPullId} COMMIT_HASH=${ghprbActualCommit} release-centos7/build/upload-ci-build.sh"
}
}
Expand Down
80 changes: 41 additions & 39 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
---
BasedOnStyle: Google
Language: Cpp
AlignAfterOpenBracket: false
AlignAfterOpenBracket: Align
AlignEscapedNewlines: Left
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: Inline
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping: {
AfterCaseLabel: 'true'
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'true'
BeforeElse : 'true'
IndentBraces : 'false'
SplitEmptyFunction: 'false'
}

BreakConstructorInitializersBeforeComma: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum : true
AfterFunction : true
AfterNamespace : true
AfterStruct : true
AfterUnion : true
BeforeCatch : true
BeforeElse : true
IndentBraces : false
SplitEmptyFunction: false
BreakConstructorInitializers: BeforeComma
BreakInheritanceList : BeforeComma
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Cpp11BracedListStyle: true
ColumnLimit: 140
ConstructorInitializerAllOnOneLineOrOnePerLine: true
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: true
UseTab: Never
TabWidth: 4
FixNamespaceComments: true
IndentCaseLabels: false
IndentWidth: 4
Standard: Cpp11
PointerAlignment: Middle
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
KeepEmptyLinesAtTheStartOfBlocks: true
#AllowShortFunctionsOnASingleLine: Inline
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: true
IndentCaseLabels: true
#SpaceAfterTemplateKeyword: true
#SortIncludes: true
FixNamespaceComments: true

#PPIndentWidth: 2 # clang-format version 12.0.0 doesn't support yet
PointerAlignment: Middle
ReflowComments: false
AlignEscapedNewlinesLeft: true
SortIncludes: true
SpaceAfterTemplateKeyword: true
Standard: Cpp11
TabWidth: 4
UseTab: Never

# Not changed:
AccessModifierOffset: -4
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
CommentPragmas: '^ IWYU pragma:'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Prerequisites

- CMake 3.13.2+
- clang-format 12.0.0+

### Setup Compiler

Expand Down Expand Up @@ -57,3 +58,4 @@ Before submitting pull request, please use [format-diff.py](format-diff.py) to f
$ python3 format-diff.py --diff_from `git merge-base ${TARGET_REMOTE_BRANCH} HEAD`
```

You can download the `clang-format` from [muttleyxd/clang-tools-static-binaries](https://github.com/muttleyxd/clang-tools-static-binaries/releases). clang-format 12.0.0+ is required.
112 changes: 53 additions & 59 deletions dbms/src/AggregateFunctions/IAggregateFunction.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
#pragma once

#include <cstddef>
#include <memory>
#include <vector>
#include <type_traits>

#include <Core/Types.h>
#include <Core/Field.h>
#include <Columns/ColumnsNumber.h>
#include <Common/Exception.h>
#include <Common/assert_cast.h>
#include <Core/Field.h>
#include <Core/Types.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
#include <Storages/Transaction/Collator.h>

#include <cstddef>
#include <memory>
#include <type_traits>
#include <vector>


namespace DB
{

namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
extern const int NOT_IMPLEMENTED;
}

class Arena;
Expand Down Expand Up @@ -91,10 +90,7 @@ class IAggregateFunction
virtual void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, Arena * arena) const = 0;

/// Returns true if a function requires Arena to handle own states (see add(), merge(), deserialize()).
virtual bool allocatesMemoryInArena() const
{
return false;
}
virtual bool allocatesMemoryInArena() const { return false; }

/// Inserts results into a column.
virtual void insertResultInto(ConstAggregateDataPtr __restrict place, IColumn & to, Arena * arena) const = 0;
Expand Down Expand Up @@ -134,7 +130,11 @@ class IAggregateFunction
/** The same for single place.
*/
virtual void addBatchSinglePlace(
size_t batch_size, AggregateDataPtr place, const IColumn ** columns, Arena * arena, ssize_t if_argument_pos = -1) const = 0;
size_t batch_size,
AggregateDataPtr place,
const IColumn ** columns,
Arena * arena,
ssize_t if_argument_pos = -1) const = 0;

/** The same for single place when need to aggregate only filtered data.
*/
Expand All @@ -147,8 +147,12 @@ class IAggregateFunction
ssize_t if_argument_pos = -1) const = 0;

virtual void addBatchSinglePlaceFromInterval(
size_t batch_begin, size_t batch_end, AggregateDataPtr place, const IColumn ** columns, Arena * arena, ssize_t if_argument_pos = -1)
const = 0;
size_t batch_begin,
size_t batch_end,
AggregateDataPtr place,
const IColumn ** columns,
Arena * arena,
ssize_t if_argument_pos = -1) const = 0;

/** In addition to addBatch, this method collects multiple rows of arguments into array "places"
* as long as they are between offsets[i-1] and offsets[i]. This is used for arrayReduce and
Expand Down Expand Up @@ -181,7 +185,7 @@ class IAggregateFunction
*/
virtual const char * getHeaderFilePath() const = 0;

virtual void setCollators(TiDB::TiDBCollators & ) {}
virtual void setCollators(TiDB::TiDBCollators &) {}
};

/// Implement method to obtain an address of 'add' function.
Expand Down Expand Up @@ -235,7 +239,11 @@ class IAggregateFunctionHelper : public IAggregateFunction
}

void addBatchSinglePlace(
size_t batch_size, AggregateDataPtr place, const IColumn ** columns, Arena * arena, ssize_t if_argument_pos = -1) const override
size_t batch_size,
AggregateDataPtr place,
const IColumn ** columns,
Arena * arena,
ssize_t if_argument_pos = -1) const override
{
if (if_argument_pos >= 0)
{
Expand Down Expand Up @@ -277,8 +285,12 @@ class IAggregateFunctionHelper : public IAggregateFunction
}

void addBatchSinglePlaceFromInterval(
size_t batch_begin, size_t batch_end, AggregateDataPtr place, const IColumn ** columns, Arena * arena, ssize_t if_argument_pos = -1)
const override
size_t batch_begin,
size_t batch_end,
AggregateDataPtr place,
const IColumn ** columns,
Arena * arena,
ssize_t if_argument_pos = -1) const override
{
if (if_argument_pos >= 0)
{
Expand All @@ -297,8 +309,12 @@ class IAggregateFunctionHelper : public IAggregateFunction
}

void addBatchArray(
size_t batch_size, AggregateDataPtr * places, size_t place_offset, const IColumn ** columns, const UInt64 * offsets, Arena * arena)
const override
size_t batch_size,
AggregateDataPtr * places,
size_t place_offset,
const IColumn ** columns,
const UInt64 * offsets,
Arena * arena) const override
{
size_t current_offset = 0;
for (size_t i = 0; i < batch_size; ++i)
Expand Down Expand Up @@ -356,25 +372,19 @@ namespace _IAggregateFunctionImpl
template <bool with_collator = false>
struct CollatorsHolder
{
void setCollators(const TiDB::TiDBCollators &)
{
}
void setCollators(const TiDB::TiDBCollators &) {}

template <typename T>
void setDataCollators(T *) const
{
}
{}
};

template <>
struct CollatorsHolder<true>
{
TiDB::TiDBCollators collators;

void setCollators(const TiDB::TiDBCollators & collators_)
{
collators = collators_;
}
void setCollators(const TiDB::TiDBCollators & collators_) { collators = collators_; }

template <typename T>
void setDataCollators(T * data) const
Expand All @@ -389,19 +399,16 @@ struct AggregationCollatorsWrapper
{
void setCollators(const TiDB::TiDBCollators &) {}

StringRef getUpdatedValueForCollator(StringRef & in, size_t)
{
return in;
}
StringRef getUpdatedValueForCollator(StringRef & in, size_t) { return in; }

std::pair<std::shared_ptr<TiDB::ITiDBCollator>, std::string *> getCollatorAndSortKeyContainer(size_t )
std::pair<std::shared_ptr<TiDB::ITiDBCollator>, std::string *> getCollatorAndSortKeyContainer(size_t)
{
return std::make_pair(static_cast<std::shared_ptr<TiDB::ITiDBCollator>>(nullptr), &TiDB::dummy_sort_key_contaner);
}

void writeCollators(WriteBuffer & ) const {}
void writeCollators(WriteBuffer &) const {}

void readCollators(ReadBuffer & ) {}
void readCollators(ReadBuffer &) {}
};

template <>
Expand Down Expand Up @@ -468,7 +475,9 @@ struct AggregationCollatorsWrapper<true>

/// Implements several methods for manipulation with data. T - type of structure with data for aggregation.
template <typename T, typename Derived, bool with_collator = false>
class IAggregateFunctionDataHelper : public IAggregateFunctionHelper<Derived>, protected _IAggregateFunctionImpl::CollatorsHolder<with_collator>
class IAggregateFunctionDataHelper
: public IAggregateFunctionHelper<Derived>
, protected _IAggregateFunctionImpl::CollatorsHolder<with_collator>
{
protected:
using Data = T;
Expand All @@ -482,31 +491,16 @@ class IAggregateFunctionDataHelper : public IAggregateFunctionHelper<Derived>, p
_IAggregateFunctionImpl::CollatorsHolder<with_collator>::setCollators(collators_);
}

void create(AggregateDataPtr __restrict place) const override
{
this->setDataCollators(new (place) Data);
}
void create(AggregateDataPtr __restrict place) const override { this->setDataCollators(new (place) Data); }

void destroy(AggregateDataPtr __restrict place) const noexcept override
{
data(place).~Data();
}
void destroy(AggregateDataPtr __restrict place) const noexcept override { data(place).~Data(); }

bool hasTrivialDestructor() const override
{
return std::is_trivially_destructible_v<Data>;
}
bool hasTrivialDestructor() const override { return std::is_trivially_destructible_v<Data>; }

size_t sizeOfData() const override
{
return sizeof(Data);
}
size_t sizeOfData() const override { return sizeof(Data); }

/// NOTE: Currently not used (structures with aggregation state are put without alignment).
size_t alignOfData() const override
{
return alignof(Data);
}
size_t alignOfData() const override { return alignof(Data); }

void addBatchLookupTable8(
size_t batch_size,
Expand Down
Loading

0 comments on commit 1b50582

Please sign in to comment.