Skip to content

Commit

Permalink
common: add lcov exclusions in KU_UNREACHABLE
Browse files Browse the repository at this point in the history
This allows us to avoid the annoying comments everywhere we have
unreachable code in the codebase.
  • Loading branch information
Riolku committed Nov 8, 2023
1 parent fd388b4 commit eb54a18
Show file tree
Hide file tree
Showing 27 changed files with 6 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

- name: Generate coverage report
run: |
lcov -c -d ./ --no-external -o cover.info &&\
lcov --config-file .lcovrc -c -d ./ --no-external -o cover.info &&\
lcov --remove cover.info $(< .github/workflows/lcov_exclude) -o cover.info
- name: Upload coverage report
Expand Down
1 change: 1 addition & 0 deletions .lcovrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lcov_excl_line = LCOV_EXCL_LINE|KU_UNREACHABLE
4 changes: 0 additions & 4 deletions src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ expression_vector Binder::bindExpectedNodeFileColumns(
expectedColumnTypes.push_back(property->getDataType()->copy());
}
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
// Detect columns from file.
std::vector<std::string> detectedColumnNames;
Expand Down Expand Up @@ -246,11 +244,9 @@ expression_vector Binder::bindExpectedRelFileColumns(
readerConfig.columnTypes.push_back(std::move(columnType));
}
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
// Detect columns from file.
std::vector<std::string> detectedColumnNames;
Expand Down
4 changes: 0 additions & 4 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ std::unique_ptr<BoundCreateTableInfo> Binder::bindCreateTableInfo(
case TableType::RDF: {
return bindCreateRdfGraphInfo(info);
}
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
return nullptr;
}
Expand Down Expand Up @@ -213,11 +211,9 @@ std::unique_ptr<BoundStatement> Binder::bindAlter(const parser::Statement& state
case AlterType::RENAME_PROPERTY: {
return bindRenameProperty(statement);
}
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
return nullptr;
}
Expand Down
6 changes: 0 additions & 6 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ std::shared_ptr<RelExpression> Binder::bindQueryRel(const RelPattern& relPattern
dstNode = rightNode;
directionType = RelDirectionType::BOTH;
} break;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
// bind variable length
std::shared_ptr<RelExpression> queryRel;
Expand Down Expand Up @@ -562,10 +560,8 @@ std::vector<table_id_t> Binder::getNodeTableIDs(const std::vector<table_id_t>& t
case TableType::NODE: {
return tableIDs;
}
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -597,10 +593,8 @@ std::vector<table_id_t> Binder::getRelTableIDs(const std::vector<table_id_t>& ta
case TableType::REL: {
return tableIDs;
}
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ void Binder::sniffFiles(const common::ReaderConfig& readerConfig,
} break;
case FileType::TURTLE:
break;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/binder/bind/bind_updating_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ std::unique_ptr<BoundUpdatingClause> Binder::bindUpdatingClause(
case ClauseType::DELETE_: {
return bindDeleteClause(updatingClause);
}
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ std::shared_ptr<Expression> ExpressionBinder::bindFunctionExpression(
parsedExpression, functionName, parsedFunctionExpression.getIsDistinct());
case ExpressionType::MACRO:
return bindMacroExpression(parsedExpression, functionName);
// LOCV_EXCL_START
default:
KU_UNREACHABLE;
// LOCV_EXCL_STOP
}
return nullptr;
}
Expand Down Expand Up @@ -254,10 +252,8 @@ std::shared_ptr<Expression> ExpressionBinder::bindLabelFunction(const Expression
std::make_unique<Value>(*listType, populateLabelValues(relTableIDs, *catalogContent));
children.push_back(createLiteralExpression(std::move(labelsValue)));
} break;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
auto execFunc = function::LabelFunction::execFunction;
auto bindData =
Expand Down
2 changes: 0 additions & 2 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ std::unique_ptr<BoundStatement> Binder::bind(const Statement& statement) {
case StatementType::TRANSACTION: {
boundStatement = bindTransaction(statement);
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
BoundStatementRewriter::rewrite(*boundStatement, catalog);
return boundStatement;
Expand Down
2 changes: 0 additions & 2 deletions src/common/copier_config/copier_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ std::string FileTypeUtils::toString(FileType fileType) {
case FileType::TURTLE: {
return "TURTLE";
}
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/common/types/interval_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,8 @@ int32_t Interval::getIntervalPart(DatePartSpecifier specifier, interval_t& inter
return (interval.micros % Interval::MICROS_PER_HOUR) / Interval::MICROS_PER_MINUTE;
case DatePartSpecifier::HOUR:
return interval.micros / Interval::MICROS_PER_HOUR;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ std::string PhysicalTypeUtils::physicalTypeToString(PhysicalTypeID physicalType)
return "STRUCT";
case PhysicalTypeID::VAR_LIST:
return "VAR_LIST";
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -92,10 +90,8 @@ uint32_t PhysicalTypeUtils::getFixedTypeSize(PhysicalTypeID physicalType) {
return sizeof(interval_t);
case PhysicalTypeID::INTERNAL_ID:
return sizeof(internalID_t);
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -517,10 +513,8 @@ void LogicalType::setPhysicalType() {
case LogicalTypeID::RDF_VARIANT: {
physicalType = PhysicalTypeID::STRUCT;
} break;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -650,10 +644,8 @@ std::string LogicalTypeUtils::toString(LogicalTypeID dataTypeID) {
return "MAP";
case LogicalTypeID::UNION:
return "UNION";
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/common/types/value/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ void Value::copyValueFrom(const Value& other) {
}
} break;
default:
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -437,9 +435,7 @@ std::string Value::toString() const {
return relToString();
}
default:
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ std::string LoggerUtils::getLoggerName(LoggerConstants::LoggerEnum loggerEnum) {
case LoggerConstants::LoggerEnum::WAL: {
return "wal";
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
}
} // namespace common
Expand Down
8 changes: 0 additions & 8 deletions src/common/vector/value_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ void ValueVector::copyFromValue(uint64_t pos, const Value& value) {
case PhysicalTypeID::FLOAT: {
memcpy(bufferToWrite, &val->getValueReference<float_t>(), numBytesPerChildValue);
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
bufferToWrite += numBytesPerChildValue;
}
Expand All @@ -227,11 +225,9 @@ void ValueVector::copyFromValue(uint64_t pos, const Value& value) {
structFields[i]->copyFromValue(pos, *NestedVal::getChildVal(&value, i));
}
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -315,10 +311,8 @@ std::unique_ptr<Value> ValueVector::getAsValue(uint64_t pos) {
case PhysicalTypeID::FLOAT: {
FixedListVector::getAsValue<float>(this, children, pos, numElements);
} break;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
value->childrenSize = numElements;
value->children = std::move(children);
Expand All @@ -333,11 +327,9 @@ std::unique_ptr<Value> ValueVector::getAsValue(uint64_t pos) {
value->childrenSize = children.size();
value->children = std::move(children);
} break;
// LCOV_EXCL_START
default: {
KU_UNREACHABLE;
}
// LCOV_EXCL_STOP
}
return value;
}
Expand Down
4 changes: 0 additions & 4 deletions src/function/aggregate_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ std::unique_ptr<AggregateFunction> AggregateFunctionUtil::getSumFunc(const std::
case common::LogicalTypeID::FLOAT:
return getAggFunc<SumFunction<float_t>>(
name, std::move(inputType), std::move(resultType), isDistinct);
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down Expand Up @@ -94,10 +92,8 @@ std::unique_ptr<AggregateFunction> AggregateFunctionUtil::getAvgFunc(const std::
case common::LogicalTypeID::FLOAT:
return getAggFunc<AvgFunction<float_t>>(
name, std::move(inputType), std::move(resultType), isDistinct);
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/function/vector_cast_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,8 @@ static std::unique_ptr<ScalarFunction> bindCastToStringFunction(
func = ScalarFunction::UnaryCastExecFunction<union_entry_t, ku_string_t, CastToString>;
} break;
// ToDo(Kebing): RECURSIVE_REL to string
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
return std::make_unique<ScalarFunction>(
functionName, std::vector<LogicalTypeID>{sourceTypeID}, LogicalTypeID::STRING, func);
Expand Down
14 changes: 2 additions & 12 deletions src/include/parser/expression/parsed_parameter_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@ class ParsedParameterExpression : public ParsedExpression {

static std::unique_ptr<ParsedParameterExpression> deserialize(
common::Deserializer& /*deserializer*/) {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}

inline std::unique_ptr<ParsedExpression> copy() const override {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
inline std::unique_ptr<ParsedExpression> copy() const override { KU_UNREACHABLE; }

private:
void serializeInternal(common::Serializer& /*serializer*/) const override {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
void serializeInternal(common::Serializer& /*serializer*/) const override { KU_UNREACHABLE; }

private:
std::string parameterName;
Expand Down
14 changes: 2 additions & 12 deletions src/include/parser/expression/parsed_subquery_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,13 @@ class ParsedSubqueryExpression : public ParsedExpression {

static std::unique_ptr<ParsedSubqueryExpression> deserialize(
common::Deserializer& /*deserializer*/) {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}

std::unique_ptr<ParsedExpression> copy() const override {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
std::unique_ptr<ParsedExpression> copy() const override { KU_UNREACHABLE; }

private:
void serializeInternal(common::Serializer& /*serializer*/) const override {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
void serializeInternal(common::Serializer& /*serializer*/) const override { KU_UNREACHABLE; }

private:
std::vector<std::unique_ptr<PatternElement>> patternElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ class OrderByKeyEncoder {

template<typename type>
static void encodeData(type /*data*/, uint8_t* /*resultPtr*/, bool /*swapBytes*/) {
// LCOV_EXCL_START
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}

static inline uint8_t flipSign(uint8_t key_byte) { return key_byte ^ 128; }
Expand Down
2 changes: 0 additions & 2 deletions src/optimizer/acc_hash_join_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,8 @@ std::shared_ptr<planner::LogicalOperator> HashJoinSIPOptimizer::appendNodeSemiMa
key = extend->getNbrNode()->getInternalID();
nodeTableIDs = extend->getNbrNode()->getTableIDs();
} break;
// LCOV_EXCL_START
default:
KU_UNREACHABLE;
// LCOV_EXCL_STOP
}
auto semiMasker = std::make_shared<LogicalSemiMasker>(SemiMaskType::NODE, std::move(key),
std::move(nodeTableIDs), opsToApplySemiMask, std::move(child));
Expand Down
Loading

0 comments on commit eb54a18

Please sign in to comment.