lib/generators: withRecursion: don't break attr-sets with special attrs#168374
Merged
infinisil merged 1 commit intoNixOS:masterfrom May 23, 2022
Merged
lib/generators: withRecursion: don't break attr-sets with special attrs#168374infinisil merged 1 commit intoNixOS:masterfrom
infinisil merged 1 commit intoNixOS:masterfrom
Conversation
Closes NixOS#168327 The issue reported there can be demonstrated with the following expression: → nix-instantiate --eval -E "with import ./. {}; pkgs.lib.options.showDefs [ { file = \"foo\"; value = pkgs.rust.packages.stable.buildRustPackages; } ]" error: attempt to call something which is not a function but a string at /home/ma27/Projects/nixpkgs/lib/trivial.nix:442:35: 441| isFunction = f: builtins.isFunction f || 442| (f ? __functor && isFunction (f.__functor f)); | ^ 443| Basically, if a `__functor` is in an attribute-set at depth-limit, `__functor` will be set to `"<unevaluated>"`. This however breaks `lib.isFunction` which checks for a `__functor` by invoking `__functor` with `f` itself. The same issue - "magic" attributes being shadowed by `withRecursion` - also applies to others such as `__pretty`/`__functionArgs`/`__toString`. Since these attributes have a low-risk of causing a stack overflow (because these are flat attr-sets or even functions), ignoring them in `withRecursion` seems like a valid solution.
13 tasks
lheckemann
approved these changes
May 22, 2022
infinisil
approved these changes
May 23, 2022
Member
|
For the record, I’m not happy with the direction the generators are taking. Stuff like limiting recursion depth just does not belong into these functions, it should be a separate mechanism. I don’t have enough time to prevent this stuff from happening, but I’m kinda sad about it. |
Member
|
Like, these functions do not do anything complicated, yet they are getting absurdly complex. |
Member
|
I might have misunderstood, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
Note: This is an alternative implementation for #168327. Please also read the discussion about the pros and cons of this vs the other PRs in #168327 before deciding which patch is preferable.
cc @Profpatsch @K900 @infinisil @lheckemann
Closes #168327
The issue reported there can be demonstrated with the following
expression:
Basically, if a
__functoris in an attribute-set at depth-limit,__functorwill be set to"<unevaluated>". This however breakslib.isFunctionwhich checks for a__functorby invoking__functorwith
fitself.The same issue - "magic" attributes being shadowed by
withRecursion-also applies to others such as
__pretty/__functionArgs/__toString.Since these attributes have a low-risk of causing a stack overflow
(because these are flat attr-sets or even functions), ignoring them in
withRecursionseems like a valid solution.Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes