-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
doc: Document "evaluation order", some strictness, equality quirk, ||, &&
#14728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xokdvium
merged 3 commits into
NixOS:master
from
roberth:doc-evaluation-infinite-recursion
Dec 7, 2025
+166
−5
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
1 change: 1 addition & 0 deletions
1
tests/functional/lang/eval-okay-equal-function-attrset-distinct-similar.exp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| false |
3 changes: 3 additions & 0 deletions
3
tests/functional/lang/eval-okay-equal-function-attrset-distinct-similar.nix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Distinct but not identical functions in attribute set compare as unequal | ||
| # See https://nix.dev/manual/nix/latest/language/operators#equality | ||
| { a = (x: x); } == { a = (x: x); } |
1 change: 1 addition & 0 deletions
1
tests/functional/lang/eval-okay-equal-function-attrset-identical.exp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| true |
10 changes: 10 additions & 0 deletions
10
tests/functional/lang/eval-okay-equal-function-attrset-identical.nix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Function comparison in attribute set uses value identity optimization | ||
| # See https://nix.dev/manual/nix/latest/language/operators#value-identity-optimization | ||
| let | ||
| f = x: x; | ||
| in | ||
| { | ||
| a = f; | ||
| } == { | ||
| a = f; | ||
| } |
1 change: 1 addition & 0 deletions
1
tests/functional/lang/eval-okay-equal-function-direct-distinct-similar.exp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| false |
3 changes: 3 additions & 0 deletions
3
tests/functional/lang/eval-okay-equal-function-direct-distinct-similar.nix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Direct comparison of distinct but not identical functions returns false | ||
| # See https://nix.dev/manual/nix/latest/language/operators#equality | ||
| (x: x) == (x: x) |
1 change: 1 addition & 0 deletions
1
tests/functional/lang/eval-okay-equal-function-direct-identical.exp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| false |
6 changes: 6 additions & 0 deletions
6
tests/functional/lang/eval-okay-equal-function-direct-identical.nix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Direct comparison of identical function returns false | ||
| # See https://nix.dev/manual/nix/latest/language/operators#equality | ||
| let | ||
| f = x: x; | ||
| in | ||
| f == f |
1 change: 1 addition & 0 deletions
1
tests/functional/lang/eval-okay-equal-function-list-distinct-similar.exp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| false |
3 changes: 3 additions & 0 deletions
3
tests/functional/lang/eval-okay-equal-function-list-distinct-similar.nix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Distinct but not identical functions in list compare as unequal | ||
| # See https://nix.dev/manual/nix/latest/language/operators#equality | ||
| [ (x: x) ] == [ (x: x) ] |
1 change: 1 addition & 0 deletions
1
tests/functional/lang/eval-okay-equal-function-list-identical.exp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| true |
6 changes: 6 additions & 0 deletions
6
tests/functional/lang/eval-okay-equal-function-list-identical.nix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Function comparison in list uses value identity optimization | ||
| # See https://nix.dev/manual/nix/latest/language/operators#value-identity-optimization | ||
| let | ||
| f = x: x; | ||
| in | ||
| [ f ] == [ f ] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a tad confusing, since attribute name order depends on the symbol table order and that can be a source of unsoundness. Not sure this is worth documenting yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have an unsoundness problem, but a nondeterminism problem in terms of whether it succeeds to even evaluate or not, which is not a soundness problem if you define equality to be strict in
deepSeq [a b].But yeah. See that comment with "woeful" in it I guess.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much, yeah. It's deterministic in a sense that at least it doesn't change from one run to another for a particular nix version (modulo any sort of parallel evaluation that has been floating around). But for the user it might as well be unspecified and we must be able to add stuff to the static pre-filled symbol table, which will change attribute ordering anyway. It's a very messy situation to be in tbh if one wants to compare attribute sets deterministically.
This discussion opens up the notion that changing anything around which symbols get added to the symbol table and in which order have the opportunity to change what code succeeds to evaluate and which doesn't...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Value equality is something to avoid anyway, so maybe just make it alphabetic? Slightly slower, but problem solved.
If I may apologize in advance for this writing style while I have some fun...
Why bad, you may ask?
"But I'm not comparing for equality, but values being unequal!"
"But I have a functional key that's not a string, so I can use an attrset!"