test(tvix/eval): genericClosure (pointer) comparison support
genericClosure has very limited support for pointer equality: It relies on comparison (not equality!) in C++ Nix, so as soon as C++ Nix supports comparing lists (langVersion >= 6) we can rely on pointer equality for key. Since Tvix uses equality, not comparison for the insert, our behavior is currently different, as documented by the notyetpassing tests. Change-Id: Ifcd741ed4fc3ccc3825f7038875d56a9918b786a Reviewed-on: https://cl.tvl.fyi/c/depot/+/8720 Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
0005737f11
commit
0f71d8f813
5 changed files with 38 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
[ { key = [ { foo = <LAMBDA>; } ]; val = null; } ]
|
|
@ -0,0 +1,15 @@
|
|||
let
|
||||
foo = x: x;
|
||||
in
|
||||
|
||||
# key needs to be a list since it uses comparison, not equality checks:
|
||||
# lists are comparable in Nix if all non-comparable items in them are equal (e.g.
|
||||
# functions, attribute sets).
|
||||
builtins.genericClosure {
|
||||
startSet = [
|
||||
{ key = [ { inherit foo; } ]; val = null; }
|
||||
];
|
||||
operator = { val, ... }: if val != null then [] else [
|
||||
{ key = [ { inherit foo; } ]; val = throw "no pointer equality? 🥺👉👈"; }
|
||||
];
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
# Attribute sets can't be compared, only checked for equality
|
||||
builtins.genericClosure {
|
||||
startSet = [
|
||||
{ key = { foo = 21; }; }
|
||||
];
|
||||
operator = _: [
|
||||
{ key = { bar = 21; }; }
|
||||
];
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
let
|
||||
id = x: x;
|
||||
in
|
||||
|
||||
builtins.genericClosure {
|
||||
startSet = [ { key = id; first = true; } ];
|
||||
operator =
|
||||
{ first, ... }:
|
||||
if first then [
|
||||
{ key = id; first = false; }
|
||||
] else [];
|
||||
}
|
|
@ -55,6 +55,7 @@ let
|
|||
"eval-okay-sort.nix" = [ nix ];
|
||||
"eval-okay-compare-lists.nix" = [ nix ];
|
||||
"eval-okay-value-pointer-compare.nix" = [ nix ];
|
||||
"eval-okay-builtins-genericClosure-pointer-equality.nix" = [ nix ];
|
||||
# getAttrPos gains support for functionArgs-returned sets after 2.3
|
||||
"eval-okay-getattrpos-functionargs.nix" = [ nix ];
|
||||
# groupBy appeared (long) after 2.3
|
||||
|
|
Loading…
Reference in a new issue