Skip to content

Allow specifying a recursionLimit for toPretty#98477

Closed
infinisil wants to merge 4 commits intoNixOS:masterfrom
infinisil:toPrettyLimits
Closed

Allow specifying a recursionLimit for toPretty#98477
infinisil wants to merge 4 commits intoNixOS:masterfrom
infinisil:toPrettyLimits

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.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Sep 22, 2020
@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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants