refactor(bvar): expand metric constructor macro - #3400
Conversation
Inline default/name/prefix constructors in Adder, Maxer, Miner, and IntRecorder, and drop the shared macro from variable.h. Co-authored-by: Cursor <cursoragent@cursor.com>
chenBright
left a comment
There was a problem hiding this comment.
I think this is to simplify the code, which is fine, like the DISALLOW_COPY_AND_ASSIGN macro.
There was a problem hiding this comment.
Pull request overview
This PR refactors the bvar public headers by removing the COMMON_VARIABLE_CONSTRUCTOR macro and expanding its usages into explicit, readable constructors (primarily for the WITH_BABYLON_COUNTER specializations). The intent is to preserve the existing construction behavior (default, expose(name), expose_as(prefix, name)) while improving navigability and searchability in C++ tooling.
Changes:
- Removed
COMMON_VARIABLE_CONSTRUCTORfrombvar/variable.h. - Replaced macro usage with explicit constructors in
Adder,Maxer, andMinerBabylon-counter specializations. - Replaced macro usage with explicit constructors in the Babylon-counter
IntRecordervariant.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/bvar/variable.h | Removes the shared constructor macro from a publicly installed bvar header. |
| src/bvar/reducer.h | Expands the macro into explicit constructors for Babylon-counter Adder/Maxer/Miner. |
| src/bvar/recorder.h | Expands the macro into explicit constructors for the Babylon-counter IntRecorder. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| DECLARE_bool(save_series); | ||
|
|
||
| #define COMMON_VARIABLE_CONSTRUCTOR(TypeName) \ | ||
| TypeName() = default; \ | ||
| TypeName(const butil::StringPiece& name) { \ | ||
| this->expose(name); \ | ||
| } \ | ||
| TypeName(const butil::StringPiece& prefix, const butil::StringPiece& name) { \ | ||
| this->expose_as(prefix, name); \ | ||
| } \ | ||
|
|
||
|
|
||
| // Bitwise masks of displayable targets |
Agree |
I agree the macro reduces a few lines, but it hides public constructors, which are part of the API surface and important for readability/tooling. Since these constructors are simple and type-specific, spelling them out makes the public interface clearer. That said, because variable.h is installed as a public header, removing the macro may break downstream users. I can keep a deprecated compatibility definition for one release while removing internal usages, then remove it in a later breaking-change cycle. |
Summary
COMMON_VARIABLE_CONSTRUCTORmacroAdder,Maxer,Miner, andIntRecorderwith explicit constructorsexpose(name), andexpose_as(prefix, name)Motivation
COMMON_VARIABLE_CONSTRUCTORhid public constructors behind macro expansion, making the code harder to read, search, and navigate with regular C++ tooling.This change keeps the API behavior unchanged while making the constructors visible at their declaration sites.
using Base::Basewas intentionally avoided because it would expose additional internal base constructors in the Babylon counter path and could broaden the publicAPI.
Testing
cmake --build build --target brpc-static -j6git diff --checkrg COMMON_VARIABLE_CONSTRUCTOR . -g '!build/**'Notes
The
WITH_BABYLON_COUNTERpath was not compiled locally because the available Bazel setup is missing the repository-required Bazel7.2.1binary.