Skip to content
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

Extend function reflection #10350

Open
roberth opened this issue Mar 28, 2024 · 2 comments
Open

Extend function reflection #10350

roberth opened this issue Mar 28, 2024 · 2 comments
Labels
error-messages Confusing messages and better diagnostics feature Feature request or proposal language The Nix expression language; parser, interpreter, primops, evaluation, etc

Comments

@roberth
Copy link
Member

roberth commented Mar 28, 2024

Is your feature request related to a problem? Please describe.

Function reflection is an important part of everyday use of the Nix language, in callPackage and the module system, to improve syntax and to make strict functions lazy.

However, the information is too limited, creating pitfalls that "library" code such as callPackage can not currently compensate.

Furthermore, it prevents improvements to be made without breaking compatibility:

Describe the solution you'd like

Two solutions have been already been proposed:

They could hardly be more different. Open design questions:

  • One primop returning attrset or multiple primops?
  • Use names that relate to the syntax or names that relate to the semantics?
    • Syntax-based: arg, args, ellipsis, hasArgs
    • Semantics-based: bindsAllAttrs, args, isOpen, strict

Currently implemented by neither:

  • Support __functor.

Describe alternatives you've considered

  • Reject function reflection altogether. This would make the language more predictable, but that ship has sailed a very long time ago.
  • "I want as little reflection as possible, because reflection is complicated and the language should be simple."
    • This suggests a linear relation between the "amount of reflection" and difficulty, which is a simplistic view that's false.
    • Everyday users don't need to interact with this newly exposed info at all. They do get to enjoy more robust reflection.
  • "This will cause reflection to be used more often and cause never ending problems. What else do we need to expose next?"
    • More use isn't all that bad, because users are already forced to interact with functionArgs through callPackage and the module system.
    • I believe the proposed interfaces cover all relevant function behaviors, and it's unlikely that we'll need more until perhaps the language itself is extended.

Additional context

Priorities

Add 👍 to issues you find important.

@roberth roberth added feature Feature request or proposal error-messages Confusing messages and better diagnostics language The Nix expression language; parser, interpreter, primops, evaluation, etc labels Mar 28, 2024
@roberth roberth added this to Nix team Mar 28, 2024
@github-project-automation github-project-automation bot moved this to To triage in Nix team Mar 28, 2024
@anna328p
Copy link
Member

https://github.com/anna328p/nix-prelude/blob/main/introspection.nix

Most of this is already possible in a hacky way using toXML. I use it in my Nix code.

@roberth
Copy link
Member Author

roberth commented Mar 28, 2024

@infinisil has also written something like that in NixOS/nixpkgs#194992

I suppose it's an extra argument for making this info available: it already is available.
Of course it shouldn't have to be hacky or slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messages Confusing messages and better diagnostics feature Feature request or proposal language The Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
Status: ⚖ To discuss
Development

No branches or pull requests

2 participants