Repository navigation
libexpr: throw a more helpful eval-error if a builtin is not available due to a missing feature-flag - #5301
Conversation
thufschmitt
left a comment
There was a problem hiding this comment.
The logic seems right, but I’m (very vaguely) worried about a possible performance impact on the evaluation (because the check for a missing feature needs to happen at each primop call).
Maybe you could rewrite the primop registration logic as something along the lines of:
if (!primOp.requiredFeature || settings.isExperimentalFeatureEnabled(*primOp.requiredFeature))
addPrimOp({
.fun = primOp.fun,
...
});
else
addPrimOp({
.fun = [](EvalState foo, Pos pos, Value ** args, Value & v){ throw EvalError("Builtin %s requires the experimental feature %s", primOp.name, *primOp.requiredFeature),
...
});
...
});so that we don’t need to check anything anymore when calling it
|
@regnat this is basically what I wanted to implement first, however it didn't really work out:
In the end, this is why I left |
|
@regnat FWIW this is what I tried first and is now lying around in my git stash: https://gist.github.com/Ma27/32c502dcc39b46bfe3f4b301d0b616eb |
thufschmitt
left a comment
There was a problem hiding this comment.
this is basically what I wanted to implement first, however it didn't really work out
Right. I think we could make this work by ensuring that we capture by copy everything that needs to be, but we can leave it out for now.
I just have one minor naming comment then, otherwise it’s good-to-go
| Symbol name; | ||
| std::vector<std::string> args; | ||
| const char * doc = nullptr; | ||
| std::optional<std::string> missingFeature; |
There was a problem hiding this comment.
| std::optional<std::string> missingFeature; | |
| std::optional<std::string> requiredFeature; |
(Unless you really want it to mean missingFeature, in which case I assume it should only be non-null if the feature is actually missing, but that’s not what the code is doing currently)
|
This breaks the intent of why it's implemented the way it is: namely to allow Nix expressions to check for the availability of a feature by doing e.g. |
|
@edolstra I see your point and yeah, it's probably even better to just use However, I think it's a rather obscure way to check for feature-availability via
Hence my suggestion to
From my PoV this can be done until 2.4 is out, after that it's difficult because changing the outcome of WDYT? :) |
|
It just occurred to me that allowing any kind of feature check in Nix expressions (whether So it's probably best to turn this into an uncatchable error using |
|
Fair. Will update the PR accordingly later today :) |
c169826 to
66a01a9
Compare
|
Applied, thanks! |
…e due to a missing feature-flag
I found it somewhat confusing to have an error like
error: attribute 'getFlake' missing
if the required experimental-feature (`flakes`) is not enabled. Instead,
I'd expect Nix to throw an error just like it's the case when using e.g. `nix
flake` without `flakes` being enabled.
With this change, the error looks like this:
$ nix-instantiate -E 'builtins.getFlake "nixpkgs"'
error: Cannot call 'builtins.getFlake' because experimental Nix feature 'flakes' is disabled. You can enable it via '--extra-experimental-features flakes'.
at «string»:1:1:
1| builtins.getFlake "nixpkgs"
| ^
I didn't use `settings.requireExperimentalFeature` here on purpose
because this doesn't contain a position. Also, it doesn't seem as if we
need to catch the error and check for the missing feature here since
this already happens at evaluation time.
e22d65e to
2b02ce0
Compare
|
@edolstra applied your suggestions, thanks! |
|
Thanks! |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
I found it somewhat confusing to have an error like
if the required experimental-feature (
flakes) is not enabled. Instead,I'd expect Nix to throw an error just like it's the case when using e.g.
nix flakewithoutflakesbeing enabled.With this change, the error looks like this:
I didn't use
settings.requireExperimentalFeaturehere on purposebecause this doesn't contain a position. Also, it doesn't seem as if we
need to catch the error and check for the missing feature here since
this already happens at evaluation time.
cc @edolstra @regnat