Skip to content

Extend function reflection #10350

@roberth

Description

@roberth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error-messagesConfusing messages and better diagnosticsfeatureFeature request or proposallanguageThe Nix expression language; parser, interpreter, primops, evaluation, etc
    No fields configured for issues without a type.

    Projects

    Status

    ⚖ To discuss

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions