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
module system: rework module merging #45038
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe also add some explanatory comments? The old code had some lines as well, would be good to not decrease this amount, as the code is rather hard to get already
Other than these things, I don't see a reason not to merge this.
Ping @edolstra @nbp @Profpatsch
lib/modules.nix
Outdated
) acc (attrNames module.${attr}) | ||
) {} modules; | ||
declsByName = byName "options" | ||
(module: option: [{ inherit (module) file; options= option; }]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is really only a single option afaik, I think it makes sense to rename options
to option
here, so options= option
-> inherit option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work. The attrset here must be a module for recursive calls, and a module has its options in the attribute... options
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
lib/modules.nix
Outdated
(module: value: [{ inherit (module) file; inherit value; }]) | ||
configs; | ||
in | ||
(mapAttrs (name: decls: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flip mapAttrs declsByName (name: decls:...
would be more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@infinisil you are right about the comments. I readded them as such. notably I don't understand the third. I have no idea what |
@infinisil could you refresh your review? @vcunat @edolstra any opinions? Thinking of merging this before branching off. |
lib/modules.nix
Outdated
) {} modules; | ||
# an attrset 'name' => list of submodules that declare ‘name’. | ||
declsByName = byName "options" | ||
(module: option: [{ inherit (module) file; options= option; }]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping you would fix the spacing here, but oh well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
The asymptotic complexity is now much lower.
The asymptotic complexity is now much lower.
Here is a comparision (before on the left, after on the right) of
All the functions called more than 100000 times are gone, time decreased by more than 20% and memory allocations are down by 5%.
Testing: the hashes of tests are the same according to
nox-review --with-tests
The change to
foldAttrs
is unrelated but the code is more readable and as marginally faster as before.