Skip to content

Root values cleanup#554

Merged
edolstra merged 4 commits into
mainfrom
root-values-cleanup
Jul 10, 2026
Merged

Root values cleanup#554
edolstra merged 4 commits into
mainfrom
root-values-cleanup

Conversation

@edolstra

@edolstra edolstra commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Followup to #546. Get rid of the unused RootValue type and rename UniqueRootValue to RootValue. This makes the upstream diff smaller.

Context

Summary by CodeRabbit

  • Refactor
    • Reworked internal value rooting and lifetime management for more consistent handling across evaluation.
    • Updated evaluation caches, installable attribute paths, JSON parsing, and parallel evaluation to use the unified root-value mechanism.
    • Simplified the root-value interface: the root value handle is now move-only, with updated wrapping behavior in parallel force paths and related evaluation utilities.

@coderabbitai

coderabbitai Bot commented Jul 10, 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: 0c441722-8143-44e7-b4d3-3bdfb70a394a

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf0965 and d2a00e3.

📒 Files selected for processing (3)
  • src/libexpr/include/nix/expr/parallel-eval.hh
  • src/libexpr/parallel-eval.cc
  • src/libexpr/value-to-json.cc
✅ Files skipped from review due to trivial changes (1)
  • src/libexpr/include/nix/expr/parallel-eval.hh
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/libexpr/value-to-json.cc
  • src/libexpr/parallel-eval.cc

📝 Walkthrough

Walkthrough

RootValue becomes a move-only owning class replacing UniqueRootValue and root allocation helpers. Evaluator storage, JSON state, parallel work items, installable paths, and generic closures are migrated to the new type.

Changes

Root value ownership migration

Layer / File(s) Summary
RootValue lifecycle implementation
src/libexpr/include/nix/expr/root-value.hh, src/libexpr/root-value.cc
RootValue owns its slot, supports move operations, and performs allocation and release through member methods.
Evaluator cache and binding migration
src/libexpr/include/nix/expr/eval*.hh, src/libexpr/eval*.cc, src/libexpr/json-to-value.cc
Evaluator maps, caches, attribute cursors, static bindings, internal primops, file evaluation, and JSON state use RootValue.
Parallel evaluation root handling
src/libexpr/parallel-eval.cc, src/libexpr/value-to-json.cc, src/libexpr/include/nix/expr/parallel-eval.hh
Parallel work items wrap values in shared RootValue instances and update dereferencing.
Remaining root value consumers
src/libcmd/..., src/libexpr/primops.cc, src/libexpr/include/nix/expr/get-drvs.hh
Installable attribute paths and generic closure rooting construct RootValue, and the related FIXME comment is updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: cole-h

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is relevant but too vague to clearly convey the main change in the PR. Rename it to describe the core change, e.g. "Rename UniqueRootValue to RootValue".
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch root-values-cleanup

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

cole-h
cole-h previously approved these changes Jul 10, 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/libexpr/include/nix/expr/root-value.hh`:
- Around line 11-16: Update the documentation comments for the RootValue class
to remove stale comparisons with the removed UniqueRootValue/copyable variant.
In both affected doc blocks, including the one near RootValue’s declaration and
the block around lines 29–33, delete the “Prefer this over RootValue” and
“RootValue/RootValue” comparison wording while retaining accurate description of
RootValue’s behavior and usage.
🪄 Autofix (Beta)

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: 6edc5bb3-5839-4ccd-9220-2c14f82fb045

📥 Commits

Reviewing files that changed from the base of the PR and between 9b78439 and f7ddbd9.

📒 Files selected for processing (11)
  • src/libcmd/include/nix/cmd/installable-attr-path.hh
  • src/libcmd/installable-attr-path.cc
  • src/libexpr/eval-cache.cc
  • src/libexpr/eval.cc
  • src/libexpr/include/nix/expr/eval-cache.hh
  • src/libexpr/include/nix/expr/eval.hh
  • src/libexpr/include/nix/expr/get-drvs.hh
  • src/libexpr/include/nix/expr/root-value.hh
  • src/libexpr/json-to-value.cc
  • src/libexpr/primops.cc
  • src/libexpr/root-value.cc

Comment on lines 11 to 16
/**
* A move-only handle rooting a Value, i.e. keeping it and everything
* reachable from it alive across garbage collections. Prefer this
* over `RootValue` unless the handle must be copyable (e.g. when it's
* captured in a `std::function`-backed lambda).
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale doc comments left over from the UniqueRootValue rename.

Both doc blocks reference the old two-type distinction that no longer exists:

  • Line 14: "Prefer this over RootValue…" — the documented class is RootValue, so this now advises preferring the type over itself.
  • Line 32: "Use RootValue/RootValue rather than calling this directly." — the duplicated token was previously RootValue/UniqueRootValue.

Since the copyable variant was removed, drop the comparison wording.

📝 Suggested doc wording
 /**
- * A move-only handle rooting a Value, i.e. keeping it and everything
- * reachable from it alive across garbage collections. Prefer this
- * over `RootValue` unless the handle must be copyable (e.g. when it's
- * captured in a `std::function`-backed lambda).
+ * A move-only handle rooting a Value, i.e. keeping it and everything
+ * reachable from it alive across garbage collections.
  */
     /**
      * Allocate a slot from the root value pool, i.e. a GC-visible
      * `Value *` cell that keeps the value it points to alive across
-     * garbage collections. Use `RootValue`/`RootValue` rather than
-     * calling this directly.
+     * garbage collections. Use the `RootValue(Value *)` constructor
+     * rather than calling this directly.
      */

Also applies to: 29-33

🤖 Prompt for 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.

In `@src/libexpr/include/nix/expr/root-value.hh` around lines 11 - 16, Update the
documentation comments for the RootValue class to remove stale comparisons with
the removed UniqueRootValue/copyable variant. In both affected doc blocks,
including the one near RootValue’s declaration and the block around lines 29–33,
delete the “Prefer this over RootValue” and “RootValue/RootValue” comparison
wording while retaining accurate description of RootValue’s behavior and usage.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request July 10, 2026 16:12 Inactive
@edolstra edolstra force-pushed the root-values-cleanup branch from 1bf0965 to d2a00e3 Compare July 10, 2026 16:43
@github-actions github-actions Bot temporarily deployed to pull request July 10, 2026 16:59 Inactive
@edolstra edolstra enabled auto-merge July 10, 2026 17:02
@edolstra edolstra added this pull request to the merge queue Jul 10, 2026
Merged via the queue into main with commit 100e748 Jul 10, 2026
32 checks passed
@edolstra edolstra deleted the root-values-cleanup branch July 10, 2026 18:11
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