This is an archive of the discontinued LLVM Phabricator instance.

[libc++][PSTL] Implement std::transform
ClosedPublic

Authored by philnik on May 1 2023, 2:06 PM.

Diff Detail

Event Timeline

philnik created this revision.May 1 2023, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 2:06 PM
philnik requested review of this revision.May 1 2023, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 2:06 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik updated this revision to Diff 518792.May 2 2023, 10:26 AM

Try to fix CI

ldionne requested changes to this revision.May 2 2023, 12:17 PM
ldionne added inline comments.
libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp
22

We should also include a SFINAE test that checks that we SFINAE-out whenever the first argument is not an execution policy. We could do that in a single big test file for all the algorithms, like we did for some ranges algorithms.

30

I think we're missing tests for constraints here and in the other test.

libcxx/test/support/type_algorithms.h
56–60

I would suggest this instead:

template <template <class...> class F, class ...T>
struct partial_instantiation {
  template <class ...Args>
  using apply = F<T..., Args...>;
};

This suggests that we're doing partial application of the template F. apply is often used in these cases so it's kind of idiomatic (e.g. the old MPL and derivatives of it).

This revision now requires changes to proceed.May 2 2023, 12:17 PM
philnik updated this revision to Diff 518886.May 2 2023, 3:26 PM
philnik marked an inline comment as done.

Address comments

libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp
30

What kind of constraints do you mean?

libcxx/test/support/type_algorithms.h
56–60

template <class...> doesn't work when template <class> is expected. I first had it the way you have it right now.

ldionne accepted this revision.May 3 2023, 8:27 AM
ldionne added inline comments.
libcxx/include/__algorithm/pstl_transform.h
36–38

Per your suggestion, we could name those _ForwardIterator and _ForwardOutIterator. And for the binary version, _ForwardIterator1, _ForwardIterator2, and _ForwardOutIterator.

libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp
30

I meant the execution policy constraint that you added a test for, thanks! I don't know why I left two comments that were so similar, maybe I wanted to point out that it was missing from both the tests.

50

We need to test the result type of this algorithm (and all the other PSTL algorithms we have so far, where I think we've neglected that).

libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.unary.pass.cpp
29

Here, let's add a comment explaining "we can't test the constraint on the execution policy, because that would conflict with the binary transform algorithm that doesn't take an execution policy, which is not constrained at all".

This revision is now accepted and ready to land.May 3 2023, 8:27 AM
philnik updated this revision to Diff 519091.May 3 2023, 8:44 AM
philnik marked 4 inline comments as done.

Address comments

ldionne added inline comments.May 3 2023, 1:53 PM
libcxx/test/support/type_algorithms.h
56–60

Ahhhh yeah I remember that issue. I still think apply would be a naming improvement though.

philnik updated this revision to Diff 519281.May 3 2023, 3:23 PM
philnik marked 2 inline comments as done.

Address comments

philnik updated this revision to Diff 519894.May 5 2023, 9:20 AM

Try to fix CI

philnik updated this revision to Diff 520366.May 8 2023, 7:18 AM
  • Rebased
  • Try to fix CI
philnik updated this revision to Diff 520705.May 9 2023, 8:17 AM

Try to fix CI

philnik updated this revision to Diff 521164.May 10 2023, 4:58 PM

Rebased on top of new dispatching scheme

philnik requested review of this revision.May 10 2023, 4:58 PM
philnik updated this revision to Diff 521399.May 11 2023, 11:52 AM

Fix formatting

philnik updated this revision to Diff 521472.May 11 2023, 3:27 PM

Generate files

ldionne accepted this revision.May 12 2023, 8:26 AM

LGTM w/ comments and CI. Thanks!!!

libcxx/include/__algorithm/pstl_transform.h
51

We need to reject the case where a non-forward iterator is provided as the output (and also for the input I guess). Otherwise, folks could try to pass something like back_inserter which is not only invalid but also potentially dangerous (race conditions).

We don't have to do this in this patch, but let's add appropriate static asserts pretty aggressively in the frontend "layer" of all the parallel algorithms in another patch. And from then on let's do it for all the algos.

libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/pstl.transform.binary.pass.cpp
78

I think we can do the lambda trick here. And in all the other patches you have open too, I guess.

This revision is now accepted and ready to land.May 12 2023, 8:26 AM
philnik updated this revision to Diff 521687.May 12 2023, 9:33 AM
philnik marked an inline comment as done.

Address comments

philnik updated this revision to Diff 521734.May 12 2023, 11:28 AM

Try to fix CI

philnik updated this revision to Diff 521777.May 12 2023, 1:23 PM

Try to fix CI

This revision was automatically updated to reflect the committed changes.
philnik reopened this revision.May 15 2023, 6:58 AM
This revision is now accepted and ready to land.May 15 2023, 6:58 AM
This revision was automatically updated to reflect the committed changes.