Commit Graph

5456 Commits

Author SHA1 Message Date
Philip Taron
39ccc6e5a5 lib.platforms: preprocess instead of generating at eval time (#550871) 2026-11-10 21:51:01 +00:00
Naïm Camille Favier
ebccd4562f lib/strings: remove misleading comment in concatLines (#572782) 2026-11-08 19:11:32 +00:00
Sergei Zimmerman
35fc769276 various: remove references to NIX_BUILD_HOOK
It hasn't been a thing for a very long time (dropped circa 2.0).
2026-11-08 19:27:06 +03:00
Sergei Zimmerman
0dc6f5691f lib/path/tests: plumb through correct nix from test-with-nix.nix
Previously nixVersions.latest.tests.nixpkgs-lib was testing the stable version,
which we definitely don't expect. Since test-with-nix.nix is also used by lix
it meant that it didn't actually run lib.path tests at all.
2026-11-08 19:17:10 +03:00
Philip Taron
798bad8bca lib/platforms/generate.sh: keep generated.json if evaluation fails
If we don't do this, we end up with an annoying malformed generated.json
and have to revert it somehow. Easy, but annoying, so let's just pay
attention to error codes and commit only when it's succeeded.
2026-11-08 07:25:02 -08:00
Philip Taron
9cda3d37ab lib/tests/systems: check which platforms contain the primary systems
Can't do this for every platform, but these are the big three and
deserve a little known-answer testing.
2026-11-08 07:22:48 -08:00
Philip Taron
3e76faa262 lib/tests/systems: restore platform invariant tests 2026-11-08 07:14:13 -08:00
Philip Taron
459e43a21b lib.modules: further performance cleanups (#583396) 2026-11-08 12:24:05 +00:00
Philip Taron
11e8e9fc8c lib/tests/systems: compare lib.platforms exactly against the generator 2026-11-07 15:30:34 -08:00
Philip Taron
6ae0e5b6f2 lib.types: small performance improvements (#549252) 2026-11-07 22:59:31 +00:00
Philip Taron
c180776557 lib/types: destructure definitions in listOf's merge
Wins vs. parent:

- 3k fewer envs
- 7k fewer thunks
- 5k fewer lookups
2026-11-06 17:22:04 -08:00
Philip Taron
1f14410544 lib/types: destructure definitions when pushing down positions
Wins vs. parent:

- 5k fewer envs
- 7k fewer thunks
- 3k fewer lookups
2026-11-06 17:21:43 -08:00
Philip Taron
e9b9dd80ec lib/modules: destructure definitions in mergeDefinitions
Wins vs. parent:

- 71k fewer thunks
- 41k fewer lookups

I think this is safe. It's slightly less lazy. I couldn't come up with a
case that it breaks, though.
2026-11-06 17:16:06 -08:00
Philip Taron
d5a8e49611 lib/modules: destructure the declaration in evalSingleOptionDecl
Wins vs. parent:

- 44k fewer thunks
- 24k fewer lookups
2026-11-06 17:15:19 -08:00
Philip Taron
ec9ed03f3c lib/modules: destructure configs when collecting definitions
Wins vs. parent:

- 138k fewer thunks
- 96k fewer lookups
2026-11-06 17:14:43 -08:00
Philip Taron
a82b702ec6 lib/modules: destructure modules when collecting declarations
Every declaration copied `module._file` with a select, which costs a
thunk per declared option. If instead we destructure the module,
we bind `_file` and `options` once, and the declarations can refer
to them directly.

Wins vs. parent:

- 35k fewer envs
- 91k fewer thunks
- 35k fewer lookups
2026-11-06 17:03:58 -08:00
Philip Taron
8aa7491f56 lib/modules: reuse definitions that have no property to push down
Module configs passed to mergeModules' were `{ file, config }`, while
the definitions they are split into are `{ file, value }`.

Wins vs. parent:

- 14k fewer thunks
- 10k fewer attrsets
- 552 KiB saved in attrset bytes
2026-11-06 16:59:33 -08:00
Eman Resu
1f00d6da2b lib/modules/dischargeProperties: avoid isBool 2026-11-06 16:13:57 -08:00
Philip Taron
4e47504aac lib/tests/modules: make sure options stay lazy in unmatched definitions 2026-11-06 16:11:52 -08:00
Philip Taron
8be36b7986 lib/modules: only call addMeta and addFreeformType when needed
Wins vs. parent:

- 33k fewer envs
- 33k fewer thunks
- 33k fewer function calls

It's a little noisy, but not too bad.
2026-11-06 16:03:12 -08:00
Philip Taron
41b8ab1539 lib/modules: inline checkModule and collectResults
Wins vs. parent:

- 25k fewer envs
- 2k fewer thunks
- 29k fewer function calls

And the code gets easier to read, too.
2026-11-06 16:02:58 -08:00
Philip Taron
f6dc1cff0e lib/modules: recurse with genList in collectStructuredModules
Since imap1 is itself implemented with genList, calling genList directly
saves a function call per module.

Wins vs. parent:

- 59k fewer envs
- 12k fewer thunks
- 59k fewer function calls

And no regressions. A win.
2026-11-06 16:02:41 -08:00
Philip Taron
7bf82709af lib/modules: push down definitions without a lambda per definition
Most definitions carry no property to push down, so check for `_type`
first and only map over pushDownProperties when there is one.

Modules (`_file`, `config`) and definitions (`file`, `value`) spell
their attributes differently, so each call site destructures its own.

Wins vs. parent:

- 59k fewer envs
- 122k fewer thunks
- 59k fewer function calls
- 29k fewer primops
2026-11-06 15:59:58 -08:00
Philip Taron
9d547c8089 lib/modules: derive pushed-down definitions from rawDefinitionsByName
We don't need to iterate a second time; we can check that each config
is an attribute set **while** building rawDefinitionsByName.

That check runs at every level, including the root, so the duplicate
root-level check in mergeModules can go too. This also restores the
check for direct callers of mergeModules'.

The pushed-down definitions are only needed when descending into a name,
so build them right there, and only if that name has any definitions.

The wins here vs. last commit on that minimal NixOS config:

- 9k fewer envs
- 40k fewer thunks
- 9k fewer function calls
- 41k fewer primop calls
- 11k fewer attrsets
- 600 KiB saved in attrset bytes

Pareto improvement.
2026-11-06 15:52:52 -08:00
Philip Taron
bdcc5f9a0b lib/modules: avoid per-name lambdas when collecting unmatchedDefns
The idea here is that, to construct unmatchedDefns, we use a combo of mapAttrs and mapAttrsToList over every name at every level.

But notice: almost all of those names are options with no unmatched definitions!

So, instead of doing that, we can have nested results prefix their own unmatched definitions, so the parent can concatenate them with catAttrs.

The wins here vs. last commit on that minimal NixOS config:

- 188k fewer envs
- 201k fewer function calls
- 7k fewer primop calls
- 7k fewer attrsets
- 1.4 MiB saved in attrset bytes

There are 3k more thunks, but we'll make that up with the next patches.
2026-11-06 15:34:44 -08:00
Philip Taron
c31c04edbf lib/modules: build single-declaration options with one update
It's a truism that almost every option is declared exactly once.

For those singletons, mergeModules' went through mergeOptionDecls,
fixupOptionType and evalOptionValue, each of which builds a new attrset
from the previous one.

If we instead check the declaration's `_type` inline and build
the evaluated option (as in, its declaration and value attributes)
in a single attribute set update, it's a lot cheaper.

It comes at the cost of repeating evalOptionValue's attribute list,
so the two need to be marked to be kept in sync.

Since mergeOptionDecls is now never called with a single declaration
from within Nixpkgs (types.optionType already short-circuits that case),
we can then drop its single-declaration special case.

Now that fixupOptionType is idempotent, mergeOptionDecls can apply it
itself, resolving the TODO. Every caller already followed one with the
other, and callers outside Nixpkgs that still do are unaffected.

I really hate this duplication, but it does save (vs. parent)
a *lot* on the minimal NixOS config cited in the comments.

- 164k envs
- 51k thunks
- 140k function calls
- 52k attrsets
- 570 KiB in attrset bytes

There is a gratuitous capitalization and reflowing of a comment in this
patch. Sorry, I like to do that.
2026-11-06 15:33:18 -08:00
Philip Taron
d17afffc0a lib/modules: make fixupOptionType idempotent
fixupOptionType substitutes the submodules collected in `options` into
the option's type, then clears `options`. Applied a second time, it
substituted that empty list, dropping every submodule from the type.

With no submodules left to substitute, there is nothing to fix up, so
return the option as-is. This lets mergeOptionDecls do the fixup itself
without breaking callers that still call fixupOptionType afterwards.
2026-11-06 15:26:20 -08:00
Philip Taron
f0fd56e32b lib/modules: factor throwReadOnly out of evalOptionValue 2026-11-06 15:02:37 -08:00
Philip Taron
a628ffcc9f lib/tests/modules: make sure the error communicates the nested path
Regression test for 3d8f3041eb
2026-11-06 15:02:37 -08:00
Leona Maroni
be0d2859ed Revert "lib.licenses.helpers: handle string and list licenses correctly" 2026-11-05 18:49:07 +01:00
Eman Resu
bc14f73fd5 lib.licenses.helpers: handle string and list licenses correctly (#574361) 2026-11-05 15:16:25 +00:00
jopejoe1
f132ef03a0 lib.licenses.helpers: handle string and list licenses correctly 2026-11-05 10:49:33 +01:00
Eman Resu
40440ef72d lib/modules: save thunks by avoiding inherit statements 2026-11-04 16:13:50 -05:00
Eman Resu
196f45d266 lib/modules/mergeModules: avoid mapping over empty list 2026-11-04 16:13:50 -05:00
Eman Resu
0888478846 lib/modules/mergeModules: avoid defining empty unmatchedDefns 2026-11-04 16:13:49 -05:00
Eman Resu
52d7933d1c lib/modules: inline isOption usage
We inline other similar functions within this file, and this is a key
improvement for some contexts.
2026-11-04 16:13:49 -05:00
Eman Resu
6d6a008e2b lib/modules/collectStructuredModules: don't recurse on empty imports 2026-11-04 16:13:48 -05:00
Eman Resu
20768b1ba6 lib/modules/collectStructuredModules: prevent no-op concat 2026-11-04 16:13:47 -05:00
Eman Resu
3d8f3041eb lib/modules/mergeModules: inline attrs check for config
We could probably drop this at some point in the future - but for now,
inlining it prevents the need to iterate again.
2026-11-04 16:12:04 -05:00
Eman Resu
7e30e5e240 lib/modules/mergeModules: inline variables only used once 2026-11-04 01:21:51 -05:00
Eman Resu
cfffa65d8c lib/modules/applyModuleArgs: inline let binding 2026-11-04 01:21:50 -05:00
Eman Resu
e2b35cbb23 lib/modules/pushDownProperties: avoid nested calls for common case
Previously, we would always call `pushDownProperties` recursively - but
now we only do it if the second layer also needs to be pushed. Saves a
`map` and a function call on each definition.
2026-11-04 01:21:50 -05:00
Eman Resu
d9a395ea01 lib/modules/pushDownProperties: partially apply function calls 2026-11-04 01:21:50 -05:00
Eman Resu
855f47f807 lib/modules/collectModules: only pass args once
Saves unnecessary function calls, since args are always constant.
2026-11-04 01:21:39 -05:00
Eman Resu
d9cbd05f0d lib/modules/mergeOptionDecls: special-case a single declaration 2026-11-04 01:21:06 -05:00
Philip Taron
87c3b8b8cb lib/modules: avoid redundant bothHave closure and opt.options (#582387) 2026-11-04 01:08:23 +00:00
Skye Soss
65197661cd lib: fix typos in license operators' doc-comments 2026-11-03 16:32:28 -06:00
Eman Resu
a059874a11 lib/modules: use a single let binding for mergeOptionDecls 2026-11-03 09:08:04 -05:00
Tom Bereknyei
8463ce558f lib/modules: avoid per-step closure and redundant selects in mergeOptionDecls
Inline the bothHave closure into 4 direct checks, and bind opt.options
once instead of reselecting it 8 times per fold step.

Measured on a real NixOS+Plasma eval, output byte-identical:
nrFunctionCalls -2.35%, Envs -1.98% (-1.58% bytes), cpuTime -3.53%,
GC totalBytes -0.27%.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-02 14:55:10 -05:00
Silvan Mosberger
50878700a1 lib: throw instead of warn for invalid fromHexString input (#580221) 2026-10-30 03:04:07 +00:00