Skip to content

Span: drop the <iterator> include - #8

Merged
eyalamirmusic merged 2 commits into
mainfrom
span-drop-iterator-include
Nov 29, 2026
Merged

eyalamirmusic merged 2 commits into
mainfrom
span-drop-iterator-include

Conversation

@eyalamirmusic

@eyalamirmusic eyalamirmusic commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Motivation

Span.h included <iterator> only for std::reverse_iterator<T*> in rbegin/rend. <iterator> is a heavy header, and Span.h is reached from Containers.h and so from most downstream translation units. Dropping it saves about 11% of the Span.h/Containers.h parse cost in isolation, and about 1.5–5% per TU in a downstream project built with _LIBCPP_REMOVE_TRANSITIVE_INCLUDES.

Portability

<span> already makes std::reverse_iterator available on all three standard libraries, because std::span's own reverse_iterator member type needs it:

  • libc++: <span> includes <__iterator/reverse_iterator.h>.
  • libstdc++ (gcc 16): <span> includes <bits/stl_iterator.h>. Verified that a TU including only <span> and using std::reverse_iterator<int*> compiles with g++ and with clang + libstdc++ at C++20, C++23 and C++26.
  • MSVC STL (14.52): <span> includes <xutility>, which defines reverse_iterator.

Verification

  • Library tests: 563/563 pass locally on macOS.
  • Every library header compiles standalone identically before and after on libc++, g++ and clang + libstdc++.
  • A downstream project's 556 TUs that use Span or iterators syntax-check unchanged.
  • Measured instruction counts: Span.h alone 1142M → 998M (-12.6%), Containers.h -10.9%; downstream Core.h -1.7%, Strings.cpp -4.9%.

CI fix (second commit)

The windows-latest image moved to MSVC STL 14.52, which refuses Clang older than 22 (STL1000), so "Windows Clang" failed before compiling anything — on any branch, not because of this change. The second commit builds both clang-cl lanes with the clang-cl inside Visual Studio (VC\Tools\Llvm) instead of the image's standalone LLVM on PATH, the same fix eacp took. It is included here so this PR's CI can go green.

Span.h included <iterator> only for std::reverse_iterator<T*> in
rbegin/rend. <span> already makes std::reverse_iterator available
(std::span's own reverse_iterator member type needs it) on libc++,
libstdc++ and MSVC STL.

Saves ~11% of the Span.h/Containers parse cost in isolation, and
~1.5-5% per TU in a downstream project under
_LIBCPP_REMOVE_TRANSITIVE_INCLUDES.
The windows-latest image moved to MSVC 14.52, whose STL refuses any Clang
older than 22 (STL1000). The x64 lane picked up the image's standalone
LLVM from PATH, so it failed before compiling anything. Both clang-cl
lanes now take the clang-cl under VC\Tools\Llvm, the one the STL was
released against, and hand it to CMake as CC and CXX.
@eyalamirmusic
eyalamirmusic merged commit 63f513c into main Nov 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant