Skip to content

refactor(bvar): expand metric constructor macro - #3400

Open
darion-yaphet wants to merge 1 commit into
apache:masterfrom
darion-yaphet:modernize-bvar-constructors
Open

refactor(bvar): expand metric constructor macro#3400
darion-yaphet wants to merge 1 commit into
apache:masterfrom
darion-yaphet:modernize-bvar-constructors

Conversation

@darion-yaphet

Copy link
Copy Markdown
Contributor

Summary

  • Remove the COMMON_VARIABLE_CONSTRUCTOR macro
  • Replace its uses in the Babylon counter variants of Adder, Maxer, Miner, and IntRecorder with explicit constructors
  • Preserve the existing constructor behavior for default construction, expose(name), and expose_as(prefix, name)

Motivation

COMMON_VARIABLE_CONSTRUCTOR hid 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::Base was intentionally avoided because it would expose additional internal base constructors in the Babylon counter path and could broaden the public
API.

Testing

  • cmake --build build --target brpc-static -j6
  • git diff --check
  • rg COMMON_VARIABLE_CONSTRUCTOR . -g '!build/**'

Notes

The WITH_BABYLON_COUNTER path was not compiled locally because the available Bazel setup is missing the repository-required Bazel 7.2.1 binary.

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 chenBright left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is to simplify the code, which is fine, like the DISALLOW_COPY_AND_ASSIGN macro.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_CONSTRUCTOR from bvar/variable.h.
  • Replaced macro usage with explicit constructors in Adder, Maxer, and Miner Babylon-counter specializations.
  • Replaced macro usage with explicit constructors in the Babylon-counter IntRecorder variant.

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.

Comment thread src/bvar/variable.h
Comment on lines 40 to 42
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
@wwbmmm

wwbmmm commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

I think this is to simplify the code, which is fine, like the DISALLOW_COPY_AND_ASSIGN macro.

Agree

@darion-yaphet

Copy link
Copy Markdown
Contributor Author

I think this is to simplify the code, which is fine, like the DISALLOW_COPY_AND_ASSIGN macro.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants