Skip to content

Commit f742092

Browse files
committed
wip
1 parent 803b98c commit f742092

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

src/libexpr-tests/nix_api_expr.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_value)
118118

119119
TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_build)
120120
{
121-
// TODO(@connorbaker): Fails because "allow-import-from-derivation" is disabled on host.
122121
auto expr = R"(
123122
derivation { name = "letsbuild";
124123
system = builtins.currentSystem;
@@ -137,7 +136,6 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_build)
137136
TEST_F(nix_api_expr_test, nix_expr_realise_context)
138137
{
139138
// TODO (ca-derivations): add a content-addressed derivation output, which produces a placeholder
140-
// TODO(@connorbaker): Fails because "allow-import-from-derivation" is disabled on host.
141139
auto expr = R"(
142140
''
143141
a derivation output: ${

src/libexpr/eval-inline.hh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,13 @@ inline Value * EvalState::allocValue()
6565
}
6666

6767

68-
// TODO(@connorbaker):
69-
// Is it possible using the batched alloc resulted in a performance regression?
70-
// $ hyperfine --warmup 2 --min-runs 20 --export-markdown system-eval-bench.md --parameter-list nix-version nix-after-batch-alloc './{nix-version}/bin/nix eval --no-eval-cache --read-only github:ConnorBaker/nixos-configs/39f01b05c37494627242162863b4725e38600b50#nixosConfigurations.nixos-desktop.config.system.build.toplevel' && hyperfine --warmup 2 --min-runs 20 --export-markdown list-concat-eval-bench.md --parameter-list nix-version nix-after-batch-alloc './{nix-version}/bin/nix eval --no-eval-cache --read-only --json --file ./nixpkgs-91bc7dadf7bf0bf3fb9203e611bd856f40fc2b66/pkgs/top-level/release-attrpaths-superset.nix names'
71-
// Benchmark 1: ./nix-after-batch-alloc/bin/nix eval --no-eval-cache --read-only github:ConnorBaker/nixos-configs/39f01b05c37494627242162863b4725e38600b50#nixosConfigurations.nixos-desktop.config.system.build.toplevel
72-
// Time (mean ± σ): 3.357 s ± 0.030 s [User: 3.003 s, System: 0.339 s]
73-
// Range (min … max): 3.327 s … 3.442 s 20 runs
74-
//
75-
// Benchmark 1: ./nix-after-batch-alloc/bin/nix eval --no-eval-cache --read-only --json --file ./nixpkgs-91bc7dadf7bf0bf3fb9203e611bd856f40fc2b66/pkgs/top-level/release-attrpaths-superset.nix names
76-
// Time (mean ± σ): 19.000 s ± 0.050 s [User: 17.066 s, System: 1.888 s]
77-
// Range (min … max): 18.932 s … 19.145 s 20 runs
7868
[[nodiscard]]
7969
[[using gnu: hot, always_inline, returns_nonnull, malloc]]
8070
inline ValueList * EvalState::allocList()
8171
{
8272
void * p = nullptr;
8373

8474
// See the comment in allocValue for an explanation of this block.
85-
// TODO(@connorbaker): Beginning cargo-culting.
86-
// 1. Do we need to assign to an intermediate variable, like `allocEnv` does?
87-
// 2. Do we need to use a C-style cast?
8875
if constexpr (HAVE_BOEHMGC) {
8976
if (*listAllocCache == nullptr) [[unlikely]] {
9077
*listAllocCache = GC_malloc_many(sizeof(ValueList));

src/libexpr/eval.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ void EvalState::forceValueDeep(Value & v)
21202120
addErrorTrace(e, i.pos, "while evaluating the attribute '%1%'", symbols[i.name]);
21212121
throw;
21222122
}
2123-
}
2123+
}
21242124
}
21252125

21262126
else if (v.isList()) {
@@ -2129,7 +2129,7 @@ void EvalState::forceValueDeep(Value & v)
21292129
// Increases the heap size by a fair amount, potentially because of the lambda capture.
21302130
for (auto * const v2 : v.list()) {
21312131
recurse(*v2);
2132-
}
2132+
}
21332133
}
21342134
};
21352135

src/libexpr/get-drvs.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ bool PackageInfo::checkMeta(Value & v)
215215
return checkMeta(*elem);
216216
});
217217
}
218-
else if (v.type() == nAttrs) {
219-
if (v.attrs()->get(state->sOutPath)) return false;
218+
219+
if (v.type() == nAttrs) {
220+
if (v.attrs()->get(state->sOutPath) != nullptr) {
221+
return false;
222+
}
220223
return ranges::all_of(*v.attrs(), [&](const auto & i) {
221224
return checkMeta(*i.value);
222225
});
223226
}
224-
else return v.type() == nInt || v.type() == nBool || v.type() == nString ||
227+
228+
return v.type() == nInt || v.type() == nBool || v.type() == nString ||
225229
v.type() == nFloat;
226230
}
227231

src/libexpr/primops.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,18 +4407,28 @@ static void prim_concatStringsSep(EvalState & state, const PosIdx pos, Value * *
44074407
{
44084408
NixStringContext context;
44094409

4410-
auto sep = state.forceString(*args[0], context, pos, "while evaluating the first argument (the separator string) passed to builtins.concatStringsSep");
4410+
const auto sep = state.forceString(*args[0], context, pos, "while evaluating the first argument (the separator string) passed to builtins.concatStringsSep");
44114411
state.forceList(*args[1], pos, "while evaluating the second argument (the list of strings to concat) passed to builtins.concatStringsSep");
4412+
const auto list = args[1]->list();
4413+
const auto numElements = list.size();
44124414

44134415
std::string res;
4414-
res.reserve((args[1]->listSize() + 32) * sep.size());
4415-
bool first = true;
44164416

4417-
// TODO(@connorbaker): Resume rewrite and update here. See if ranges has something for this.
4417+
if (numElements == 0) {
4418+
v.mkString(res, context);
4419+
return;
4420+
}
44184421

4419-
for (auto elem : args[1]->list()) {
4420-
if (first) first = false; else res += sep;
4421-
res += *state.coerceToString(pos, *elem, context, "while evaluating one element of the list of strings to concat passed to builtins.concatStringsSep");
4422+
// Manually handle the first element for the singleton case.
4423+
auto * const head = list.front();
4424+
res = *state.coerceToString(pos, *head, context, "while evaluating one element of the list of strings to concat passed to builtins.concatStringsSep");
4425+
4426+
if (numElements > 1) {
4427+
res.reserve((numElements + 32) * sep.size());
4428+
immer::for_each(list.drop(1), [&](auto * const elem) {
4429+
res += sep;
4430+
res += *state.coerceToString(pos, *elem, context, "while evaluating one element of the list of strings to concat passed to builtins.concatStringsSep");
4431+
});
44224432
}
44234433

44244434
v.mkString(res, context);

0 commit comments

Comments
 (0)