-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
clarify note on forcing thunks in the C API #10848
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this isn't correct, and it's not really actionable before other changes. (#10499)
src/libexpr-c/nix_api_expr.h
Outdated
* @note This function is mainly needed before calling @ref getters. | ||
* All API calls that return a `Value` force thunks automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Philipp <[email protected]>
Co-authored-by: Robert Hensing <[email protected]>
@@ -129,8 +129,7 @@ nix_err nix_value_call_multi( | |||
* | |||
* This function converts these Values into their final type. | |||
* | |||
* @note You do not need this function as long as you only use API calls that return a `Value`. This function is mainly | |||
* needed before calling @ref getters. | |||
* @note This function is called before calling `nix_get_type()` (and therefore before most other @ref getters), because lazy evaluation should be transparent to users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @note This function is called before calling `nix_get_type()` (and therefore before most other @ref getters), because lazy evaluation should be transparent to users. | |
* @note This function should be called before calling `nix_get_type()` (and therefore before most other @ref getters), because lazy evaluation should be transparent to users. |
Otherwise it sounds a bit like we're describing what the bindings do. It is the reader's responsibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @note This function is called before calling `nix_get_type()` (and therefore before most other @ref getters), because lazy evaluation should be transparent to users. | |
* @note You only need to call this function before `nix_get_type()` (and therefore before most other @ref getters), because lazy evaluation should be transparent to users of this API. |
How about this then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not necessarily true. Suppose in your application you have a hardcoded Nix function, defined in a string literal, so you know how it behaves. For example:
# passed to nix_expr_eval_from_string
{ foo, bar }:
let
# fancy application-specific computations are declared here
in
{
inherit baz;
n = builtins.length qux;
}
In such a case it's valid to
- call the function
- retrieve the
n
Value
nix_value_force
n
- not check the type, because we know its type statically
- call
nix_get_int
Obviously a toy example, but this is a useful implementation pattern when you have a situation where a few things related things need to be computed by Nix and the application then reads the values it needs. Unlike individual function calls, you take advantage of shared computations this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, maybe I'm misunderstanding something big time here. Apparently it's not required to call it beforehand, but sometimes it is? But saying "you should" is not very informative - do you have to or not, what are the considerations exactly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe just delete the note if it's not gonna age well anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prednaz follow-up on #10842 (comment)
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.