POP icon indicating copy to clipboard operation
POP copied to clipboard

Supers are not lazily evaluated

Open Pacman99 opened this issue 2 years ago • 8 comments
trafficstars

nix-repl> pop.lib.pop { supers = [ { a = throw "err"; b = 5; } ]; }
error: err

An attribute in a pop containing an error shouldn't error out the entire pop. Other attributes should still be accessible even if one attribute errors out.

The following code should print out 5, but it would just error out now.

p = pop.lib.pop { supers = [ { a = throw "err"; b = 5; } ]; }
p.b

cc @fare

Pacman99 avatar May 16 '23 22:05 Pacman99

That sounds like a bug indeed: the list of supers should be eagerly evaluated to resolve the multiple inheritance hierarchy, but the fields of the super itself shouldn't. Maybe the bug though isn't in the super handling, but in the casting of prototype-less record to pop prototype? Even then that would be a bug, but a different one.

fare avatar May 17 '23 03:05 fare

Maybe the bug though isn't in the super handling, but in the casting of prototype-less record to pop prototype?

I dont think so, I just used the plain attribute set as an example, but it happens even if that attrset was wrapped in a kPop.

pop.lib.pop { supers = [ (kPop { a = throw "err"; b = 5; }) ]; }

Also errors out.

Pacman99 avatar May 17 '23 04:05 Pacman99

@fare Are there any inquiries pertaining to this matter? I also got the same problem when I trying embed POP into my instance. Thanks

GTrunSec avatar Aug 23 '23 05:08 GTrunSec

I opened this https://github.com/NixOS/nix/issues/8364

Pacman99 avatar Aug 28 '23 07:08 Pacman99

https://twitter.com/Ngnghm/status/1717684526720094339

Lacking the ability to compare structures or functions by pointer identity, or system-provided nonces as identity tags, the only reliable solution is user-provided labels with some naming conventions to retrieve some modularity.

fare avatar Oct 26 '23 23:10 fare

Akshully, we might be able to do proper pointer equality: https://code.tvl.fyi/about/tvix/docs/value-pointer-equality.md

fare avatar Nov 28 '23 16:11 fare

Yeah I just saw that thread! I might give that a try to see if we can fix this issue. I tried something similar with lists which sometimes worked, so hopefully this trick will work fully.

Pacman99 avatar Nov 28 '23 17:11 Pacman99

Note that one part of the problem is ensuring that true is returned when the two are pointer-equal, the other part of the problem is ensuring that false is returned when they are not, instead of an error being thrown or an infinite branch taken.

fare avatar Nov 28 '23 18:11 fare