From cdc1a0bb6ec52cd05c1a72c00c3c3a4f716a429a Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 18 Jul 2020 16:40:15 +0100 Subject: refactor(3p/nix/libexpr): Back Nix lists with std::vector This change does away with the previous special-casing of lists of certain element sizes, and the use of raw C-style arrays. Lists are now backed by a std::vector of nix::Value*, which uses the traceable GC allocator. This change is unfortunately quite noisy because the accessor methods were updated/removed accordingly, so all callsites of Nix-related lists have changed. For some operations in primops.cc where keeping the previous code structure would have been more difficult with a "proper" vector, the implementation has been replaced with std::vector methods. For example, list concatenation now uses appropriate range inserts. Anecdotally the performance of this is about equal, to even slightly better, than the previous implementation. All language tests pass and the depot paths I've used for testing still evaluate. Change-Id: Ib5eca6c0207429cb323a330c838c3a2200b2c693 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1266 Tested-by: BuildkiteCI Reviewed-by: isomer Reviewed-by: Kane York Reviewed-by: glittershark --- third_party/nix/src/libexpr/primops/context.cc | 4 ++-- third_party/nix/src/libexpr/primops/fromTOML.cc | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'third_party/nix/src/libexpr/primops') diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc index 3a39e03eabc7..841a45c61c03 100644 --- a/third_party/nix/src/libexpr/primops/context.cc +++ b/third_party/nix/src/libexpr/primops/context.cc @@ -123,7 +123,7 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args, state.mkList(outputsVal, info.second.outputs.size()); size_t i = 0; for (const auto& output : info.second.outputs) { - mkString(*(outputsVal.listElems()[i++] = state.allocValue()), output); + mkString(*((*outputsVal.list)[i++] = state.allocValue()), output); } } } @@ -184,7 +184,7 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args, i->name, i->pos); } for (unsigned int n = 0; n < iter->second.value->listSize(); ++n) { - auto name = state.forceStringNoCtx(*iter->second.value->listElems()[n], + auto name = state.forceStringNoCtx(*(*iter->second.value->list)[n], *iter->second.pos); context.insert("!" + name + "!" + std::string(i->name)); } diff --git a/third_party/nix/src/libexpr/primops/fromTOML.cc b/third_party/nix/src/libexpr/primops/fromTOML.cc index 66e2e1b4094f..389ac080677a 100644 --- a/third_party/nix/src/libexpr/primops/fromTOML.cc +++ b/third_party/nix/src/libexpr/primops/fromTOML.cc @@ -31,7 +31,7 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args, size_t size2 = i2->get().size(); state.mkList(v2, size2); for (size_t j = 0; j < size2; ++j) - visit(*(v2.listElems()[j] = state.allocValue()), i2->get()[j]); + visit(*((*v2.list)[j] = state.allocValue()), i2->get()[j]); } else visit(v2, i.second); } @@ -43,7 +43,7 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args, state.mkList(v, size); for (size_t i = 0; i < size; ++i) - visit(*(v.listElems()[i] = state.allocValue()), t2->get()[i]); + visit(*((*v.list)[i] = state.allocValue()), t2->get()[i]); } // Handle cases like 'a = [[{ a = true }]]', which IMHO should be @@ -56,7 +56,7 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args, state.mkList(v, size); for (size_t j = 0; j < size; ++j) - visit(*(v.listElems()[j] = state.allocValue()), t2->get()[j]); + visit(*((*v.list)[j] = state.allocValue()), t2->get()[j]); } else if (t->is_value()) { -- cgit 1.4.1