Skip to content

[libcu++] Specialize cuda::std::formatter for tuple#9593

Open
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:libcuxx_format_tuple
Open

[libcu++] Specialize cuda::std::formatter for tuple#9593
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:libcuxx_format_tuple

Conversation

@davebayer

@davebayer davebayer commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This PR implements:

@davebayer davebayer requested a review from a team as a code owner June 25, 2026 12:29
@davebayer davebayer requested a review from ericniebler June 25, 2026 12:29
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 25, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Note: CodeRabbit is enabled on this repository as a convenience for maintainers and contributors. Use your best judgment when considering its review comments and suggestions — a suggested change may be inadequate, unnecessary, or safe to ignore.
Contributors are not expected to address every comment. Human reviews are what ultimately matter for merging.

Added tuple/pair formatting support to cuda::std::formatter, including the formatter plumbing needed for cppreference’s “tuple_formatter” feature and (when available) corresponding host-stdlib std::tuple/std::pair specializations.

Key changes:

  • Implemented width-aware tuple/pair formatting by introducing __fmt_retarget_buffer and a basic_format_context partial specialization that retargets output for tuple/pair formatting.
  • Added tuple-specific formatter infrastructure in cuda/std/__format/formatters/tuple.h, supporting configurable opening/closing brackets, separators, and the m format specifier for 2-element (pair-like) types; parse validation was extended accordingly.
  • Updated formatter declarations/forward declarations to support the new tuple formatter path (including removing the default _CharT = char for cuda::std::formatter and adjusting __fwd/format.h declarations).
  • Extended output formatting helpers to efficiently handle retarget-buffer iterators (__fmt_copy, __fmt_transform, __fmt_fill).
  • Added tuple-related formatter spec helpers (__fmt_spec_fields_tuple()) and supporting string-literal utilities/macros (notably _CCCL_STRLIT) with associated literal test coverage.
  • Expanded/added tuple-focused tests for tuple formatter behavior and format_to/vformat_to, including additional coverage gated by TEST_FORMAT_LIMITED_ITERATOR_TESTING, plus tests for parse, set_brackets, set_separator, formatting output, and relevant exception/validation paths.

Walkthrough

Adds tuple and pair formatting support in libcudacxx, including formatter plumbing, a retarget buffer/context path, tuple formatter specializations, and tests for format, parse, bracket, separator, format_to, and vformat_to behavior.

Changes

Tuple formatting support

Layer / File(s) Summary
Formatter plumbing
libcudacxx/include/cuda/std/__fwd/format.h, libcudacxx/include/cuda/std/__format/formatter.h, libcudacxx/include/cuda/std/__format_, libcudacxx/include/cuda/std/__format/format_spec_parser.h
Forward declares formatter, removes the _CharT default, includes tuple formatter support, and adds tuple-specific format-spec defaults.
Retarget buffer and context
libcudacxx/include/cuda/std/__format/buffer.h, libcudacxx/include/cuda/std/__format/format_context.h, libcudacxx/include/cuda/std/__format/output_utils.h
Adds __fmt_retarget_buffer<_CharT>, a matching basic_format_context specialization, and retarget-aware output fast paths.
Tuple formatter implementation
libcudacxx/include/cuda/std/__format/formatters/tuple.h
Implements __fmt_formatter_tuple and formatter specializations for cuda::std::pair, cuda::std::tuple, and host std::pair/std::tuple.
Direct formatter tests
libcudacxx/test/support/format_functions_common.h, libcudacxx/test/libcudacxx/std/text/format/format.tuple/*
Adds parse-call validator support and direct tuple formatter tests for format, parse, bracket, and separator behavior.
Iterator tuple tests
libcudacxx/include/cuda/std/__string/literal.h, libcudacxx/test/support/literal.h, libcudacxx/test/libcudacxx/libcxx/literals/str.pass.cpp, libcudacxx/test/libcudacxx/std/text/format/format.functions/*, libcudacxx/test/libcudacxx/std/text/format/format.functions/tests/tuple.h, libcudacxx/test/libcudacxx/std/text/format/format.functions/format_to.tuple.pass.cpp, libcudacxx/test/libcudacxx/std/text/format/format.functions/vformat_to.tuple.pass.cpp
Adds string-literal helpers, shared tuple test helpers, checker guards, and the format_to/vformat_to tuple pass files for iterator-based coverage.

Suggested labels

libcu++

Suggested reviewers

  • ericniebler
  • miscco

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
libcudacxx/include/cuda/std/__format/formatters/tuple.h (1)

10-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Fix the include guard spelling to match the full path.

FORMATERS is missing a T; this violates the project’s full-path include-guard rule.

-#ifndef _CUDA_STD___FORMAT_FORMATERS_TUPLE_H
-#define _CUDA_STD___FORMAT_FORMATERS_TUPLE_H
+#ifndef _CUDA_STD___FORMAT_FORMATTERS_TUPLE_H
+#define _CUDA_STD___FORMAT_FORMATTERS_TUPLE_H
...
-#endif // _CUDA_STD___FORMAT_FORMATERS_TUPLE_H
+#endif // _CUDA_STD___FORMAT_FORMATTERS_TUPLE_H

As per coding guidelines, “Headers must use include guards named from the uppercase full path.”

Also applies to: 207-207

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fa5bfd9d-0946-4920-9049-d87f3bd28a13

📥 Commits

Reviewing files that changed from the base of the PR and between 161beb9 and 856f4d6.

📒 Files selected for processing (20)
  • libcudacxx/include/cuda/std/__format/buffer.h
  • libcudacxx/include/cuda/std/__format/format_context.h
  • libcudacxx/include/cuda/std/__format/format_spec_parser.h
  • libcudacxx/include/cuda/std/__format/formatter.h
  • libcudacxx/include/cuda/std/__format/formatters/tuple.h
  • libcudacxx/include/cuda/std/__format_
  • libcudacxx/include/cuda/std/__fwd/format.h
  • libcudacxx/include/cuda/std/__string/literal.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/format_to.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/format_to_n.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/vformat_to.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/format_to.tuple.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/tests/tuple.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/vformat_to.tuple.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/format.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/parse.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/set_brackets.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/set_separator.pass.cpp
  • libcudacxx/test/support/format_functions_common.h
  • libcudacxx/test/support/literal.h

Comment thread libcudacxx/include/cuda/std/__format/format_context.h
@davebayer davebayer force-pushed the libcuxx_format_tuple branch from 856f4d6 to f378167 Compare June 25, 2026 12:43
Comment thread libcudacxx/include/cuda/std/__format/formatters/tuple.h
}
else
{
::cuda::std::__throw_format_error("Type m requires a pair or a tuple with two elements");

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.

Should this reference "tuple presentation types"?

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.

Yes, exactly!

Comment thread libcudacxx/include/cuda/std/__format/buffer.h Outdated
Comment thread libcudacxx/include/cuda/std/__format/buffer.h Outdated
Comment thread libcudacxx/include/cuda/std/__format/buffer.h Outdated
Comment thread libcudacxx/include/cuda/std/__format/buffer.h Outdated
Comment thread libcudacxx/include/cuda/std/__format/buffer.h Outdated
@github-actions

This comment has been minimized.

@davebayer davebayer force-pushed the libcuxx_format_tuple branch from e335053 to 1d22f09 Compare June 27, 2026 07:21

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f60d3e52-ac80-4fda-a4f1-bb32c1417520

📥 Commits

Reviewing files that changed from the base of the PR and between e335053 and 1d22f09.

📒 Files selected for processing (22)
  • libcudacxx/include/cuda/std/__format/buffer.h
  • libcudacxx/include/cuda/std/__format/format_context.h
  • libcudacxx/include/cuda/std/__format/format_spec_parser.h
  • libcudacxx/include/cuda/std/__format/formatter.h
  • libcudacxx/include/cuda/std/__format/formatters/tuple.h
  • libcudacxx/include/cuda/std/__format/output_utils.h
  • libcudacxx/include/cuda/std/__format_
  • libcudacxx/include/cuda/std/__fwd/format.h
  • libcudacxx/include/cuda/std/__string/literal.h
  • libcudacxx/test/libcudacxx/libcxx/literals/str.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/format_to.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/format_to_n.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/vformat_to.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/format_to.tuple.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/tests/tuple.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/vformat_to.tuple.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/format.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/parse.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/set_brackets.pass.cpp
  • libcudacxx/test/libcudacxx/std/text/format/format.tuple/set_separator.pass.cpp
  • libcudacxx/test/support/format_functions_common.h
  • libcudacxx/test/support/literal.h
✅ Files skipped from review due to trivial changes (4)
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/format_to_n.h
  • libcudacxx/include/cuda/std/_format
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/format_to.tuple.pass.cpp
  • libcudacxx/include/cuda/std/__fwd/format.h
🚧 Files skipped from review as they are similar to previous changes (12)
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/vformat_to.tuple.pass.cpp
  • libcudacxx/include/cuda/std/__string/literal.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/vformat_to.h
  • libcudacxx/test/support/format_functions_common.h
  • libcudacxx/include/cuda/std/__format/format_spec_parser.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/checkers/format_to.h
  • libcudacxx/test/support/literal.h
  • libcudacxx/include/cuda/std/__format/formatter.h
  • libcudacxx/include/cuda/std/__format/buffer.h
  • libcudacxx/include/cuda/std/__format/formatters/tuple.h
  • libcudacxx/include/cuda/std/__format/format_context.h
  • libcudacxx/test/libcudacxx/std/text/format/format.functions/tests/tuple.h

@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 1h 49m: Pass: 80%/120 | Total: 3d 07h | Max: 1h 48m | Hits: 54%/607498

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: In Review

Development

Successfully merging this pull request may close these issues.

2 participants