-
-
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
Lazy set patterns (argument unpacking) #9159
Comments
Yeah this is somewhat unexpected, when you destructure an attribute set argument, it does so before evaluating the function body. @roberth has a PR to help with this in Nixpkgs: NixOS/nixpkgs#194514 |
I really feel that the relaxed behavior I am proposing should be implemented in Nix rather than in Nixpkgs. Notice, that my (fairly short) example doesn't use Also, I would like to point out that there are some quite significant differences between what I am proposing and what My proposal on the other hand doesn't change the "extra attribute" strictness and as a consequence it ONLY works with argument expansions that have a |
Changing the language is risky. Strictness can sometimes be better, as it tends to have shorter traces that are more relevant. It may be possible to make If #4090 were to be implemented, such a function could still be considered too strict, for evaluating the whole attrset instead of only the attr it needs. In other words, by making attrset laziness fine grained, it requires any checks to be strict. It's not a coincidence that the words "strict" is applied both to things that check, and to things that are not lazy. |
One possible way to preserve the ability to write strict attrset functions, is to add a feature. Example
It may also be possible to add I don't like adding to the language, but at least by having the feature we can both shine a light on the issue of strictness and provide a convenient solution. |
It seems that my initial proposal wasn't super clear, so let me try to clarify my point. I am proposing to change the current behaviour of the Nix language ONLY for argument unpacking with Argument unpacking with let
fun = { a, b, ... }: a + b;
oops = {
a = 1;
b = 2;
c = builtins.throw "never evaluated";
};
in
fun oops # returns 3 I am simply proposing to extend this non-strictness to also affect attribute names (not just the values). What I am proposing is similar to #4090, but much smaller in scope. I believe, that my proposal should be fairly easy to implement, because unlike #4090, it doesn't require completely changing the semantics of the language in regard to attrset keys. In somewhat simplified pseudocode:
Edit: okay, so it's not quite "whatever let
fun = { a, b, c, ... }: a + b;
oops = { a = 1; b = 2; d = "is not c"; };
in
fun oops # should still fail with "function 'fun' called without required argument 'c'" |
Yeah, it's subtle.
We only need to be concerned with the names. Attribute values are consistently non-strict.
This just isn't the case.
Nitpick: Nix. I feel like the idea of it being lazy but still checked on access just blurs the line too much for something that has a performance cost as well. To make it behave like |
Actually, the fact that the value of My point was that To me, this seems like an implementation detail. The whole point of
To be honest, I don't think I quite follow what you are arguing here? Are you talking about the Honestly, I am kind of +/-0 on this issue. Ideally I would prefer to retain the current semantics, but if it's really impossible to "inline" this check somewhere reasonable, then I am totally fine with using the "plain" Actually, unused unpacked arguments could be pretty easily caught with static analysis (whether by linters or by nix itself). |
Consider the following example:
Currently,
overlay1
works as expected (producing{ a = 1; b = 2; c = 3; }
), butoverlay2
fails with an infinite recursion error despite being semantically equivalent (I think?).It would be nice if
overlay2
just worked as well.Additional context
Tangentially related to #4090.
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: