-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-48588: [C++] use std::span #48615
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
base: main
Are you sure you want to change the base?
GH-48588: [C++] use std::span #48615
Conversation
|
|
WillAyd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
cpp/src/arrow/array/data.h
Outdated
| #include "arrow/util/bit_util.h" | ||
| #include "arrow/util/macros.h" | ||
| #include "arrow/util/span.h" | ||
| #include <span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the span include to be with the other stdlib headers, rather than down here with the arrow headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
cpp/src/arrow/util/span_test.cc
Outdated
| static_assert(std::is_same_v<decltype(span(vec)), span<int>>); | ||
| static_assert(std::is_same_v<decltype(span(const_arr)), span<const int>>); | ||
| static_assert(std::is_same_v<decltype(span(const_vec)), span<const int>>); | ||
| static_assert(std::is_same_v<decltype(span(arr)), std::span<int>>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static_assert(std::is_same_v<decltype(span(arr)), std::span<int>>); | |
| static_assert(std::is_same_v<decltype(std::span(arr)), std::span<int>>); |
Should these have the namespace too?
cpp/src/arrow/util/span_test.cc
Outdated
| using testing::PrintToString; | ||
|
|
||
| namespace arrow::util { | ||
| namespace arrow_util_span_test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still required for other members?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, i think this test file is no longer needed, so i will remove it.
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "arrow/array/util.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our style conventions currently favor putting the .h inclusion corresponding to a .cc file at the top of said .cc file, so you could leave this as-is.
(no strong feelings from me, though)
cpp/src/arrow/array/util.cc
Outdated
| #include <cstring> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you didn't have to do any code-level changes in this file, then probably <span> does not need to be included at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. this file no longer includes <span> since it isn’t used.
|
|
||
| using arrow::internal::VisitSetBitRunsVoid; | ||
| using arrow::util::span; | ||
| using std::span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this and spell std::span in full everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do the updates.
| using ::arrow::internal::checked_cast; | ||
| using ::arrow::internal::FirstTimeBitmapWriter; | ||
| using ::arrow::util::span; | ||
| using std::span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
| namespace arrow::compute::internal { | ||
|
|
||
| using ::arrow::util::span; | ||
| using std::span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
| namespace arrow::compute::internal { | ||
|
|
||
| using ::arrow::util::span; | ||
| using std::span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in all other similar places too :)
| #include <span> | ||
| #include <utility> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move those up again? The GTest inclusion should be separate from standard library inclusions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated. The GTest include is now separated from the stdlib headers in the affected test files.
| #if defined(ARROW_USE_OPENSSL) | ||
| # include <openssl/crypto.h> | ||
| # include <openssl/opensslv.h> | ||
| #endif | ||
|
|
||
| #include "arrow/util/windows_compatibility.h" | ||
| #if defined(_WIN32) | ||
| # include <windows.h> | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove all these? Most probably they're required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an accidental removal on my part, and I’ll restore the required items.
cpp/src/arrow/util/secure_string.h
Outdated
| #include <string> | ||
|
|
||
| #include "arrow/util/span.h" | ||
| #include <span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's no other change in this header, then <span> is probably not required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<span> is required here because SecureString::as_span() returns std::span, so the header needs the include.
| #include <openssl/aes.h> | ||
| #include <openssl/err.h> | ||
| #include <openssl/evp.h> | ||
| #include <openssl/rand.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like with GTest, can we keep OpenSSL inclusions separate from standard library inclusions?
| #include <vector> | ||
|
|
||
| #include "arrow/util/span.h" | ||
| #include <span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this up with stdlib inclusions.
cpp/src/parquet/metadata.cc
Outdated
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "parquet/metadata.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this at the top of file as it was.
cpp/src/parquet/size_statistics.h
Outdated
| #include <vector> | ||
|
|
||
| #include "arrow/util/span.h" | ||
| #include <span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
cpp/src/parquet/thrift_internal.h
Outdated
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "parquet/windows_compatibility.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this in its former place.
|
Thanks for doing this @chakkk309! Can you make sure you address all the review comments I posted? Also, please watch for CI results and try to address any failures if they look related :-) |
Rationale for this change
Replace custom
arrow::util::spanimplementation with C++20std::spanas suggested in issue #48588. This modernizes the codebase and removes ~130 lines of custom code.What changes are included in this PR?
src/arrow/util/span.h(custom span implementation)arrow::util::span<T>usage withstd::span<T>(95 occurrences)#include "arrow/util/span.h"to#include <span>(41 files)Are these changes tested?
Yes - created comprehensive tests verifying std::span compatibility with all original arrow::util::span functionality including construction, subspan, element access, and byte conversion.
Are there any user-facing changes?
No user-facing changes.