refactor(libutil/topo-sort): return variant instead of throwing#14479
Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom Nov 10, 2025
Merged
refactor(libutil/topo-sort): return variant instead of throwing#14479Ericson2314 merged 1 commit intoNixOS:masterfrom
Ericson2314 merged 1 commit intoNixOS:masterfrom
Conversation
roberth
approved these changes
Nov 7, 2025
| auto orifu = get(outputReferencesIfUnregistered, name); | ||
| if (!orifu) | ||
| auto topoSortResult = topoSort(outputsToSort, {[&](const std::string & name) { | ||
| auto orifu = get(outputReferencesIfUnregistered, name); |
Member
There was a problem hiding this comment.
Non-blocking: too complicated name. Refactor might improve that by moving to a smaller scope, but no concrete suggestions.
Member
There was a problem hiding this comment.
(existing name it looks like)
| [&](const AlreadyRegistered &) { return StringSet{}; }, | ||
| [&](const PerhapsNeedToRegister & refs) { | ||
| StringSet referencedOutputs; | ||
| /* FIXME build inverted map up front so no quadratic waste here */ |
Member
Author
There was a problem hiding this comment.
The next PR has a fix for that :)
Ericson2314
reviewed
Nov 7, 2025
Ericson2314
reviewed
Nov 7, 2025
Ericson2314
reviewed
Nov 7, 2025
Ericson2314
reviewed
Nov 7, 2025
Member
Ericson2314
left a comment
There was a problem hiding this comment.
tiny nits, then tiny unit test, then looks good!
14c70d0 to
273f7a0
Compare
The variant has on the left-hand side the topologically sorted vector and the right-hand side is a pair showing the path and its parent that represent a cycle in the graph making the sort impossible. This change prepares for enhanced cycle error messages that can provide more context about the cycle. The variant approach allows callers to handle cycles more flexibly, enabling better error reporting that shows the full cycle path and which files are involved. Adapted from Lix commit f7871fc. Change-Id: I70a987f470437df8beb3b1cc203ff88701d0aa1b Co-Authored-By: Maximilian Bosch <maximilian@mbosch.me>
273f7a0 to
182ae39
Compare
Ericson2314
approved these changes
Nov 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The variant has on the left-hand side the topologically sorted vector
and the right-hand side is a pair showing the path and its parent that
represent a cycle in the graph making the sort impossible.
This change prepares for enhanced cycle error messages that can provide
more context about the cycle. The variant approach allows callers to
handle cycles more flexibly, enabling better error reporting that shows
the full cycle path and which files are involved.
Adapted from Lix commit f7871fc.
Change-Id: I70a987f470437df8beb3b1cc203ff88701d0aa1b
Context
Taking another shot at #14218 with inspiration from how the Lix folks handled it :)
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.