-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Function equality is broken #3371
Comments
Hm, as What does modules system |
I marked this as stale due to inactivity. → More info |
This is still an issue to this date. Just came across the same behaviour while trying to generate random numbers in pure eval... |
I marked this as stale due to inactivity. → More info |
I looked into this again to be able to reimplement it accurately and tried writing up a summary. I think this also accounts aspects of the behavior that were not well-known before (i.e. that it works with non-functions as well and the wrapping value need not be an attribute set). Also I came to the conclusion that we can't remove it as the platform sets in nixpkgs need to be comparable and contain functions. Even if we remove this in nixpkgs, we'll loose the ability to evaluate nixpkgs revisions people will care about. Maybe an experimental feature to disable it down the line would be possible. |
One (good?) thing is that pointer equality is based on the let
inherit (builtins) add;
set = { inherit (builtins) add; };
in
[
(set == set) # => true
({ inherit (set) add; } == { inherit (set) add; }) # => false
({ inherit (builtins) add; } == { inherit (builtins) add; }) # => false
({ inherit add; } == { inherit add; }) # => true
] See also #8462 (comment). |
I want to expand on the C++ Nix behavior, since it seems relevant to note that a lot of operations in C++ Nix (like select) don't preserve pointer equality (see <NixOS/nix#3371 (comment)>). It is especially so, as Tvix establishes pointer equality in a different way and thus shows differing behavior. Therefore I want to additionally document Tvix's current behavior and make it more explicit to what extent nixpkgs needs pointer equality. Change-Id: I9b4ba75dacb749c9fcbba4b9646c6b48bb57bbad Reviewed-on: https://cl.tvl.fyi/c/depot/+/8852 Autosubmit: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
As foretold by the code,
nix/src/libexpr/eval.cc
Line 1749 in 2e953b5
And this seems to be true. If we try to evaluate this:
We get a nice
false
result, as expected. But, what if ... we put the lambda in an attrset?Now, all of a sudden, the two attrsets are equal! But this is impossible, as functions are incomparable!
The reason for this is a 2010 hack added to support "some old broken code that relies on pointer equality":
nix/src/libexpr/eval.cc
Lines 1689 to 1692 in 2e953b5
The text was updated successfully, but these errors were encountered: