Skip to content

[libcu++] Add ranges::__static_size_v trait - #12573

Merged
davebayer merged 1 commit into
NVIDIA:mainfrom
davebayer:static_range_size
Nov 10, 2026
Merged

davebayer merged 1 commit into
NVIDIA:mainfrom
davebayer:static_range_size

Conversation

@davebayer

Copy link
Copy Markdown
Contributor

This PR implements ranges::__static_size_v traits that holds the size of the range if it can be statically determined, dynamic_extent otherwise.

@davebayer
davebayer requested a review from a team as a code owner November 10, 2026 14:09
@davebayer
davebayer requested a review from fbusato November 10, 2026 14:09
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Nov 10, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Nov 10, 2026
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 5b5249e
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 48991e00-3486-4854-bc6a-d3d968efdfab
Commits

Reviewing files that changed from the base of the PR and between e525bcf and 239dde8.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added compile-time size information for ranges with statically known sizes, including built-in arrays, cuda::std::array, fixed-extent spans, and supported custom ranges. Ranges with dynamic or unavailable sizes are identified as having a dynamic extent.
  • Tests
    • Added compile-time coverage for supported range types, cv/ref variations, and dynamic or unavailable sizes, including ranges with non-default-constructible element types.

The change adds cuda::std::ranges::__static_size_v. It yields a compile-time size when ranges::size is a size_t constant expression, and otherwise yields dynamic_extent. Compile-time tests cover built-in and custom range types.

Changes: Static Range Size

Layer / File(s) Summary
Static size computation
libcudacxx/include/cuda/std/__ranges/size.h
The header adds dependencies and defines __static_size_v to compute a static size or return dynamic_extent.
Compile-time validation
libcudacxx/test/libcudacxx/std/ranges/range.access/static_size.compile.pass.cpp
The tests check fixed-size and dynamic-size ranges, unsupported cases, cv/ref forms, and the variable’s result type.

Change: Feature

Merge Risk: Minimal · previous review e525b

This adds a new internal trait, ranges::__static_size_v, and compile-time tests for it. No existing behavior changes, and no merge-blocking risk was found.

Architecture risk: Low · up to 0bfc3

The change affects 1 system.

Changed systems: libcudacxx

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — libcudacxx (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in libcudacxx/test/libcudacxx/std/ranges/range.access/static_size.compile.pass.cpp: Adds headers and test types representing fixed-size and dynamic-size ranges, including member-size, ADL-size, runtime-size, value-dependent-size, sentinel-sized, and disabled-sized cases.
  • observed — Modified behavior in libcudacxx/test/libcudacxx/std/ranges/range.access/static_size.compile.pass.cpp: Adds test_cvref, which asserts the expected static size for mutable, const, volatile, and reference-qualified forms of a type, and verifies the result type is const cuda::std::size_t.
  • observed — Modified behavior in libcudacxx/test/libcudacxx/std/ranges/range.access/static_size.compile.pass.cpp: Adds a compile-time test covering expected sizes for arrays, cuda::std::array, fixed-extent spans, and custom fixed-size ranges; it checks dynamic_extent for dynamic or unsupported cases and runs the test from main.
  • observed — Modified behavior in libcudacxx/include/cuda/std/__ranges/size.h: The header adds the span forward declaration and includes integral_constant and void_t; the other listed includes remain in place.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: NVIDIA/cccl
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 5060e9b
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 03e0f518-c6b0-4bf3-b405-265515bf2d37
Commits

Reviewing files that changed from the base of the PR and between 0bfc31e and e525bcf.

Files selected for processing: 1

  • libcudacxx/include/cuda/std/__ranges/size.h
Files skipped from review as they are similar to previous changes: 1

  • libcudacxx/include/cuda/std/__ranges/size.h

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment on lines +202 to +203
template <class _Tp>
extern _Tp __static_size_object;

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.

declval?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can't be declval, because it would be invoked, triggering the static_assertion inside it

inline constexpr size_t __static_size_impl<
_Tp,
true,
void_t<typename integral_constant<size_t, ::cuda::std::ranges::size(__static_size_object<_Tp>)>::type>> =

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.

Why extract the ::type here? void_t<integral_constant> is enough to exercise the SFINAE. Or I guess void_t<decltype(range::size(...))> would do it too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

void_t<decltype(range::size(...))> wouldn't be enough, we need the value of the invocation, not the return type. We query ::type because we need to make sure that the range::size(...) is a constant expression and instantiates integral_constant

@davebayer
davebayer enabled auto-merge (squash) November 10, 2026 19:45
@davebayer
davebayer merged commit fad3448 into NVIDIA:main Nov 10, 2026
254 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 5h 50m: Pass: 100%/230 | Total: 9d 18h | Max: 5h 50m | Hits: 30%/4260751

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants