Skip to content

Use std::move_only_function for parallel evel work items - #585

Merged
edolstra merged 2 commits into
mainfrom
move-work-items
Aug 4, 2026
Merged

Use std::move_only_function for parallel evel work items#585
edolstra merged 2 commits into
mainfrom
move-work-items

Conversation

@edolstra

@edolstra edolstra commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Motivation

This avoids having to put RootValues in std::shared_ptrs.

Context

Summary by CodeRabbit

  • Performance
    • Improved efficiency during parallel evaluation and deep value processing.
    • Reduced overhead when handling concurrent tasks and recursively processing complex values.
    • Improved responsiveness for workloads involving extensive parallel computation or JSON conversion.
  • Reliability
    • Enhanced handling of parallel work for safer execution.
    • Improved support for non-copyable tasks, reducing potential issues during concurrent processing.

std::function requires its callable to be copy-constructible, so work
items that need to root a Value had to wrap the move-only RootValue
in a std::shared_ptr, costing a heap-allocated control block and
atomic reference counting per work item.

Since we build with C++23, we can use std::move_only_function
instead, allowing work items to capture a RootValue directly.

Note that FutureVector::spawn() can no longer brace-initialize the
WorkItems vector, since std::initializer_list requires copyable
elements.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd4e71ea-6efa-47eb-bbb6-41a45ed2cddc

📥 Commits

Reviewing files that changed from the base of the PR and between 78339f6 and 539d5f9.

📒 Files selected for processing (3)
  • src/libexpr/include/nix/expr/parallel-eval.hh
  • src/libutil/include/nix/util/meson.build
  • src/libutil/include/nix/util/move-only-function.hh
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/libutil/include/nix/util/meson.build
  • src/libexpr/include/nix/expr/parallel-eval.hh

📝 Walkthrough

Walkthrough

The parallel evaluation work-item type now accepts move-only callables through a portable MoveOnlyFunction wrapper. Single-item spawning forwards an explicit work-item vector. Evaluation and JSON deep-forcing callbacks capture RootValue directly.

Changes

Parallel evaluation ownership

Layer / File(s) Summary
Move-only function implementation
src/libutil/include/nix/util/move-only-function.hh, src/libutil/include/nix/util/meson.build
Adds the MoveOnlyFunction wrapper with a standard-library implementation path and a move-only type-erased fallback. Registers the header in the public header list.
Move-only work-item API
src/libexpr/include/nix/expr/parallel-eval.hh
Executor::work_t now uses MoveOnlyFunction<void()>. The single-item FutureVector::spawn overload constructs and forwards an Executor::WorkItems vector.
Direct RootValue callback captures
src/libexpr/parallel-eval.cc, src/libexpr/value-to-json.cc
Callbacks capture RootValue directly and use a single dereference when forcing values.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

Suggested reviewers: cole-h

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change to use move-only functions for parallel evaluator work items, despite a minor typo in "evel."
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch move-work-items

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

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request August 4, 2026 12:38 Inactive
cole-h
cole-h previously approved these changes Aug 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/libutil/include/nix/util/move-only-function.hh`:
- Around line 42-43: Update the fallback `Impl` constructor in
`move-only-function.hh` to use forwarding-reference deduction while constraining
construction against the decayed callable type, so copyable lvalue callables are
accepted. Preserve move construction for rvalues and initialize the stored `f`
member through the forwarded argument.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c7ce8a66-099d-47f6-a501-00be6c01225b

📥 Commits

Reviewing files that changed from the base of the PR and between d9ef669 and 78339f6.

📒 Files selected for processing (3)
  • src/libexpr/include/nix/expr/parallel-eval.hh
  • src/libutil/include/nix/util/meson.build
  • src/libutil/include/nix/util/move-only-function.hh
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/libexpr/include/nix/expr/parallel-eval.hh

Comment thread src/libutil/include/nix/util/move-only-function.hh Outdated
@github-actions
github-actions Bot temporarily deployed to pull request August 4, 2026 15:40 Inactive
…e_only_function

libc++ (as of version 21) doesn't implement std::move_only_function
yet, breaking the libcxxStdenv build. Add nix::MoveOnlyFunction,
which aliases std::move_only_function when available (per the
__cpp_lib_move_only_function feature macro) and otherwise provides a
minimal type-erased wrapper that only requires the callable to be
move-constructible.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
@github-actions
github-actions Bot temporarily deployed to pull request August 4, 2026 16:05 Inactive
@edolstra
edolstra enabled auto-merge August 4, 2026 16:22
@edolstra
edolstra added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit e8f0c5f Aug 4, 2026
61 of 64 checks passed
@edolstra
edolstra deleted the move-work-items branch August 4, 2026 16:55
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.

2 participants