Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Cleanup includes - #519

Merged
liuzicheng1987 merged 17 commits into
munich-data-engineering:mainfrom
KostinPavel:cleanup-includes
Oct 13, 2025
Merged

liuzicheng1987 merged 17 commits into
munich-data-engineering:mainfrom
KostinPavel:cleanup-includes

Conversation

@KostinPavel

Copy link
Copy Markdown
Contributor
  1. try 3

KostinPavel and others added 16 commits October 8, 2025 15:22
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ast.hpp и неиспользуемые include из Result.hpp

- Удален #include <bit> из include/rfl/internal/ptr_cast.hpp (не используется в коде)
- Удалены неиспользуемые include из include/rfl/Result.hpp:
  - #include <algorithm> (не используется)
  - #include <iostream> (не используется)
  - #include <optional> (не используется)
Этап 2: Базовые типы (средний риск)

Удалены неиспользуемые include из файла Tuple.hpp:
- <algorithm> - не используется в коде
- <bit> - не используется в коде
- <cstdint> - не используется в коде
- <limits> - не используется в коде
- <memory> - не используется в коде
- <optional> - не используется в коде

Оставлены только необходимые заголовки:
- <array> - используется для std::array
- <tuple> - используется для std::tuple
- <type_traits> - используется для различных type traits
- <utility> - используется для std::integer_sequence и других утилит

Все остальные файлы (Literal.hpp, Field.hpp, Object.hpp, Variant.hpp)
уже имели оптимальный набор include файлов без неиспользуемых зависимостей.

Компиляция проекта проверена и проходит успешно.
…вки <string>, <version>, упрощен оператор сравнения spaceship
unused arguments
shaded variables
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @KostinPavel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on a significant cleanup and refinement of the rfl library's codebase. The changes span across build configurations, dependency management, and core serialization logic for various formats. The primary goal is to enhance code quality, reduce compilation overhead by eliminating redundant includes, and improve the robustness of the Avro and Cap'n Proto backends through better error handling and type safety. These improvements contribute to a more efficient and maintainable library.

Highlights

  • Static Analysis Configuration: A new .clang-tidy configuration file has been added to enforce coding standards and identify potential issues such as unused includes, redundant preprocessor directives, and modern C++ usage.
  • Build System Enhancements: The CMakeLists.txt file has been updated to enable the export of compile commands, which is beneficial for IDE integration and static analysis tools. Compiler options for Debug and Release builds have also been refined, adding more strict warnings like -Wpedantic, -Wshadow, and -Wconversion for non-MSVC compilers in Debug mode.
  • Extensive Include Cleanup: Numerous unused #include directives have been removed across a wide range of files, including benchmark files and core rfl library headers for various serialization formats (Avro, BSON, Cap'n Proto, CBOR, Flexbuf, Generic, MessagePack, TOML, UBJSON, XML, YAML). This significantly reduces compilation times and improves code clarity by removing unnecessary dependencies.
  • Avro Error Handling Improvements: Comprehensive error checking and std::runtime_error exceptions have been added to the Avro Writer for various avro_value operations (e.g., set_null, append, add, get_by_name, set_branch, set_string_len, set_bytes, set_boolean, set_double, set_long, set_enum). Similar error checks were added to the Avro Reader for avro_value_get_boolean, avro_value_get_size, and avro_value_get_by_index calls, making the Avro backend more robust.
  • Cap'n Proto Type Safety: A SafeSizeToUInt helper function was introduced in the Cap'n Proto Writer to safely cast size_t values to unsigned int, preventing potential integer overflows when initializing Cap'n Proto lists and arrays.
  • Refactored std::hash Implementations: The std::hash specializations for rfl::Box and rfl::Ref have been updated to explicitly use std::hash<std::unique_ptr<T>>{} and std::hash<std::shared_ptr<T>>{}, respectively, ensuring correct and explicit hashing behavior for smart pointers.
  • Parameter Simplification in Writers: Several Writer methods across various backends (Avro, BSON, Cap'n Proto, CBOR, Flexbuf, Generic, MessagePack, TOML, UBJSON, XML, YAML) have had unused _size and _parent parameters removed or marked as unused, streamlining function signatures and indicating a more focused design.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

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

Copy link
Copy Markdown

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 is a significant cleanup and refactoring effort. It successfully removes a large number of unused includes across the codebase, which is great for build times and code hygiene. The error handling in the Avro backend has been substantially improved by adding checks for avro_* function return values and throwing exceptions on failure. Additionally, the code has been modernized by using explicit std::hash, brace initialization for members, and simplifying operator<=> to rely on C++20 features.

I've added a few comments on potential improvements, mainly concerning error handling consistency and a potential overflow bug in the Cap'n Proto writer. Overall, this is an excellent pull request that improves code quality and robustness.

Comment thread src/rfl/avro/Writer.cpp
OutputUnionType* _parent) const {
avro_value_t new_array;
avro_value_set_branch(&_parent->val_, static_cast<int>(_index), &new_array);
int result = avro_value_set_branch(&_parent->val_, static_cast<int>(_index), &new_array);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The _index parameter is a size_t, but it's cast to an int for avro_value_set_branch. This can lead to an integer overflow if _index is larger than INT_MAX. A check should be added to prevent this, similar to the one in add_value_to_union in Writer.hpp. This issue also applies to add_map_to_union, add_object_to_union, add_union_to_union, and add_null_to_union in this file.

For example:

if (_index > static_cast<size_t>(INT_MAX)) {
  throw std::runtime_error(std::string(__FUNCTION__) + " index error");
}

Comment on lines +13 to +18
inline unsigned int SafeSizeToUInt(size_t sizeValue) {
if (sizeValue > static_cast<size_t>(std::numeric_limits<unsigned int>::max())) {
throw std::overflow_error("size_t value is too big to fit into an unsigned int.");
}
return static_cast<unsigned int>(sizeValue);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This is a great utility function for safe conversions. However, it's defined as inline within a .cpp file, limiting its scope to this translation unit. The template methods in include/rfl/capnproto/Writer.hpp (e.g., add_value_to_array) also perform size_t to unsigned int conversions implicitly when calling capnp methods, and they could benefit from this check to prevent potential overflows. Consider moving SafeSizeToUInt to a shared internal header and applying it in the template methods within Writer.hpp as well.

int result_value = 0;
int result = avro_value_get_boolean(_var.val_, &result_value);
if (result != 0) {
return error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Constructing error messages using + on std::string can lead to multiple memory allocations, which can be inefficient. Consider using std::stringstream to build the error string more efficiently. This pattern is repeated in this file and others (like avro/Writer.hpp).

For example:

std::stringstream ss;
ss << __FUNCTION__ << " error(" << result << "): " << avro_strerror();
return error(ss.str());

avro_value_set_double avro_value_set_long bug?
@KostinPavel KostinPavel reopened this Oct 13, 2025
@KostinPavel

Copy link
Copy Markdown
Contributor Author

Please let us know what else is needed to merge the branches?

@liuzicheng1987

Copy link
Copy Markdown
Collaborator

@KostinPavel , nothing. I will merge right now. Thank you so much for your effort!

@liuzicheng1987
liuzicheng1987 merged commit 732e9fe into munich-data-engineering:main Oct 13, 2025
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
…arnings/linters

Isolate reflect-cpp from consumer warning/linter policies while keeping
top-level CI warning coverage intact (building on #113 / 4861aaf):

- Split target_include_directories(reflectcpp ...) into non-SYSTEM
  PRIVATE includes for compiling reflectcpp itself and
  ${_REFLECTCPP_INCLUDE_SYSTEM} INTERFACE includes for consumers, where
  _REFLECTCPP_INCLUDE_SYSTEM is SYSTEM only when NOT
  _REFLECTCPP_IS_TOP_LEVEL and NOT REFLECTCPP_STRICT_WARNINGS. Top-level
  builds and REFLECTCPP_STRICT_WARNINGS=ON keep non-SYSTEM interface
  includes so CI still catches warnings inside include/rfl/. (On CMake >=
  3.23, FILE_SET reflectcpp_headers preserves SYSTEM because
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES already contains the same
  include directory.)
- Mark bundled thirdparty include directory SYSTEM PUBLIC, remove the
  duplicate thirdparty target_include_directories() call, and silence
  warnings on vendored src/yyjson.c with -w / /w.
- Mark transitive pugixml include directories SYSTEM (and YAS private
  includes SYSTEM).
- When embedded as a subproject, clear CXX_CLANG_TIDY / C_CLANG_TIDY,
  CXX_CPPCHECK / C_CPPCHECK, and CXX_INCLUDE_WHAT_YOU_USE /
  C_INCLUDE_WHAT_YOU_USE on reflectcpp, and (unless
  REFLECTCPP_STRICT_WARNINGS=ON) disable COMPILE_WARNING_AS_ERROR
  (CMake >= 3.24) and add PRIVATE -Wno-error -w (GNU/Clang/AppleClang) or
  /WX- /w (MSVC) so strict parent flags (-Weverything, -Wconversion,
  -Wold-style-cast, -Werror) neither fail nor spam reflectcpp's own
  sources while keeping all warnings active on top-level builds and
  REFLECTCPP_STRICT_WARNINGS=ON.
- Remove the redundant target_compile_options(reflectcpp PRIVATE
  $<$<CONFIG:Release>:-DNDEBUG>) block left over from munich-data-engineering#519 (CMake's
  CMAKE_CXX_FLAGS_RELEASE already defines -DNDEBUG / /DNDEBUG on Release
  builds, and injecting -DNDEBUG unconditionally via compile options
  duplicated the flag and overrode custom parent Release flags).
- Initialize .values = {} / .fields = {} in src/rfl/env/Writer.cpp to
  eliminate -Wmissing-field-initializers /
  -Wmissing-designated-field-initializers warnings in compiled sources
  on Clang and GCC.

Addresses #140.
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
…arnings/linters

Isolate reflect-cpp from consumer warning/linter policies while keeping
top-level CI warning coverage intact (building on #113 / 4861aaf):

- Split target_include_directories(reflectcpp ...) into non-SYSTEM
  PRIVATE includes for compiling reflectcpp itself and
  ${_REFLECTCPP_INCLUDE_SYSTEM} INTERFACE includes for consumers, where
  _REFLECTCPP_INCLUDE_SYSTEM is SYSTEM only when NOT
  _REFLECTCPP_IS_TOP_LEVEL and NOT REFLECTCPP_STRICT_WARNINGS. Top-level
  builds and REFLECTCPP_STRICT_WARNINGS=ON keep non-SYSTEM interface
  includes so CI still catches warnings inside include/rfl/. (On CMake >=
  3.23, FILE_SET reflectcpp_headers preserves SYSTEM because
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES already contains the same
  include directory.)
- Mark bundled thirdparty include directory SYSTEM PUBLIC, remove the
  duplicate thirdparty target_include_directories() call, and silence
  warnings on vendored src/yyjson.c with -w / /w.
- Mark transitive pugixml include directories SYSTEM (and YAS private
  includes SYSTEM).
- When embedded as a subproject, clear CXX_CLANG_TIDY / C_CLANG_TIDY,
  CXX_CPPCHECK / C_CPPCHECK, and CXX_INCLUDE_WHAT_YOU_USE /
  C_INCLUDE_WHAT_YOU_USE on reflectcpp, and (unless
  REFLECTCPP_STRICT_WARNINGS=ON) disable COMPILE_WARNING_AS_ERROR
  (CMake >= 3.24) and add PRIVATE -Wno-error -w (GNU/Clang/AppleClang) or
  /WX- /w (MSVC) so strict parent flags (-Weverything, -Wconversion,
  -Wold-style-cast, -Werror) neither fail nor spam reflectcpp's own
  sources while keeping all warnings active on top-level builds and
  REFLECTCPP_STRICT_WARNINGS=ON.
- Remove the redundant target_compile_options(reflectcpp PRIVATE
  $<$<CONFIG:Release>:-DNDEBUG>) block left over from munich-data-engineering#519 (CMake's
  CMAKE_CXX_FLAGS_RELEASE already defines -DNDEBUG / /DNDEBUG on Release
  builds, and injecting -DNDEBUG unconditionally via compile options
  duplicated the flag and overrode custom parent Release flags).
- Initialize .values = {} / .fields = {} in src/rfl/env/Writer.cpp to
  eliminate -Wmissing-field-initializers /
  -Wmissing-designated-field-initializers warnings in compiled sources
  on Clang and GCC.

Addresses #140.
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
…arnings/linters

Isolate reflect-cpp from consumer warning/linter policies while keeping
top-level CI warning coverage intact (building on #113 / 4861aaf):

- Split target_include_directories(reflectcpp ...) into non-SYSTEM
  PRIVATE includes for compiling reflectcpp itself and
  ${_REFLECTCPP_INCLUDE_SYSTEM} INTERFACE includes for consumers, where
  _REFLECTCPP_INCLUDE_SYSTEM is SYSTEM only when NOT
  _REFLECTCPP_IS_TOP_LEVEL and NOT REFLECTCPP_STRICT_WARNINGS. Top-level
  builds and REFLECTCPP_STRICT_WARNINGS=ON keep non-SYSTEM interface
  includes so CI still catches warnings inside include/rfl/. (On CMake >=
  3.23, FILE_SET reflectcpp_headers preserves SYSTEM because
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES already contains the same
  include directory.)
- Mark bundled thirdparty include directory SYSTEM PUBLIC, remove the
  duplicate thirdparty target_include_directories() call, and silence
  warnings on vendored src/yyjson.c with -w (GNU/Clang) or /W0 (MSVC /
  clang-cl, which maps to MSBuild <WarningLevel>TurnOffAllWarnings</WarningLevel>
  instead of emitting D9025 overrides from /w in <AdditionalOptions>).
- Mark transitive pugixml include directories SYSTEM (and YAS private
  includes SYSTEM).
- When embedded as a subproject, clear CXX_CLANG_TIDY / C_CLANG_TIDY,
  CXX_CPPCHECK / C_CPPCHECK, and CXX_INCLUDE_WHAT_YOU_USE /
  C_INCLUDE_WHAT_YOU_USE on reflectcpp, and (unless
  REFLECTCPP_STRICT_WARNINGS=ON) disable COMPILE_WARNING_AS_ERROR
  (CMake >= 3.24) and add PRIVATE -Wno-error -w (GNU/Clang/AppleClang) or
  /W0 (MSVC / clang-cl). On MSVC, strip inherited /W[0-4], /Wall, /w,
  /WX, /WX- (plus GCC/Clang -W* / -w flags on clang-cl) from local
  CMAKE_{CXX,C}_FLAGS* and directory COMPILE_OPTIONS before
  add_library(reflectcpp ...) snapshots directory options, preventing
  D9025 override spam in both VS MSBuild and Ninja MSVC without mutating
  parent scope or corrupting /wd*, /WIN32, /bigobj, or -Wl,... flags.
- Replace -Wall with /W4 on MSVC / clang-cl under
  REFLECTCPP_STRICT_WARNINGS (stripping inherited /W[0-4], /Wall, /w
  first to prevent /W3 -> /W4 D9025 warnings) so strict warnings no
  longer expand to MSVC /Wall or clang-cl -Weverything.
- Remove the redundant target_compile_options(reflectcpp PRIVATE
  $<$<CONFIG:Release>:-DNDEBUG>) block left over from munich-data-engineering#519 (CMake's
  CMAKE_CXX_FLAGS_RELEASE already defines -DNDEBUG / /DNDEBUG on Release
  builds, and injecting -DNDEBUG unconditionally via compile options
  duplicated the flag and overrode custom parent Release flags).
- Fix compiled-source warnings under strict Clang/GCC and MSVC /W4:
  - Initialize .values = {} / .fields = {} in src/rfl/env/Writer.cpp
    (-Wmissing-field-initializers).
  - Explicitly declare and out-of-line default copy/move special members
    on rfl::parsing::schema::Type (MSVC C5267 / -Wdeprecated-copy-dtor).
  - Rename structured-binding locals in src/rfl/json/to_schema.cpp so
    default_value no longer hides rfl::default_value (MSVC C4459), and
    move trailing return t into explicit else branches of if constexpr
    in handle_size_variant (MSVC C4702).

Addresses #140.
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
…arnings/linters

Isolate reflect-cpp from consumer warning/linter policies while keeping
top-level CI warning coverage intact (building on #113 / 4861aaf):

- Split target_include_directories(reflectcpp ...) into non-SYSTEM
  PRIVATE includes for compiling reflectcpp itself and
  ${_REFLECTCPP_INCLUDE_SYSTEM} INTERFACE includes for consumers, where
  _REFLECTCPP_INCLUDE_SYSTEM is SYSTEM only when NOT
  _REFLECTCPP_IS_TOP_LEVEL and NOT REFLECTCPP_STRICT_WARNINGS. Top-level
  builds and REFLECTCPP_STRICT_WARNINGS=ON keep non-SYSTEM interface
  includes so CI still catches warnings inside include/rfl/. (On CMake >=
  3.23, FILE_SET reflectcpp_headers preserves SYSTEM because
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES already contains the same
  include directory.)
- Mark bundled thirdparty include directory SYSTEM PUBLIC, remove the
  duplicate thirdparty target_include_directories() call, and silence
  warnings on vendored src/yyjson.c with -w (GNU/Clang) or /W0 (MSVC /
  clang-cl, which maps to MSBuild <WarningLevel>TurnOffAllWarnings</WarningLevel>
  instead of emitting D9025 overrides from /w in <AdditionalOptions>).
- Mark transitive pugixml include directories SYSTEM (and YAS private
  includes SYSTEM).
- When embedded as a subproject, clear CXX_CLANG_TIDY / C_CLANG_TIDY,
  CXX_CPPCHECK / C_CPPCHECK, and CXX_INCLUDE_WHAT_YOU_USE /
  C_INCLUDE_WHAT_YOU_USE on reflectcpp, and (unless
  REFLECTCPP_STRICT_WARNINGS=ON) disable COMPILE_WARNING_AS_ERROR
  (CMake >= 3.24) and add PRIVATE -Wno-error -w (GNU/Clang/AppleClang) or
  /W0 (MSVC / clang-cl). On MSVC, strip inherited /W[0-4], /Wall, /w,
  /WX, /WX- (plus GCC/Clang -W* / -w flags on clang-cl) from local
  CMAKE_{CXX,C}_FLAGS* and directory COMPILE_OPTIONS before
  add_library(reflectcpp ...) snapshots directory options, preventing
  D9025 override spam in both VS MSBuild and Ninja MSVC without mutating
  parent scope or corrupting /wd*, /WIN32, /bigobj, or -Wl,... flags.
- Replace -Wall with /W4 on MSVC / clang-cl under
  REFLECTCPP_STRICT_WARNINGS (stripping inherited /W[0-4], /Wall, /w
  first to prevent /W3 -> /W4 D9025 warnings) so strict warnings no
  longer expand to MSVC /Wall or clang-cl -Weverything.
- Remove the redundant target_compile_options(reflectcpp PRIVATE
  $<$<CONFIG:Release>:-DNDEBUG>) block left over from munich-data-engineering#519 (CMake's
  CMAKE_CXX_FLAGS_RELEASE already defines -DNDEBUG / /DNDEBUG on Release
  builds, and injecting -DNDEBUG unconditionally via compile options
  duplicated the flag and overrode custom parent Release flags).
- Fix compiled-source warnings under strict Clang/GCC and MSVC /W4:
  - Initialize .values = {} / .fields = {} in src/rfl/env/Writer.cpp
    (-Wmissing-field-initializers).
  - Explicitly declare and out-of-line default copy/move special members
    on rfl::parsing::schema::Type (MSVC C5267 / -Wdeprecated-copy-dtor).
  - Rename structured-binding locals in src/rfl/json/to_schema.cpp so
    default_value no longer hides rfl::default_value (MSVC C4459), and
    move trailing return t into explicit else branches of if constexpr
    in handle_size_variant (MSVC C4702).

Addresses #140.
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.

2 participants