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

[oneDPL][ranges][tests] a fix for std::ranges::<algo> using with Windows C++ standard library. #1920

Merged
merged 10 commits into from
Nov 18, 2024

Conversation

MikeDvorskiy
Copy link
Contributor

[oneDPL][ranges][tests] a fix for std::ranges::sort using with Windows C++ standard library.
This PR is a sequel for #1885.

@dmitriy-sobolev dmitriy-sobolev added the test Test only Change label Oct 23, 2024
@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/std_ranges_test_sort_fix_windows branch 2 times, most recently from a4b1db9 to 6f8de9b Compare October 23, 2024 16:52
@@ -21,18 +21,24 @@ main()
#if _ENABLE_STD_RANGES_TESTING
using namespace test_std_ranges;
namespace dpl_ranges = oneapi::dpl::ranges;
auto sort_checker =
#if _ONEDPL_STD_RANGES_ALGO_CPP_FUN
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you introduce a similar macro in the tests in order not to rely on oneDPL internals?

Copy link
Contributor Author

@MikeDvorskiy MikeDvorskiy Oct 24, 2024

Choose a reason for hiding this comment

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

I still strong disagree to make the code duplication.
Rather lets consider a an option to make public that macro....

Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev Oct 24, 2024

Choose a reason for hiding this comment

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

I do not think that having a public macro for that is a good idea given that it is a workaround for a niche issue, not resulting in enablement of any oneDPL feature. Also, I understand that duplication increases maintenance burden,
but I would duplicate this small code section to decouple the tests and implementation. I guess we need a mediator here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Relocating my comment here, I missed this discussion in my initial review. I agree with Dmitriy here, this has been the convention as established by @akukanov.

We have tried to stay away from using internal helpers / utilities / implementation details in our tests.

If we want to use the same macro here, I think we probably want to re-define it here test/support/utils.h, or somewhere similar as _TEST_PREPARE_CALLABLE, or something like that, then use that throughout the tests.

Copy link
Contributor

@akukanov akukanov Nov 14, 2024

Choose a reason for hiding this comment

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

In the essence, here we have two good engineering practices contradicting each other, and we need to choose between "avoid code duplication" and "avoid test dependencies on implementation internals". I choose the second, because most if not all code duplications between the implementation and its tests are simple self-contained utilities or macros and duplicating those does not seem problematic to me.

Moreover, strictly speaking, the tests in this patch do not even have to use _ONEDPL_PREPARE_CALLABLE - range algorithms can always be wrapped into a lambda, possibly with a small "syntax sugar" helper.

Added: actually, since C++20 does not guarantee that range algorithms are function objects (this might change in C++26, but that's a separate question), the code that assumes that is at best implementation dependent. While we may want to do it in the implementation for the sake of performance or compilation efficiency (though it would better be proven with data as well), I see no single reason to do it in the tests. So I would say the tests should always wrap range algorithms into a lambda.

Copy link
Contributor Author

@MikeDvorskiy MikeDvorskiy Nov 15, 2024

Choose a reason for hiding this comment

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

I see..
But we missed a way with passing a callable function by reference - foo(f&& f) - https://godbolt.org/z/j1P6MKdvn
Is the implementation of a C++ function/algorithm with doesn't match to foo(f&& f)?

Update: another issue in case of F&&:

<source>(18): error C2672: 'foo': no matching overloaded function found
<source>(18): error C2783: 'void foo(F &&)': could not deduce template argument for 'F'
<source>(8): note: see declaration of 'foo'

@MikeDvorskiy MikeDvorskiy changed the title [oneDPL][ranges][tests] a fix for std::ranges::sort using with Windows C++ standard library. [oneDPL][ranges][tests] a fix for std::ranges::<algo> using with Windows C++ standard library. Oct 24, 2024
Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev left a comment

Choose a reason for hiding this comment

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

The PR solves the problem, but I cannot decide whether to approve it or not due to the approach (using internal macro in the tests, using a macro, where it is possible to have an ordinary function). Let's add more reviewers for more opinions.

Update regarding "it is possible to have an ordinary function": I was not able to find such a solution. Providing specializations for signatures of specific algorithms (similar to the existing "checker" entities in the tests) is an alternative, but the solution with a macro is simpler.

@danhoeflinger
Copy link
Contributor

I think I agree with the clang-format suggestions, but not a blocker for me.

@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/std_ranges_test_sort_fix_windows branch 3 times, most recently from 322e0ea to 545cd75 Compare November 8, 2024 13:47
@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/std_ranges_test_sort_fix_windows branch from 5a9bcaf to 8ff4006 Compare November 18, 2024 09:35
Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev left a comment

Choose a reason for hiding this comment

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

The PR looks good to me leaving aside a couple of issues easy to fix.

@MikeDvorskiy MikeDvorskiy merged commit 4898de2 into main Nov 18, 2024
22 checks passed
@MikeDvorskiy MikeDvorskiy deleted the dev/mdvorski/std_ranges_test_sort_fix_windows branch November 18, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Test only Change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants