Skip to content

refactor(parameter): introduce macros to eliminate CheckCompatibility boilerplate#2153

Merged
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:claude/refactor-checkcompatibility-macros
Jun 8, 2026
Merged

refactor(parameter): introduce macros to eliminate CheckCompatibility boilerplate#2153
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:claude/refactor-checkcompatibility-macros

Conversation

@LHT129
Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 commented Jun 8, 2026

Summary

Introduce PARAM_CAST_OR_RETURN, CHECK_FIELD_EQ, and CHECK_SUB_PARAM macros in src/utils/param_compat_macros.h to replace the repetitive dynamic_pointer_cast + logger::error + return false pattern duplicated across 23 parameter files.

24 files changed, +175 / -549 lines (net -374 lines)

Changes

  • New file: src/utils/param_compat_macros.h — three utility macros for parameter compatibility checks
  • Refactored all 23 CheckCompatibility() implementations to use the new macros
  • Custom logic (computed fields, std::is_permutation, conditional sub-param checks) is preserved; only the mechanical cast/compare/log boilerplate is replaced

Test Plan

  • All existing [CheckCompatibility] tagged tests pass (46 assertions in 4 test cases)
  • [GNOIMIParameter] and [VectorTransformerParameter] tests pass
  • Full Release build passes with no warnings

Closes: #2152

@LHT129 LHT129 self-assigned this Jun 8, 2026
@LHT129 LHT129 added kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) version/1.0 labels Jun 8, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 8, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require kind label

Wonderful, this rule succeeded.
  • label~=^kind/

🟢 Require version label

Wonderful, this rule succeeded.
  • label~=^version/

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a set of helper macros (PARAM_CAST_OR_RETURN, CHECK_FIELD_EQ, and CHECK_SUB_PARAM) in a new header file src/utils/param_compat_macros.h to standardize and simplify parameter compatibility checks across various classes, significantly reducing boilerplate code. The review feedback is highly constructive and should be addressed: it identifies a potential null pointer dereference hazard in the CHECK_SUB_PARAM macro when sub-parameters are null, and recommends parenthesizing macro arguments in PARAM_CAST_OR_RETURN to prevent operator precedence issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/utils/param_compat_macros.h
Comment thread src/utils/param_compat_macros.h
… boilerplate

Add PARAM_CAST_OR_RETURN, CHECK_FIELD_EQ, and CHECK_SUB_PARAM macros
in src/utils/param_compat_macros.h to replace the repetitive
dynamic_pointer_cast + logger::error + return false pattern that was
duplicated across 23 parameter files.

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Co-authored-by: opencode <opencode@anthropic.com>
@LHT129 LHT129 force-pushed the claude/refactor-checkcompatibility-macros branch from 817e5a2 to 3394d98 Compare June 8, 2026 04:07
Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

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

lgtm

@LHT129 LHT129 merged commit 4f7ea17 into antgroup:main Jun 8, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) size/XL version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: introduce macros to eliminate CheckCompatibility boilerplate

2 participants