Skip to content

Conversation

@chakkk309
Copy link

@chakkk309 chakkk309 commented Dec 21, 2025

Rationale for this change

Replace custom arrow::util::span implementation with C++20 std::span as suggested in issue #48588. This modernizes the codebase and removes ~130 lines of custom code.

What changes are included in this PR?

  • Removed src/arrow/util/span.h (custom span implementation)
  • Replaced all arrow::util::span<T> usage with std::span<T> (95 occurrences)
  • Updated all #include "arrow/util/span.h" to #include <span> (41 files)
  • Modified span tests to use std namespace

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.

@chakkk309 chakkk309 requested a review from wgtmac as a code owner December 21, 2025 08:00
@github-actions
Copy link

⚠️ GitHub issue #48588 has been automatically assigned in GitHub to PR creator.

Copy link
Contributor

@WillAyd WillAyd left a 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!

#include "arrow/util/bit_util.h"
#include "arrow/util/macros.h"
#include "arrow/util/span.h"
#include <span>
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

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

sure

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>>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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?

using testing::PrintToString;

namespace arrow::util {
namespace arrow_util_span_test {
Copy link
Contributor

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?

Copy link
Author

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.

@chakkk309 chakkk309 requested a review from WillAyd December 24, 2025 13:18
// specific language governing permissions and limitations
// under the License.

#include "arrow/array/util.h"
Copy link
Member

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)

#include <cstring>
#include <limits>
#include <memory>
#include <span>
Copy link
Member

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?

Copy link
Author

@chakkk309 chakkk309 Jan 14, 2026

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;
Copy link
Member

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?

Copy link
Author

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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 :)

Comment on lines 21 to 22
#include <span>
#include <utility>
Copy link
Member

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.

Copy link
Author

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.

Comment on lines 24 to 33
#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

Copy link
Member

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.

Copy link
Author

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.

#include <string>

#include "arrow/util/span.h"
#include <span>
Copy link
Member

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?

Copy link
Author

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.

Comment on lines 22 to 25
#include <openssl/aes.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
Copy link
Member

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>
Copy link
Member

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.

#include <utility>
#include <vector>

#include "parquet/metadata.h"
Copy link
Member

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.

#include <vector>

#include "arrow/util/span.h"
#include <span>
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

#include <utility>
#include <vector>

#include "parquet/windows_compatibility.h"
Copy link
Member

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.

@pitrou
Copy link
Member

pitrou commented Jan 12, 2026

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 :-)

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants