Fix non-deterministic inherit printing #11123
Merged
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
In very rare cases (I had about 7 cases out of 32200 files!), the order of how inherit-from bindings are printed when using
nix-instantiate --parse
gets messed up.The cause of this seems to be because the std::map the bindings are placed in is keyed on a pointer, which then uses an implementation-defined strict total order.
The fix here is to key the bindings on their displacement instead, which maintains the same order as they appear in the file.
Unfortunately I wasn't able to make a reproducible test for this in the source, there's something about the local environment that makes it unreproducible for me.
However I was able to make a reproducible test in a Nix build on a Nix version from a very recent master:
which shows the difference (prettified for easy viewing):
Context
I've found this when I tried to verify that
nix-instantiate --parse
doesn't change upon applying a formatter on Nixpkgs. Turns out it does change at least because of this.Another unrelated instance of this is #11120
Priorities and Process
This work is sponsored by Antithesis ✨
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.