Skip to content

Comments

[nothing to see here] lib: Add functionInfo#194992

Closed
infinisil wants to merge 1 commit intoNixOS:masterfrom
infinisil:functionInfo
Closed

[nothing to see here] lib: Add functionInfo#194992
infinisil wants to merge 1 commit intoNixOS:masterfrom
infinisil:functionInfo

Conversation

@infinisil
Copy link
Member

Description of changes

Adds a powerful functionInfo function, giving you more information about your functions!

functionInfo builtins.add ->
  {
    type = "builtin";
  }

functionInfo (arg: arg + 1) ->
  {
    type = "argument";
    argumentName = "arg";
  }

functionInfo (arg@{ a }: a + 1) ->
  {
    type = "attributes";
    argumentName = "arg";
    attributes = { a = false; };
    ellipsis = false;
  }
functionInfo ({ a ? 0, ...}: a + 1) ->
  {
    type = "attributes";
    argumentName = null;
    attributes = { a = true; };
    ellipsis = true;
  }

PS: Don't look at the implementation

PPS: This PR is only half-serious, motivation came from #194514 (comment), where this PR would actually have a good use case (cc @roberth)

Things done

@infinisil infinisil mentioned this pull request Oct 7, 2022
13 tasks
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Oct 7, 2022
function = getFunction f;
xmlString = builtins.toXML function;
builtinString = "<?xml version='1.0' encoding='utf-8'?>\n<expr>\n <unevaluated />\n</expr>\n";
argumentRegex = "<\\?xml version='1.0' encoding='utf-8'\\?>\n<expr>\n <function>\n <varpat name=\"(.*)\" />\n </function>\n</expr>\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:O

I'll see myself out.

@roberth
Copy link
Member

roberth commented Oct 7, 2022

argumentName doesn't seem useful.

ellipsis : bool is slightly more useful, but I don't think it leads to an improvement. lazyFunction does have a "problem" with ..., which is that those don't end up in the @ param. However, we simply can't put anything in ... without figuring out the attribute names of the argument. Something like the lazy attribute names thing you've worked on might help, if mapAttrs (k: v: arg.${k}) getArgs // arg has the right behavior in such an implementation of lazy attribute names.

Interesting PR... :D

@infinisil infinisil closed this Oct 12, 2022
@infinisil infinisil deleted the functionInfo branch November 17, 2022 14:44
vkryachko added a commit to vkryachko/nixpkgs that referenced this pull request Sep 9, 2023
Having used `callPackage` a bit, it seems a bit odd and inconsistent that modules
require `...` in their signatures as opposed to figuring out the
signature and passing only what's requested, like `callPackage` does.

Now I don't know if there is an actual reason for why it is important
for modules to require `...`, but I could not find any and upon a brief
chat with @infinisil, it seemed like there might not be a reason. So if
you know of a reason, please let me know.

Worth noting that, as currently implemented, it's is a breaking change,
namely modules that use at-pattern arg capture don't work (`{ ...
}@args`, args used to contain all available module args, but is now
empty, see newly added failing test for details). I don't have any data
on how common it is to write modules with at-pattern capturing, so would
like to get some guidance on how important it is to preserve this
behavior.

It's possible to make it a non-breaking change by detecting `...` and/or `@args`
with something like NixOS#194992 or rather with a new builtin like
was proposed in NixOS#7317, and passing all available arguments if detected.

Would like to get your thoughts on the idea to see if there are any
strong objections to pursuing this further.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants