Skip to content

chore(log): add unreachable() based on the current logging infra #2893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
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
4 changes: 4 additions & 0 deletions src/common/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ template <typename... Args>
std::abort();
}

[[noreturn]] inline void unreachable(spdlog::source_loc loc = CurrentLocation()) { // NOLINT
fatal({"UNREACHABLE REACHED: please submit a bug report with the stacktrace below.", loc});
}

// This is a simulation of glog API, with a spdlog backend.
// TODO: We use it as a transition from glog to spdlog,
// and it will be removed when the migration is complete.
Expand Down
5 changes: 2 additions & 3 deletions src/search/executors/filter_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct QueryExprEvaluator {
return Visit(v);
}

CHECK(false) << "unreachable";
unreachable();
}

StatusOr<bool> Visit(AndExpr *v) const {
Expand Down Expand Up @@ -112,8 +112,7 @@ struct QueryExprEvaluator {
case NumericCompareExpr::GET:
return l >= r;
default:
CHECK(false) << "unreachable";
__builtin_unreachable();
unreachable();
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/search/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ StatusOr<FieldValueRetriever> FieldValueRetriever::Create(IndexOnDataType type,
if (!s.ok()) return {Status::NotOK, s.ToString()};
return FieldValueRetriever(value);
} else {
assert(false && "unreachable code: unexpected IndexOnDataType");
__builtin_unreachable();
unreachable();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/ir_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct Visitor : Pass {
return Visit(std::move(v));
}

__builtin_unreachable();
unreachable();
}

template <typename T>
Expand Down
3 changes: 2 additions & 1 deletion src/search/passes/cost_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ struct CostModel {
return Visit(v);
}

CHECK(false) << "plan operator type not supported";
// plan operator type not supported
unreachable();
}

static size_t Visit([[maybe_unused]] const FullIndexScan *node) { return 100; }
Expand Down
5 changes: 3 additions & 2 deletions src/search/passes/index_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ struct IndexSelection : Visitor {
if (order->field->info->MetadataAs<redis::NumericFieldMetadata>()) {
return std::make_unique<NumericFieldScan>(order->field->CloneAs<FieldRef>(), Interval::Full(), order->order);
} else {
CHECK(false) << "current only numeric field is supported for ordering";
// current only numeric field is supported for ordering
unreachable();
}
}

Expand Down Expand Up @@ -130,7 +131,7 @@ struct IndexSelection : Visitor {
return VisitExpr(v);
}

CHECK(false) << "unreachable";
unreachable();
}

std::unique_ptr<PlanOperator> MakeFullIndexFilter(QueryExpr *node) const {
Expand Down
2 changes: 1 addition & 1 deletion src/search/plan_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct ExecutorContextVisitor {
return Visit(v);
}

CHECK(false) << "unreachable";
unreachable();
}

void Visit(Limit *op) {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ Status Storage::Open(DBOpenMode mode) {
break;
}
default:
__builtin_unreachable();
unreachable();
}
auto end = std::chrono::high_resolution_clock::now();
int64_t duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
Expand Down
4 changes: 1 addition & 3 deletions src/types/redis_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ rocksdb::Status Hash::RandField(engine::Context &ctx, const Slice &user_key, int
break;
}
case HashFetchType::kOnlyValue:
// Unreachable.
DCHECK(false);
break;
unreachable();
}
return rocksdb::Status::OK();
}
Expand Down
Loading