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

Allow specifying a recursionLimit for toPretty #98477

Closed
wants to merge 4 commits into from

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Sep 22, 2020

Motivation for this change

For being able to print infinitely-recursing values in #98155

Also, toPretty now adds relevant error context when recursing

See also #97133 which did other toPretty improvements

Ping @Profpatsch

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@infinisil
Copy link
Member Author

The error trace shows like this:

$ nix-instantiate --eval -E 'with import ./lib; generators.toPretty {} { x.y = [ (throw "nope") ]; }' --show-trace
error: while evaluating 'go' at /home/infinisil/src/nixpkgs/lib/generators.nix:211:17, called from (string):1:20:
while evaluating anonymous function at /home/infinisil/src/nixpkgs/lib/attrsets.nix:234:10, called from undefined position:
while evaluating anonymous function at /home/infinisil/src/nixpkgs/lib/generators.nix:262:22, called from /home/infinisil/src/nixpkgs/lib/attrsets.nix:234:16:
while lib.generators.toPretty descended into the `x' attribute
while evaluating 'go' at /home/infinisil/src/nixpkgs/lib/generators.nix:211:17, called from /home/infinisil/src/nixpkgs/lib/generators.nix:264:57:
while evaluating anonymous function at /home/infinisil/src/nixpkgs/lib/attrsets.nix:234:10, called from undefined position:
while evaluating anonymous function at /home/infinisil/src/nixpkgs/lib/generators.nix:262:22, called from /home/infinisil/src/nixpkgs/lib/attrsets.nix:234:16:
while lib.generators.toPretty descended into the `y' attribute
while evaluating 'go' at /home/infinisil/src/nixpkgs/lib/generators.nix:211:17, called from /home/infinisil/src/nixpkgs/lib/generators.nix:264:57:
while evaluating anonymous function at /home/infinisil/src/nixpkgs/lib/lists.nix:106:29, called from undefined position:
while evaluating anonymous function at /home/infinisil/src/nixpkgs/lib/generators.nix:240:61, called from /home/infinisil/src/nixpkgs/lib/lists.nix:106:32:
while lib.generators.toPretty descended into list index `0'
while evaluating 'go' at /home/infinisil/src/nixpkgs/lib/generators.nix:211:17, called from /home/infinisil/src/nixpkgs/lib/generators.nix:242:14:
nope

@Profpatsch
Copy link
Member

I’m getting a bit worried that toPretty is becoming really complicated, and kind of a bit of a kitchen sink. What can we do to make it simpler again?

@Profpatsch
Copy link
Member

Like, the __pretty argument was explicitly designed to avoid this kind of scenario, and now we are moving in a direction I’m very uncomfortable with. For my taste the function is already twice as long as it should be, even before this change.

@infinisil
Copy link
Member Author

Closing this for now as I have other changes relating to this

@infinisil infinisil closed this Sep 24, 2020
@infinisil infinisil deleted the toPrettyLimits branch September 25, 2020 13:22
@infinisil
Copy link
Member Author

Now #98761 adds the recursionLimit argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants