Skip to content
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

Continue C++20 modernization #688

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Continue C++20 modernization #688

merged 1 commit into from
Feb 12, 2025

Conversation

laurynas-biveinis
Copy link
Owner

@laurynas-biveinis laurynas-biveinis commented Feb 7, 2025

  • qsbr.hpp: replace std::enable_if_t with requires
  • db_test_utils.hpp: replace std::enable_if_t with requires, iterator pairs
    with ranges, update includes, fix clang-tidy warning on const field.

Summary by CodeRabbit

  • Refactor

    • Modernized the thread initialization interface by removing certain restrictions, offering greater flexibility when launching operations.
    • Improved the structure and readability of test utilities by updating method signatures and leveraging modern language constructs.
  • Tests

    • Enhanced test utilities by updating dependency inclusions and streamlining method signatures with modern language constructs, resulting in clearer and more maintainable verification routines.

@laurynas-biveinis laurynas-biveinis self-assigned this Feb 7, 2025
Copy link

coderabbitai bot commented Feb 7, 2025

Walkthrough

This update removes a template constraint from the qsbr_thread constructor in qsbr.hpp, allowing the constructor to accept any callable type without enforcing that it is not a qsbr_thread. In test/db_test_utils.hpp, header inclusions have been revised, and several functions in the tree_verifier class have been refactored to use C++20 concepts with requires clauses. Additionally, equality checking now utilizes std::ranges::equal, and the copy constructor for tree_verifier has been deleted. These changes streamline function signatures and modernize the code.

Changes

File Change Summary
qsbr.hpp Modified qsbr_thread constructor by removing the template parameter constraint that disallowed passing qsbr_thread as the callable type.
test/db_test_utils.hpp Updated headers: added <iomanip>, removed <__fwd/sstream.h>, <iterator>, and commented-out <gtest/gtest.h>; refactored assert_value_eq to use std::ranges::equal; simplified tree_verifier method templates using requires clauses; deleted the copy constructor.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant qsbr_thread
  User->>qsbr_thread: Call constructor with function & arguments
  qsbr_thread-->>User: Instance created (no constraint enforced)
Loading
sequenceDiagram
  participant Test
  participant tree_verifier
  participant Database
  Test->>tree_verifier: Invoke do_insert(key, value)
  alt Db is non-olc type
    tree_verifier->>Database: Perform insertion (non-olc branch)
  else Db is olc type
    tree_verifier->>Database: Perform insertion (olc branch)
  end
  Database-->>tree_verifier: Confirmation
  tree_verifier-->>Test: Return result
Loading

Poem

I'm a hopping coder, stealing a glance,
At changes that let functions freely dance.
No more limits in thread creation's art,
Tree verifiers now play a modern part.
With headers aligned and clauses so neat,
I nibble on code carrots—oh, how sweet!
Hop on, code friends, let progress be our treat!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec94d78 and 6127fc7.

📒 Files selected for processing (2)
  • qsbr.hpp (1 hunks)
  • test/db_test_utils.hpp (12 hunks)
🔇 Additional comments (13)
test/db_test_utils.hpp (12)

16-16: Consider removing unused pragma.
The pragma for <iomanip> is still present, but there is no visible usage of <iomanip> in this file.


31-31: Consider removing the <gmock/gmock.h> include.
No references to gMock APIs are apparent, so this include seems unnecessary.


38-38: Remove or confirm the necessity of art_internal.hpp.
No direct references to content from "art_internal.hpp" are evident, so it may be unused.


146-149: Migrate from std::enable_if_t to requires.
These lines mention a future migration to C++20 concepts. Now that the PR adopts C++20 features, consider replacing std::enable_if_t immediately if the compiler support is guaranteed.


163-163: No concerns.
This line marks the end of the lint suppression. Nothing actionable here.


223-227: Migrate from std::enable_if_t to requires.
This section repeats the same notice. If you’re consistently on C++20, removing these comments and using concepts might keep the codebase more streamlined.


240-240: No concerns.
This line also just marks the end of a lint suppression.


348-352: Migrate from std::enable_if_t to requires.
Similar to the earlier blocks, you can remove or replace enable_if with concepts if C++20 is fully supported.


378-378: No concerns.
Lint suppression end marker.


401-405: Migrate from std::enable_if_t to requires.
Again, repeating the same note for future modernization.


418-418: No concerns.
Another lint suppression end marker.


500-501: Good job removing copy/assignment.
Explicitly deleting both the copy constructor and assignment operator clarifies the non-copyable design.

qsbr.hpp (1)

1242-1244: Nice usage of C++20 requires.
Replacing SFINAE logic with a requires clause aligns with the PR’s modernization goal. This approach simplifies template constraints and increases clarity.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a89f5f and f91e3b3.

📒 Files selected for processing (2)
  • qsbr.hpp (1 hunks)
  • test/db_test_utils.hpp (9 hunks)
🔇 Additional comments (5)
test/db_test_utils.hpp (4)

16-16: No functional change in IWYU pragma
This line merely updates the IWYU directive; it does not affect functionality or compilation.


222-232: Clean transition to requires
Using requires here instead of template specializations clarifies intent and modernizes the code. Looks good.


340-361: Consistently applied requires-based overloads
All overloads split logically for olc_db and non-olc_db. No issues found.


383-392: Requires usage for try_get
The pattern matches other methods—quiescent state handling in olc_db only. This is consistent and clear.

qsbr.hpp (1)

1245-1247: Modern requires clause
Switching from std::enable_if_t to a requires clause simplifies the constructor constraints and is more readable in C++20. No issues found.

@laurynas-biveinis laurynas-biveinis force-pushed the c++20-requires branch 2 times, most recently from efdabde to 863f7c8 Compare February 9, 2025 13:01
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efdabde and 863f7c8.

📒 Files selected for processing (2)
  • qsbr.hpp (1 hunks)
  • test/db_test_utils.hpp (10 hunks)
🔇 Additional comments (14)
test/db_test_utils.hpp (13)

16-16: No issues with the updated IWYU pragma.
This line merely adjusts a no-include directive; no action required.


91-94: Good modernization to std::ranges::equal.
Switching from std::equal to std::ranges::equal is consistent with C++20 features and clarifies behavior for range-based comparisons.


146-149: Redundant comment about eventual use of requires.


163-163: No concerns with ending the linter suppress directive.


222-222: No issues with closing preprocessor directive.


223-227: Repeats earlier mention of migrating to requires.


348-349: Modernization: C++20 requires constraint.
Transitioning from std::enable_if_t to requires for remove(...) clarifies the intended preconditions.


353-354: Consistent requires-based overload.
The second remove(...) overload correctly applies the opposite constraint for OLC databases.


359-360: try_remove(...) constraint alignment.
Using requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) here matches the style established above.


364-365: OLC-specific try_remove(...) overload.
Declaring requires(std::is_same_v<Db, unodb::olc_db<key_type>>) for the OLC path maintains consistency.


391-392: Modern constraints for try_get(...)
Applying requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) ensures the method is hidden for OLC DB types.


396-397: OLC specialization for try_get(...)
Overloading with requires(std::is_same_v<Db, unodb::olc_db<key_type>>) follows the pattern for specialized functions.


482-483: Deleted copy/assignment for tree_verifier.

qsbr.hpp (1)

1242-1244: Using C++20 requires for constructor constraints.
Replacing std::enable_if_t with requires improves readability and aligns with modern C++ guidelines.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
test/db_test_utils.hpp (1)

38-38: Verify necessity of "art_internal.hpp".
It’s unclear if entities from "art_internal.hpp" are used in this file. Consider removing this include if it’s no longer needed.

- #include "art_internal.hpp"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.


📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 863f7c8 and 8c8cb56.

📒 Files selected for processing (2)
  • qsbr.hpp (1 hunks)
  • test/db_test_utils.hpp (11 hunks)
🔇 Additional comments (14)
test/db_test_utils.hpp (13)

31-31: Header usage looks good.
<gmock/gmock.h> is actively used by matchers like ::testing::ElementsAreArray in this file, so this inclusion is justified.


91-91: Excellent adoption of std::ranges::equal.
Ensure your build environment includes <ranges> or that your standard library’s version of <algorithm> has the C++20 <ranges> facility.


94-94: Same note on std::ranges::equal.
Confirm that the necessary C++20 headers are available.


146-149: Reference to replacing std::enable_if_t with requires.
This duplicates a past comment recommending a switch to C++20 constraints. Thanks for adding a note about planned migration.


223-227: Repeated plan for migrating to requires.
A similar note applies here regarding eventual replacement of std::enable_if_t.


240-240: NOLINT block end detected.
No concerns; the comment block is clearly marked.


348-352: Repeated plan for migrating these methods to requires.
Again, this comment mirrors prior references to future C++20 changes.


365-365: NOLINT block end detected.
No issues; the code style suppression is neatly closed.


367-368: Well-structured requires usage.
Replacing SFINAE with constraints clarifies intent and cleans up the signature.


372-374: Consistent requires usage for try_remove.
This follows the same pattern as above, adding clarity to method constraints.


399-400: Use of requires improves readability.
Eliminates the need for repetitive template boilerplate and is consistent with C++20 style.


404-405: C++20 requires again well-applied.
Maintaining two overloads with distinct conditions is more transparent than enable_if.


490-492: Copy constructor & assignment operator now deleted.
This addresses prior feedback about making non-copyable intentions explicit.

qsbr.hpp (1)

1242-1245: Constructor now uses a requires clause.
Great modernization to enforce that qsbr_thread cannot construct itself with the same type, simplifying template logic.

@laurynas-biveinis laurynas-biveinis added bug Something isn't working and removed bug Something isn't working labels Feb 11, 2025
- qsbr.hpp: replace std::enable_if_t with requires
- db_test_utils.hpp: comment on replacing std::enable_if_t with requires once
- LLVM 15 is the oldest supported LLVM version, replace iterator pairs with
  ranges, update includes, fix clang-tidy warning on a const field.
@laurynas-biveinis laurynas-biveinis merged commit 3044234 into master Feb 12, 2025
198 of 201 checks passed
@laurynas-biveinis laurynas-biveinis deleted the c++20-requires branch February 12, 2025 11:52
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.

1 participant