docs(tvix): document when pointer equality is preserved in C++ Nix
This explicitly documents behavior of C++ Nix that goes against the intuition you'd gather from this document: that e.g. a simple select from an attribute set causes a value to no longer be pointer equal to its former self. The point of documenting this is that we can show in a to be written section on the use of pointer equality in nixpkgs that pointer equality is only needed in a limited sense for evaluating it (C++ Nix's exterior pointer equality). Tvix's pointer equality is far more powerful since value identity preserving operations also preserve pointer equality, generally speaking (this is because we implement interior pointer equality in my made up terminology). This should eventually also be documented. Change-Id: I6ce7ef2d67b012f5ebc92f9e81bba33fb9dce7d0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8856 Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
4ba624efae
commit
8adc9c56f2
5 changed files with 169 additions and 6 deletions
|
|
@ -1 +1 @@
|
|||
[ true true true true true true true true false false true ]
|
||||
[ true true true true true true true true true true ]
|
||||
|
|
|
|||
|
|
@ -12,9 +12,14 @@ in
|
|||
(alias == builtins.builtins)
|
||||
([ builtins ] == [ builtins ])
|
||||
|
||||
# Surprisingly this only works with the set
|
||||
([ builtins.add ] == [ builtins.add ])
|
||||
({ inherit (builtins) import; } == { inherit (builtins) import; })
|
||||
# But this does
|
||||
# Surprisingly the following expressions don't work. They are
|
||||
# here for documentation purposes and covered only
|
||||
# by eval-okay-select-pointer-inequality.nix. Reasoning is that
|
||||
# we may not want / be able to replicate this behavior at all.
|
||||
# ([ builtins.add ] == [ builtins.add ])
|
||||
# ({ inherit (builtins) import; } == { inherit (builtins) import; })
|
||||
|
||||
# These expressions work as expected, however:
|
||||
(let x = { inherit (builtins) add; }; in x == x)
|
||||
(let inherit (builtins) add; in [ add ] == [ add ])
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
[ false false false false false true false false ]
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
# C++ Nix frequently creates copies of Value structs when evaluating
|
||||
# a variety of expressions. As a result, pointer equality doesn't
|
||||
# work for many (all?) expressions that go beyond simple identifier
|
||||
# access from the scope: Even if the inner representation of the
|
||||
# value still has the same memory location, C++ Nix has created
|
||||
# a copy of the struct that holds the pointer to this memory.
|
||||
# Since pointer equality is established via the location of
|
||||
# the latter, not the former, the values are no longer equal
|
||||
# by pointer.
|
||||
let
|
||||
foo = { bar = x: x; };
|
||||
|
||||
id = x: x;
|
||||
in
|
||||
|
||||
[
|
||||
({ inherit (foo) bar; } == { inherit (foo) bar; })
|
||||
([ foo.bar ] == [ foo.bar ])
|
||||
|
||||
([ builtins.add ] == [ builtins.add ])
|
||||
({ inherit (builtins) import; } == { inherit (builtins) import; })
|
||||
|
||||
([ (id id) ] == [ (id id) ])
|
||||
([ id ] == [ id ])
|
||||
|
||||
(with foo; [ bar ] == [ bar ])
|
||||
(with builtins; [ add ] == [ add ])
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue