Skip to content

Split part of concepts.h into range_concepts.h#5294

Merged
randombit merged 1 commit intomasterfrom
jack/range-concepts-h
Feb 9, 2026
Merged

Split part of concepts.h into range_concepts.h#5294
randombit merged 1 commit intomasterfrom
jack/range-concepts-h

Conversation

@randombit
Copy link
Owner

Due to this header is quite expensive to compile, and the ranges parts aren't needed by many users of concepts.h - and in fact isn't needed at all in the public API outside of the (deprecated for public use) mem_ops.h

Move the parts of concepts.h related to strong types to that header.

Remove the opportunistic exposure of checked accessors in strong type; it wasn't used outside of tests and the concept is somewhat complicated.

@coveralls
Copy link

coveralls commented Feb 7, 2026

Coverage Status

coverage: 90.075%. remained the same
when pulling 4086b4c on jack/range-concepts-h
into f708c36 on master.

@randombit randombit force-pushed the jack/range-concepts-h branch 5 times, most recently from c9195fc to 0bb839a Compare February 7, 2026 19:18
@randombit randombit requested a review from Copilot February 7, 2026 19:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces compile-time cost of <botan/concepts.h> by splitting range-related concepts/utilities into a dedicated <botan/range_concepts.h>, and relocates strong-type related concepts into <botan/strong_type.h>. It also removes the “opportunistic” forwarding of bounds-checked container accessors (at()) from Strong<>.

Changes:

  • Introduce src/lib/utils/range_concepts.h and move Botan::ranges::* concepts/helpers there.
  • Move strong-type traits/concepts (is_strong_type_v, concepts::*_strong_type, etc.) from concepts.h into strong_type.h, and drop forwarding of at() in the strong container adapter.
  • Update various includes (and a couple missing standard includes) to reflect the header split.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tests/unit_x509.cpp Adds <algorithm> to support std::ranges::find usage.
src/tests/test_strong_type.cpp Removes tests for bounds-checked accessor forwarding (Strong<>::at()).
src/lib/utils/strong_type.h Adds strong-type traits/concepts previously in concepts.h; removes at() forwarding from container adapter.
src/lib/utils/stl_util.h Includes the new <botan/range_concepts.h> (range utilities now live there).
src/lib/utils/range_concepts.h New header providing Botan::ranges::* concepts and byte-length assertion helpers.
src/lib/utils/mem_ops.h Switches from <botan/concepts.h> to <botan/range_concepts.h> for range helpers.
src/lib/utils/loadstor.h Adjusts includes to use <botan/range_concepts.h> after the split.
src/lib/utils/info.txt Exposes range_concepts.h as public (with a TODO note).
src/lib/utils/ct_utils.h Switches from <botan/concepts.h> to <botan/range_concepts.h> for ranges::* usage.
src/lib/utils/concepts.h Removes Botan::ranges::* and strong-type related concepts/traits.
src/lib/utils/assert.cpp Switches include to <botan/range_concepts.h> (contains memory_region_size_violation decl now).
src/lib/utils/alignment_buffer.h Adds <tuple> for std::tuple return type usage.
src/lib/pubkey/ec_group/ec_scalar.h Adds <string_view> for std::string_view parameter usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

inline constexpr void assert_exact_byte_length(const R& r) {
const std::span s{r};
if constexpr(statically_spanable_range<R>) {
static_assert(s.size_bytes() == expected, "memory region does not have expected byte lengths");
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The static_assert message says "expected byte lengths" (plural) although it checks a single expected length. Consider changing it to "expected byte length" to match the condition and to improve diagnostics.

Suggested change
static_assert(s.size_bytes() == expected, "memory region does not have expected byte lengths");
static_assert(s.size_bytes() == expected, "memory region does not have expected byte length");

Copilot uses AI. Check for mistakes.
Due to <ranges> this header is quite expensive to compile, and the
ranges parts aren't needed by many users of concepts.h - and in fact
isn't needed at all in the public API outside of the (deprecated for
public use) mem_ops.h

Move the parts of concepts.h related to strong types to that header.

Remove the opportunistic exposure of checked accessors in strong type;
it wasn't used outside of tests and the concept is somewhat complicated.
@randombit randombit force-pushed the jack/range-concepts-h branch from 5d75e32 to 4086b4c Compare February 9, 2026 10:52
@randombit randombit merged commit 6689463 into master Feb 9, 2026
46 checks passed
@randombit randombit deleted the jack/range-concepts-h branch February 9, 2026 12:29
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.

3 participants