Skip to content

GH-48588: [C++] use std::span - #48615

Closed
chakkk309 wants to merge 7 commits into
apache:mainfrom
chakkk309:refactor-replace-arrowutilspan-with-stdspan
Closed

chakkk309 wants to merge 7 commits into
apache:mainfrom
chakkk309:refactor-replace-arrowutilspan-with-stdspan

Conversation

@chakkk309

@chakkk309 chakkk309 commented Dec 21, 2025 •

Copy link
Copy Markdown

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
Copy Markdown

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

@WillAyd WillAyd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

Comment thread 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>

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure

Comment thread 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>>);

Copy link
Copy Markdown
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?

Comment thread cpp/src/arrow/util/span_test.cc Outdated
using testing::PrintToString;

namespace arrow::util {
namespace arrow_util_span_test {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)

Comment thread cpp/src/arrow/array/util.cc Outdated
#include <cstring>
#include <limits>
#include <memory>
#include <span>

Copy link
Copy Markdown
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?

@chakkk309 chakkk309 Jan 14, 2026 •

Copy link
Copy Markdown
Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread cpp/src/arrow/util/secure_string.h Outdated
#include <string>

#include "arrow/util/span.h"
#include <span>

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread cpp/src/parquet/metadata.cc Outdated
#include <utility>
#include <vector>

#include "parquet/metadata.h"

Copy link
Copy Markdown
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.

Comment thread cpp/src/parquet/size_statistics.h Outdated
#include <vector>

#include "arrow/util/span.h"
#include <span>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

Comment thread cpp/src/parquet/thrift_internal.h Outdated
#include <utility>
#include <vector>

#include "parquet/windows_compatibility.h"

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

pitrou commented Jan 12, 2026

Copy link
Copy Markdown
Member

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

@pitrou

pitrou commented Feb 18, 2026

Copy link
Copy Markdown
Member

@chakkk309 Sorry, I missed the updates here. Is this waiting for another review? Feel free to ping us when you're waiting for feedback!

@chakkk309
chakkk309 requested a review from pitrou March 4, 2026 06:35
@chakkk309

Copy link
Copy Markdown
Author

@chakkk309 Sorry, I missed the updates here. Is this waiting for another review? Feel free to ping us when you're waiting for feedback!

Thanks! Yes, it's currently waiting for review :)

@pitrou

pitrou commented Mar 4, 2026

Copy link
Copy Markdown
Member

@chakkk309 Ok, could you clean up unrelated changes? I see you moved some includes, removed some newlines, etc.

@thisisnic

Copy link
Copy Markdown
Member

Closing this as I believe it is obsolete; please feel free to reopen if not!

🤖 : Close as superseded: #49492 (Anakin100100) migrated to std::span and was merged, closing GH-48588 on 2026-03-24. Context: Replaces arrow::util::span with std::span; pitrou asked for unrelated include churn to be removed and a different PR landed the same change first.

@thisisnic thisisnic closed this Oct 23, 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.

4 participants